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

Commit 50599f77 authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge "Add stub_libs properties to bootclasspath_fragment snapshot"

parents 0948060f 895c7140
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -433,6 +433,10 @@ type bootclasspathFragmentSdkMemberProperties struct {
	// Contents of the bootclasspath fragment
	Contents []string

	// Stub_libs properties.
	Stub_libs               []string
	Core_platform_stub_libs []string

	// Flag files by *hiddenAPIFlagFileCategory
	Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
}
@@ -447,6 +451,10 @@ func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx andro
	mctx := ctx.SdkModuleContext()
	flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
	b.Flag_files_by_category = flagFileInfo.categoryToPaths

	// Copy stub_libs properties.
	b.Stub_libs = module.properties.Api.Stub_libs
	b.Core_platform_stub_libs = module.properties.Core_platform_api.Stub_libs
}

func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
@@ -454,11 +462,22 @@ func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.
		propertySet.AddProperty("image_name", *b.Image_name)
	}

	builder := ctx.SnapshotBuilder()
	requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)

	if len(b.Contents) > 0 {
		propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true))
		propertySet.AddPropertyWithTag("contents", b.Contents, requiredMemberDependency)
	}

	if len(b.Stub_libs) > 0 {
		apiPropertySet := propertySet.AddPropertySet("api")
		apiPropertySet.AddPropertyWithTag("stub_libs", b.Stub_libs, requiredMemberDependency)
	}
	if len(b.Core_platform_stub_libs) > 0 {
		corePlatformApiPropertySet := propertySet.AddPropertySet("core_platform_api")
		corePlatformApiPropertySet.AddPropertyWithTag("stub_libs", b.Core_platform_stub_libs, requiredMemberDependency)
	}

	builder := ctx.SnapshotBuilder()
	if b.Flag_files_by_category != nil {
		hiddenAPISet := propertySet.AddPropertySet("hidden_api")
		for _, category := range hiddenAPIFlagFileCategories {
+34 −6
Original line number Diff line number Diff line
@@ -125,10 +125,20 @@ func TestBootclasspathFragment_Coverage(t *testing.T) {
			contents: [
				"mybootlib",
			],
			api: {
				stub_libs: [
					"mysdklibrary",
				],
			},
			coverage: {
				contents: [
					"coveragelib",
				],
				api: {
					stub_libs: [
						"mycoveragestubs",
					],
				},
			},
		}

@@ -147,6 +157,21 @@ func TestBootclasspathFragment_Coverage(t *testing.T) {
			sdk_version: "none",
			compile_dex: true,
		}

		java_sdk_library {
			name: "mysdklibrary",
			srcs: ["Test.java"],
			compile_dex: true,
			public: {enabled: true},
			system: {enabled: true},
		}

		java_sdk_library {
			name: "mycoveragestubs",
			srcs: ["Test.java"],
			compile_dex: true,
			public: {enabled: true},
		}
	`)

	checkContents := func(t *testing.T, result *android.TestResult, expected ...string) {
@@ -154,19 +179,22 @@ func TestBootclasspathFragment_Coverage(t *testing.T) {
		android.AssertArrayString(t, "contents property", expected, module.properties.Contents)
	}

	t.Run("without coverage", func(t *testing.T) {
		result := android.GroupFixturePreparers(
	preparer := android.GroupFixturePreparers(
		prepareForTestWithBootclasspathFragment,
		PrepareForTestWithJavaSdkLibraryFiles,
		FixtureWithLastReleaseApis("mysdklibrary", "mycoveragestubs"),
		prepareWithBp,
		).RunTest(t)
	)

	t.Run("without coverage", func(t *testing.T) {
		result := preparer.RunTest(t)
		checkContents(t, result, "mybootlib")
	})

	t.Run("with coverage", func(t *testing.T) {
		result := android.GroupFixturePreparers(
			prepareForTestWithBootclasspathFragment,
			prepareForTestWithFrameworkCoverage,
			prepareWithBp,
			preparer,
		).RunTest(t)
		checkContents(t, result, "mybootlib", "coveragelib")
	})
+110 −0
Original line number Diff line number Diff line
@@ -165,15 +165,25 @@ sdk_snapshot {
func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
	result := android.GroupFixturePreparers(
		prepareForSdkTestWithJava,
		java.PrepareForTestWithJavaDefaultModules,
		java.PrepareForTestWithJavaSdkLibraryFiles,
		java.FixtureWithLastReleaseApis("mysdklibrary", "mycoreplatform"),
		android.FixtureWithRootAndroidBp(`
			sdk {
				name: "mysdk",
				bootclasspath_fragments: ["mybootclasspathfragment"],
				java_sdk_libs: ["mysdklibrary", "mycoreplatform"],
			}

			bootclasspath_fragment {
				name: "mybootclasspathfragment",
				contents: ["mybootlib"],
				api: {
					stub_libs: ["mysdklibrary"],
				},
				core_platform_api: {
					stub_libs: ["mycoreplatform"],
				},
			}

			java_library {
@@ -183,6 +193,20 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
				sdk_version: "none",
				compile_dex: true,
			}

			java_sdk_library {
				name: "mysdklibrary",
				srcs: ["Test.java"],
				compile_dex: true,
				public: {enabled: true},
			}

			java_sdk_library {
				name: "mycoreplatform",
				srcs: ["Test.java"],
				compile_dex: true,
				public: {enabled: true},
			}
		`),
	).RunTest(t)

@@ -196,6 +220,12 @@ prebuilt_bootclasspath_fragment {
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    contents: ["mybootlib"],
    api: {
        stub_libs: ["mysdklibrary"],
    },
    core_platform_api: {
        stub_libs: ["mycoreplatform"],
    },
}

java_import {
@@ -205,6 +235,38 @@ java_import {
    apex_available: ["//apex_available:platform"],
    jars: ["java/mybootlib.jar"],
}

java_sdk_library_import {
    name: "mysdklibrary",
    prefer: false,
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    shared_library: true,
    compile_dex: true,
    public: {
        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
        stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
        current_api: "sdk_library/public/mysdklibrary.txt",
        removed_api: "sdk_library/public/mysdklibrary-removed.txt",
        sdk_version: "current",
    },
}

java_sdk_library_import {
    name: "mycoreplatform",
    prefer: false,
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    shared_library: true,
    compile_dex: true,
    public: {
        jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
        stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
        current_api: "sdk_library/public/mycoreplatform.txt",
        removed_api: "sdk_library/public/mycoreplatform-removed.txt",
        sdk_version: "current",
    },
}
`),
		checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -215,6 +277,12 @@ prebuilt_bootclasspath_fragment {
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    contents: ["mysdk_mybootlib@current"],
    api: {
        stub_libs: ["mysdk_mysdklibrary@current"],
    },
    core_platform_api: {
        stub_libs: ["mysdk_mycoreplatform@current"],
    },
}

java_import {
@@ -225,15 +293,57 @@ java_import {
    jars: ["java/mybootlib.jar"],
}

java_sdk_library_import {
    name: "mysdk_mysdklibrary@current",
    sdk_member_name: "mysdklibrary",
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    shared_library: true,
    compile_dex: true,
    public: {
        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
        stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
        current_api: "sdk_library/public/mysdklibrary.txt",
        removed_api: "sdk_library/public/mysdklibrary-removed.txt",
        sdk_version: "current",
    },
}

java_sdk_library_import {
    name: "mysdk_mycoreplatform@current",
    sdk_member_name: "mycoreplatform",
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    shared_library: true,
    compile_dex: true,
    public: {
        jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
        stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
        current_api: "sdk_library/public/mycoreplatform.txt",
        removed_api: "sdk_library/public/mycoreplatform-removed.txt",
        sdk_version: "current",
    },
}

sdk_snapshot {
    name: "mysdk@current",
    visibility: ["//visibility:public"],
    bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
    java_boot_libs: ["mysdk_mybootlib@current"],
    java_sdk_libs: [
        "mysdk_mysdklibrary@current",
        "mysdk_mycoreplatform@current",
    ],
}
`),
		checkAllCopyRules(`
.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt
`))
}