summaryrefslogtreecommitdiff
path: root/flags/aconfig.gni
blob: 2f5c2a1eb0a35dcf61673880be4809eb69ae76e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#
#  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}" ]
  }
}