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

Commit d4f5d932 authored by Dennis Shen's avatar Dennis Shen
Browse files

Add soong unit test for trimmed apex build

BUG: b/259381334
TEST: m nothing
Change-Id: I49e5d31a6f5c4f9a72a6a4b3b2ab7114b996adbc
parent fd659ef7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1125,6 +1125,11 @@ func SetKatiEnabledForTests(config Config) {
	config.katiEnabled = true
}

func SetTrimmedApexEnabledForTests(config Config) {
	config.productVariables.TrimmedApex = new(bool)
	*config.productVariables.TrimmedApex = true
}

func AndroidMkEntriesForTest(t *testing.T, ctx *TestContext, mod blueprint.Module) []AndroidMkEntries {
	t.Helper()
	var p AndroidMkEntriesProvider
+67 −0
Original line number Diff line number Diff line
@@ -9862,3 +9862,70 @@ func TestApexBuildsAgainstApiSurfaceStubLibraries(t *testing.T) {
	libcCoreVariant := result.ModuleForTests("libc.apiimport", "android_arm64_armv8-a_shared").Module()
	android.AssertBoolEquals(t, "core variant should link against source libc", true, hasDep(libfooCoreVariant, libcCoreVariant))
}

func TestTrimmedApex(t *testing.T) {
	bp := `
		apex {
			name: "myapex",
			key: "myapex.key",
			native_shared_libs: ["libfoo","libbaz"],
			min_sdk_version: "29",
			trim_against: "mydcla",
    }
		apex {
			name: "mydcla",
			key: "myapex.key",
			native_shared_libs: ["libfoo","libbar"],
			min_sdk_version: "29",
			file_contexts: ":myapex-file_contexts",
			dynamic_common_lib_apex: true,
		}
		apex_key {
			name: "myapex.key",
		}
		cc_library {
			name: "libfoo",
			shared_libs: ["libc"],
			apex_available: ["myapex","mydcla"],
			min_sdk_version: "29",
		}
		cc_library {
			name: "libbar",
			shared_libs: ["libc"],
			apex_available: ["myapex","mydcla"],
			min_sdk_version: "29",
		}
		cc_library {
			name: "libbaz",
			shared_libs: ["libc"],
			apex_available: ["myapex","mydcla"],
			min_sdk_version: "29",
		}
		cc_api_library {
			name: "libc",
			src: "libc.so",
			min_sdk_version: "29",
			recovery_available: true,
		}
		api_imports {
			name: "api_imports",
			shared_libs: [
				"libc",
			],
			header_libs: [],
		}
		`
	ctx := testApex(t, bp)
	module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
	apexRule := module.MaybeRule("apexRule")
	if apexRule.Rule == nil {
		t.Errorf("Expecting regular apex rule but a non regular apex rule found")
	}

	ctx = testApex(t, bp, android.FixtureModifyConfig(android.SetTrimmedApexEnabledForTests))
	trimmedApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("TrimmedApexRule")
	libs_to_trim := trimmedApexRule.Args["libs_to_trim"]
	android.AssertStringDoesContain(t, "missing lib to trim", libs_to_trim, "libfoo")
	android.AssertStringDoesContain(t, "missing lib to trim", libs_to_trim, "libbar")
	android.AssertStringDoesNotContain(t, "unexpected libs in the libs to trim", libs_to_trim, "libbaz")
}