OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 merge_for_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 # The source list includes headers which should not be |
| 48 # compiled, and Objective C files which will be special cased |
| 49 # later since they will not compile correctly if included in a |
| 50 # C++ file. We will just skip them here for now. |
| 51 if filename.endswith((".h", ".mm")): |
| 52 continue |
| 53 |
| 54 out.write("#include \"%s\"\n" % filename) |
| 55 |
| 56 if args.verbose: |
| 57 print("Generated %s (%d files) based on %s" % (str(args.outputs), |
| 58 written_inputs, |
| 59 args.file_list)) |
| 60 |
| 61 if __name__ == "__main__": |
| 62 main() |
OLD | NEW |