1 2import os 3import shutil 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class TestClangModuleAppUpdate(TestBase): 12 13 @add_test_categories(["gmodules"]) 14 def test_rebuild_app_modules_untouched(self): 15 with open(self.getBuildArtifact("module.modulemap"), "w") as f: 16 f.write(""" 17 module Foo { header "f.h" } 18 """) 19 with open(self.getBuildArtifact("f.h"), "w") as f: 20 f.write(""" 21 @import ObjectiveC; 22 @interface Foo : NSObject { 23 int i; 24 } 25 +(instancetype)init; 26 @end 27 """) 28 29 mod_cache = self.getBuildArtifact("private-module-cache") 30 import os 31 if os.path.isdir(mod_cache): 32 shutil.rmtree(mod_cache) 33 self.build() 34 self.assertTrue(os.path.isdir(mod_cache), "module cache exists") 35 36 target, process, _, bkpt = lldbutil.run_to_source_breakpoint( 37 self, "break here", lldb.SBFileSpec("main.m")) 38 bar = target.FindTypes('Bar').GetTypeAtIndex(0) 39 foo = bar.GetDirectBaseClassAtIndex(0).GetType() 40 self.assertEqual(foo.GetNumberOfFields(), 1) 41 self.assertEqual(foo.GetFieldAtIndex(0).GetName(), "i") 42 43 # Rebuild. 44 process.Kill() 45 os.remove(self.getBuildArtifact('main.o')) 46 os.remove(self.getBuildArtifact('a.out')) 47 self.build() 48 49 # Reattach. 50 target, process, _, _ = lldbutil.run_to_breakpoint_do_run(self, target, bkpt) 51 bar = target.FindTypes('Bar').GetTypeAtIndex(0) 52 foo = bar.GetDirectBaseClassAtIndex(0).GetType() 53 self.assertEqual(foo.GetNumberOfFields(), 1) 54 self.assertEqual(foo.GetFieldAtIndex(0).GetName(), "i") 55