diff options
author | 2024-11-06 10:32:06 -0800 | |
---|---|---|
committer | 2024-11-06 10:40:41 -0800 | |
commit | 996b52223ab1e2e95bbcc36e2ca860e0feb12f2a (patch) | |
tree | 2c38a1889148d4df454474ba2e0b93e2435272f5 | |
parent | 09b2a1477a9d969cc108356b161922561be08d83 (diff) |
Replace RuleBuilders in android_info module
Static rules are more performant / lead to smaller ninja files,
and in my opinion, cleaner.
Bug: 375500423
Test: m nothing --no-skip-soong-tests
Change-Id: I10c0e72dce9a6d958886d43ac18b000e81bd887d
-rw-r--r-- | android/android_info.go | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/android/android_info.go b/android/android_info.go index dd78ee42a..a8d3d4e2c 100644 --- a/android/android_info.go +++ b/android/android_info.go @@ -15,9 +15,23 @@ package android import ( + "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) +var ( + mergeAndRemoveComments = pctx.AndroidStaticRule("merge_and_remove_comments", + blueprint.RuleParams{ + Command: "cat $in | grep -v '#' > $out", + }, + ) + androidInfoTxtToProp = pctx.AndroidStaticRule("android_info_txt_to_prop", + blueprint.RuleParams{ + Command: "grep 'require version-' $in | sed -e 's/require version-/ro.build.expect./g' > $out", + }, + ) +) + type androidInfoProperties struct { // Name of output file. Defaults to module name Stem *string @@ -41,28 +55,28 @@ func (p *androidInfoModule) GenerateAndroidBuildActions(ctx ModuleContext) { ctx.ModuleErrorf("Either Board_info_files or Bootloader_board_name should be set. Please remove one of them\n") return } - outName := proptools.StringDefault(p.properties.Stem, ctx.ModuleName()+".txt") - androidInfoTxt := PathForModuleOut(ctx, outName).OutputPath + androidInfoTxtName := proptools.StringDefault(p.properties.Stem, ctx.ModuleName()+".txt") + androidInfoTxt := PathForModuleOut(ctx, androidInfoTxtName) androidInfoProp := androidInfoTxt.ReplaceExtension(ctx, "prop") - rule := NewRuleBuilder(pctx, ctx) - if boardInfoFiles := PathsForModuleSrc(ctx, p.properties.Board_info_files); len(boardInfoFiles) > 0 { - rule.Command().Text("cat").Inputs(boardInfoFiles). - Text(" | grep").FlagWithArg("-v ", "'#'").FlagWithOutput("> ", androidInfoTxt) + ctx.Build(pctx, BuildParams{ + Rule: mergeAndRemoveComments, + Inputs: boardInfoFiles, + Output: androidInfoTxt, + }) } else if bootloaderBoardName := proptools.String(p.properties.Bootloader_board_name); bootloaderBoardName != "" { - rule.Command().Text("echo").Text("'board="+bootloaderBoardName+"'").FlagWithOutput("> ", androidInfoTxt) + WriteFileRule(ctx, androidInfoTxt, "board="+bootloaderBoardName) } else { - rule.Command().Text("echo").Text("''").FlagWithOutput("> ", androidInfoTxt) + WriteFileRule(ctx, androidInfoTxt, "") } - rule.Build(ctx.ModuleName(), "generating android-info.prop") - // Create android_info.prop - rule = NewRuleBuilder(pctx, ctx) - rule.Command().Text("cat").Input(androidInfoTxt). - Text(" | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' >").Output(androidInfoProp) - rule.Build(ctx.ModuleName()+"prop", "generating android-info.prop") + ctx.Build(pctx, BuildParams{ + Rule: androidInfoTxtToProp, + Input: androidInfoTxt, + Output: androidInfoProp, + }) ctx.SetOutputFiles(Paths{androidInfoProp}, "") } |