LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -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 | |
| 15 | package build_flags |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | pctx = android.NewPackageContext("android/soong/aconfig/build_flags") |
| 25 | |
| 26 | // For build_flag_declarations: Generate cache file |
| 27 | buildFlagRule = pctx.AndroidStaticRule("build-flag-declarations", |
| 28 | blueprint.RuleParams{ |
| 29 | Command: `${buildFlagDeclarations} ` + |
| 30 | ` ${declarations}` + |
| 31 | ` --format pb` + |
| 32 | ` --output ${out}.tmp` + |
| 33 | ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`, |
| 34 | CommandDeps: []string{ |
| 35 | "${buildFlagDeclarations}", |
| 36 | }, |
| 37 | Restat: true, |
| 38 | }, "release_version", "declarations") |
| 39 | |
| 40 | buildFlagTextRule = pctx.AndroidStaticRule("build-flag-declarations-text", |
| 41 | blueprint.RuleParams{ |
| 42 | Command: `${buildFlagDeclarations} --format=textproto` + |
| 43 | ` --intermediate ${in}` + |
| 44 | ` --format textproto` + |
| 45 | ` --output ${out}.tmp` + |
| 46 | ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`, |
| 47 | CommandDeps: []string{ |
| 48 | "${buildFlagDeclarations}", |
| 49 | }, |
| 50 | Restat: true, |
| 51 | }) |
| 52 | |
| 53 | allDeclarationsRule = pctx.AndroidStaticRule("all-build-flag-declarations-dump", |
| 54 | blueprint.RuleParams{ |
| 55 | Command: `${buildFlagDeclarations} ${intermediates} --format pb --output ${out}`, |
| 56 | CommandDeps: []string{ |
| 57 | "${buildFlagDeclarations}", |
| 58 | }, |
| 59 | }, "intermediates") |
| 60 | |
| 61 | allDeclarationsRuleTextProto = pctx.AndroidStaticRule("All_build_flag_declarations_dump_textproto", |
| 62 | blueprint.RuleParams{ |
| 63 | Command: `${buildFlagDeclarations} --intermediate ${in} --format textproto --output ${out}`, |
| 64 | CommandDeps: []string{ |
| 65 | "${buildFlagDeclarations}", |
| 66 | }, |
| 67 | }) |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 68 | |
| 69 | allReleaseConfigContributionsRule = pctx.AndroidStaticRule("all-release-config-contributions-dump", |
| 70 | blueprint.RuleParams{ |
| 71 | Command: `${releaseConfigContributions} ${dirs} --format ${format} --output ${out}`, |
| 72 | CommandDeps: []string{ |
| 73 | "${releaseConfigContributions}", |
| 74 | }, |
| 75 | }, "dirs", "format") |
| 76 | allReleaseConfigContributionsRuleText = pctx.AndroidStaticRule("all-release-config-contributions-dumptext", |
| 77 | blueprint.RuleParams{ |
| 78 | Command: `${releaseConfigContributions} ${dirs} --format ${format} --output ${out}`, |
| 79 | CommandDeps: []string{ |
| 80 | "${releaseConfigContributions}", |
| 81 | }, |
| 82 | }, "dirs", "format") |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 83 | ) |
| 84 | |
| 85 | func init() { |
| 86 | RegisterBuildComponents(android.InitRegistrationContext) |
Justin Yun | 5f53869 | 2024-05-22 20:35:20 +0900 | [diff] [blame] | 87 | pctx.Import("android/soong/android") |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 88 | pctx.HostBinToolVariable("buildFlagDeclarations", "build-flag-declarations") |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 89 | pctx.HostBinToolVariable("releaseConfigContributions", "release-config-contributions") |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | func RegisterBuildComponents(ctx android.RegistrationContext) { |
| 93 | ctx.RegisterModuleType("build_flag_declarations", DeclarationsFactory) |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 94 | ctx.RegisterModuleType("release_config_contributions", ReleaseConfigContributionsFactory) |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 95 | ctx.RegisterParallelSingletonType("all_build_flag_declarations", AllBuildFlagDeclarationsFactory) |
| 96 | } |