Skip to content

Commit 0173e49

Browse files
[lldb] Add clang-explicit-module-build caching test for gmodule
1 parent 4dbd095 commit 0173e49

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Usage: clang-explicit-module-build.py [-cas-path CAS_PATH] -- CLANG_COMMAND
4+
5+
The script builds with clang explicit module. If `-cas-path` is used, clang
6+
explicit module build is going to enable compilation caching.
7+
"""
8+
9+
import argparse
10+
import json
11+
import os
12+
import subprocess
13+
import sys
14+
15+
16+
def main():
17+
argv = sys.argv[1:]
18+
if "--" not in argv:
19+
print("missing clang command")
20+
exit(1)
21+
dash_idx = argv.index("--")
22+
clang_args = argv[dash_idx + 1:]
23+
if len(clang_args) == 0:
24+
print("empty clang command")
25+
exit(1)
26+
27+
parser = argparse.ArgumentParser()
28+
parser.add_argument("-cas-path", required=False)
29+
args = parser.parse_args(argv[:dash_idx])
30+
31+
clang_exe = clang_args[0]
32+
clang_scan_deps = os.path.join(
33+
os.path.dirname(clang_exe), "clang-scan-deps")
34+
35+
scan_cmd = [clang_scan_deps]
36+
if args.cas_path is None:
37+
scan_cmd.extend(["-format", "experimental-full", "-o", "-", "--"])
38+
else:
39+
scan_cmd.extend(["-format", "experimental-include-tree-full",
40+
"-cas-path", args.cas_path, "-o", "-", "--"])
41+
scan_cmd.extend(clang_args)
42+
scan_result = json.loads(subprocess.check_output(scan_cmd))
43+
44+
# build module: assuming modules in reverse dependency order.
45+
for module in reversed(scan_result["modules"]):
46+
cmd = [clang_exe] + module["command-line"]
47+
print(*cmd)
48+
subprocess.check_call(cmd)
49+
50+
# build tu: assuming only one TU.
51+
tu_cmd = [clang_exe] + \
52+
scan_result["translation-units"][0]["commands"][0]["command-line"]
53+
print(*tu_cmd)
54+
subprocess.check_call(tu_cmd)
55+
56+
57+
if __name__ == "__main__":
58+
main()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# REQUIRES: system-darwin
2+
# RUN: rm -rf %t
3+
# RUN: split-file %s %t
4+
# RUN: sed "s|DIR|%/t|g" %t/cas-config.template > %t/.cas-config
5+
6+
# RUN: %python %S/../../../scripts/clang-explicit-module-build.py -cas-path %t/cas -- %clang_host -c -g -o %t/test.o %t/tu.c -fmodules -gmodules -fmodules-cache-path=%t/module-cache
7+
# RUN: %clang_host %t/test.o -o %t/main
8+
# RUN: %lldb %t/main -s %t/lldb.script 2>&1 | FileCheck %s
9+
# CHECK: loading module 'Bottom' using CASID
10+
# CHECK: loading module 'Top' using CASID
11+
# CHECK: top = (x = 1)
12+
13+
//--- module.modulemap
14+
module Top { header "Top.h" export *}
15+
module Bottom { header "Bottom.h" export *}
16+
17+
//--- Top.h
18+
#pragma once
19+
struct Top { int x; };
20+
21+
//--- Bottom.h
22+
#pragma once
23+
#include "Top.h"
24+
struct Bottom { struct Top top; };
25+
26+
//--- tu.c
27+
#include "Bottom.h"
28+
29+
int main(void) {
30+
struct Bottom _bottom;
31+
_bottom.top.x = 1;
32+
33+
return 0; // BREAK HERE
34+
}
35+
36+
//--- cas-config.template
37+
{
38+
"CASPath": "DIR/cas"
39+
}
40+
41+
//--- lldb.script
42+
log enable lldb module
43+
b tu.c:7
44+
run
45+
expr _bottom
46+
quit

0 commit comments

Comments
 (0)