From 58b783b4608309b4da7a0d78f2f9feb8c4ce2918 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 25 May 2021 17:24:47 -0700 Subject: [PATCH 1/3] Remove unused cc.copyDirectlyInAnyApexDependencyTag Bug: 183759446 Test: go test ./build/soong/cc Change-Id: I967f5c42cbf7722843a6455cbc2867a8912033cb Merged-In: I967f5c42cbf7722843a6455cbc2867a8912033cb (cherry picked from commit 243f3c250e46ec48640c7f1e71ab1f16372e055c) --- cc/cc.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 8b279b44a..4bfb132da 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -729,12 +729,6 @@ var ( llndkStubDepTag = dependencyTag{name: "llndk stub"} ) -type copyDirectlyInAnyApexDependencyTag dependencyTag - -func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {} - -var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{} - func IsSharedDepTag(depTag blueprint.DependencyTag) bool { ccLibDepTag, ok := depTag.(libraryDependencyTag) return ok && ccLibDepTag.shared() From 3225be468abf38711a167f4e4af2ab43fc0c1bf5 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 25 May 2021 18:12:57 -0700 Subject: [PATCH 2/3] Make CopyDirectlyInAnyApex match the documentation CopyDirectlyInAnyApex was documented to copy from child to parent, but was copying from parent to child. It is unused, so reverse it to match the documentation. Bug: 183759446 Test: next CL Change-Id: I950c9b5416d66e83d76ca489aeb5e0572e005d5d Merged-In: I950c9b5416d66e83d76ca489aeb5e0572e005d5d (cherry picked from commit 4d4f7d6114abff6db05169701c2be98ed79fa95d) --- android/apex.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/apex.go b/android/apex.go index a79b207a8..4618fe97e 100644 --- a/android/apex.go +++ b/android/apex.go @@ -656,8 +656,8 @@ func UpdateDirectlyInAnyApex(mctx BottomUpMutatorContext, am ApexModule) { mctx.VisitDirectDeps(func(dep Module) { if _, ok := mctx.OtherModuleDependencyTag(dep).(CopyDirectlyInAnyApexTag); ok { depBase := dep.(ApexModule).apexModuleBase() - base.ApexProperties.DirectlyInAnyApex = depBase.ApexProperties.DirectlyInAnyApex - base.ApexProperties.InAnyApex = depBase.ApexProperties.InAnyApex + depBase.ApexProperties.DirectlyInAnyApex = base.ApexProperties.DirectlyInAnyApex + depBase.ApexProperties.InAnyApex = base.ApexProperties.InAnyApex } }) From cbb2b8172df4f1d1191803996434bcccf7528736 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 25 May 2021 18:16:02 -0700 Subject: [PATCH 3/3] Treat java libraries in classpath fragments as directly in apex Coverage is applied to java libraries that are directly in an apex. Mark java libraries that are in an apex through a bootclasspath_fragment or a systemserverclasspath_fragment as directly in the apex by implementing CopyDirectlyInAnyApexTag on the dependency tags used for their contents. Bug: 183759446 Test: TestApexJavaCoverage Change-Id: I0116f5f415083b5194000988cb257454ef115200 Merged-In: I0116f5f415083b5194000988cb257454ef115200 (cherry picked from commit c33e5216f1eb3f837dee89cc65208eff058e9c5e) --- apex/apex_test.go | 74 +++++++++++++++++++++++++ java/bootclasspath_fragment.go | 6 ++ java/systemserver_classpath_fragment.go | 7 +++ 3 files changed, 87 insertions(+) diff --git a/apex/apex_test.go b/apex/apex_test.go index 485743360..8a71d4fb9 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -7439,6 +7439,80 @@ func TestPrebuiltStubLibDep(t *testing.T) { } } +func TestApexJavaCoverage(t *testing.T) { + bp := ` + apex { + name: "myapex", + key: "myapex.key", + java_libs: ["mylib"], + bootclasspath_fragments: ["mybootclasspathfragment"], + systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], + updatable: false, + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + java_library { + name: "mylib", + srcs: ["mylib.java"], + apex_available: ["myapex"], + compile_dex: true, + } + + bootclasspath_fragment { + name: "mybootclasspathfragment", + contents: ["mybootclasspathlib"], + apex_available: ["myapex"], + } + + java_library { + name: "mybootclasspathlib", + srcs: ["mybootclasspathlib.java"], + apex_available: ["myapex"], + compile_dex: true, + } + + systemserverclasspath_fragment { + name: "mysystemserverclasspathfragment", + contents: ["mysystemserverclasspathlib"], + apex_available: ["myapex"], + } + + java_library { + name: "mysystemserverclasspathlib", + srcs: ["mysystemserverclasspathlib.java"], + apex_available: ["myapex"], + compile_dex: true, + } + ` + + result := android.GroupFixturePreparers( + PrepareForTestWithApexBuildComponents, + prepareForTestWithMyapex, + java.PrepareForTestWithJavaDefaultModules, + android.PrepareForTestWithAndroidBuildComponents, + android.FixtureWithRootAndroidBp(bp), + android.FixtureMergeEnv(map[string]string{ + "EMMA_INSTRUMENT": "true", + }), + ).RunTest(t) + + // Make sure jacoco ran on both mylib and mybootclasspathlib + if result.ModuleForTests("mylib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { + t.Errorf("Failed to find jacoco rule for mylib") + } + if result.ModuleForTests("mybootclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { + t.Errorf("Failed to find jacoco rule for mybootclasspathlib") + } + if result.ModuleForTests("mysystemserverclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { + t.Errorf("Failed to find jacoco rule for mysystemserverclasspathlib") + } +} + func TestMain(m *testing.M) { os.Exit(m.Run()) } diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 44803a9ec..792193f9f 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -22,6 +22,7 @@ import ( "android/soong/android" "android/soong/dexpreopt" + "github.com/google/blueprint/proptools" "github.com/google/blueprint" @@ -76,12 +77,17 @@ func (b bootclasspathFragmentContentDependencyTag) ExportMember() bool { return true } +// Contents of bootclasspath fragments in an apex are considered to be directly in the apex, as if +// they were listed in java_libs. +func (b bootclasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {} + // The tag used for the dependency between the bootclasspath_fragment module and its contents. var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{} var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag var _ android.SdkMemberTypeDependencyTag = bootclasspathFragmentContentDepTag +var _ android.CopyDirectlyInAnyApexTag = bootclasspathFragmentContentDepTag func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool { return tag == bootclasspathFragmentContentDepTag diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index f973cf45a..7ffb05602 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -17,6 +17,7 @@ package java import ( "android/soong/android" "android/soong/dexpreopt" + "github.com/google/blueprint" ) @@ -118,6 +119,12 @@ type systemServerClasspathFragmentContentDependencyTag struct { blueprint.BaseDependencyTag } +// Contents of system server fragments in an apex are considered to be directly in the apex, as if +// they were listed in java_libs. +func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {} + +var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag + // The tag used for the dependency between the systemserverclasspath_fragment module and its contents. var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}