Check package restrictions for Java libs.
Test: m checkbuild; inspect verbose log. Test: Manual - compile with unmet restrictions. Bug: 122937705 Change-Id: I9360ae8b6d9ce016b7827be5e8ffc6eb521809b7
This commit is contained in:
@@ -79,6 +79,10 @@ func (library *Library) AndroidMk() android.AndroidMkData {
|
||||
fmt.Fprintln(w, "LOCAL_EXPORT_SDK_LIBRARIES :=", strings.Join(library.exportedSdkLibs, " "))
|
||||
}
|
||||
|
||||
if len(library.additionalCheckedModules) != 0 {
|
||||
fmt.Fprintln(w, "LOCAL_ADDITIONAL_CHECKED_MODULE +=", strings.Join(library.additionalCheckedModules.Strings(), " "))
|
||||
}
|
||||
|
||||
// Temporary hack: export sources used to compile framework.jar to Make
|
||||
// to be used for droiddoc
|
||||
// TODO(ccross): remove this once droiddoc is in soong
|
||||
|
@@ -113,6 +113,15 @@ var (
|
||||
},
|
||||
"rulesFile")
|
||||
|
||||
packageCheck = pctx.AndroidStaticRule("packageCheck",
|
||||
blueprint.RuleParams{
|
||||
Command: "rm -f $out && " +
|
||||
"${config.PackageCheckCmd} $in $packages && " +
|
||||
"touch $out",
|
||||
CommandDeps: []string{"${config.PackageCheckCmd}"},
|
||||
},
|
||||
"packages")
|
||||
|
||||
jetifier = pctx.AndroidStaticRule("jetifier",
|
||||
blueprint.RuleParams{
|
||||
Command: "${config.JavaCmd} -jar ${config.JetifierJar} -l error -o $out -i $in",
|
||||
@@ -356,6 +365,19 @@ func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
})
|
||||
}
|
||||
|
||||
func CheckJarPackages(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
classesJar android.Path, permittedPackages []string) {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: packageCheck,
|
||||
Description: "packageCheck",
|
||||
Output: outputFile,
|
||||
Input: classesJar,
|
||||
Args: map[string]string{
|
||||
"packages": strings.Join(permittedPackages, " "),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TransformJetifier(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
inputFile android.Path) {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
|
@@ -91,6 +91,7 @@ func init() {
|
||||
pctx.SourcePathVariable("GenKotlinBuildFileCmd", "build/soong/scripts/gen-kotlin-build-file.sh")
|
||||
|
||||
pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
|
||||
pctx.SourcePathVariable("PackageCheckCmd", "build/soong/scripts/package-check.sh")
|
||||
pctx.HostBinToolVariable("ExtractJarPackagesCmd", "extract_jar_packages")
|
||||
pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
|
||||
pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
|
||||
|
20
java/java.go
20
java/java.go
@@ -117,6 +117,10 @@ type CompilerProperties struct {
|
||||
// If set to true, include sources used to compile the module in to the final jar
|
||||
Include_srcs *bool
|
||||
|
||||
// If not empty, classes are restricted to the specified packages and their sub-packages.
|
||||
// This restriction is checked after applying jarjar rules and including static libs.
|
||||
Permitted_packages []string
|
||||
|
||||
// List of modules to use as annotation processors
|
||||
Plugins []string
|
||||
|
||||
@@ -320,6 +324,9 @@ type Module struct {
|
||||
// expanded Jarjar_rules
|
||||
expandJarjarRules android.Path
|
||||
|
||||
// list of additional targets for checkbuild
|
||||
additionalCheckedModules android.Paths
|
||||
|
||||
hiddenAPI
|
||||
dexpreopter
|
||||
}
|
||||
@@ -1196,6 +1203,19 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
j.implementationJarFile = outputFile
|
||||
if j.headerJarFile == nil {
|
||||
j.headerJarFile = j.implementationJarFile
|
||||
|
Reference in New Issue
Block a user