Ejemplo n.º 1
0
    def test_dsym_swiftinterface(self):
        """Test that LLDB can import .swiftinterface files inside a .dSYM bundle."""
        self.build()
        self.assertFalse(os.path.isdir(self.getBuildArtifact("AA.dylib.dSYM")),
                         "dylib dsym exists")

        # The custom swift module cache location
        swift_mod_cache = self.getBuildArtifact("cache")
        self.assertTrue(
            os.path.isfile(
                self.getBuildArtifact(
                    "a.out.dSYM/Contents/Resources/Swift/x86_64/AA.swiftinterface"
                )), "dsymutil doesn't support Swift interfaces")
        # Delete the .swiftinterface form the build dir.
        os.remove(self.getBuildArtifact("AA.swiftinterface"))

        # Clear the swift module cache (populated by the Makefile build)
        shutil.rmtree(swift_mod_cache)
        import glob
        self.assertFalse(os.path.isdir(swift_mod_cache),
                         "module cache should not exist")

        # Update the settings to use the custom module cache location
        self.runCmd('settings set symbols.clang-modules-cache-path "%s"' %
                    swift_mod_cache)

        # Set a breakpoint in and launch the main executable
        lldbutil.run_to_source_breakpoint(self, "break here",
                                          lldb.SBFileSpec("main.swift"))

        # Check we are able to access the public fields of variables whose
        # types are from the .swiftinterface-only dylibs
        var = self.frame().FindVariable("x")
        lldbutil.check_variable(self, var, False, typename="AA.MyPoint")

        child_y = var.GetChildMemberWithName("y")  # MyPoint.y is public
        lldbutil.check_variable(self, child_y, False, value="0")

        child_x = var.GetChildMemberWithName("x")  # MyPoint.x isn't public
        self.assertFalse(child_x.IsValid())

        # Expression evaluation using types from the .swiftinterface only
        # dylibs should work too
        lldbutil.check_expression(self,
                                  self.frame(),
                                  "y.magnitudeSquared",
                                  "404",
                                  use_summary=False)
        lldbutil.check_expression(self,
                                  self.frame(),
                                  "MyPoint(x: 1, y: 2).magnitudeSquared",
                                  "5",
                                  use_summary=False)

        # Check the swift module cache was populated with the .swiftmodule
        # files of the loaded modules
        self.assertTrue(os.path.isdir(swift_mod_cache), "module cache exists")
        a_modules = glob.glob(os.path.join(swift_mod_cache,
                                           'AA-*.swiftmodule'))
        self.assertEqual(len(a_modules), 1)
Ejemplo n.º 2
0
    def do_test(self):
        # The custom swift module cache location
        swift_mod_cache = self.getBuildArtifact("MCP")

        # Clear the swift module cache (populated by the Makefile build)
        shutil.rmtree(swift_mod_cache)
        self.assertFalse(os.path.isdir(swift_mod_cache),
                         "module cache should not exist")

        # Update the settings to use the custom module cache location.
        # Note: the clang module cache path setting is used for this currently.
        self.runCmd('settings set symbols.clang-modules-cache-path "%s"' %
                    swift_mod_cache)

        # Set a breakpoint in and launch the main executable
        lldbutil.run_to_source_breakpoint(
            self,
            'break here',
            lldb.SBFileSpec('main.swift'),
            exe_name=self.getBuildArtifact("main"))

        # Check we are able to access the public fields of variables whose
        # types are from the .swiftinterface-only modules
        var = self.frame().FindVariable("x")
        lldbutil.check_variable(self, var, False, typename="AA.MyPoint")

        child_y = var.GetChildMemberWithName("y")  # MyPoint.y is public
        lldbutil.check_variable(self, child_y, False, value="0")

        child_x = var.GetChildMemberWithName("x")  # MyPoint.x isn't public
        self.assertFalse(child_x.IsValid())

        # Expression evaluation using types from the .swiftinterface only
        # modules should work too
        lldbutil.check_expression(self,
                                  self.frame(),
                                  "y.magnitudeSquared",
                                  "404",
                                  use_summary=False)
        lldbutil.check_expression(self,
                                  self.frame(),
                                  "MyPoint(x: 1, y: 2).magnitudeSquared",
                                  "5",
                                  use_summary=False)

        # Check the swift module cache was populated with the .swiftmodule
        # files of the loaded modules
        self.assertTrue(os.path.isdir(swift_mod_cache), "module cache exists")
        a_modules = glob.glob(os.path.join(swift_mod_cache,
                                           'AA-*.swiftmodule'))
        b_modules = glob.glob(os.path.join(swift_mod_cache,
                                           'BB-*.swiftmodule'))
        c_modules = glob.glob(os.path.join(swift_mod_cache,
                                           'CC-*.swiftmodule'))
        self.assertEqual(len(a_modules), 1)
        self.assertEqual(len(b_modules), 1)
        self.assertEqual(len(c_modules), 0)

        # Update the timestamps of the modules to a time well in the past
        for file in a_modules + b_modules:
            make_old(file)

        # Re-import module A and B
        self.runCmd("expr import AA")
        self.runCmd("expr import BB")

        # Import C for the first time
        self.runCmd("expr import CC")

        # Check we still have a single .swiftmodule in the cache for A and B
        # and that there is now one for C too
        a_modules = glob.glob(os.path.join(swift_mod_cache,
                                           'AA-*.swiftmodule'))
        b_modules = glob.glob(os.path.join(swift_mod_cache,
                                           'BB-*.swiftmodule'))
        c_modules = glob.glob(os.path.join(swift_mod_cache,
                                           'CC-*.swiftmodule'))
        self.assertEqual(len(a_modules), 1,
                         "unexpected number of swiftmodules for A.swift")
        self.assertEqual(len(b_modules), 1,
                         "unexpected number of swiftmodules for B.swift")
        self.assertEqual(len(c_modules), 1,
                         "unexpected number of swiftmodules for C.swift")

        # Make sure the .swiftmodule files of A and B were re-used rather than
        # re-generated when they were re-imported
        for file in a_modules + b_modules:
            self.assertTrue(
                is_old(file),
                "Swiftmodule file was regenerated rather than reused")