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

Commit 40f98736 authored by Wei Li's avatar Wei Li
Browse files

Convert the property "manifest" properly for override_apex.

1) When it is not set in base apex, default file name should be set explicitly in bp2build converter of apex
2) The manifest file path should be used as-is when base apex and override_apex is in the same Android.bp
3) The manifest file path should be prepended with package of base apex when base apex and override_apex is in different Android.bp

Bug: 216442475
Test: m nothing
Change-Id: Icd3523ebc31d885f67bea02aec05dbfc77671e87
parent 707f65d3
Loading
Loading
Loading
Loading
+23 −12
Original line number Diff line number Diff line
@@ -2497,6 +2497,19 @@ func (o *OverrideApex) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
		if !ok {
			continue
		}

		// Manifest is either empty or a file in the directory of base APEX and is not overridable.
		// After it is converted in convertWithBp2build(baseApex, ctx),
		// the attrs.Manifest.Value.Label is the file path relative to the directory
		// of base apex. So the following code converts it to a label that looks like
		// <package of base apex>:<path of manifest file> if base apex and override
		// apex are not in the same package.
		baseApexPackage := ctx.OtherModuleDir(a)
		overrideApexPackage := ctx.ModuleDir()
		if baseApexPackage != overrideApexPackage {
			attrs.Manifest.Value.Label = "//" + baseApexPackage + ":" + attrs.Manifest.Value.Label
		}

		// Key
		if overridableProperties.Key != nil {
			attrs.Key = bazel.LabelAttribute{}
@@ -2760,7 +2773,7 @@ func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
// A small list of exceptions where static executables are allowed in APEXes.
func isStaticExecutableAllowed(apex string, exec string) bool {
	m := map[string][]string{
		"com.android.runtime": []string{
		"com.android.runtime": {
			"linker",
			"linkerconfig",
		},
@@ -3397,11 +3410,11 @@ func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) [
// Adding code to the bootclasspath in new packages will cause issues on module update.
func qBcpPackages() map[string][]string {
	return map[string][]string{
		"conscrypt": []string{
		"conscrypt": {
			"android.net.ssl",
			"com.android.org.conscrypt",
		},
		"updatable-media": []string{
		"updatable-media": {
			"android.media",
		},
	}
@@ -3411,32 +3424,32 @@ func qBcpPackages() map[string][]string {
// Adding code to the bootclasspath in new packages will cause issues on module update.
func rBcpPackages() map[string][]string {
	return map[string][]string{
		"framework-mediaprovider": []string{
		"framework-mediaprovider": {
			"android.provider",
		},
		"framework-permission": []string{
		"framework-permission": {
			"android.permission",
			"android.app.role",
			"com.android.permission",
			"com.android.role",
		},
		"framework-sdkextensions": []string{
		"framework-sdkextensions": {
			"android.os.ext",
		},
		"framework-statsd": []string{
		"framework-statsd": {
			"android.app",
			"android.os",
			"android.util",
			"com.android.internal.statsd",
			"com.android.server.stats",
		},
		"framework-wifi": []string{
		"framework-wifi": {
			"com.android.server.wifi",
			"com.android.wifi.x",
			"android.hardware.wifi",
			"android.net.wifi",
		},
		"framework-tethering": []string{
		"framework-tethering": {
			"android.net",
		},
	}
@@ -3478,9 +3491,7 @@ func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {

func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (bazelApexBundleAttributes, bazel.BazelTargetModuleProperties) {
	var manifestLabelAttribute bazel.LabelAttribute
	if a.properties.Manifest != nil {
		manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
	}
	manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")))

	var androidManifestLabelAttribute bazel.LabelAttribute
	if a.properties.AndroidManifest != nil {
+139 −0
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ apex {
		expectedBazelTargets: []string{
			makeBazelTarget("apex", "com.android.apogee", attrNameToString{
				"file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}
@@ -217,6 +218,7 @@ apex {
		expectedBazelTargets: []string{
			makeBazelTarget("apex", "com.android.apogee", attrNameToString{
				"file_contexts": `"file_contexts_file"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}
@@ -245,6 +247,7 @@ apex {
		expectedBazelTargets: []string{
			makeBazelTarget("apex", "com.android.apogee", attrNameToString{
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}
@@ -288,6 +291,7 @@ filegroup {
        "//conditions:default": [],
    })`,
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}
@@ -336,6 +340,7 @@ filegroup {
        "//conditions:default": [],
    })`,
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}
@@ -366,6 +371,7 @@ filegroup {
        "//conditions:default": [],
    })`,
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}
@@ -401,6 +407,7 @@ filegroup {
        "//conditions:default": [],
    })`,
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}
@@ -643,3 +650,135 @@ override_apex {
			}),
		}})
}

func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
	runOverrideApexTestCase(t, bp2buildTestCase{
		description:                "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
		moduleTypeUnderTest:        "override_apex",
		moduleTypeUnderTestFactory: apex.OverrideApexFactory,
		filesystem: map[string]string{
			"system/sepolicy/apex/Android.bp": `
filegroup {
	name: "com.android.apogee-file_contexts",
	srcs: [ "apogee-file_contexts", ],
	bazel_module: { bp2build_available: false },
}`,
			"a/b/Android.bp": `
apex {
	name: "com.android.apogee",
	bazel_module: { bp2build_available: false },
}
`,
		},
		blueprint: `
override_apex {
	name: "com.google.android.apogee",
	base: ":com.android.apogee",
}
`,
		expectedBazelTargets: []string{
			makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"//a/b:apex_manifest.json"`,
			}),
		}})
}

func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
	runOverrideApexTestCase(t, bp2buildTestCase{
		description:                "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
		moduleTypeUnderTest:        "override_apex",
		moduleTypeUnderTestFactory: apex.OverrideApexFactory,
		filesystem: map[string]string{
			"system/sepolicy/apex/Android.bp": `
filegroup {
	name: "com.android.apogee-file_contexts",
	srcs: [ "apogee-file_contexts", ],
	bazel_module: { bp2build_available: false },
}`,
			"a/b/Android.bp": `
apex {
	name: "com.android.apogee",
  manifest: "apogee_manifest.json",
	bazel_module: { bp2build_available: false },
}
`,
		},
		blueprint: `
override_apex {
	name: "com.google.android.apogee",
  base: ":com.android.apogee",
}
`,
		expectedBazelTargets: []string{
			makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"//a/b:apogee_manifest.json"`,
			}),
		}})
}

func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
	runOverrideApexTestCase(t, bp2buildTestCase{
		description:                "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
		moduleTypeUnderTest:        "override_apex",
		moduleTypeUnderTestFactory: apex.OverrideApexFactory,
		filesystem: map[string]string{
			"system/sepolicy/apex/Android.bp": `
filegroup {
	name: "com.android.apogee-file_contexts",
	srcs: [ "apogee-file_contexts", ],
	bazel_module: { bp2build_available: false },
}`,
		},
		blueprint: `
apex {
	name: "com.android.apogee",
	bazel_module: { bp2build_available: false },
}

override_apex {
	name: "com.google.android.apogee",
  base: ":com.android.apogee",
}
`,
		expectedBazelTargets: []string{
			makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"apex_manifest.json"`,
			}),
		}})
}

func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
	runOverrideApexTestCase(t, bp2buildTestCase{
		description:                "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
		moduleTypeUnderTest:        "override_apex",
		moduleTypeUnderTestFactory: apex.OverrideApexFactory,
		filesystem: map[string]string{
			"system/sepolicy/apex/Android.bp": `
filegroup {
	name: "com.android.apogee-file_contexts",
	srcs: [ "apogee-file_contexts", ],
	bazel_module: { bp2build_available: false },
}`,
		},
		blueprint: `
apex {
	name: "com.android.apogee",
  manifest: "apogee_manifest.json",
	bazel_module: { bp2build_available: false },
}

override_apex {
	name: "com.google.android.apogee",
  base: ":com.android.apogee",
}
`,
		expectedBazelTargets: []string{
			makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
				"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":      `"apogee_manifest.json"`,
			}),
		}})
}