mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
|
|
def fatal(msg):
|
|
print(msg, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
def find_swift_files(path):
|
|
for parent, dirs, files in os.walk(path, topdown=True):
|
|
for filename in files:
|
|
if not filename.endswith('.swift'):
|
|
continue
|
|
yield (parent, filename)
|
|
|
|
|
|
def main(arguments):
|
|
parser = argparse.ArgumentParser(
|
|
description='Generate an output file map for the given directory')
|
|
parser.add_argument('-o', dest='output_dir',
|
|
help='Directory to which the file map will be emitted')
|
|
parser.add_argument('-r', dest='response_output_file',
|
|
help="""Directory to which a matching response file
|
|
will be emitted""")
|
|
parser.add_argument('input_dir', help='a directory of swift files')
|
|
args = parser.parse_args(arguments)
|
|
|
|
if not args.output_dir:
|
|
fatal("output directory is required")
|
|
|
|
# Create the output directory if it doesn't already exist.
|
|
if not os.path.isdir(args.output_dir):
|
|
os.makedirs(args.output_dir)
|
|
|
|
output_path = os.path.join(args.output_dir, 'output.json')
|
|
|
|
if not os.path.isdir(args.input_dir):
|
|
fatal("input directory does not exist, or is not a directory")
|
|
|
|
swift_files = find_swift_files(args.input_dir)
|
|
if not swift_files:
|
|
fatal("no swift files in the given input directory")
|
|
|
|
response_file_contents = []
|
|
all_records = {}
|
|
for (root, swift_file) in swift_files:
|
|
file_name = os.path.splitext(swift_file)[0]
|
|
all_records['./' + swift_file] = {
|
|
'object': './' + file_name + '.o',
|
|
'swift-dependencies': './' + file_name + '.swiftdeps',
|
|
}
|
|
response_file_contents.append(os.path.join(root, swift_file))
|
|
all_records[""] = {
|
|
'swift-dependencies': './main-buildrecord.swiftdeps'
|
|
}
|
|
|
|
with open(output_path, 'wb') as f:
|
|
json.dump(all_records, f)
|
|
|
|
if args.response_output_file is not None:
|
|
with open(args.response_output_file, 'wb') as f:
|
|
for line in response_file_contents:
|
|
f.write(line + " ")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main(sys.argv[1:]))
|