blob: 256b213cc205ab54aa3497c43ee035d26d1689dd [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 (
Yu Liufa297642024-06-11 00:13:02 +000018 "encoding/gob"
19
Joe Onoratofee845a2023-05-09 08:14:14 -070020 "android/soong/android"
Vinh Tran457ddef2023-08-02 13:50:26 -040021
Joe Onoratofee845a2023-05-09 08:14:14 -070022 "github.com/google/blueprint"
23)
24
25var (
Yu Liufa297642024-06-11 00:13:02 +000026 pkgPath = "android/soong/aconfig"
27 pctx = android.NewPackageContext(pkgPath)
Joe Onoratofee845a2023-05-09 08:14:14 -070028
Joe Onorato981c9262023-06-21 15:16:23 -070029 // For aconfig_declarations: Generate cache file
Joe Onoratofee845a2023-05-09 08:14:14 -070030 aconfigRule = pctx.AndroidStaticRule("aconfig",
31 blueprint.RuleParams{
32 Command: `${aconfig} create-cache` +
Joe Onorato81b25ed2023-06-21 13:49:37 -070033 ` --package ${package}` +
Yu Liueeff2222024-03-19 23:07:34 +000034 ` ${container}` +
Zhi Dou8a35a6f2023-07-19 18:04:24 +000035 ` ${declarations}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070036 ` ${values}` +
Zhi Dou3f65a412023-08-10 21:47:40 +000037 ` ${default-permission}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070038 ` --cache ${out}.tmp` +
Zhi Dou9dc24512023-07-24 21:19:55 +000039 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
Joe Onoratofee845a2023-05-09 08:14:14 -070040 // ` --build-id ${release_version}` +
41 CommandDeps: []string{
42 "${aconfig}",
43 },
44 Restat: true,
Yu Liueeff2222024-03-19 23:07:34 +000045 }, "release_version", "package", "container", "declarations", "values", "default-permission")
Joe Onoratofee845a2023-05-09 08:14:14 -070046
Jihoon Kangcca3e0c2023-11-29 19:35:29 +000047 // For create-device-config-sysprops: Generate aconfig flag value map text file
48 aconfigTextRule = pctx.AndroidStaticRule("aconfig_text",
49 blueprint.RuleParams{
Yu Liu748ade22024-02-08 19:11:39 +000050 Command: `${aconfig} dump-cache --dedup --format='{fully_qualified_name}={state:bool}'` +
Jihoon Kangcca3e0c2023-11-29 19:35:29 +000051 ` --cache ${in}` +
52 ` --out ${out}.tmp` +
53 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
54 CommandDeps: []string{
55 "${aconfig}",
56 },
57 Restat: true,
58 })
59
Mårten Kongstadfacb8d62023-11-20 14:03:29 +010060 // For all_aconfig_declarations: Combine all parsed_flags proto files
Yu Liueae7b362023-11-16 17:05:47 -080061 AllDeclarationsRule = pctx.AndroidStaticRule("All_aconfig_declarations_dump",
Joe Onorato2f99c472023-06-21 18:10:28 -070062 blueprint.RuleParams{
Yu Liu748ade22024-02-08 19:11:39 +000063 Command: `${aconfig} dump-cache --dedup --format protobuf --out ${out} ${cache_files}`,
Joe Onorato2f99c472023-06-21 18:10:28 -070064 CommandDeps: []string{
65 "${aconfig}",
66 },
67 }, "cache_files")
Mårten Kongstad2a1adcc2024-02-20 12:43:21 +010068 AllDeclarationsRuleTextProto = pctx.AndroidStaticRule("All_aconfig_declarations_dump_textproto",
69 blueprint.RuleParams{
70 Command: `${aconfig} dump-cache --dedup --format textproto --out ${out} ${cache_files}`,
71 CommandDeps: []string{
72 "${aconfig}",
73 },
74 }, "cache_files")
Colin Crossd788b3e2023-11-28 13:14:56 -080075
Yu Liubba555e2024-02-17 00:36:42 +000076 CreateStorageRule = pctx.AndroidStaticRule("aconfig_create_storage",
77 blueprint.RuleParams{
78 Command: `${aconfig} create-storage --container ${container} --file ${file_type} --out ${out} ${cache_files}`,
79 CommandDeps: []string{
80 "${aconfig}",
81 },
82 }, "container", "file_type", "cache_files")
83
Mårten Kongstadc82f1182023-11-20 15:04:30 +010084 // For exported_java_aconfig_library: Generate a JAR from all
85 // java_aconfig_libraries to be consumed by apps built outside the
86 // platform
87 exportedJavaRule = pctx.AndroidStaticRule("exported_java_aconfig_library",
Mårten Kongstad1258acf2023-12-18 13:47:57 +010088 // For each aconfig cache file, if the cache contains any
89 // exported flags, generate Java flag lookup code for the
90 // exported flags (only). Finally collect all generated code
91 // into the ${out} JAR file.
Mårten Kongstadc82f1182023-11-20 15:04:30 +010092 blueprint.RuleParams{
93 Command: `rm -rf ${out}.tmp` +
Mårten Kongstad1258acf2023-12-18 13:47:57 +010094 `&& for cache in ${cache_files}; do ` +
Yu Liu748ade22024-02-08 19:11:39 +000095 ` if [ -n "$$(${aconfig} dump-cache --dedup --cache $$cache --filter=is_exported:true --format='{fully_qualified_name}')" ]; then ` +
Mårten Kongstad1258acf2023-12-18 13:47:57 +010096 ` ${aconfig} create-java-lib --cache $$cache --mode=exported --out ${out}.tmp; ` +
97 ` fi ` +
98 `done` +
Mårten Kongstadc82f1182023-11-20 15:04:30 +010099 `&& $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
100 `&& rm -rf ${out}.tmp`,
101 CommandDeps: []string{
102 "$aconfig",
103 "$soong_zip",
104 },
105 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -0700106)
107
108func init() {
Yu Liu2cc802a2023-09-05 17:19:45 -0700109 RegisterBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -0700110 pctx.HostBinToolVariable("aconfig", "aconfig")
111 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Yu Liufa297642024-06-11 00:13:02 +0000112
113 gob.Register(android.AconfigDeclarationsProviderData{})
114 gob.Register(android.ModuleOutPath{})
Joe Onoratofee845a2023-05-09 08:14:14 -0700115}
116
Yu Liu2cc802a2023-09-05 17:19:45 -0700117func RegisterBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -0700118 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
119 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
120 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -0700121 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Mårten Kongstadc82f1182023-11-20 15:04:30 +0100122 ctx.RegisterParallelSingletonType("exported_java_aconfig_library", ExportedJavaDeclarationsLibraryFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -0700123}