xref: /llvm-project/lldb/test/API/lang/objc/modules-app-update/TestClangModulesAppUpdate.py (revision 99451b4453688a94c6014cac233d371ab4cc342d)
1
2import unittest2
3import os
4import shutil
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class TestClangModuleAppUpdate(TestBase):
13    mydir = TestBase.compute_mydir(__file__)
14
15    @skipUnlessDarwin
16    @skipIf(debug_info=no_match(["gmodules"]))
17    def test_rebuild_app_modules_untouched(self):
18        with open(self.getBuildArtifact("module.modulemap"), "w") as f:
19            f.write("""
20                    module Foo { header "f.h" }
21                    """)
22        with open(self.getBuildArtifact("f.h"), "w") as f:
23            f.write("""
24                    @import Foundation;
25                    @interface Foo : NSObject {
26                       int i;
27                    }
28                    +(instancetype)init;
29                    @end
30                    """)
31
32        mod_cache = self.getBuildArtifact("private-module-cache")
33        import os
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        bar = target.FindTypes('Bar').GetTypeAtIndex(0)
42        foo = bar.GetDirectBaseClassAtIndex(0).GetType()
43        self.assertEqual(foo.GetNumberOfFields(), 1)
44        self.assertEqual(foo.GetFieldAtIndex(0).GetName(), "i")
45
46        # Rebuild.
47        process.Kill()
48        os.remove(self.getBuildArtifact('main.o'))
49        os.remove(self.getBuildArtifact('a.out'))
50        self.build()
51
52        # Reattach.
53        target, process, _, _ = lldbutil.run_to_breakpoint_do_run(self, target, bkpt)
54        bar = target.FindTypes('Bar').GetTypeAtIndex(0)
55        foo = bar.GetDirectBaseClassAtIndex(0).GetType()
56        self.assertEqual(foo.GetNumberOfFields(), 1)
57        self.assertEqual(foo.GetFieldAtIndex(0).GetName(), "i")
58