From 1975d3e326250f8fd002b02faa74b82124b7bae7 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Mon, 16 Oct 2023 23:24:11 +0000 Subject: [PATCH] Disable from-text stub build for coverage build Coverage builds depend on `native` properties for API elements, which are not included in the API signature files and consequently in from-text stubs. As no robust solution for handling this has been planned out at the moment, from-text stub build is disabled for coverage builds. Per go/android-code-coverage-quickstart , Java code coverage is enabled by the three environment variables: `EMMA_INSTRUMENT`, `EMMA_INSTRUMENT_STAIC` and `EMMA_INSTRUMENT_FRAMEWORK`. This change disables from-text stub build if any of the three variables are set to true. Test: go test ./java && m EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true nothing --build-from-text-stub and inspect ninja query to verify that the stub java library module depends on the from-source stub module Bug: 304271961 Change-Id: Ie485c784145de6c253611e698354c4f9e4a30685 --- android/config.go | 9 ++++++++- java/java_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/android/config.go b/android/config.go index 8f72239b9..00dc86e5c 100644 --- a/android/config.go +++ b/android/config.go @@ -2059,8 +2059,15 @@ func (c *config) ApiSurfacesDir(s ApiSurface, version string) string { version) } +func (c *config) JavaCoverageEnabled() bool { + return c.IsEnvTrue("EMMA_INSTRUMENT") || c.IsEnvTrue("EMMA_INSTRUMENT_STATIC") || c.IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") +} + func (c *config) BuildFromTextStub() bool { - return c.buildFromTextStub + // TODO: b/302320354 - Remove the coverage build specific logic once the + // robust solution for handling native properties in from-text stub build + // is implemented. + return c.buildFromTextStub && !c.JavaCoverageEnabled() } func (c *config) SetBuildFromTextStub(b bool) { diff --git a/java/java_test.go b/java/java_test.go index c4fc55bc4..c54c0e68f 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2599,3 +2599,33 @@ func TestApiLibraryDroidstubsDependency(t *testing.T) { currentApiTimestampPath, ) } + +func TestDisableFromTextStubForCoverageBuild(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + PrepareForTestWithJavaSdkLibraryFiles, + PrepareForTestWithJacocoInstrumentation, + FixtureWithLastReleaseApis("foo"), + android.FixtureModifyConfig(func(config android.Config) { + config.SetApiLibraries([]string{"foo"}) + config.SetBuildFromTextStub(true) + }), + android.FixtureModifyEnv(func(env map[string]string) { + env["EMMA_INSTRUMENT"] = "true" + }), + ).RunTestWithBp(t, ` + java_sdk_library { + name: "foo", + srcs: ["A.java"], + } + `) + android.AssertBoolEquals(t, "stub module expected to depend on from-source stub", + true, CheckModuleHasDependency(t, result.TestContext, + apiScopePublic.stubsLibraryModuleName("foo"), "android_common", + apiScopePublic.sourceStubLibraryModuleName("foo"))) + + android.AssertBoolEquals(t, "stub module expected to not depend on from-text stub", + false, CheckModuleHasDependency(t, result.TestContext, + apiScopePublic.stubsLibraryModuleName("foo"), "android_common", + apiScopePublic.apiLibraryModuleName("foo"))) +}