Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [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 | |
| 15 | package codegen |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | pctx = android.NewPackageContext("android/soong/aconfig/codegen") |
| 25 | |
| 26 | // For java_aconfig_library: Generate java library |
| 27 | javaRule = pctx.AndroidStaticRule("java_aconfig_library", |
| 28 | blueprint.RuleParams{ |
| 29 | Command: `rm -rf ${out}.tmp` + |
| 30 | ` && mkdir -p ${out}.tmp` + |
| 31 | ` && ${aconfig} create-java-lib` + |
| 32 | ` --mode ${mode}` + |
| 33 | ` --cache ${in}` + |
| 34 | ` --out ${out}.tmp` + |
Zhi Dou | b94c779 | 2024-09-25 21:21:15 +0000 | [diff] [blame] | 35 | ` --allow-instrumentation ${debug}` + |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 36 | ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` + |
| 37 | ` && rm -rf ${out}.tmp`, |
| 38 | CommandDeps: []string{ |
| 39 | "$aconfig", |
| 40 | "$soong_zip", |
| 41 | }, |
| 42 | Restat: true, |
Zhi Dou | b94c779 | 2024-09-25 21:21:15 +0000 | [diff] [blame] | 43 | }, "mode", "debug") |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 44 | |
| 45 | // For cc_aconfig_library: Generate C++ library |
| 46 | cppRule = pctx.AndroidStaticRule("cc_aconfig_library", |
| 47 | blueprint.RuleParams{ |
| 48 | Command: `rm -rf ${gendir}` + |
| 49 | ` && mkdir -p ${gendir}` + |
| 50 | ` && ${aconfig} create-cpp-lib` + |
| 51 | ` --mode ${mode}` + |
| 52 | ` --cache ${in}` + |
Ted Bauer | 10fff94 | 2024-04-29 19:30:23 +0000 | [diff] [blame] | 53 | ` --out ${gendir}` + |
| 54 | ` --allow-instrumentation ${debug}`, |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 55 | CommandDeps: []string{ |
| 56 | "$aconfig", |
| 57 | }, |
Ted Bauer | 10fff94 | 2024-04-29 19:30:23 +0000 | [diff] [blame] | 58 | }, "gendir", "mode", "debug") |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 59 | |
| 60 | // For rust_aconfig_library: Generate Rust library |
| 61 | rustRule = pctx.AndroidStaticRule("rust_aconfig_library", |
| 62 | blueprint.RuleParams{ |
| 63 | Command: `rm -rf ${gendir}` + |
| 64 | ` && mkdir -p ${gendir}` + |
| 65 | ` && ${aconfig} create-rust-lib` + |
| 66 | ` --mode ${mode}` + |
| 67 | ` --cache ${in}` + |
Dennis Shen | 58378c9 | 2024-04-03 19:26:36 +0000 | [diff] [blame] | 68 | ` --allow-instrumentation ${debug}` + |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 69 | ` --out ${gendir}`, |
| 70 | CommandDeps: []string{ |
| 71 | "$aconfig", |
| 72 | }, |
Dennis Shen | 58378c9 | 2024-04-03 19:26:36 +0000 | [diff] [blame] | 73 | }, "gendir", "mode", "debug") |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 74 | ) |
| 75 | |
| 76 | func init() { |
| 77 | RegisterBuildComponents(android.InitRegistrationContext) |
| 78 | pctx.HostBinToolVariable("aconfig", "aconfig") |
| 79 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
| 80 | } |
| 81 | |
| 82 | func RegisterBuildComponents(ctx android.RegistrationContext) { |
Jihoon Kang | 2a43e56 | 2024-02-12 19:05:12 +0000 | [diff] [blame] | 83 | ctx.RegisterModuleType("aconfig_declarations_group", AconfigDeclarationsGroupFactory) |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 84 | ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory) |
| 85 | ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory) |
| 86 | ctx.RegisterModuleType("rust_aconfig_library", RustAconfigLibraryFactory) |
| 87 | } |