# # Copyright 2024 Google, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Generate c++ files for each aconfig file # # Parameters: # sources: aconfig source files # package: aconfig package template("aconfig") { assert(defined(invoker.sources), "sources must be set") assert(defined(invoker.package), "package must be set") outdir = rebase_path(target_gen_dir) aconfig_cpp_file_name = string_replace(invoker.package, ".", "_") aconfig_declarations = [] foreach(source, invoker.sources) { source = rebase_path(source) aconfig_declarations += [ "--declarations=${source}" ] } aconfig_cache = "${target_name}_cache" action(aconfig_cache) { script = "//common-mk/file_generator_wrapper.py" args = [ "aconfig", "create-cache", "--package=${invoker.package}", "--cache=${outdir}/${aconfig_cache}", ] + aconfig_declarations sources = invoker.sources outputs = [ "${outdir}/${aconfig_cache}" ] } action("${target_name}_cpp") { script = "//common-mk/file_generator_wrapper.py" args = [ "aconfig", "create-cpp-lib", "--cache=${outdir}/${aconfig_cache}", "--out=${outdir}", ] outputs = [ "${outdir}/include/${aconfig_cpp_file_name}.h", "${outdir}/${aconfig_cpp_file_name}.cc", ] deps = [ ":${aconfig_cache}" ] } all_dependent_config_name = "_${target_name}_all_dependent_config" config(all_dependent_config_name) { include_dirs = [ "${outdir}/include" ] } static_library(target_name) { sources = [ "${outdir}/${aconfig_cpp_file_name}.cc" ] deps = [ ":${target_name}_cpp" ] + invoker.deps all_dependent_configs = [ ":${all_dependent_config_name}" ] } }