Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: build/config/merge_for_jumbo.py

Issue 2972533002: Support C and Objective-C in jumbo base scripts. (Closed)
Patch Set: Fixup for fixup for core/editing for mac and objective-c Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2016 The Chromium Authors. All rights reserved. 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 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 """This script creates a "jumbo" file which merges all incoming files 7 """This script creates a "jumbo" file which merges all incoming files
8 for compiling. 8 for compiling.
9 9
10 """ 10 """
11 11
12 from __future__ import print_function 12 from __future__ import print_function
13 13
14 import argparse 14 import argparse
15 15
16 def write_jumbo_files(inputs, outputs, written_input_set, written_output_set):
17 output_count = len(outputs)
18 input_count = len(inputs)
19
20 written_inputs = 0
21 for output_index, output_file in enumerate(outputs):
22 written_output_set.add(output_file)
23 # TODO: Check if the file is right already and then do not update it.
Dirk Pranke 2017/07/04 17:15:16 You might as well do this before landing the chang
Daniel Bratell 2017/07/05 09:21:45 Done.
24 with open(output_file, "w") as out:
25 out.write("/* This is a Jumbo file. Don't edit. */\n\n")
26 out.write("/* Generated with jumbo.py. */\n\n")
27 input_limit = (output_index + 1) * input_count / output_count
28 while written_inputs < input_limit:
29 filename = inputs[written_inputs]
30 written_inputs += 1
31 out.write("#include \"%s\"\n" % filename)
32 written_input_set.add(filename)
33
16 34
17 def main(): 35 def main():
18 parser = argparse.ArgumentParser() 36 parser = argparse.ArgumentParser()
19 parser.add_argument("--outputs", nargs="+", required=True, 37 parser.add_argument("--outputs", nargs="+", required=True,
20 help='List of output files to split input into') 38 help='List of output files to split input into')
21 parser.add_argument("--file-list", required=True) 39 parser.add_argument("--file-list", required=True)
22 parser.add_argument("--verbose", action="store_true") 40 parser.add_argument("--verbose", action="store_true")
23 args = parser.parse_args() 41 args = parser.parse_args()
24 42
25 output_count = len(args.outputs)
26
27 lines = [] 43 lines = []
28 # If written with gn |write_file| each file is on its own line. 44 # If written with gn |write_file| each file is on its own line.
29 with open(args.file_list) as file_list_file: 45 with open(args.file_list) as file_list_file:
30 lines = [line.strip() for line in file_list_file if line.strip()] 46 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. 47 # If written with gn |response_file_contents| the files are space separated.
32 inputs = [] 48 all_inputs = []
33 for line in lines: 49 for line in lines:
34 inputs.extend(line.split()) 50 all_inputs.extend(line.split())
35 input_count = len(inputs)
36 51
37 written_inputs = 0 52 written_output_set = set() # Just for double checking
38 for output_index, output_file in enumerate(args.outputs): 53 written_input_set = set() # Just for double checking
39 # TODO: Check if the file is right already and then do not update it. 54 for language_ext in (".cc", ".c", ".mm"):
40 with open(output_file, "w") as out: 55 if language_ext == ".cc":
41 out.write("/* This is a Jumbo file. Don't edit. */\n\n") 56 ext_pattern = (".cc", ".cpp")
42 out.write("/* Generated with merge_for_jumbo.py. */\n\n") 57 else:
43 input_limit = (output_index + 1) * input_count / output_count 58 ext_pattern = tuple([language_ext])
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 59
54 out.write("#include \"%s\"\n" % filename) 60 outputs = [x for x in args.outputs if x.endswith(ext_pattern)]
61 inputs = [x for x in all_inputs if x.endswith(ext_pattern)]
Dirk Pranke 2017/07/04 17:15:16 interesting, I didn't realize you could pass a tup
55 62
63 if not outputs:
64 assert not inputs
65 continue
66
67 write_jumbo_files(inputs, outputs, written_input_set, written_output_set)
68
69 header_files = set([x for x in all_inputs if x.endswith(".h")])
70 assert set(args.outputs) == written_output_set, "Did not fill all outputs"
71 files_not_included = set(all_inputs) - written_input_set - header_files
72 assert not files_not_included, "Did not include files: " + files_not_included
56 if args.verbose: 73 if args.verbose:
57 print("Generated %s (%d files) based on %s" % (str(args.outputs), 74 print("Generated %s (%d files) based on %s" % (
58 written_inputs, 75 str(args.outputs), written_inputs, args.file_list))
59 args.file_list))
60 76
61 if __name__ == "__main__": 77 if __name__ == "__main__":
62 main() 78 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698