OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import("//build/split_static_library.gni") # When someone uses that target_type | |
6 | |
7 declare_args() { | |
8 # If true, use a jumbo build (files compiled together) to speed up | |
9 # compilation. | |
10 use_blink_jumbo_build = false | |
Daniel Bratell
2017/06/28 14:31:00
It is named "blink" here, but considering that the
Dirk Pranke
2017/06/29 23:09:46
How opposed are you to using the 'unity' name rath
Daniel Bratell
2017/06/30 08:22:19
I don't think it's good to call it unity because i
| |
11 | |
12 # A target to exclude from jumbo builds, for optimal round trip time | |
13 # when frequently changing a single cpp file. | |
14 jumbo_build_excluded = "" | |
15 } | |
16 | |
17 # Use this to generate a target which merges sources if possible to | |
18 # compile much faster. | |
19 # | |
20 # Special values. | |
21 # | |
22 # target_type | |
23 # The kind of target to build. For example the string | |
24 # "static_library". | |
25 # | |
26 # jumbo_build_override | |
27 # If set to true, then use jumbo compile even when it is globally | |
28 # disabled. If set to false, then it is disabled even if jumbo is | |
29 # globally enabled. | |
Dirk Pranke
2017/06/29 23:09:46
Overloading a single flag like this seems kinda aw
Daniel Bratell
2017/06/30 08:22:19
Yes, renaming this one would really be useful for
Daniel Bratell
2017/06/30 10:09:53
Done.
| |
30 # | |
31 # jumbo_excluded_sources | |
32 # If set to a list of files, those files will not be merged with | |
33 # the rest. Can be used if files are problematic. | |
34 template("jumbo_target") { | |
35 use_jumbo_build = use_blink_jumbo_build | |
36 if (defined(invoker.jumbo_build_override)) { | |
37 use_jumbo_build = invoker.jumbo_build_override | |
38 } | |
39 if (target_name == jumbo_build_excluded) { | |
40 use_jumbo_build = false | |
41 } | |
42 excluded_sources = [] | |
43 if (defined(invoker.jumbo_excluded_sources)) { | |
44 excluded_sources += invoker.jumbo_excluded_sources | |
45 } | |
46 invoker_sources = invoker.sources | |
47 gen_target_dir = get_path_info(invoker_sources[0], "gen_dir") | |
48 assert(excluded_sources != [] || true) # Prevent "unused variable". | |
49 assert(gen_target_dir != "") # Prevent "unused variable". | |
50 | |
51 if (use_jumbo_build) { | |
52 jumbo_files = [] | |
53 | |
54 # Split the sources list into chunks that are not excessively large | |
55 files_per_chunk = 200 | |
Dirk Pranke
2017/06/29 23:09:46
Maybe we should make this configurable so we can t
Daniel Bratell
2017/06/30 08:22:19
I can make it a declare_args configurable variable
Daniel Bratell
2017/06/30 10:09:53
Done.
| |
56 current_file_index = 0 | |
57 next_chunk_start = 0 | |
58 next_chunk_number = 1 | |
59 foreach(source_file, invoker.sources) { | |
60 if (current_file_index == next_chunk_start) { | |
61 jumbo_files += [ "$gen_target_dir/" + target_name + "_jumbo_" + | |
62 next_chunk_number + ".cc" ] | |
63 next_chunk_number += 1 | |
64 next_chunk_start += files_per_chunk | |
65 } | |
66 current_file_index += 1 | |
67 } | |
68 | |
69 # Create an action that calls a script that merges all the source files. | |
70 action(target_name + "_jumbo") { | |
71 script = "//build/jumbo.py" | |
72 response_file_contents = | |
73 rebase_path(invoker.sources - excluded_sources, gen_target_dir) | |
74 outputs = jumbo_files | |
75 args = [ "--outputs" ] + rebase_path(outputs, root_build_dir) + | |
76 [ "--file-list={{response_file_name}}" ] | |
77 } | |
78 } | |
79 | |
80 target_type = invoker.target_type | |
81 if (use_jumbo_build && target_type == "split_static_library") { | |
82 # Meaningless and also impossible if split_count > len(jumbo_files) | |
83 target_type = "static_library" | |
84 | |
85 # Prevent "unused variable" warning. | |
86 assert(!defined(invoker.split_count) || invoker.split_count > 0) | |
87 } | |
88 | |
89 # Perform the actual operation, either on the original sources or | |
90 # the sources post-jumbo merging. | |
91 target(target_type, target_name) { | |
92 deps = [] | |
93 if (defined(invoker.deps)) { | |
94 deps += invoker.deps | |
95 } | |
96 | |
97 # Take everything else not handled above from the invoker. | |
98 variables_to_not_forward = [ "deps" ] | |
99 if (use_jumbo_build) { | |
100 deps += [ ":" + target_name + "_jumbo" ] | |
101 variables_to_not_forward += [ "sources" ] | |
102 assert(jumbo_files != []) | |
103 sources = jumbo_files + excluded_sources | |
104 | |
105 # Need to keep the headers in sources so that dependency checks | |
106 # work, and we need to keep Objective-C code since they | |
107 # cannot be merged into a cc file (FIXME). | |
108 foreach(source_file, invoker.sources) { | |
109 source_ext = get_path_info(source_file, "extension") | |
110 if (source_ext == "h" || source_ext == "mm") { | |
Daniel Bratell
2017/06/28 14:31:00
I have plans for Objective-C eventually, but I don
| |
111 sources += [ source_file ] | |
112 } | |
113 } | |
114 } | |
115 forward_variables_from(invoker, "*", variables_to_not_forward) | |
116 } | |
117 } | |
118 | |
119 set_defaults("jumbo_target") { | |
120 # This sets the default list of configs when the content_source_set target | |
121 # is defined. The default_compiler_configs comes from BUILDCONFIG.gn and | |
122 # is the list normally applied to static libraries and source sets. | |
123 configs = default_compiler_configs | |
124 } | |
OLD | NEW |