blob: 2f5c2a1eb0a35dcf61673880be4809eb69ae76e1 [file] [log] [blame]
David Duarte6b1f0882024-04-16 01:02:34 +00001#
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
22template("aconfig") {
David Duarte8e65a692024-05-07 22:47:08 +000023 assert(defined(invoker.sources), "sources must be set")
24 assert(defined(invoker.package), "package must be set")
David Duarte6b1f0882024-04-16 01:02:34 +000025
26 outdir = rebase_path(target_gen_dir)
27
David Duarte8e65a692024-05-07 22:47:08 +000028 aconfig_cpp_file_name = string_replace(invoker.package, ".", "_")
David Duarte6b1f0882024-04-16 01:02:34 +000029
30 aconfig_declarations = []
31
David Duarte8e65a692024-05-07 22:47:08 +000032 foreach(source, invoker.sources) {
David Duarte6b1f0882024-04-16 01:02:34 +000033 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 Duarte8e65a692024-05-07 22:47:08 +000044 "--package=${invoker.package}",
David Duarte6b1f0882024-04-16 01:02:34 +000045 "--cache=${outdir}/${aconfig_cache}",
46 ] + aconfig_declarations
47
David Duarte8e65a692024-05-07 22:47:08 +000048 sources = invoker.sources
David Duarte6b1f0882024-04-16 01:02:34 +000049 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 Duarte6b1f0882024-04-16 01:02:34 +000075 sources = [ "${outdir}/${aconfig_cpp_file_name}.cc" ]
76 deps = [ ":${target_name}_cpp" ] + invoker.deps
77 all_dependent_configs = [ ":${all_dependent_config_name}" ]
78 }
79}