From e74ac73bc9d04276bffbdedb3284c9a5aa2fc9c6 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 6 Feb 2020 13:51:46 +0000 Subject: [PATCH] java_sdk_library - Allow it to be replaced by prebuilt Previously, a java_sdk_library called "SDKLIB" would create a prebuilt_etc module called "SDKLIB.xml" which installs the generated XML permission file to /etc/permissions/SDKLIB.xml. That module depended on the java_sdk_library "SDKLIB" to generate the XML file as one of its outputs by specifying srcs: [":SDKLIB{.xml}"]. If the java_sdk_library is replaced by a prebuilt then the SDKLIB.xml module expects the prebuilt to provide the XML permissions file which it doesn't because that is an implementation detail and so the build breaks. A couple of alternative approaches were looked at to fix this. One was to have the logic that replaced the source module with the prebuilt to inform the source module that it was being replaced so it could disable its created module. That lead to a dependency cycle where SDKLIB -> SDKLIB.xml -> SDKLIB{.xml} Another solution was to mark dependency tags in such a way that the prebuilt could automatically identify and disable the SDKLIB.xml module. Similar to how the visibility code will ignore dependencies that are tagged with ExcludeFromVisibilityEnforcementTag. That became very convoluted. Instead the java_sdk_library was changed so that it was not responsible for creating the XML permissions file. Instead it created a genrule called "gen-SDKLIB.xml" to create it and then "SDKLIB.xml" depended on that. The java_sdk_library also depended on the genrule to make the XML permissions file available for APEX and testing. Some refactoring of the APEX code and tests was necessary because they had knowledge of the internal implementation of java_sdk_library. The refactoring insulates them a little better from those details. Bug: 148080325 Test: m droid && TARGET_BUILD_APPS=Camera2 m Change-Id: I597bccbb177b6b6320c3a3edeff467243230d384 --- apex/apex.go | 6 ++-- apex/apex_test.go | 5 +-- java/sdk_library.go | 79 +++++++++++++++++++++++++++++---------------- 3 files changed, 58 insertions(+), 32 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 53bdc1249..eec98da27 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1342,12 +1342,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { } filesInfo = append(filesInfo, af) - pf, _ := sdkLib.OutputFiles(".xml") - if len(pf) != 1 { + pf := sdkLib.XmlPermissionsFile() + if pf == nil { ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName) return false } - filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil)) + filesInfo = append(filesInfo, newApexFile(ctx, pf, pf.Base(), "etc/permissions", etc, nil)) return true // track transitive dependencies } else { ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child)) diff --git a/apex/apex_test.go b/apex/apex_test.go index faf7ae579..8200c8748 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -3470,8 +3470,9 @@ func TestJavaSDKLibrary(t *testing.T) { "etc/permissions/foo.xml", }) // Permission XML should point to the activated path of impl jar of java_sdk_library - xml := ctx.ModuleForTests("foo", "android_common_myapex").Output("foo.xml") - ensureContains(t, xml.Args["content"], ` '$(out)'"), + Out: []string{module.xmlFileName()}, + } + + mctx.CreateModule(genrule.GenRuleFactory, &genRuleProps) + // creates a prebuilt_etc module to actually place the xml file under // /etc/permissions etcProps := struct { @@ -637,7 +662,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) { System_ext_specific *bool }{} etcProps.Name = proptools.StringPtr(module.xmlFileName()) - etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}") + etcProps.Src = proptools.StringPtr(":" + genRuleName) etcProps.Sub_dir = proptools.StringPtr("permissions") if module.SocSpecific() { etcProps.Soc_specific = proptools.BoolPtr(true)