Chromium Code Reviews| Index: ios/chrome/tools/build/ios_generate_forwarding_headers.py |
| diff --git a/ios/chrome/tools/build/ios_generate_forwarding_headers.py b/ios/chrome/tools/build/ios_generate_forwarding_headers.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..88f5683b91a61b989e26fee1c391d6f3e807cb75 |
| --- /dev/null |
| +++ b/ios/chrome/tools/build/ios_generate_forwarding_headers.py |
| @@ -0,0 +1,71 @@ |
| +#!/usr/bin/env python |
|
sdefresne
2016/02/22 16:36:48
Rename to copy_files.py
|
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import argparse |
| +import datetime |
|
sdefresne
2016/02/22 16:36:48
Remove.
|
| +import os |
| +import sys |
|
sdefresne
2016/02/22 16:36:48
import shutil
|
| + |
| +COPYRIGHT = """// Copyright {0} The Chromium Authors. All rights reserved. |
|
sdefresne
2016/02/22 16:36:48
Remove.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file.\n |
| +""".format(datetime.date.today().year) |
| + |
| +def filter_header_files(inputs): |
|
sdefresne
2016/02/22 16:36:48
Remove.
|
| + return [filename for filename in inputs if filename.endswith('.h')] |
| + |
| +def get_output_filename(input_filename, dest_dir): |
| + return os.path.join(dest_dir, os.path.basename(input_filename)) |
| + |
| +def list_inputs(possible_inputs): |
|
sdefresne
2016/02/22 16:36:48
Remove.
|
| + return ' '.join(filter_header_files(possible_inputs)) |
| + |
| +def list_outputs(possible_inputs, dest_dir): |
|
sdefresne
2016/02/22 16:36:48
s/possible_inputs/inputs/
|
| + outputs = [] |
|
sdefresne
2016/02/22 16:36:48
outputs = [ get_output_filename(filename, dest_dir
|
| + for filename in filter_header_files(possible_inputs): |
| + outputs.append(get_output_filename(filename, dest_dir)) |
| + return ' '.join(outputs) |
| + |
| +def generate_headers(possible_inputs, dest_dir): |
|
sdefresne
2016/02/22 16:36:48
Remove and replace with:
def copy_files(inputs, d
|
| + for filename in filter_header_files(possible_inputs): |
| + content = COPYRIGHT + '#import "{0}"\n'.format(filename) |
| + forwarding_header = get_output_filename(filename, dest_dir) |
| + if os.path.isfile(forwarding_header): |
| + with open(forwarding_header, 'r') as header: |
| + old_content = header.read() |
| + if old_content == content: |
| + continue |
| + with open(forwarding_header, 'w') as header: |
| + header.write(content) |
| + |
| +def DoMain(argv): |
| + parser = argparse.ArgumentParser(description='Generate forwarding headers.') |
| + parser.add_argument('-i', '--list-inputs', action='store_true', |
|
sdefresne
2016/02/22 16:36:48
Remove '-i' argument.
|
| + help='List input files and exit.') |
| + parser.add_argument('-o', '--list-outputs', action='store_true', |
| + help='List output files and exit.') |
| + parser.add_argument('-d', '--dest-dir', type=str, |
| + help=('Output directory for forwarding headers.')) |
| + parser.add_argument('filenames', metavar='filename', type=str, nargs='+', |
| + help='Input filenames.') |
| + |
| + args = parser.parse_args(argv) |
| + if args.list_inputs: |
|
sdefresne
2016/02/22 16:36:48
Remove.
|
| + return list_inputs(args.filenames) |
| + |
| + if not args.dest_dir: |
| + print '--dest-dir is required for this command.' |
| + sys.exit(1) |
| + if args.list_outputs: |
| + return list_outputs(args.filenames, args.dest_dir) |
| + |
| + if not os.path.isdir(args.dest_dir): |
| + os.makedirs(args.dest_dir) |
| + generate_headers(args.filenames, args.dest_dir) |
|
sdefresne
2016/02/22 16:36:48
copy_files(args.filenames, args.dest_dir)
|
| + return |
| + |
| +if __name__ == '__main__': |
| + results = DoMain(sys.argv[1:]) |
| + print results |