Files
swift-mirror/test/CAS/Inputs/BuildCommandExtractor.py
Steven Wu 52671e1a6a [Caching] Improve swift caching related tests
Improve caching related tests to make them faster and test the situation
closer to what actually happens during explicit module build. Most
noticable changes are:
* Avoid swift stdlib dependency during the tests to save time
* Use dependency scanner output to construct test cases
* Update old test cases that try to simulate caching from file system
  inputs to using only CAS inputs.
2024-01-28 22:06:59 -08:00

39 lines
973 B
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':
cmd = deps['modules'][1]['details']['swift']['bridgingHeader']['commandLine']
printCmd(cmd)
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'])