blob: 634612d635dafe94623b85a571291b887d976c6f [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}` +
32 ` --cache ${out}.tmp` +
33 ` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
34 // ` --build-id ${release_version}` +
35 CommandDeps: []string{
36 "${aconfig}",
37 },
38 Restat: true,
Zhi Dou8a35a6f2023-07-19 18:04:24 +000039 }, "release_version", "package", "declarations", "values")
Joe Onoratofee845a2023-05-09 08:14:14 -070040
Joe Onorato981c9262023-06-21 15:16:23 -070041 // For java_aconfig_library: Generate java file
Joe Onoratofee845a2023-05-09 08:14:14 -070042 srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar",
43 blueprint.RuleParams{
44 Command: `rm -rf ${out}.tmp` +
45 ` && mkdir -p ${out}.tmp` +
46 ` && ${aconfig} create-java-lib` +
47 ` --cache ${in}` +
48 ` --out ${out}.tmp` +
49 ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
50 ` && rm -rf ${out}.tmp`,
51 CommandDeps: []string{
52 "$aconfig",
53 "$soong_zip",
54 },
55 Restat: true,
56 })
Joe Onorato2f99c472023-06-21 18:10:28 -070057
58 // For all_aconfig_declarations
59 allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
60 blueprint.RuleParams{
61 Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
62 CommandDeps: []string{
63 "${aconfig}",
64 },
65 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -070066)
67
68func init() {
69 registerBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -070070 pctx.HostBinToolVariable("aconfig", "aconfig")
71 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -070072}
73
74func registerBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -070075 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
76 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
77 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
78 ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -070079 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -070080}