Strip META-INF/services from implementation jars when using as header jars
If a header jar couldn't be built (for example when an API generating annoation processor is in use) the implementation jar is reused as the header jar. If the implementation jar contains an annotation processor listed in META-INF/services/javax.annotation.processing.Processor then later javac executions with the implementation jar in the classpath could attempt to run the annotation processors unexpectedly. Remove the META-INF/services directory when using an implementation jar as a header jar. Bug: 290933559 Test: builds Change-Id: I40d48644bc5a09a9564dc2c4b38f627edd00fcf8
This commit is contained in:
parent
12a1f9182d
commit
f06d8dc8e3
6 changed files with 33 additions and 8 deletions
|
@ -340,6 +340,9 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
|
|||
// App module names can be overridden.
|
||||
entries.SetString("LOCAL_MODULE", app.installApkName)
|
||||
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", app.appProperties.PreventInstall)
|
||||
if app.headerJarFile != nil {
|
||||
entries.SetPath("LOCAL_SOONG_HEADER_JAR", app.headerJarFile)
|
||||
}
|
||||
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", app.exportPackage)
|
||||
if app.dexJarFile.IsSet() {
|
||||
entries.SetPath("LOCAL_SOONG_DEX_JAR", app.dexJarFile.Path())
|
||||
|
|
|
@ -1477,7 +1477,13 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
|||
|
||||
j.implementationJarFile = outputFile
|
||||
if j.headerJarFile == nil {
|
||||
j.headerJarFile = j.implementationJarFile
|
||||
// If this module couldn't generate a header jar (for example due to api generating annotation processors)
|
||||
// then use the implementation jar. Run it through zip2zip first to remove any files in META-INF/services
|
||||
// so that javac on modules that depend on this module don't pick up annotation processors (which may be
|
||||
// missing their implementations) from META-INF/services/javax.annotation.processing.Processor.
|
||||
headerJarFile := android.PathForModuleOut(ctx, "javac-header", jarName)
|
||||
convertImplementationJarToHeaderJar(ctx, j.implementationJarFile, headerJarFile)
|
||||
j.headerJarFile = headerJarFile
|
||||
}
|
||||
|
||||
// enforce syntax check to jacoco filters for any build (http://b/183622051)
|
||||
|
|
|
@ -268,6 +268,12 @@ var (
|
|||
Description: "Check zip alignment",
|
||||
},
|
||||
)
|
||||
|
||||
convertImplementationJarToHeaderJarRule = pctx.AndroidStaticRule("convertImplementationJarToHeaderJar",
|
||||
blueprint.RuleParams{
|
||||
Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} -x 'META-INF/services/**/*'`,
|
||||
CommandDeps: []string{"${config.Zip2ZipCmd}"},
|
||||
})
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -630,6 +636,15 @@ func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePa
|
|||
})
|
||||
}
|
||||
|
||||
func convertImplementationJarToHeaderJar(ctx android.ModuleContext, implementationJarFile android.Path,
|
||||
headerJarFile android.WritablePath) {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: convertImplementationJarToHeaderJarRule,
|
||||
Input: implementationJarFile,
|
||||
Output: headerJarFile,
|
||||
})
|
||||
}
|
||||
|
||||
func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
classesJar android.Path, rulesFile android.Path) {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
|
|
|
@ -135,6 +135,7 @@ func TestHostForDevice(t *testing.T) {
|
|||
|
||||
hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
|
||||
hostJavac := hostModule.Output("javac/host_module.jar")
|
||||
hostJavacHeader := hostModule.Output("javac-header/host_module.jar")
|
||||
hostRes := hostModule.Output("res/host_module.jar")
|
||||
|
||||
hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOSCommonTarget.String())
|
||||
|
@ -148,7 +149,7 @@ func TestHostForDevice(t *testing.T) {
|
|||
|
||||
// check classpath of device module with dependency on host_for_device_module
|
||||
expectedClasspath := "-classpath " + strings.Join(android.Paths{
|
||||
hostJavac.Output,
|
||||
hostJavacHeader.Output,
|
||||
hostImportCombined.Output,
|
||||
}.Strings(), ":")
|
||||
|
||||
|
|
|
@ -71,8 +71,8 @@ func TestJavaFuzz(t *testing.T) {
|
|||
}
|
||||
|
||||
baz := result.ModuleForTests("baz", osCommonTarget).Rule("javac").Output.String()
|
||||
barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac", "bar.jar")
|
||||
bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac", "baz.jar")
|
||||
barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac-header", "bar.jar")
|
||||
bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac-header", "baz.jar")
|
||||
|
||||
android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barOut)
|
||||
android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazOut)
|
||||
|
|
|
@ -160,7 +160,7 @@ java_import {
|
|||
}
|
||||
`),
|
||||
checkAllCopyRules(`
|
||||
.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/myjavalib.jar
|
||||
.intermediates/myjavalib/linux_glibc_common/javac-header/myjavalib.jar -> java/myjavalib.jar
|
||||
aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl
|
||||
`),
|
||||
)
|
||||
|
@ -206,7 +206,7 @@ java_import {
|
|||
`),
|
||||
checkAllCopyRules(`
|
||||
.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/android/myjavalib.jar
|
||||
.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/linux_glibc/myjavalib.jar
|
||||
.intermediates/myjavalib/linux_glibc_common/javac-header/myjavalib.jar -> java/linux_glibc/myjavalib.jar
|
||||
`),
|
||||
)
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ java_system_modules_import {
|
|||
libs: ["mysdk_system-module"],
|
||||
}
|
||||
`),
|
||||
checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac/system-module.jar -> java/system-module.jar"),
|
||||
checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac-header/system-module.jar -> java/system-module.jar"),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -879,7 +879,7 @@ java_import {
|
|||
}
|
||||
`),
|
||||
checkAllCopyRules(`
|
||||
.intermediates/hostjavalib/linux_glibc_common/javac/hostjavalib.jar -> java/hostjavalib.jar
|
||||
.intermediates/hostjavalib/linux_glibc_common/javac-header/hostjavalib.jar -> java/hostjavalib.jar
|
||||
.intermediates/androidjavalib/android_common/turbine-combined/androidjavalib.jar -> java/androidjavalib.jar
|
||||
.intermediates/myjavalib/android_common/javac/myjavalib.jar -> java/android/myjavalib.jar
|
||||
.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/linux_glibc/myjavalib.jar
|
||||
|
|
Loading…
Reference in a new issue