Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
Dirk Pranke
2017/06/30 21:38:46
I worry a bit that "jumbo.py" might be too opaque
Daniel Bratell
2017/07/03 09:21:17
Done.
| |
| 2 # | |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """This script creates a "jumbo" file which merges all incoming files | |
| 8 for compiling. | |
| 9 | |
| 10 """ | |
| 11 | |
| 12 from __future__ import print_function | |
| 13 | |
| 14 import argparse | |
| 15 | |
| 16 | |
| 17 def main(): | |
| 18 parser = argparse.ArgumentParser() | |
| 19 parser.add_argument("--outputs", nargs="+", required=True, | |
| 20 help='List of output files to split input into') | |
| 21 parser.add_argument("--file-list", required=True) | |
| 22 parser.add_argument("--verbose", action="store_true") | |
| 23 args = parser.parse_args() | |
| 24 | |
| 25 output_count = len(args.outputs) | |
| 26 | |
| 27 lines = [] | |
| 28 # If written with gn |write_file| each file is on its own line. | |
| 29 with open(args.file_list) as file_list_file: | |
| 30 lines = [line.strip() for line in file_list_file if line.strip()] | |
| 31 # If written with gn |response_file_contents| the files are space separated. | |
| 32 inputs = [] | |
| 33 for line in lines: | |
| 34 inputs.extend(line.split()) | |
| 35 input_count = len(inputs) | |
| 36 | |
| 37 written_inputs = 0 | |
| 38 for output_index, output_file in enumerate(args.outputs): | |
| 39 # TODO: Check if the file is right already and then do not update it. | |
| 40 with open(output_file, "w") as out: | |
| 41 out.write("/* This is a Jumbo file. Don't edit. */\n\n") | |
| 42 out.write("/* Generated with jumbo.py. */\n\n") | |
| 43 input_limit = (output_index + 1) * input_count / output_count | |
| 44 while written_inputs < input_limit: | |
| 45 filename = inputs[written_inputs] | |
| 46 written_inputs += 1 | |
| 47 if filename.endswith((".h", ".mm")): | |
|
Dirk Pranke
2017/06/30 21:38:46
Can you add a comment here about why we're skippin
Daniel Bratell
2017/07/03 09:21:17
Done.
Note: The code will change completely when
| |
| 48 continue | |
| 49 | |
| 50 out.write("#include \"%s\"\n" % filename) | |
| 51 | |
| 52 if args.verbose: | |
| 53 print("Generated %s (%d files) based on %s" % (str(args.outputs), | |
| 54 written_inputs, | |
| 55 args.file_list)) | |
| 56 | |
| 57 if __name__ == "__main__": | |
| 58 main() | |
| OLD | NEW |