OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 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 template("split_static_library") { |
| 6 assert(defined(invoker.split_count), |
| 7 "Must define split_count for split_static_library") |
| 8 |
| 9 # In many conditions the number of inputs will be 1 (because the count will |
| 10 # be conditional on platform or configuration) so optimize that. |
| 11 if (invoker.split_count == 1) { |
| 12 static_library(target_name) { |
| 13 forward_variables_from(invoker, "*") |
| 14 } |
| 15 } else { |
| 16 group_name = target_name |
| 17 |
| 18 generated_static_libraries = [] |
| 19 current_library_index = 0 |
| 20 foreach(current_sources, split_list(invoker.sources, invoker.split_count)) { |
| 21 current_name = "${target_name}_$current_library_index" |
| 22 assert( |
| 23 current_sources != [], |
| 24 "Your values for splitting a static library generate one that has no s
ources.") |
| 25 generated_static_libraries += [ ":$current_name" ] |
| 26 |
| 27 static_library(current_name) { |
| 28 # Generated static library shard gets everything but sources (which |
| 29 # we're redefining) and visibility (which is set to be the group |
| 30 # below). |
| 31 forward_variables_from(invoker, |
| 32 "*", |
| 33 [ |
| 34 "sources", |
| 35 "visibility", |
| 36 ]) |
| 37 sources = current_sources |
| 38 visibility = [ ":$group_name" ] |
| 39 } |
| 40 |
| 41 current_library_index = current_library_index + 1 |
| 42 } |
| 43 |
| 44 group(group_name) { |
| 45 public_deps = generated_static_libraries |
| 46 forward_variables_from(invoker, |
| 47 [ |
| 48 "testonly", |
| 49 "visibility", |
| 50 ]) |
| 51 } |
| 52 } |
| 53 } |
OLD | NEW |