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