David Duarte | 6b1f088 | 2024-04-16 01:02:34 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2024 Google, Inc. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at: |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | # Generate c++ files for each aconfig file |
| 18 | # |
| 19 | # Parameters: |
| 20 | # sources: aconfig source files |
| 21 | # package: aconfig package |
| 22 | template("aconfig") { |
David Duarte | 8e65a69 | 2024-05-07 22:47:08 +0000 | [diff] [blame] | 23 | assert(defined(invoker.sources), "sources must be set") |
| 24 | assert(defined(invoker.package), "package must be set") |
David Duarte | 6b1f088 | 2024-04-16 01:02:34 +0000 | [diff] [blame] | 25 | |
| 26 | outdir = rebase_path(target_gen_dir) |
| 27 | |
David Duarte | 8e65a69 | 2024-05-07 22:47:08 +0000 | [diff] [blame] | 28 | aconfig_cpp_file_name = string_replace(invoker.package, ".", "_") |
David Duarte | 6b1f088 | 2024-04-16 01:02:34 +0000 | [diff] [blame] | 29 | |
| 30 | aconfig_declarations = [] |
| 31 | |
David Duarte | 8e65a69 | 2024-05-07 22:47:08 +0000 | [diff] [blame] | 32 | foreach(source, invoker.sources) { |
David Duarte | 6b1f088 | 2024-04-16 01:02:34 +0000 | [diff] [blame] | 33 | source = rebase_path(source) |
| 34 | aconfig_declarations += [ "--declarations=${source}" ] |
| 35 | } |
| 36 | |
| 37 | aconfig_cache = "${target_name}_cache" |
| 38 | |
| 39 | action(aconfig_cache) { |
| 40 | script = "//common-mk/file_generator_wrapper.py" |
| 41 | args = [ |
| 42 | "aconfig", |
| 43 | "create-cache", |
David Duarte | 8e65a69 | 2024-05-07 22:47:08 +0000 | [diff] [blame] | 44 | "--package=${invoker.package}", |
David Duarte | 6b1f088 | 2024-04-16 01:02:34 +0000 | [diff] [blame] | 45 | "--cache=${outdir}/${aconfig_cache}", |
| 46 | ] + aconfig_declarations |
| 47 | |
David Duarte | 8e65a69 | 2024-05-07 22:47:08 +0000 | [diff] [blame] | 48 | sources = invoker.sources |
David Duarte | 6b1f088 | 2024-04-16 01:02:34 +0000 | [diff] [blame] | 49 | outputs = [ "${outdir}/${aconfig_cache}" ] |
| 50 | } |
| 51 | |
| 52 | action("${target_name}_cpp") { |
| 53 | script = "//common-mk/file_generator_wrapper.py" |
| 54 | args = [ |
| 55 | "aconfig", |
| 56 | "create-cpp-lib", |
| 57 | "--cache=${outdir}/${aconfig_cache}", |
| 58 | "--out=${outdir}", |
| 59 | ] |
| 60 | |
| 61 | outputs = [ |
| 62 | "${outdir}/include/${aconfig_cpp_file_name}.h", |
| 63 | "${outdir}/${aconfig_cpp_file_name}.cc", |
| 64 | ] |
| 65 | |
| 66 | deps = [ ":${aconfig_cache}" ] |
| 67 | } |
| 68 | |
| 69 | all_dependent_config_name = "_${target_name}_all_dependent_config" |
| 70 | config(all_dependent_config_name) { |
| 71 | include_dirs = [ "${outdir}/include" ] |
| 72 | } |
| 73 | |
| 74 | static_library(target_name) { |
David Duarte | 6b1f088 | 2024-04-16 01:02:34 +0000 | [diff] [blame] | 75 | sources = [ "${outdir}/${aconfig_cpp_file_name}.cc" ] |
| 76 | deps = [ ":${target_name}_cpp" ] + invoker.deps |
| 77 | all_dependent_configs = [ ":${all_dependent_config_name}" ] |
| 78 | } |
| 79 | } |