Files
swift-mirror/test/CAS/Inputs/BuildCommandExtractor.py
Steven Wu 9d59044bb1 [BrdigingHeader] Auto bridging header chaining
Add ability to automatically chaining the bridging headers discovered from all
dependencies module when doing swift caching build. This will eliminate all
implicit bridging header imports from the build and make the bridging header
importing behavior much more reliable, while keep the compatibility at maximum.

For example, if the current module A depends on module B and C, and both B and
C are binary modules that uses bridging header, when building module A,
dependency scanner will construct a new header that chains three bridging
headers together with the option to build a PCH from it. This will make all
importing errors more obvious while improving the performance.
2025-02-05 09:41:04 -08:00

43 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
#
# Usage: BuildCommandExtractor.py file.json ModuleName
import json
import sys
input_json = sys.argv[1]
module_name = sys.argv[2]
mode = "swift"
if module_name.startswith("clang:"):
mode = "clang"
module_name = module_name[6:]
elif module_name.startswith("swiftPrebuiltExternal:"):
mode = "swiftPrebuiltExternal"
module_name = module_name[22:]
def printCmd(cmd):
for c in cmd:
print('"{}"'.format(c))
with open(input_json, "r") as file:
deps = json.load(file)
if module_name == "bridgingHeader":
info = deps["modules"][1]["details"]["swift"]
# the first argument is `-frontend`
cmd = info["bridgingHeader"]["commandLine"][1:]
printCmd(cmd)
# print input file name.
print(info["chainedBridgingHeaderPath"])
else:
module_names = deps["modules"][::2]
module_details = deps["modules"][1::2]
for name, detail in zip(module_names, module_details):
if name.get(mode, "") != module_name:
continue
printCmd(detail["details"][mode]["commandLine"])