Exemple #1
0
def get_arguments(command, cwd):
    """ Capture Clang invocation.

    This method returns the front-end invocation that would be executed as
    a result of the given driver invocation. """
    def lastline(stream):
        last = None
        for line in stream:
            last = line
        if last is None:
            raise Exception("output not found")
        return last

    cmd = command[:]
    cmd.insert(1, '-###')
    logging.debug('exec command in %s: %s', cwd, ' '.join(cmd))
    child = subprocess.Popen(cmd,
                             cwd=cwd,
                             universal_newlines=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
    line = lastline(child.stdout)
    child.stdout.close()
    child.wait()
    if child.returncode == 0:
        if re.search(r'clang(.*): error:', line):
            raise Exception(line)
        return decode(line)
    else:
        raise Exception(line)
Exemple #2
0
def get_arguments(command, cwd):
    """ Capture Clang invocation.

    This method returns the front-end invocation that would be executed as
    a result of the given driver invocation. """

    def lastline(stream):
        last = None
        for line in stream:
            last = line
        if last is None:
            raise Exception("output not found")
        return last

    cmd = command[:]
    cmd.insert(1, '-###')
    logging.debug('exec command in %s: %s', cwd, ' '.join(cmd))
    child = subprocess.Popen(cmd,
                             cwd=cwd,
                             universal_newlines=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
    line = lastline(child.stdout)
    child.stdout.close()
    child.wait()
    if child.returncode == 0:
        if re.search(r'clang(.*): error:', line):
            raise Exception(line)
        return decode(line)
    else:
        raise Exception(line)
Exemple #3
0
def entry_hash(entry):
    """ Implement unique hash method for compilation database entries. """

    # For faster lookup in set filename is reverted
    filename = entry['file'][::-1]
    # For faster lookup in set directory is reverted
    directory = entry['directory'][::-1]
    # On OS X the 'cc' and 'c++' compilers are wrappers for
    # 'clang' therefore both call would be logged. To avoid
    # this the hash does not contain the first word of the
    # command.
    command = ' '.join(decode(entry['command'])[1:])

    return '<>'.join([filename, directory, command])
Exemple #4
0
def get_arguments(command, cwd):
    """ Capture Clang invocation.

    :param command: the compilation command
    :param cwd:     the current working directory
    :return:        the detailed front-end invocation command """

    cmd = command[:]
    cmd.insert(1, '-###')

    output = run_command(cmd, cwd=cwd)
    # The relevant information is in the last line of the output.
    # Don't check if finding last line fails, would throw exception anyway.
    last_line = output[-1]
    if re.search(r'clang(.*): error:', last_line):
        raise Exception(last_line)
    return decode(last_line)
Exemple #5
0
def get_arguments(command, cwd):
    """ Capture Clang invocation.

    :param command: the compilation command
    :param cwd:     the current working directory
    :return:        the detailed front-end invocation command """

    cmd = command[:]
    cmd.insert(1, '-###')

    output = run_command(cmd, cwd=cwd)
    # The relevant information is in the last line of the output.
    # Don't check if finding last line fails, would throw exception anyway.
    last_line = output[-1]
    if re.search(r'clang(.*): error:', last_line):
        raise Exception(last_line)
    return decode(last_line)
Exemple #6
0
def get_arguments(command, cwd):
    """ Capture Clang invocation.

    :param command: the compilation command
    :param cwd:     the current working directory
    :return:        the detailed front-end invocation command """

    cmd = command[:]
    cmd.insert(1, '-###')
    logging.debug('exec command in %s: %s', cwd, ' '.join(cmd))

    output = subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)
    # The relevant information is in the last line of the output.
    # Don't check if finding last line fails, would throw exception anyway.
    last_line = output.decode('utf-8').splitlines()[-1]
    if re.search(r'clang(.*): error:', last_line):
        raise Exception(last_line)
    return decode(last_line)
Exemple #7
0
def get_arguments(command, cwd):
    """ Capture Clang invocation.

    :param command: the compilation command
    :param cwd:     the current working directory
    :return:        the detailed front-end invocation command """

    cmd = command[:]
    cmd.insert(1, '-###')
    logging.debug('exec command in %s: %s', cwd, ' '.join(cmd))

    output = subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)
    # The relevant information is in the last line of the output.
    # Don't check if finding last line fails, would throw exception anyway.
    last_line = output.decode('utf-8').splitlines()[-1]
    if re.search(r'clang(.*): error:', last_line):
        raise Exception(last_line)
    return decode(last_line)
Exemple #8
0
def run(opts):
    """ Entry point to run (or not) static analyzer against a single entry
    of the compilation database.

    This complex task is decomposed into smaller methods which are calling
    each other in chain. If the analyzis is not possibe the given method
    just return and break the chain.

    The passed parameter is a python dictionary. Each method first check
    that the needed parameters received. (This is done by the 'require'
    decorator. It's like an 'assert' to check the contract between the
    caller and the called method.) """

    try:
        command = opts.pop('command')
        logging.debug("Run analyzer against '%s'", command)
        opts.update(classify_parameters(decode(command)))

        return action_check(opts)
    except Exception:
        logging.error("Problem occured during analyzis.", exc_info=1)
        return None
 def test(value):
     self.assertEqual(sut.decode(sut.encode(value)), value)
Exemple #10
0
 def test(value):
     self.assertEqual(sut.decode(sut.encode(value)), value)