blob: 52d0755723205f079ca8fccd1e9dfe3480efc589 [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"
Vinh Tran457ddef2023-08-02 13:50:26 -040019
Joe Onoratofee845a2023-05-09 08:14:14 -070020 "github.com/google/blueprint"
21)
22
23var (
Joe Onorato981c9262023-06-21 15:16:23 -070024 pctx = android.NewPackageContext("android/soong/aconfig")
Joe Onoratofee845a2023-05-09 08:14:14 -070025
Joe Onorato981c9262023-06-21 15:16:23 -070026 // For aconfig_declarations: Generate cache file
Joe Onoratofee845a2023-05-09 08:14:14 -070027 aconfigRule = pctx.AndroidStaticRule("aconfig",
28 blueprint.RuleParams{
29 Command: `${aconfig} create-cache` +
Joe Onorato81b25ed2023-06-21 13:49:37 -070030 ` --package ${package}` +
Zhi Dou8a35a6f2023-07-19 18:04:24 +000031 ` ${declarations}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070032 ` ${values}` +
Zhi Dou3f65a412023-08-10 21:47:40 +000033 ` ${default-permission}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070034 ` --cache ${out}.tmp` +
Zhi Dou9dc24512023-07-24 21:19:55 +000035 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
Joe Onoratofee845a2023-05-09 08:14:14 -070036 // ` --build-id ${release_version}` +
37 CommandDeps: []string{
38 "${aconfig}",
39 },
40 Restat: true,
Zhi Dou3f65a412023-08-10 21:47:40 +000041 }, "release_version", "package", "declarations", "values", "default-permission")
Joe Onoratofee845a2023-05-09 08:14:14 -070042
Jihoon Kangcca3e0c2023-11-29 19:35:29 +000043 // For create-device-config-sysprops: Generate aconfig flag value map text file
44 aconfigTextRule = pctx.AndroidStaticRule("aconfig_text",
45 blueprint.RuleParams{
46 Command: `${aconfig} dump --format bool` +
47 ` --cache ${in}` +
48 ` --out ${out}.tmp` +
49 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
50 CommandDeps: []string{
51 "${aconfig}",
52 },
53 Restat: true,
54 })
55
Mårten Kongstadfacb8d62023-11-20 14:03:29 +010056 // For all_aconfig_declarations: Combine all parsed_flags proto files
Yu Liueae7b362023-11-16 17:05:47 -080057 AllDeclarationsRule = pctx.AndroidStaticRule("All_aconfig_declarations_dump",
Joe Onorato2f99c472023-06-21 18:10:28 -070058 blueprint.RuleParams{
59 Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
60 CommandDeps: []string{
61 "${aconfig}",
62 },
63 }, "cache_files")
Colin Crossd788b3e2023-11-28 13:14:56 -080064
65 mergeAconfigFilesRule = pctx.AndroidStaticRule("mergeAconfigFilesRule",
66 blueprint.RuleParams{
67 Command: `${aconfig} dump --dedup --format protobuf --out $out $flags`,
68 CommandDeps: []string{"${aconfig}"},
69 }, "flags")
Mårten Kongstadc82f1182023-11-20 15:04:30 +010070 // For exported_java_aconfig_library: Generate a JAR from all
71 // java_aconfig_libraries to be consumed by apps built outside the
72 // platform
73 exportedJavaRule = pctx.AndroidStaticRule("exported_java_aconfig_library",
Mårten Kongstad1258acf2023-12-18 13:47:57 +010074 // For each aconfig cache file, if the cache contains any
75 // exported flags, generate Java flag lookup code for the
76 // exported flags (only). Finally collect all generated code
77 // into the ${out} JAR file.
Mårten Kongstadc82f1182023-11-20 15:04:30 +010078 blueprint.RuleParams{
79 Command: `rm -rf ${out}.tmp` +
Mårten Kongstad1258acf2023-12-18 13:47:57 +010080 `&& for cache in ${cache_files}; do ` +
81 ` if [[ -n "$$(${aconfig} dump --cache $$cache --filter=is_exported:true --format='{fully_qualified_name}')" ]]; then ` +
82 ` ${aconfig} create-java-lib --cache $$cache --mode=exported --out ${out}.tmp; ` +
83 ` fi ` +
84 `done` +
Mårten Kongstadc82f1182023-11-20 15:04:30 +010085 `&& $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
86 `&& rm -rf ${out}.tmp`,
87 CommandDeps: []string{
88 "$aconfig",
89 "$soong_zip",
90 },
91 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -070092)
93
94func init() {
Yu Liu2cc802a2023-09-05 17:19:45 -070095 RegisterBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -070096 pctx.HostBinToolVariable("aconfig", "aconfig")
97 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -070098}
99
Yu Liu2cc802a2023-09-05 17:19:45 -0700100func RegisterBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -0700101 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
102 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
103 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -0700104 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Mårten Kongstadc82f1182023-11-20 15:04:30 +0100105 ctx.RegisterParallelSingletonType("exported_java_aconfig_library", ExportedJavaDeclarationsLibraryFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -0700106}