Browse Source

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
Jaewoong Jung 3 years ago
parent
commit
3ef77e89f0
3 changed files with 104 additions and 0 deletions
  1. 16 0
      androidmk/androidmk/androidmk.go
  2. 20 0
      bpfix/bpfix/bpfix.go
  3. 68 0
      bpfix/bpfix/bpfix_test.go

+ 16 - 0
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{

+ 20 - 0
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{

+ 68 - 0
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)
+			})
+		})
+	}
+}