| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 from datetime import date | 8 from datetime import date |
| 9 import re | 9 import re |
| 10 import optparse | 10 import optparse |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 expected = set(assert_files_list) | 299 expected = set(assert_files_list) |
| 300 if not actual == expected: | 300 if not actual == expected: |
| 301 need_to_add = list(actual - expected) | 301 need_to_add = list(actual - expected) |
| 302 need_to_remove = list(expected - actual) | 302 need_to_remove = list(expected - actual) |
| 303 raise Exception('Output files list does not match expectations. Please ' | 303 raise Exception('Output files list does not match expectations. Please ' |
| 304 'add %s and remove %s.' % (need_to_add, need_to_remove)) | 304 'add %s and remove %s.' % (need_to_add, need_to_remove)) |
| 305 | 305 |
| 306 def DoMain(argv): | 306 def DoMain(argv): |
| 307 usage = 'usage: %prog [options] [output_dir] input_file(s)...' | 307 usage = 'usage: %prog [options] [output_dir] input_file(s)...' |
| 308 parser = optparse.OptionParser(usage=usage) | 308 parser = optparse.OptionParser(usage=usage) |
| 309 build_utils.AddDepfileOption(parser) |
| 309 | 310 |
| 310 parser.add_option('--assert_file', action="append", default=[], | 311 parser.add_option('--assert_file', action="append", default=[], |
| 311 dest="assert_files_list", help='Assert that the given ' | 312 dest="assert_files_list", help='Assert that the given ' |
| 312 'file is an output. There can be multiple occurrences of ' | 313 'file is an output. There can be multiple occurrences of ' |
| 313 'this flag.') | 314 'this flag.') |
| 314 parser.add_option('--srcjar', | 315 parser.add_option('--srcjar', |
| 315 help='When specified, a .srcjar at the given path is ' | 316 help='When specified, a .srcjar at the given path is ' |
| 316 'created instead of individual .java files.') | 317 'created instead of individual .java files.') |
| 317 parser.add_option('--print_output_only', help='Only print output paths.', | 318 parser.add_option('--print_output_only', help='Only print output paths.', |
| 318 action='store_true') | 319 action='store_true') |
| 319 parser.add_option('--verbose', help='Print more information.', | 320 parser.add_option('--verbose', help='Print more information.', |
| 320 action='store_true') | 321 action='store_true') |
| 321 | 322 |
| 322 options, args = parser.parse_args(argv) | 323 options, args = parser.parse_args(argv) |
| 324 |
| 325 if options.srcjar: |
| 326 if not args: |
| 327 parser.error('Need to specify at least one input file') |
| 328 input_paths = args |
| 329 else: |
| 330 if len(args) < 2: |
| 331 parser.error( |
| 332 'Need to specify output directory and at least one input file') |
| 333 output_dir = args[0] |
| 334 input_paths = args[1:] |
| 335 |
| 336 if options.depfile: |
| 337 python_deps = build_utils.GetPythonDependencies() |
| 338 build_utils.WriteDepfile(options.depfile, input_paths + python_deps) |
| 339 |
| 323 if options.srcjar: | 340 if options.srcjar: |
| 324 if options.print_output_only: | 341 if options.print_output_only: |
| 325 parser.error('--print_output_only does not work with --srcjar') | 342 parser.error('--print_output_only does not work with --srcjar') |
| 326 if options.assert_files_list: | 343 if options.assert_files_list: |
| 327 parser.error('--assert_file does not work with --srcjar') | 344 parser.error('--assert_file does not work with --srcjar') |
| 328 | 345 |
| 329 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar: | 346 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar: |
| 330 for output_path, data in DoGenerate(args): | 347 for output_path, data in DoGenerate(input_paths): |
| 331 srcjar.writestr(build_utils.CreateHermeticZipInfo(output_path), data) | 348 srcjar.writestr(build_utils.CreateHermeticZipInfo(output_path), data) |
| 332 else: | 349 else: |
| 333 # TODO(agrieve): Delete this non-srcjar branch once GYP is gone. | 350 # TODO(agrieve): Delete this non-srcjar branch once GYP is gone. |
| 334 if len(args) < 2: | |
| 335 parser.error( | |
| 336 'Need to specify output directory and at least one input file') | |
| 337 | |
| 338 output_dir = args[0] | |
| 339 output_paths = [] | 351 output_paths = [] |
| 340 for output_path, data in DoGenerate(args[1:]): | 352 for output_path, data in DoGenerate(input_paths): |
| 341 full_path = os.path.join(output_dir, output_path) | 353 full_path = os.path.join(output_dir, output_path) |
| 342 output_paths.append(full_path) | 354 output_paths.append(full_path) |
| 343 if not options.print_output_only: | 355 if not options.print_output_only: |
| 344 build_utils.MakeDirectory(os.path.dirname(full_path)) | 356 build_utils.MakeDirectory(os.path.dirname(full_path)) |
| 345 with open(full_path, 'w') as out_file: | 357 with open(full_path, 'w') as out_file: |
| 346 out_file.write(data) | 358 out_file.write(data) |
| 347 | 359 |
| 348 if options.assert_files_list: | 360 if options.assert_files_list: |
| 349 AssertFilesList(output_paths, options.assert_files_list) | 361 AssertFilesList(output_paths, options.assert_files_list) |
| 350 | 362 |
| 351 if options.verbose: | 363 if options.verbose: |
| 352 print 'Output paths:' | 364 print 'Output paths:' |
| 353 print '\n'.join(output_paths) | 365 print '\n'.join(output_paths) |
| 354 | 366 |
| 355 # Used by GYP. | 367 # Used by GYP. |
| 356 return ' '.join(output_paths) | 368 return ' '.join(output_paths) |
| 357 | 369 |
| 358 | 370 |
| 359 if __name__ == '__main__': | 371 if __name__ == '__main__': |
| 360 DoMain(sys.argv[1:]) | 372 DoMain(sys.argv[1:]) |
| OLD | NEW |