Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aa1debe authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Make runtime_resource_overlay product specific."

parents 30e3e9d2 3ef77e89
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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)
			})
		})
	}
}