From 3ef77e89f04f8554e6d7d6fe7e7d4141324e1de2 Mon Sep 17 00:00:00 2001 From: Jaewoong Jung Date: Thu, 25 Feb 2021 14:23:47 -0800 Subject: [PATCH] Make runtime_resource_overlay product specific. When mk2bp'ing a runtime_resource_overlay module, make it product specific by default so that it reflects how the current make configuration works. Bug: 155783598 Test: bpfix_test.go Change-Id: Icafa8228fe65ecc5b33ad80ad721e7997fbff383 --- androidmk/androidmk/androidmk.go | 16 ++++++++ bpfix/bpfix/bpfix.go | 20 ++++++++++ bpfix/bpfix/bpfix_test.go | 68 ++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/androidmk/androidmk/androidmk.go b/androidmk/androidmk/androidmk.go index 2d1bbb4a8..b8316a361 100644 --- a/androidmk/androidmk/androidmk.go +++ b/androidmk/androidmk/androidmk.go @@ -48,6 +48,22 @@ var invalidVariableStringToReplacement = map[string]string{ "-": "_dash_", } +// Fix steps that should only run in the androidmk tool, i.e. should only be applied to +// newly-converted Android.bp files. +var fixSteps = bpfix.FixStepsExtension{ + Name: "androidmk", + Steps: []bpfix.FixStep{ + { + Name: "RewriteRuntimeResourceOverlay", + Fix: bpfix.RewriteRuntimeResourceOverlay, + }, + }, +} + +func init() { + bpfix.RegisterFixStepExtension(&fixSteps) +} + func (f *bpFile) insertComment(s string) { f.comments = append(f.comments, &bpparser.CommentGroup{ Comments: []*bpparser.Comment{ diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index 94b825208..fae610189 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -670,6 +670,26 @@ func rewriteAndroidAppImport(f *Fixer) error { return nil } +func RewriteRuntimeResourceOverlay(f *Fixer) error { + for _, def := range f.tree.Defs { + mod, ok := def.(*parser.Module) + if !(ok && mod.Type == "runtime_resource_overlay") { + continue + } + // runtime_resource_overlays are always product specific in Make. + if _, ok := mod.GetProperty("product_specific"); !ok { + prop := &parser.Property{ + Name: "product_specific", + Value: &parser.Bool{ + Value: true, + }, + } + mod.Properties = append(mod.Properties, prop) + } + } + return nil +} + // Removes library dependencies which are empty (and restricted from usage in Soong) func removeEmptyLibDependencies(f *Fixer) error { emptyLibraries := []string{ diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go index ef9814fb8..61dfe1af4 100644 --- a/bpfix/bpfix/bpfix_test.go +++ b/bpfix/bpfix/bpfix_test.go @@ -1056,3 +1056,71 @@ func TestRemovePdkProperty(t *testing.T) { }) } } + +func TestRewriteRuntimeResourceOverlay(t *testing.T) { + tests := []struct { + name string + in string + out string + }{ + { + name: "product_specific runtime_resource_overlay", + in: ` + runtime_resource_overlay { + name: "foo", + resource_dirs: ["res"], + product_specific: true, + } + `, + out: ` + runtime_resource_overlay { + name: "foo", + resource_dirs: ["res"], + product_specific: true, + } + `, + }, + { + // It's probably wrong for runtime_resource_overlay not to be product specific, but let's not + // debate it here. + name: "non-product_specific runtime_resource_overlay", + in: ` + runtime_resource_overlay { + name: "foo", + resource_dirs: ["res"], + product_specific: false, + } + `, + out: ` + runtime_resource_overlay { + name: "foo", + resource_dirs: ["res"], + product_specific: false, + } + `, + }, + { + name: "runtime_resource_overlay without product_specific value", + in: ` + runtime_resource_overlay { + name: "foo", + resource_dirs: ["res"], + } + `, + out: ` + runtime_resource_overlay { + name: "foo", + resource_dirs: ["res"], + product_specific: true, + } + `, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + runPass(t, test.in, test.out, func(fixer *Fixer) error { + return RewriteRuntimeResourceOverlay(fixer) + }) + }) + } +}