blob: 621d619fd70c00065b5d2d876055ec406ab4b180 [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 (
Yu Liuf0721202024-07-30 17:30:45 +000024 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}` +
Yu Liueeff2222024-03-19 23:07:34 +000031 ` ${container}` +
Zhi Dou8a35a6f2023-07-19 18:04:24 +000032 ` ${declarations}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070033 ` ${values}` +
Zhi Dou3f65a412023-08-10 21:47:40 +000034 ` ${default-permission}` +
Oriol Prieto Gascó12887ba2024-12-02 22:43:29 +000035 ` ${allow-read-write}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070036 ` --cache ${out}.tmp` +
Zhi Dou9dc24512023-07-24 21:19:55 +000037 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
Joe Onoratofee845a2023-05-09 08:14:14 -070038 // ` --build-id ${release_version}` +
39 CommandDeps: []string{
40 "${aconfig}",
41 },
42 Restat: true,
Oriol Prieto Gascó12887ba2024-12-02 22:43:29 +000043 }, "release_version", "package", "container", "declarations", "values", "default-permission", "allow-read-write")
Joe Onoratofee845a2023-05-09 08:14:14 -070044
Jihoon Kangcca3e0c2023-11-29 19:35:29 +000045 // For create-device-config-sysprops: Generate aconfig flag value map text file
46 aconfigTextRule = pctx.AndroidStaticRule("aconfig_text",
47 blueprint.RuleParams{
Jihoon Kang98ea8362024-07-16 18:20:03 +000048 Command: `${aconfig} dump-cache --dedup --format='{fully_qualified_name}:{permission}={state:bool}'` +
Jihoon Kangcca3e0c2023-11-29 19:35:29 +000049 ` --cache ${in}` +
50 ` --out ${out}.tmp` +
51 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
52 CommandDeps: []string{
53 "${aconfig}",
54 },
55 Restat: true,
56 })
57
Mårten Kongstadfacb8d62023-11-20 14:03:29 +010058 // For all_aconfig_declarations: Combine all parsed_flags proto files
Yu Liueae7b362023-11-16 17:05:47 -080059 AllDeclarationsRule = pctx.AndroidStaticRule("All_aconfig_declarations_dump",
Joe Onorato2f99c472023-06-21 18:10:28 -070060 blueprint.RuleParams{
Yu Liu748ade22024-02-08 19:11:39 +000061 Command: `${aconfig} dump-cache --dedup --format protobuf --out ${out} ${cache_files}`,
Joe Onorato2f99c472023-06-21 18:10:28 -070062 CommandDeps: []string{
63 "${aconfig}",
64 },
65 }, "cache_files")
Mårten Kongstad2a1adcc2024-02-20 12:43:21 +010066 AllDeclarationsRuleTextProto = pctx.AndroidStaticRule("All_aconfig_declarations_dump_textproto",
67 blueprint.RuleParams{
68 Command: `${aconfig} dump-cache --dedup --format textproto --out ${out} ${cache_files}`,
69 CommandDeps: []string{
70 "${aconfig}",
71 },
72 }, "cache_files")
Colin Crossd788b3e2023-11-28 13:14:56 -080073
Yu Liubba555e2024-02-17 00:36:42 +000074 CreateStorageRule = pctx.AndroidStaticRule("aconfig_create_storage",
75 blueprint.RuleParams{
76 Command: `${aconfig} create-storage --container ${container} --file ${file_type} --out ${out} ${cache_files}`,
77 CommandDeps: []string{
78 "${aconfig}",
79 },
80 }, "container", "file_type", "cache_files")
81
Mårten Kongstadc82f1182023-11-20 15:04:30 +010082 // For exported_java_aconfig_library: Generate a JAR from all
83 // java_aconfig_libraries to be consumed by apps built outside the
84 // platform
85 exportedJavaRule = pctx.AndroidStaticRule("exported_java_aconfig_library",
Mårten Kongstad1258acf2023-12-18 13:47:57 +010086 // For each aconfig cache file, if the cache contains any
87 // exported flags, generate Java flag lookup code for the
88 // exported flags (only). Finally collect all generated code
89 // into the ${out} JAR file.
Mårten Kongstadc82f1182023-11-20 15:04:30 +010090 blueprint.RuleParams{
91 Command: `rm -rf ${out}.tmp` +
Mårten Kongstad1258acf2023-12-18 13:47:57 +010092 `&& for cache in ${cache_files}; do ` +
Yu Liu748ade22024-02-08 19:11:39 +000093 ` 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 +010094 ` ${aconfig} create-java-lib --cache $$cache --mode=exported --out ${out}.tmp; ` +
95 ` fi ` +
96 `done` +
Mårten Kongstadc82f1182023-11-20 15:04:30 +010097 `&& $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
98 `&& rm -rf ${out}.tmp`,
99 CommandDeps: []string{
100 "$aconfig",
101 "$soong_zip",
102 },
103 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -0700104)
105
106func init() {
Yu Liu2cc802a2023-09-05 17:19:45 -0700107 RegisterBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -0700108 pctx.HostBinToolVariable("aconfig", "aconfig")
109 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -0700110}
111
Yu Liu2cc802a2023-09-05 17:19:45 -0700112func RegisterBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -0700113 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
114 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
115 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -0700116 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Mårten Kongstadc82f1182023-11-20 15:04:30 +0100117 ctx.RegisterParallelSingletonType("exported_java_aconfig_library", ExportedJavaDeclarationsLibraryFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -0700118}