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" |
| 19 | "github.com/google/blueprint" |
| 20 | ) |
| 21 | |
| 22 | var ( |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 23 | pctx = android.NewPackageContext("android/soong/aconfig") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 24 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 25 | // For aconfig_declarations: Generate cache file |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 26 | aconfigRule = pctx.AndroidStaticRule("aconfig", |
| 27 | blueprint.RuleParams{ |
| 28 | Command: `${aconfig} create-cache` + |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 29 | ` --package ${package}` + |
Zhi Dou | 8a35a6f | 2023-07-19 18:04:24 +0000 | [diff] [blame] | 30 | ` ${declarations}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 31 | ` ${values}` + |
Zhi Dou | 3f65a41 | 2023-08-10 21:47:40 +0000 | [diff] [blame^] | 32 | ` ${default-permission}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 33 | ` --cache ${out}.tmp` + |
Zhi Dou | 9dc2451 | 2023-07-24 21:19:55 +0000 | [diff] [blame] | 34 | ` && ( 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] | 35 | // ` --build-id ${release_version}` + |
| 36 | CommandDeps: []string{ |
| 37 | "${aconfig}", |
| 38 | }, |
| 39 | Restat: true, |
Zhi Dou | 3f65a41 | 2023-08-10 21:47:40 +0000 | [diff] [blame^] | 40 | }, "release_version", "package", "declarations", "values", "default-permission") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 41 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 42 | // For java_aconfig_library: Generate java file |
Joe Onorato | 37f900c | 2023-07-18 16:58:16 -0700 | [diff] [blame] | 43 | javaRule = pctx.AndroidStaticRule("java_aconfig_library", |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 44 | blueprint.RuleParams{ |
| 45 | Command: `rm -rf ${out}.tmp` + |
| 46 | ` && mkdir -p ${out}.tmp` + |
| 47 | ` && ${aconfig} create-java-lib` + |
Joe Onorato | b7c294a | 2023-07-28 05:30:25 -0700 | [diff] [blame] | 48 | ` --mode ${mode}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 49 | ` --cache ${in}` + |
| 50 | ` --out ${out}.tmp` + |
| 51 | ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` + |
| 52 | ` && rm -rf ${out}.tmp`, |
| 53 | CommandDeps: []string{ |
| 54 | "$aconfig", |
| 55 | "$soong_zip", |
| 56 | }, |
| 57 | Restat: true, |
Joe Onorato | b7c294a | 2023-07-28 05:30:25 -0700 | [diff] [blame] | 58 | }, "mode") |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 59 | |
Joe Onorato | 37f900c | 2023-07-18 16:58:16 -0700 | [diff] [blame] | 60 | // For java_aconfig_library: Generate java file |
| 61 | cppRule = pctx.AndroidStaticRule("cc_aconfig_library", |
| 62 | blueprint.RuleParams{ |
| 63 | Command: `rm -rf ${gendir}` + |
| 64 | ` && mkdir -p ${gendir}` + |
| 65 | ` && ${aconfig} create-cpp-lib` + |
| 66 | ` --cache ${in}` + |
| 67 | ` --out ${gendir}`, |
| 68 | CommandDeps: []string{ |
| 69 | "$aconfig", |
| 70 | "$soong_zip", |
| 71 | }, |
| 72 | }, "gendir") |
| 73 | |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 74 | // For all_aconfig_declarations |
| 75 | allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump", |
| 76 | blueprint.RuleParams{ |
| 77 | Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`, |
| 78 | CommandDeps: []string{ |
| 79 | "${aconfig}", |
| 80 | }, |
| 81 | }, "cache_files") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 82 | ) |
| 83 | |
| 84 | func init() { |
| 85 | registerBuildComponents(android.InitRegistrationContext) |
Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 86 | pctx.HostBinToolVariable("aconfig", "aconfig") |
| 87 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | func registerBuildComponents(ctx android.RegistrationContext) { |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 91 | ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory) |
| 92 | ctx.RegisterModuleType("aconfig_values", ValuesFactory) |
| 93 | ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory) |
Joe Onorato | 37f900c | 2023-07-18 16:58:16 -0700 | [diff] [blame] | 94 | ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory) |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 95 | ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory) |
Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -0700 | [diff] [blame] | 96 | ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory) |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 97 | } |