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

Commit d166f792 authored by Jooyung Han's avatar Jooyung Han Committed by Android (Google) Code Review
Browse files

Merge "apex: make allowed_files prop overridable" into rvc-dev

parents 4c21463f faa5399b
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -1031,9 +1031,6 @@ type apexBundleProperties struct {
	// List of providing APEXes' names so that this APEX can depend on provided shared libraries.
	// List of providing APEXes' names so that this APEX can depend on provided shared libraries.
	Uses []string
	Uses []string


	// A txt file containing list of files that are allowed to be included in this APEX.
	Allowed_files *string

	// package format of this apex variant; could be non-flattened, flattened, or zip.
	// package format of this apex variant; could be non-flattened, flattened, or zip.
	// imageApex, zipApex or flattened
	// imageApex, zipApex or flattened
	ApexType apexPackaging `blueprint:"mutated"`
	ApexType apexPackaging `blueprint:"mutated"`
@@ -1106,6 +1103,9 @@ type overridableProperties struct {
	// Apex Container Package Name.
	// Apex Container Package Name.
	// Override value for attribute package:name in AndroidManifest.xml
	// Override value for attribute package:name in AndroidManifest.xml
	Package_name string
	Package_name string

	// A txt file containing list of files that are allowed to be included in this APEX.
	Allowed_files *string `android:"path"`
}
}


type apexPackaging int
type apexPackaging int
@@ -1510,6 +1510,9 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
}
}


func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
	if a.overridableProperties.Allowed_files != nil {
		android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
	}
	ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
	ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
		androidAppTag, a.overridableProperties.Apps...)
		androidAppTag, a.overridableProperties.Apps...)
}
}
+55 −0
Original line number Original line Diff line number Diff line
@@ -4991,6 +4991,61 @@ func TestApexKeysTxt(t *testing.T) {
	ensureContains(t, content, `name="myapex.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`)
	ensureContains(t, content, `name="myapex.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`)
}
}


func TestAllowedFiles(t *testing.T) {
	ctx, _ := testApex(t, `
		apex {
			name: "myapex",
			key: "myapex.key",
			apps: ["app"],
			allowed_files: "allowed.txt",
		}

		apex_key {
			name: "myapex.key",
			public_key: "testkey.avbpubkey",
			private_key: "testkey.pem",
		}

		android_app {
			name: "app",
			srcs: ["foo/bar/MyClass.java"],
			package_name: "foo",
			sdk_version: "none",
			system_modules: "none",
			apex_available: [ "myapex" ],
		}
	`, withFiles(map[string][]byte{
		"sub/Android.bp": []byte(`
			override_apex {
				name: "override_myapex",
				base: "myapex",
				apps: ["override_app"],
				allowed_files: ":allowed",
			}
			// Overridable "path" property should be referenced indirectly
			filegroup {
				name: "allowed",
				srcs: ["allowed.txt"],
			}
			override_android_app {
				name: "override_app",
				base: "app",
				package_name: "bar",
			}
			`),
	}))

	rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule")
	if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual {
		t.Errorf("allowed_files_file: expected %q but got %q", expected, actual)
	}

	rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule")
	if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual {
		t.Errorf("allowed_files_file: expected %q but got %q", expected, actual)
	}
}

func TestMain(m *testing.M) {
func TestMain(m *testing.M) {
	run := func() int {
	run := func() int {
		setUp()
		setUp()
+2 −2
Original line number Original line Diff line number Diff line
@@ -369,7 +369,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
	emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
	emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
	implicitInputs = append(implicitInputs, a.manifestPbOut)
	implicitInputs = append(implicitInputs, a.manifestPbOut)


	if a.properties.Allowed_files != nil {
	if a.overridableProperties.Allowed_files != nil {
		ctx.Build(pctx, android.BuildParams{
		ctx.Build(pctx, android.BuildParams{
			Rule:        emitApexContentRule,
			Rule:        emitApexContentRule,
			Implicits:   implicitInputs,
			Implicits:   implicitInputs,
@@ -380,7 +380,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
			},
			},
		})
		})
		implicitInputs = append(implicitInputs, imageContentFile)
		implicitInputs = append(implicitInputs, imageContentFile)
		allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Allowed_files))
		allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files))


		phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
		phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
		ctx.Build(pctx, android.BuildParams{
		ctx.Build(pctx, android.BuildParams{