From 91206d9ed1a1e3cb81d1ace021580c4be8362f1f Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 2 Jun 2020 09:52:17 +0100 Subject: [PATCH] Always run package check Previously, the package check was only run when building checkbuild or the phony target created for a specific module. It would not run when building a module that depended upon a library with the permitted_packages property. That was because the package check was only run when the package-check.stamp file was built and that was only added to the phony and checkbuild targets. Instead of touching a separate package-check.stamp file to indicate that the check has been performed this change copies the input jar file to the package check to a separate ../package-check/ file which is then treated as the output of the library and is the input for any dex processing. So, any modules that depend on this library will transitively depend on the output file produced by the package check command and so will ensure that the package check is always run. Test: Removed "android.net" from the permitted_packages for "framework-tethering", build "framework-tethering" which triggered and failed the package check and "com.android.tethering" which did not. Made this change. Built "com.android.tethering" which triggered and then failed the package check. Removed change to "framework-tethering" Bug: 157649935 Change-Id: Ib01aa09e13f80282218049270eb7a58ec5f9f605 --- java/androidmk.go | 25 +------------------------ java/builder.go | 9 ++++++--- java/java.go | 11 ++++------- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/java/androidmk.go b/java/androidmk.go index 62cf169fa..6eb22fd93 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -69,26 +69,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) { hideFromMake = true } - if hideFromMake { - // May still need to add some additional dependencies. This will be called - // once for the platform variant (even if it is not being used) and once each - // for the APEX specific variants. In order to avoid adding the dependency - // multiple times only add it for the platform variant. - checkedModulePaths := library.additionalCheckedModules - if library.IsForPlatform() && len(checkedModulePaths) != 0 { - mainEntries = android.AndroidMkEntries{ - Class: "FAKE", - // Need at least one output file in order for this to take effect. - OutputFile: android.OptionalPathForPath(checkedModulePaths[0]), - Include: "$(BUILD_PHONY_PACKAGE)", - ExtraEntries: []android.AndroidMkExtraEntriesFunc{ - func(entries *android.AndroidMkEntries) { - entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", checkedModulePaths.Strings()...) - }, - }, - } - } - } else { + if !hideFromMake { mainEntries = android.AndroidMkEntries{ Class: "JAVA_LIBRARIES", DistFile: android.OptionalPathForPath(library.distFile), @@ -123,10 +104,6 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs...) - if len(library.additionalCheckedModules) != 0 { - entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...) - } - if library.proguardDictionary != nil { entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", library.proguardDictionary) } diff --git a/java/builder.go b/java/builder.go index a27e5c390..640dba93b 100644 --- a/java/builder.go +++ b/java/builder.go @@ -206,7 +206,7 @@ var ( blueprint.RuleParams{ Command: "rm -f $out && " + "${config.PackageCheckCmd} $in $packages && " + - "touch $out", + "cp $in $out", CommandDeps: []string{"${config.PackageCheckCmd}"}, }, "packages") @@ -547,8 +547,9 @@ func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath, }) } -func CheckJarPackages(ctx android.ModuleContext, outputFile android.WritablePath, - classesJar android.Path, permittedPackages []string) { +func CheckJarPackages(ctx android.ModuleContext, classesJar android.Path, permittedPackages []string) android.ModuleOutPath { + outputFile := android.PathForModuleOut(ctx, "package-check", classesJar.Base()) + ctx.Build(pctx, android.BuildParams{ Rule: packageCheck, Description: "packageCheck", @@ -558,6 +559,8 @@ func CheckJarPackages(ctx android.ModuleContext, outputFile android.WritablePath "packages": strings.Join(permittedPackages, " "), }, }) + + return outputFile } func TransformJetifier(ctx android.ModuleContext, outputFile android.WritablePath, diff --git a/java/java.go b/java/java.go index 76bfa86d6..09df2ad43 100644 --- a/java/java.go +++ b/java/java.go @@ -463,9 +463,6 @@ type Module struct { // expanded Jarjar_rules expandJarjarRules android.Path - // list of additional targets for checkbuild - additionalCheckedModules android.Paths - // Extra files generated by the module type to be added as java resources. extraResources android.Paths @@ -1521,10 +1518,10 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // Check package restrictions if necessary. if len(j.properties.Permitted_packages) > 0 { - // Check packages and copy to package-checked file. - pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp") - CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages) - j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile) + // Check packages and copy input to package-checked file. + // Use the file copied after a successful package check as the output file for this + // module so that any dependencies on this module will trigger the package check. + outputFile = CheckJarPackages(ctx, outputFile, j.properties.Permitted_packages) if ctx.Failed() { return