Пример #1
0
    def test_ParseCommandArgs(self):

        # TODO(tvl): add -F and -iframework lines to the tests once we figure
        # out how we're dealing with them.

        quote_dirs, angle_dirs, include_files, filepath, _incl_clos_f, _d_opts = (
            parse_command.ParseCommandArgs(
                parse_command.ParseCommandLine(
                    self.mock_compiler +
                    " -isystem system -Imice -iquote/and -I/men a.c "
                    " -include included_A.h "
                    " -includeincluded_B.h "
                    "-Xlinker W,l -L /ignored_by_us -o a.o"), os.getcwd(),
                self.includepath_map, self.directory_map,
                self.compiler_defaults))

        self.assertEqual(
            (self._RetrieveDirectoriesExceptSys(quote_dirs),
             self._RetrieveDirectoriesExceptSys(angle_dirs),
             [self.includepath_map.String(i)
              for i in include_files], filepath),
            (('/and', 'mice', '/men', 'system'), ('mice', '/men', 'system'),
             ["included_A.h", "included_B.h"], 'a.c'))

        self.assertRaises(
            NotCoveredError, parse_command.ParseCommandArgs,
            parse_command.ParseCommandLine(self.mock_compiler +
                                           " -I- -iquote a.c"), os.getcwd(),
            self.includepath_map, self.directory_map, self.compiler_defaults)

        quote_dirs, angle_dirs, include_files, filepath, _incl_cls_file, _d_opts = (
            parse_command.ParseCommandArgs(
                parse_command.ParseCommandLine(
                    "/usr/crosstool/v8/gcc-4.1.0-glibc-2.2.2/blah/gcc" +
                    " -fno-exceptions -funsigned-char -D__STDC_FORMAT_MACROS -g0"
                    +
                    " -D_REENTRANT -DCOMPILER_GCC3 -DCOMPILER_GCC4 -DARCH_PIII -DOS_LINUX"
                    +
                    " -fmessage-length=0 -fno-strict-aliasing -fno-tree-vrp -D_REENTRANT"
                    + " -DHAS_vsnprintf" +
                    " -Iobj/gcc-4.1.0-glibc-2.2.2-piii-linux-g0-dbg/genfiles/third_party/libxml/third_party/libxml"
                    +
                    " -Ithird_party/zlib -iquote . -fno-strict-aliasing -c -o"
                    +
                    " obj/gcc-4.1.0-glibc-2.2.2-piii-linux-g0-dbg/bin/third_party/libxml/threads.c.o"
                    + " third_party/libxml/threads.c"), os.getcwd(),
                self.includepath_map, self.directory_map,
                self.compiler_defaults))
        self.assertEqual((
            self._RetrieveDirectoriesExceptSys(quote_dirs),
            self._RetrieveDirectoriesExceptSys(angle_dirs), filepath
        ), ((
            '',
            'obj/gcc-4.1.0-glibc-2.2.2-piii-linux-g0-dbg/genfiles/third_party/libxml/third_party/libxml',
            'third_party/zlib'
        ), ('obj/gcc-4.1.0-glibc-2.2.2-piii-linux-g0-dbg/genfiles/third_party/libxml/third_party/libxml',
            'third_party/zlib'), 'third_party/libxml/threads.c'))
Пример #2
0
 def ProcessCompilationCommandLine(self, cmd, cwd):
     return (self.include_analyzer.ProcessCompilationCommand(
         cwd,
         parse_command.ParseCommandArgs(
             parse_command.ParseCommandLine(cmd), cwd,
             self.include_analyzer.includepath_map,
             self.include_analyzer.directory_map,
             self.include_analyzer.compiler_defaults)))
Пример #3
0
    def test_ParseCommandLine(self):

        self.assertEqual(
            parse_command.ParseCommandLine(
                """   "a"b"\\"c"  "a"\n"b" a  b\\"c"""),
            ['ab"c', 'a', 'b', 'a', 'b"c'])

        self.assertEqual(parse_command.ParseCommandLine("""this is a test"""),
                         ['this', 'is', 'a', 'test'])
        self.assertEqual(
            parse_command.ParseCommandLine("""   this is a test"""),
            ['this', 'is', 'a', 'test'])
        self.assertEqual(
            parse_command.ParseCommandLine("""this is a test   """),
            ['this', 'is', 'a', 'test'])

        self.assertEqual(parse_command.ParseCommandLine('this " is" a"test" '),
                         ['this', ' is', 'atest'])

        self.assertEqual(
            parse_command.ParseCommandLine(r'this " \"is" a"test" '),
            ['this', ' "is', 'atest'])

        self.assertEqual(parse_command.ParseCommandLine('this " is" a"test"'),
                         ['this', ' is', 'atest'])

        self.assertRaises(NotCoveredError, parse_command.ParseCommandLine,
                          """this is" a"test" """)
        self.assertRaises(NotCoveredError, parse_command.ParseCommandLine,
                          'this is" a"test"')
    def test__CalculateIncludeClosureExceptSystem_on_distcc(self):

        includepath_map = self.includepath_map
        canonical_path = self.canonical_path
        directory_map = self.directory_map
        realpath_map = self.realpath_map
        include_analyzer = self.include_analyzer

        current_dir = os.path.realpath("test_data/distcc")
        os.chdir(current_dir)

        src_stem = "distcc"
        cmd = self._ConstructDistccCommandLine(src_stem)

        parsed_command = (parse_command.ParseCommandArgs(
            parse_command.ParseCommandLine(cmd), current_dir,
            include_analyzer.includepath_map, include_analyzer.directory_map,
            include_analyzer.compiler_defaults))

        (include_analyzer.quote_dirs, include_analyzer.angle_dirs,
         include_analyzer.include_files, translation_unit,
         include_analyzer.result_file_prefix, _) = parsed_command

        self.assertEqual(translation_unit, "src/%s.c" % src_stem)

        expected_suffixes = [
            "src/include_me.h", "src/implicit.h", "src/distcc.c",
            "src/config.h", "src/distcc.h", "src/state.h", "src/compile.h",
            "src/trace.h", "src/exitcode.h", "src/util.h", "src/hosts.h",
            "src/bulk.h", "src/emaillog.h"
        ]

        include_closure = (include_analyzer.ProcessCompilationCommand(
            current_dir, parsed_command))

        expected_prefix = os.getcwd() + '/'

        expected = set([
            expected_prefix + expected_suffix
            for expected_suffix in expected_suffixes
        ])
        self.assertEqual(
            set([realpath_map.string[key] for key in include_closure.keys()]),
            expected)

        for rp_idx in include_closure:
            self.assertEqual(len(include_closure[rp_idx]), 0)