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}` + |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 30 | ` --declarations ${in}` + |
| 31 | ` ${values}` + |
| 32 | ` --cache ${out}.tmp` + |
| 33 | ` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`, |
| 34 | // ` --build-id ${release_version}` + |
| 35 | CommandDeps: []string{ |
| 36 | "${aconfig}", |
| 37 | }, |
| 38 | Restat: true, |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 39 | }, "release_version", "package", "values") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 40 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame^] | 41 | // For java_aconfig_library: Generate java file |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 42 | srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar", |
| 43 | blueprint.RuleParams{ |
| 44 | Command: `rm -rf ${out}.tmp` + |
| 45 | ` && mkdir -p ${out}.tmp` + |
| 46 | ` && ${aconfig} create-java-lib` + |
| 47 | ` --cache ${in}` + |
| 48 | ` --out ${out}.tmp` + |
| 49 | ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` + |
| 50 | ` && rm -rf ${out}.tmp`, |
| 51 | CommandDeps: []string{ |
| 52 | "$aconfig", |
| 53 | "$soong_zip", |
| 54 | }, |
| 55 | Restat: true, |
| 56 | }) |
| 57 | ) |
| 58 | |
| 59 | func init() { |
| 60 | registerBuildComponents(android.InitRegistrationContext) |
Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 61 | pctx.HostBinToolVariable("aconfig", "aconfig") |
| 62 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | func registerBuildComponents(ctx android.RegistrationContext) { |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame^] | 66 | ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory) |
| 67 | ctx.RegisterModuleType("aconfig_values", ValuesFactory) |
| 68 | ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory) |
| 69 | ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory) |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 70 | } |