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

Unverified Commit f7442576 authored by Jihoon Kang's avatar Jihoon Kang Committed by Alexander Winkowski
Browse files

Do not propagate boot jars in CLC construction

Bootclasspath libraries are shared and available to apps by default.
Propagating the bootclasspath libraries in CLC and adding them in
manifest fixer may lead to discrepancies between the build time CLC and
the run time CLC, making dexpreopt usesless and leading to performance
regression.

Test: m nothing --no-skip-soong-test
Bug: 390048523
Change-Id: I15bc76a83f03e4575a9a7cd7cc821969f2204bf2
parent 09f6732c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -291,6 +291,11 @@ func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathCont
	// For prebuilts, library should have the same name as the source module.
	lib = android.RemoveOptionalPrebuiltPrefix(lib)

	// Bootclasspath libraries should not be added to CLC.
	if android.InList(lib, ctx.Config().BootJars()) {
		return nil
	}

	devicePath := UnknownInstallLibraryPath
	if installPath == nil {
		if android.InList(lib, CompatUsesLibs) || android.InList(lib, OptionalCompatUsesLibs) {
+69 −0
Original line number Diff line number Diff line
@@ -3128,3 +3128,72 @@ cc_library_shared {
	deps := findDepsOfModule(res, res.ModuleForTests("myjavabin", "android_common").Module(), "mynativelib")
	android.AssertIntEquals(t, "Create a dep on the first variant", 1, len(deps))
}

func TestBootJarNotInUsesLibs(t *testing.T) {
	t.Parallel()
	result := android.GroupFixturePreparers(
		PrepareForTestWithJavaDefaultModules,
		PrepareForTestWithJavaSdkLibraryFiles,
		FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary"),
		FixtureConfigureApexBootJars("myapex:mysdklibrary"),
	).RunTestWithBp(t, `
		bootclasspath_fragment {
			name: "myfragment",
			contents: ["mysdklibrary"],
			hidden_api: {
				split_packages: ["*"],
			},
		}

		java_sdk_library {
			name: "mysdklibrary",
			srcs: ["Test.java"],
			compile_dex: true,
			public: {enabled: true},
			min_sdk_version: "2",
			permitted_packages: ["mysdklibrary"],
			sdk_version: "current",
		}

		java_sdk_library {
			name: "myothersdklibrary",
			srcs: ["Test.java"],
			compile_dex: true,
			public: {enabled: true},
			min_sdk_version: "2",
			permitted_packages: ["myothersdklibrary"],
			sdk_version: "current",
		}

		java_library {
			name: "foo",
			libs: [
				"bar",
				"mysdklibrary.stubs",
			],
			srcs: ["A.java"],
		}

		java_library {
			name: "bar",
			libs: [
				"myothersdklibrary.stubs"
			],
		}
	`)
	ctx := result.TestContext
	fooModule := ctx.ModuleForTests("foo", "android_common")

	androidMkEntries := android.AndroidMkEntriesForTest(t, ctx, fooModule.Module())[0]
	localExportSdkLibraries := androidMkEntries.EntryMap["LOCAL_EXPORT_SDK_LIBRARIES"]
	android.AssertStringListDoesNotContain(t,
		"boot jar should not be included in uses libs entries",
		localExportSdkLibraries,
		"mysdklibrary",
	)
	android.AssertStringListContains(t,
		"non boot jar is included in uses libs entries",
		localExportSdkLibraries,
		"myothersdklibrary",
	)
}