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

Commit 06417a20 authored by Paul Duffin's avatar Paul Duffin Committed by Automerger Merge Worker
Browse files

Merge "Tighten bootclasspath_fragment property validation" am: 00ceb0e7

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1716110

Change-Id: Ib22ccb73feced50491bae9a537e9d89516e73249
parents 923bb782 00ceb0e7
Loading
Loading
Loading
Loading
+56 −47
Original line number Original line Diff line number Diff line
@@ -168,12 +168,22 @@ func bootclasspathFragmentFactory() android.Module {
// necessary.
// necessary.
func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
	contents := m.properties.Contents
	contents := m.properties.Contents
	if m.properties.Image_name == nil && len(contents) == 0 {
	if len(contents) == 0 {
		ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
		ctx.PropertyErrorf("contents", "required property is missing")
		return
	}

	if m.properties.Image_name == nil {
		// Nothing to do.
		return
	}
	}


	imageName := proptools.String(m.properties.Image_name)
	imageName := proptools.String(m.properties.Image_name)
	if imageName == "art" {
	if imageName != "art" {
		ctx.PropertyErrorf("image_name", `unknown image name %q, expected "art"`, imageName)
		return
	}

	// TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
	// TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
	if android.IsModuleInVersionedSdk(m) {
	if android.IsModuleInVersionedSdk(m) {
		// The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
		// The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
@@ -223,7 +233,6 @@ func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext,
	// Store the jars in the Contents property so that they can be used to add dependencies.
	// Store the jars in the Contents property so that they can be used to add dependencies.
	m.properties.Contents = modules.CopyOfJars()
	m.properties.Contents = modules.CopyOfJars()
}
}
}


// bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this
// bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this
// module (if any) matches the contents.
// module (if any) matches the contents.
+8 −27
Original line number Original line Diff line number Diff line
@@ -29,38 +29,28 @@ var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
	dexpreopt.PrepareForTestByEnablingDexpreopt,
	dexpreopt.PrepareForTestByEnablingDexpreopt,
)
)


func TestUnknownBootclasspathFragment(t *testing.T) {
func TestBootclasspathFragment_UnknownImageName(t *testing.T) {
	prepareForTestWithBootclasspathFragment.
	prepareForTestWithBootclasspathFragment.
		ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
		ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
			`\Qimage_name: Unknown image name "unknown", expected one of art, boot\E`)).
			`\Qimage_name: unknown image name "unknown", expected "art"\E`)).
		RunTestWithBp(t, `
		RunTestWithBp(t, `
			bootclasspath_fragment {
			bootclasspath_fragment {
				name: "unknown-bootclasspath-fragment",
				name: "unknown-bootclasspath-fragment",
				image_name: "unknown",
				image_name: "unknown",
				contents: ["foo"],
			}
			}
		`)
		`)
}
}


func TestUnknownBootclasspathFragmentImageName(t *testing.T) {
func TestPrebuiltBootclasspathFragment_UnknownImageName(t *testing.T) {
	prepareForTestWithBootclasspathFragment.
	prepareForTestWithBootclasspathFragment.
		ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
		ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
			`\Qimage_name: Unknown image name "unknown", expected one of art, boot\E`)).
			`\Qimage_name: unknown image name "unknown", expected "art"\E`)).
		RunTestWithBp(t, `
			bootclasspath_fragment {
				name: "unknown-bootclasspath-fragment",
				image_name: "unknown",
			}
		`)
}

