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 ( |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [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}` + |
Zhi Dou | 8a35a6f | 2023-07-19 18:04:24 +0000 | [diff] [blame] | 31 | ` ${declarations}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 32 | ` ${values}` + |
Zhi Dou | 3f65a41 | 2023-08-10 21:47:40 +0000 | [diff] [blame] | 33 | ` ${default-permission}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 34 | ` --cache ${out}.tmp` + |
Zhi Dou | 9dc2451 | 2023-07-24 21:19:55 +0000 | [diff] [blame] | 35 | ` && ( 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] | 36 | // ` --build-id ${release_version}` + |
| 37 | CommandDeps: []string{ |
| 38 | "${aconfig}", |
| 39 | }, |
| 40 | Restat: true, |
Zhi Dou | 3f65a41 | 2023-08-10 21:47:40 +0000 | [diff] [blame] | 41 | }, "release_version", "package", "declarations", "values", "default-permission") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 42 | |
Jihoon Kang | cca3e0c | 2023-11-29 19:35:29 +0000 | [diff] [blame] | 43 | // 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 Kongstad | facb8d6 | 2023-11-20 14:03:29 +0100 | [diff] [blame] | 56 | // For all_aconfig_declarations: Combine all parsed_flags proto files |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 57 | AllDeclarationsRule = pctx.AndroidStaticRule("All_aconfig_declarations_dump", |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 58 | blueprint.RuleParams{ |
| 59 | Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`, |
| 60 | CommandDeps: []string{ |
| 61 | "${aconfig}", |
| 62 | }, |
| 63 | }, "cache_files") |
Colin Cross | d788b3e | 2023-11-28 13:14:56 -0800 | [diff] [blame] | 64 | |
| 65 | mergeAconfigFilesRule = pctx.AndroidStaticRule("mergeAconfigFilesRule", |
| 66 | blueprint.RuleParams{ |
| 67 | Command: `${aconfig} dump --dedup --format protobuf --out $out $flags`, |
| 68 | CommandDeps: []string{"${aconfig}"}, |
| 69 | }, "flags") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | func init() { |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 73 | RegisterBuildComponents(android.InitRegistrationContext) |
Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 74 | pctx.HostBinToolVariable("aconfig", "aconfig") |
| 75 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 78 | func RegisterBuildComponents(ctx android.RegistrationContext) { |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 79 | ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory) |
| 80 | ctx.RegisterModuleType("aconfig_values", ValuesFactory) |
| 81 | ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory) |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 82 | ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory) |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 83 | } |