| Index: build/jumbo.gni
|
| diff --git a/build/jumbo.gni b/build/jumbo.gni
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2a08bb9d2c68cef2c8a5b44b5adbd524fc9db3e9
|
| --- /dev/null
|
| +++ b/build/jumbo.gni
|
| @@ -0,0 +1,100 @@
|
| +import("//build/split_static_library.gni") # When someone uses that target_type
|
| +
|
| +declare_args() {
|
| + # If true, use a jumbo build (files compiled together) to speed up
|
| + # compilation.
|
| + use_blink_jumbo_build = true
|
| +
|
| + # A target to exclude from jumbo builds, for optimal round trip time
|
| + # when frequently changing a single cpp file.
|
| + jumbo_build_excluded = ""
|
| +}
|
| +
|
| +template("jumbo_target") {
|
| + use_jumbo_build = use_blink_jumbo_build
|
| + if (defined(invoker.jumbo_build_override)) {
|
| + use_jumbo_build = invoker.jumbo_build_override
|
| + }
|
| + if (target_name == jumbo_build_excluded) {
|
| + use_jumbo_build = false
|
| + }
|
| + excluded_sources = []
|
| + if (defined(invoker.jumbo_excluded_sources)) {
|
| + excluded_sources += invoker.jumbo_excluded_sources
|
| + }
|
| + invoker_sources = invoker.sources
|
| + gen_target_dir = get_path_info(invoker_sources[0], "gen_dir")
|
| + assert(excluded_sources != [] || true) # Prevent "unused variable".
|
| + assert(gen_target_dir != "") # Prevent "unused variable".
|
| +
|
| + if (use_jumbo_build) {
|
| + jumbo_files = []
|
| +
|
| + # Split the sources list into chunks that are not excessively large
|
| + files_per_chunk = 200
|
| + current_file_index = 0
|
| + next_chunk_start = 0
|
| + next_chunk_number = 1
|
| + foreach(source_file, invoker.sources) {
|
| + if (current_file_index == next_chunk_start) {
|
| + jumbo_files += [ "$gen_target_dir/" + target_name + "_jumbo_" +
|
| + next_chunk_number + ".cc" ]
|
| + next_chunk_number += 1
|
| + next_chunk_start += files_per_chunk
|
| + }
|
| + current_file_index += 1
|
| + }
|
| +
|
| + # Create an action that calls a script that merges all the source files.
|
| + action(target_name + "_jumbo") {
|
| + script = "//build/jumbo.py"
|
| + response_file_contents =
|
| + rebase_path(invoker.sources - excluded_sources, gen_target_dir)
|
| + outputs = jumbo_files
|
| + args = [ "--outputs" ] + rebase_path(outputs, root_build_dir) +
|
| + [ "--file-list={{response_file_name}}" ]
|
| + }
|
| + }
|
| +
|
| + target_type = invoker.target_type
|
| + if (use_jumbo_build && target_type == "split_static_library") {
|
| + # Meaningless and also impossible if split_count > len(jumbo_files)
|
| + target_type = "static_library"
|
| +
|
| + # Prevent "unused variable" warning.
|
| + assert(!defined(invoker.split_count) || invoker.split_count > 0)
|
| + }
|
| +
|
| + # Perform the actual operation, either on the original sources or
|
| + # the sources post-jumbo merging.
|
| + target(target_type, target_name) {
|
| + deps = []
|
| + if (defined(invoker.deps)) {
|
| + deps += invoker.deps
|
| + }
|
| +
|
| + # Take everything else not handled above from the invoker.
|
| + variables_to_not_forward = [ "deps" ]
|
| + if (use_jumbo_build) {
|
| + deps += [ ":" + target_name + "_jumbo" ]
|
| + variables_to_not_forward += [ "sources" ]
|
| + assert(jumbo_files != [])
|
| + sources = jumbo_files + excluded_sources
|
| +
|
| + # And the headers so that dependency checks work.
|
| + foreach(source_file, invoker.sources) {
|
| + if (get_path_info(source_file, "extension") == "h") {
|
| + sources += [ source_file ]
|
| + }
|
| + }
|
| + }
|
| + forward_variables_from(invoker, "*", variables_to_not_forward)
|
| + }
|
| +}
|
| +
|
| +set_defaults("jumbo_target") {
|
| + # This sets the default list of configs when the content_source_set target
|
| + # is defined. The default_compiler_configs comes from BUILDCONFIG.gn and
|
| + # is the list normally applied to static libraries and source sets.
|
| + configs = default_compiler_configs
|
| +}
|
|
|