func TestUnknownPrebuiltBootclasspathFragment(t *testing.T) {
	prepareForTestWithBootclasspathFragment.
		ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
			`\Qimage_name: Unknown image name "unknown", expected one of art, boot\E`)).
		RunTestWithBp(t, `
		RunTestWithBp(t, `
			prebuilt_bootclasspath_fragment {
			prebuilt_bootclasspath_fragment {
				name: "unknown-bootclasspath-fragment",
				name: "unknown-bootclasspath-fragment",
				image_name: "unknown",
				image_name: "unknown",
				contents: ["foo"],
			}
			}
		`)
		`)
}
}
@@ -76,6 +66,7 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_Platform(t *testing.T
			bootclasspath_fragment {
			bootclasspath_fragment {
				name: "bootclasspath-fragment",
				name: "bootclasspath-fragment",
				image_name: "art",
				image_name: "art",
				contents: ["foo", "bar"],
				apex_available: [
				apex_available: [
					"apex",
					"apex",
				],
				],
@@ -94,6 +85,7 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testin
			bootclasspath_fragment {
			bootclasspath_fragment {
				name: "bootclasspath-fragment",
				name: "bootclasspath-fragment",
				image_name: "art",
				image_name: "art",
				contents: ["foo", "bar"],
				apex_available: [
				apex_available: [
					"apex1",
					"apex1",
					"apex2",
					"apex2",
@@ -102,17 +94,6 @@ func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testin
		`)
		`)
}
}


func TestBootclasspathFragmentWithoutImageNameOrContents(t *testing.T) {
	prepareForTestWithBootclasspathFragment.
		ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
			`\Qneither of the "image_name" and "contents" properties\E`)).
		RunTestWithBp(t, `
			bootclasspath_fragment {
				name: "bootclasspath-fragment",
			}
		`)
}

func TestBootclasspathFragment_Coverage(t *testing.T) {
func TestBootclasspathFragment_Coverage(t *testing.T) {
	prepareForTestWithFrameworkCoverage := android.FixtureMergeEnv(map[string]string{
	prepareForTestWithFrameworkCoverage := android.FixtureMergeEnv(map[string]string{
		"EMMA_INSTRUMENT":           "true",
		"EMMA_INSTRUMENT":           "true",
+23 −2
Original line number Original line Diff line number Diff line
@@ -424,6 +424,7 @@ func TestBasicSdkWithBootclasspathFragment(t *testing.T) {
	android.GroupFixturePreparers(
	android.GroupFixturePreparers(
		prepareForSdkTestWithApex,
		prepareForSdkTestWithApex,
		prepareForSdkTestWithJava,
		prepareForSdkTestWithJava,
		android.FixtureAddFile("java/mybootlib.jar", nil),
		android.FixtureWithRootAndroidBp(`
		android.FixtureWithRootAndroidBp(`
		sdk {
		sdk {
			name: "mysdk",
			name: "mysdk",
@@ -433,16 +434,27 @@ func TestBasicSdkWithBootclasspathFragment(t *testing.T) {
		bootclasspath_fragment {
		bootclasspath_fragment {
			name: "mybootclasspathfragment",
			name: "mybootclasspathfragment",
			image_name: "art",
			image_name: "art",
			contents: ["mybootlib"],
			apex_available: ["myapex"],
			apex_available: ["myapex"],
		}
		}


		java_library {
			name: "mybootlib",
			apex_available: ["myapex"],
			srcs: ["Test.java"],
			system_modules: "none",
			sdk_version: "none",
			min_sdk_version: "1",
			compile_dex: true,
		}

		sdk_snapshot {
		sdk_snapshot {
			name: "mysdk@1",
			name: "mysdk@1",
			bootclasspath_fragments: ["mybootclasspathfragment_mysdk_1"],
			bootclasspath_fragments: ["mysdk_mybootclasspathfragment@1"],
		}
		}


		prebuilt_bootclasspath_fragment {
		prebuilt_bootclasspath_fragment {
			name: "mybootclasspathfragment_mysdk_1",
			name: "mysdk_mybootclasspathfragment@1",
			sdk_member_name: "mybootclasspathfragment",
			sdk_member_name: "mybootclasspathfragment",
			prefer: false,
			prefer: false,
			visibility: ["//visibility:public"],
			visibility: ["//visibility:public"],
@@ -450,6 +462,15 @@ func TestBasicSdkWithBootclasspathFragment(t *testing.T) {
				"myapex",
				"myapex",
			],
			],
			image_name: "art",
			image_name: "art",
			contents: ["mysdk_mybootlib@1"],
		}

		java_import {
			name: "mysdk_mybootlib@1",
			sdk_member_name: "mybootlib",
			visibility: ["//visibility:public"],
			apex_available: ["com.android.art"],
			jars: ["java/mybootlib.jar"],
		}
		}
	`),
	`),
	).RunTest(t)
	).RunTest(t)