blob: 887198bfc56120726731876e018495a4b79a7fda [file] [log] [blame]
Joe Onoratofee845a2023-05-09 08:14:14 -07001// Copyright 2023 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Joe Onorato981c9262023-06-21 15:16:23 -070015package aconfig
Joe Onoratofee845a2023-05-09 08:14:14 -070016
17import (
18 "android/soong/android"
19 "github.com/google/blueprint"
20)
21
22var (
Joe Onorato981c9262023-06-21 15:16:23 -070023 pctx = android.NewPackageContext("android/soong/aconfig")
Joe Onoratofee845a2023-05-09 08:14:14 -070024
Joe Onorato981c9262023-06-21 15:16:23 -070025 // For aconfig_declarations: Generate cache file
Joe Onoratofee845a2023-05-09 08:14:14 -070026 aconfigRule = pctx.AndroidStaticRule("aconfig",
27 blueprint.RuleParams{
28 Command: `${aconfig} create-cache` +
Joe Onorato81b25ed2023-06-21 13:49:37 -070029 ` --package ${package}` +
Zhi Dou8a35a6f2023-07-19 18:04:24 +000030 ` ${declarations}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070031 ` ${values}` +
Zhi Dou3f65a412023-08-10 21:47:40 +000032 ` ${default-permission}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070033 ` --cache ${out}.tmp` +
Zhi Dou9dc24512023-07-24 21:19:55 +000034 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
Joe Onoratofee845a2023-05-09 08:14:14 -070035 // ` --build-id ${release_version}` +
36 CommandDeps: []string{
37 "${aconfig}",
38 },
39 Restat: true,
Zhi Dou3f65a412023-08-10 21:47:40 +000040 }, "release_version", "package", "declarations", "values", "default-permission")
Joe Onoratofee845a2023-05-09 08:14:14 -070041
Joe Onorato981c9262023-06-21 15:16:23 -070042 // For java_aconfig_library: Generate java file
Joe Onorato37f900c2023-07-18 16:58:16 -070043 javaRule = pctx.AndroidStaticRule("java_aconfig_library",
Joe Onoratofee845a2023-05-09 08:14:14 -070044 blueprint.RuleParams{
45 Command: `rm -rf ${out}.tmp` +
46 ` && mkdir -p ${out}.tmp` +
47 ` && ${aconfig} create-java-lib` +
Joe Onoratob7c294a2023-07-28 05:30:25 -070048 ` --mode ${mode}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070049 ` --cache ${in}` +
50 ` --out ${out}.tmp` +
51 ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
52 ` && rm -rf ${out}.tmp`,
53 CommandDeps: []string{
54 "$aconfig",
55 "$soong_zip",
56 },
57 Restat: true,
Joe Onoratob7c294a2023-07-28 05:30:25 -070058 }, "mode")
Joe Onorato2f99c472023-06-21 18:10:28 -070059
Joe Onorato37f900c2023-07-18 16:58:16 -070060 // For java_aconfig_library: Generate java file
61 cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
62 blueprint.RuleParams{
63 Command: `rm -rf ${gendir}` +
64 ` && mkdir -p ${gendir}` +
65 ` && ${aconfig} create-cpp-lib` +
66 ` --cache ${in}` +
67 ` --out ${gendir}`,
68 CommandDeps: []string{
69 "$aconfig",
70 "$soong_zip",
71 },
72 }, "gendir")
73
Joe Onorato2f99c472023-06-21 18:10:28 -070074 // For all_aconfig_declarations
75 allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
76 blueprint.RuleParams{
77 Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
78 CommandDeps: []string{
79 "${aconfig}",
80 },
81 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -070082)
83
84func init() {
85 registerBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -070086 pctx.HostBinToolVariable("aconfig", "aconfig")
87 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -070088}
89
90func registerBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -070091 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
92 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
93 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
Joe Onorato37f900c2023-07-18 16:58:16 -070094 ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
Joe Onorato981c9262023-06-21 15:16:23 -070095 ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -070096 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -070097}