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 15package codegen 16 17import ( 18 "android/soong/android" 19 20 "github.com/google/blueprint" 21) 22 23var ( 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 // LINT.IfChange 30 Command: `rm -rf ${out}.tmp` + 31 ` && mkdir -p ${out}.tmp` + 32 ` && ${aconfig} create-java-lib` + 33 ` --mode ${mode}` + 34 ` --cache ${in}` + 35 ` --out ${out}.tmp` + 36 ` --allow-instrumentation ${debug}` + 37 ` --new-exported ${new_exported}` + 38 ` --check-api-level ${check_api_level}` + 39 ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` + 40 ` && rm -rf ${out}.tmp`, 41 // LINT.ThenChange(/aconfig/init.go) 42 CommandDeps: []string{ 43 "$aconfig", 44 "$soong_zip", 45 }, 46 Restat: true, 47 }, "mode", "debug", "new_exported", "check_api_level") 48 49 // For cc_aconfig_library: Generate C++ library 50 cppRule = pctx.AndroidStaticRule("cc_aconfig_library", 51 blueprint.RuleParams{ 52 Command: `rm -rf ${gendir}` + 53 ` && mkdir -p ${gendir}` + 54 ` && ${aconfig} create-cpp-lib` + 55 ` --mode ${mode}` + 56 ` --cache ${in}` + 57 ` --out ${gendir}`, 58 CommandDeps: []string{ 59 "$aconfig", 60 }, 61 }, "gendir", "mode") 62 63 // For rust_aconfig_library: Generate Rust library 64 rustRule = pctx.AndroidStaticRule("rust_aconfig_library", 65 blueprint.RuleParams{ 66 Command: `rm -rf ${gendir}` + 67 ` && mkdir -p ${gendir}` + 68 ` && ${aconfig} create-rust-lib` + 69 ` --mode ${mode}` + 70 ` --cache ${in}` + 71 ` --out ${gendir}`, 72 CommandDeps: []string{ 73 "$aconfig", 74 }, 75 }, "gendir", "mode") 76) 77 78func init() { 79 RegisterBuildComponents(android.InitRegistrationContext) 80 pctx.HostBinToolVariable("aconfig", "aconfig") 81 pctx.HostBinToolVariable("soong_zip", "soong_zip") 82} 83 84func RegisterBuildComponents(ctx android.RegistrationContext) { 85 ctx.RegisterModuleType("aconfig_declarations_group", AconfigDeclarationsGroupFactory) 86 ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory) 87 ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory) 88 ctx.RegisterModuleType("rust_aconfig_library", RustAconfigLibraryFactory) 89} 90