Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 1 | // 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 Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 15 | package aconfig |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Vinh Tran | 457ddef | 2023-08-02 13:50:26 -0400 | [diff] [blame] | 19 | |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" |
| 21 | ) |
| 22 | |
| 23 | var ( |
Yu Liu | f072120 | 2024-07-30 17:30:45 +0000 | [diff] [blame] | 24 | pctx = android.NewPackageContext("android/soong/aconfig") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 25 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 26 | // For aconfig_declarations: Generate cache file |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 27 | aconfigRule = pctx.AndroidStaticRule("aconfig", |
| 28 | blueprint.RuleParams{ |
| 29 | Command: `${aconfig} create-cache` + |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 30 | ` --package ${package}` + |
Yu Liu | eeff222 | 2024-03-19 23:07:34 +0000 | [diff] [blame] | 31 | ` ${container}` + |
Zhi Dou | 8a35a6f | 2023-07-19 18:04:24 +0000 | [diff] [blame] | 32 | ` ${declarations}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 33 | ` ${values}` + |
Zhi Dou | 3f65a41 | 2023-08-10 21:47:40 +0000 | [diff] [blame] | 34 | ` ${default-permission}` + |
Oriol Prieto Gascó | 12887ba | 2024-12-02 22:43:29 +0000 | [diff] [blame] | 35 | ` ${allow-read-write}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 36 | ` --cache ${out}.tmp` + |
Zhi Dou | 9dc2451 | 2023-07-24 21:19:55 +0000 | [diff] [blame] | 37 | ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`, |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 38 | // ` --build-id ${release_version}` + |
| 39 | CommandDeps: []string{ |
| 40 | "${aconfig}", |
| 41 | }, |
| 42 | Restat: true, |
Oriol Prieto Gascó | 12887ba | 2024-12-02 22:43:29 +0000 | [diff] [blame] | 43 | }, "release_version", "package", "container", "declarations", "values", "default-permission", "allow-read-write") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 44 | |
Jihoon Kang | cca3e0c | 2023-11-29 19:35:29 +0000 | [diff] [blame] | 45 | // For create-device-config-sysprops: Generate aconfig flag value map text file |
| 46 | aconfigTextRule = pctx.AndroidStaticRule("aconfig_text", |
| 47 | blueprint.RuleParams{ |
Jihoon Kang | 98ea836 | 2024-07-16 18:20:03 +0000 | [diff] [blame] | 48 | Command: `${aconfig} dump-cache --dedup --format='{fully_qualified_name}:{permission}={state:bool}'` + |
Jihoon Kang | cca3e0c | 2023-11-29 19:35:29 +0000 | [diff] [blame] | 49 | ` --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 Kongstad | facb8d6 | 2023-11-20 14:03:29 +0100 | [diff] [blame] | 58 | // For all_aconfig_declarations: Combine all parsed_flags proto files |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 59 | AllDeclarationsRule = pctx.AndroidStaticRule("All_aconfig_declarations_dump", |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 60 | blueprint.RuleParams{ |
Yu Liu | 748ade2 | 2024-02-08 19:11:39 +0000 | [diff] [blame] | 61 | Command: `${aconfig} dump-cache --dedup --format protobuf --out ${out} ${cache_files}`, |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 62 | CommandDeps: []string{ |
| 63 | "${aconfig}", |
| 64 | }, |
| 65 | }, "cache_files") |
Mårten Kongstad | 2a1adcc | 2024-02-20 12:43:21 +0100 | [diff] [blame] | 66 | 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 Cross | d788b3e | 2023-11-28 13:14:56 -0800 | [diff] [blame] | 73 | |
Yu Liu | bba555e | 2024-02-17 00:36:42 +0000 | [diff] [blame] | 74 | 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 Kongstad | c82f118 | 2023-11-20 15:04:30 +0100 | [diff] [blame] | 82 | // 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 Kongstad | 1258acf | 2023-12-18 13:47:57 +0100 | [diff] [blame] | 86 | // 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 Kongstad | c82f118 | 2023-11-20 15:04:30 +0100 | [diff] [blame] | 90 | blueprint.RuleParams{ |
| 91 | Command: `rm -rf ${out}.tmp` + |
Mårten Kongstad | 1258acf | 2023-12-18 13:47:57 +0100 | [diff] [blame] | 92 | `&& for cache in ${cache_files}; do ` + |
Yu Liu | 748ade2 | 2024-02-08 19:11:39 +0000 | [diff] [blame] | 93 | ` if [ -n "$$(${aconfig} dump-cache --dedup --cache $$cache --filter=is_exported:true --format='{fully_qualified_name}')" ]; then ` + |
Mårten Kongstad | 1258acf | 2023-12-18 13:47:57 +0100 | [diff] [blame] | 94 | ` ${aconfig} create-java-lib --cache $$cache --mode=exported --out ${out}.tmp; ` + |
| 95 | ` fi ` + |
| 96 | `done` + |
Mårten Kongstad | c82f118 | 2023-11-20 15:04:30 +0100 | [diff] [blame] | 97 | `&& $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 Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 104 | ) |
| 105 | |
| 106 | func init() { |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 107 | RegisterBuildComponents(android.InitRegistrationContext) |
Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 108 | pctx.HostBinToolVariable("aconfig", "aconfig") |
| 109 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 112 | func RegisterBuildComponents(ctx android.RegistrationContext) { |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 113 | ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory) |
| 114 | ctx.RegisterModuleType("aconfig_values", ValuesFactory) |
| 115 | ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory) |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 116 | ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory) |
Mårten Kongstad | c82f118 | 2023-11-20 15:04:30 +0100 | [diff] [blame] | 117 | ctx.RegisterParallelSingletonType("exported_java_aconfig_library", ExportedJavaDeclarationsLibraryFactory) |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 118 | } |