Exemple #1
0
 def test_shell_escaping(self):
     self.assertEqual(['clang', '-c', 'file.c', '-Dv=space value'],
                      sut.shell_split('clang -c file.c -Dv="space value"'))
     self.assertEqual(['clang', '-c', 'file.c', '-Dv=\"quote'],
                      sut.shell_split('clang -c file.c -Dv=\\\"quote'))
     self.assertEqual(['clang', '-c', 'file.c', '-Dv=(word)'],
                      sut.shell_split('clang -c file.c -Dv=\(word\)'))
Exemple #2
0
 def test_regular_commands(self):
     self.assertEqual([], sut.shell_split(""))
     self.assertEqual(['clang', '-c', 'file.c'],
                      sut.shell_split('clang -c file.c'))
     self.assertEqual(['clang', '-c', 'file.c'],
                      sut.shell_split('clang  -c  file.c'))
     self.assertEqual(['clang', '-c', 'file.c'],
                      sut.shell_split('clang -c\tfile.c'))
Exemple #3
0
    def from_response_file(filename):
        # type: (str) -> List[str]
        """ Read and return command line argument list from response file.

        Might throw IOException when file operations fails. """
        with open(filename[1:], 'r') as file_handle:
            return [arg.strip() for arg in shell_split(file_handle.read())]
Exemple #4
0
    def from_response_file(filename):
        # type: (str) -> List[str]
        """ Read and return command line argument list from response file.

        Might throw IOException when file operations fails. """
        with open(filename[1:], 'r') as file_handle:
            return [arg.strip() for arg in shell_split(file_handle.read())]
Exemple #5
0
    def from_db_entry(cls, entry):
        # type: (Type[Compilation], Dict[str, str]) -> Iterable[Compilation]
        """ Parser method for compilation entry.

        From compilation database entry it creates the compilation object.

        :param entry:   the compilation database entry
        :return: stream of CompilationDbEntry objects """

        command = shell_split(entry['command']) if 'command' in entry else \
            entry['arguments']
        execution = Execution(cmd=command, cwd=entry['directory'], pid=0)
        return cls.iter_from_execution(execution)
Exemple #6
0
def get_mpi_call(wrapper):
    # type: (str) -> List[str]
    """ Provide information on how the underlying compiler would have been
    invoked without the MPI compiler wrapper. """

    for query_flags in [['-show'], ['--showme']]:
        try:
            output = run_command([wrapper] + query_flags)
            if output:
                return shell_split(output[0])
        except (OSError, subprocess.CalledProcessError):
            pass
    # Fail loud
    raise RuntimeError("Could not determinate MPI flags.")
Exemple #7
0
    def from_db(entry):
        """ Factory method for compilation entry.

        From compilation database entry it creates the compilation object.

        :param entry:   the compilation database entry
        :return: a single compilation object """

        command = shell_split(entry['command']) if 'command' in entry else \
            entry['arguments']
        execution = Execution(cmd=command, cwd=entry['directory'], pid=0)
        entries = list(Compilation.from_call(execution))
        assert len(entries) == 1
        return entries[0]
Exemple #8
0
    def from_db(entry):
        """ Factory method for compilation entry.

        From compilation database entry it creates the compilation object.

        :param entry:   the compilation database entry
        :return: a single compilation object """

        command = shell_split(entry['command']) if 'command' in entry else \
            entry['arguments']
        execution = Execution(cmd=command, cwd=entry['directory'], pid=0)
        entries = list(Compilation.from_call(execution))
        assert len(entries) == 1
        return entries[0]
Exemple #9
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 shell_split(last_line)
Exemple #10
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 shell_split(last_line)
Exemple #11
0
 def test_quoted_commands(self):
     self.assertEqual(['clang', '-c', 'file.c'],
                      sut.shell_split('"clang" -c "file.c"'))
     self.assertEqual(['clang', '-c', 'file.c'],
                      sut.shell_split("'clang' -c 'file.c'"))