From 3766cb7b6a0d3c1dad9efea93cdc11eaebe52a25 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 7 Apr 2020 15:25:44 +0100 Subject: [PATCH] Ignore PrebuiltDepTag when processing APEX contents When a source and a prebuilt module are present in the same build a dependency is added from the source module to the prebuilt module. Previously, the code for generating the APEX did not recognize that tag and in some cases (e.g. for cc_(prebuilt_)library_shared) will fail the build. This change: 1) Adds a test to reproduce the problem. 2) Improves the debug message by pretty printing the tag. 3) Adds a new ExcludeFromApexContents interface that can be implemented by a tag to declare that it should be excluded from the APEX contents. 4) Ignores tags that implement that interface when generating APEX contents. 5) Implements that interface on prebuiltDependencyTag to fix the test. Bug: 153326844 Bug: 153306490 Test: m nothing Merged-In: I9dd4312c4f995c816c0a31d8d733eb5d7f56e1ea Change-Id: I9dd4312c4f995c816c0a31d8d733eb5d7f56e1ea --- android/apex.go | 11 +++++++++++ android/prebuilt.go | 6 ++++++ apex/apex.go | 5 ++++- apex/apex_test.go | 13 ++++++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/android/apex.go b/android/apex.go index d2fb6a107..9bf6fc717 100644 --- a/android/apex.go +++ b/android/apex.go @@ -19,6 +19,8 @@ import ( "sort" "strconv" "sync" + + "github.com/google/blueprint" ) const ( @@ -117,6 +119,15 @@ type ApexProperties struct { Info ApexInfo `blueprint:"mutated"` } +// Marker interface that identifies dependencies that are excluded from APEX +// contents. +type ExcludeFromApexContentsTag interface { + blueprint.DependencyTag + + // Method that differentiates this interface from others. + ExcludeFromApexContents() +} + // Provides default implementation for the ApexModule interface. APEX-aware // modules are expected to include this struct and call InitApexModule(). type ApexModuleBase struct { diff --git a/android/prebuilt.go b/android/prebuilt.go index c902ec826..82745a498 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -39,6 +39,12 @@ var PrebuiltDepTag prebuiltDependencyTag // Mark this tag so dependencies that use it are excluded from visibility enforcement. func (t prebuiltDependencyTag) ExcludeFromVisibilityEnforcement() {} +// Mark this tag so dependencies that use it are excluded from APEX contents. +func (t prebuiltDependencyTag) ExcludeFromApexContents() {} + +var _ ExcludeFromVisibilityEnforcementTag = PrebuiltDepTag +var _ ExcludeFromApexContentsTag = PrebuiltDepTag + type PrebuiltProperties struct { // When prefer is set to true the prebuilt will be used instead of any source module with // a matching name. diff --git a/apex/apex.go b/apex/apex.go index a87187a18..2a5b4cba4 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1985,6 +1985,9 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // TODO(jiyong) do this using walkPayloadDeps ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { depTag := ctx.OtherModuleDependencyTag(child) + if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok { + return false + } depName := ctx.OtherModuleName(child) if _, isDirectDep := parent.(*apexBundle); isDirectDep { switch depTag { @@ -2146,7 +2149,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName)) } } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { - ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) + ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName) } } } diff --git a/apex/apex_test.go b/apex/apex_test.go index 716e263e1..2e5a2bdc2 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -141,6 +141,7 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr "my_include": nil, "foo/bar/MyClass.java": nil, "prebuilt.jar": nil, + "prebuilt.so": nil, "vendor/foo/devkeys/test.x509.pem": nil, "vendor/foo/devkeys/test.pk8": nil, "testkey.x509.pem": nil, @@ -342,7 +343,7 @@ func TestBasicApex(t *testing.T) { apex_available: [ "myapex" ], } - cc_library { + cc_library_shared { name: "mylib2", srcs: ["mylib.cpp"], system_shared_libs: [], @@ -356,6 +357,16 @@ func TestBasicApex(t *testing.T) { ], } + cc_prebuilt_library_shared { + name: "mylib2", + srcs: ["prebuilt.so"], + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], + } + cc_library_static { name: "libstatic", srcs: ["mylib.cpp"],