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..51848153280ccdd5aa921b03c72a9948e5e81219 |
| --- /dev/null |
| +++ b/ios/chrome/tools/build/ios_generate_forwarding_headers.py |
| @@ -0,0 +1,57 @@ |
| +#!/usr/bin/env python |
| +# 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 |
| +import os |
| +import sys |
| + |
| +COPYRIGHT = """// Copyright {0} 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.\n |
| +""".format(datetime.date.today().year) |
| + |
| +def filter_header_files(inputs): |
| + 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_outputs(inputs, dest_dir): |
| + outputs = [] |
| + for filename in filter_header_files(inputs): |
| + outputs.append(get_output_filename(filename, dest_dir)) |
| + return ' '.join(outputs) |
| + |
| +def generate_headers(inputs, dest_dir): |
| + for filename in filter_header_files(inputs): |
| + forwarding_header = get_output_filename(filename, dest_dir) |
|
sdefresne
2016/02/22 09:09:49
I would change the code to the following. It will
rohitrao (ping after 24h)
2016/02/22 14:49:38
Done.
|
| + if not os.path.isfile(forwarding_header): |
| + with open(forwarding_header, 'w') as header: |
| + header.write(COPYRIGHT) |
| + header.write('#import "{0}"\n'.format(filename)) |
| + |
| +def DoMain(argv): |
| + parser = argparse.ArgumentParser(description='Generate forwarding headers.') |
| + parser.add_argument('-o', '--list-outputs', action='store_true', |
| + help='List output files and exit.') |
| + parser.add_argument('-d', '--dest-dir', type=str, required=True, |
| + 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_outputs: |
| + return list_outputs(args.filenames, args.dest_dir) |
| + if args.dest_dir: |
| + if not os.path.isdir(args.dest_dir): |
| + os.makedirs(args.dest_dir) |
| + generate_headers(args.filenames, args.dest_dir) |
| + return |
| + print >>sys.stderr, 'Neither -o nor -d passed, unsure what to do.' |
| + |
| +if __name__ == '__main__': |
| + results = DoMain(sys.argv[1:]) |
| + print results |