Merge changes I2b182cd3,Ibf6d9b79 into main
* changes:
Split jarjarIfNecessary out of compileJavaHeader
Convert JavaInfoProvider to *JavaInfo
diff --git a/java/aar.go b/java/aar.go
index 93ff7dd..23561da 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -1348,7 +1348,7 @@
a.headerJarFile = classpathFile
}
- android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
+ android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{
HeaderJars: android.PathsIfNonNil(a.headerJarFile),
ResourceJars: android.PathsIfNonNil(resourceJarFile),
TransitiveLibsHeaderJars: a.transitiveLibsHeaderJars,
diff --git a/java/base.go b/java/base.go
index ba4a729..65a8b30 100644
--- a/java/base.go
+++ b/java/base.go
@@ -1228,14 +1228,17 @@
ctx.ModuleErrorf("headers_only is enabled but Turbine is disabled.")
}
- _, j.headerJarFile, _ =
- j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName,
- extraCombinedJars)
+ _, combinedHeaderJarFile := j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName,
+ extraCombinedJars)
+
+ combinedHeaderJarFile = j.jarjarIfNecessary(ctx, combinedHeaderJarFile, jarName, "turbine")
+ combinedHeaderJarFile = j.repackageFlagsIfNecessary(ctx, combinedHeaderJarFile, jarName, "repackage-turbine")
if ctx.Failed() {
return
}
+ j.headerJarFile = combinedHeaderJarFile
- android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
+ android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{
HeaderJars: android.PathsIfNonNil(j.headerJarFile),
TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
@@ -1347,11 +1350,12 @@
// with sharding enabled. See: b/77284273.
}
extraJars := append(slices.Clone(kotlinHeaderJars), extraCombinedJars...)
- headerJarFileWithoutDepsOrJarjar, j.headerJarFile, j.repackagedHeaderJarFile =
+ var combinedHeaderJarFile android.Path
+ headerJarFileWithoutDepsOrJarjar, combinedHeaderJarFile =
j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars)
- if ctx.Failed() {
- return
- }
+
+ j.headerJarFile = j.jarjarIfNecessary(ctx, combinedHeaderJarFile, jarName, "turbine")
+ j.repackagedHeaderJarFile = j.repackageFlagsIfNecessary(ctx, j.headerJarFile, jarName, "turbine")
}
if len(uniqueJavaFiles) > 0 || len(srcJars) > 0 {
hasErrorproneableFiles := false
@@ -1548,22 +1552,17 @@
}
// jarjar implementation jar if necessary
- if j.expandJarjarRules != nil {
- // Transform classes.jar into classes-jarjar.jar
- jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
- TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
- outputFile = jarjarFile
+ jarjarFile := j.jarjarIfNecessary(ctx, outputFile, jarName, "")
+ outputFile = jarjarFile
- // jarjar resource jar if necessary
- if j.resourceJar != nil {
- resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
- TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
- j.resourceJar = resourceJarJarFile
- }
+ // jarjar resource jar if necessary
+ if j.resourceJar != nil {
+ resourceJarJarFile := j.jarjarIfNecessary(ctx, j.resourceJar, jarName, "resource")
+ j.resourceJar = resourceJarJarFile
+ }
- if ctx.Failed() {
- return
- }
+ if ctx.Failed() {
+ return
}
// Check package restrictions if necessary.
@@ -1753,7 +1752,7 @@
ctx.CheckbuildFile(outputFile)
- android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
+ android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{
HeaderJars: android.PathsIfNonNil(j.headerJarFile),
RepackagedHeaderJars: android.PathsIfNonNil(j.repackagedHeaderJarFile),
TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
@@ -1896,16 +1895,13 @@
func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
deps deps, flags javaBuilderFlags, jarName string,
- extraJars android.Paths) (headerJar, jarjarAndDepsHeaderJar, jarjarAndDepsRepackagedHeaderJar android.Path) {
+ extraJars android.Paths) (headerJar android.Path, combinedHeaderJar android.Path) {
var jars android.Paths
if len(srcFiles) > 0 || len(srcJars) > 0 {
// Compile java sources into turbine.jar.
turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
- if ctx.Failed() {
- return nil, nil, nil
- }
jars = append(jars, turbineJar)
headerJar = turbineJar
}
@@ -1918,33 +1914,11 @@
// we cannot skip the combine step for now if there is only one jar
// since we have to strip META-INF/TRANSITIVE dir from turbine.jar
- combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
- TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
+ combinedHeaderJarOutputPath := android.PathForModuleOut(ctx, "turbine-combined", jarName)
+ TransformJarsToJar(ctx, combinedHeaderJarOutputPath, "for turbine", jars, android.OptionalPath{},
false, nil, []string{"META-INF/TRANSITIVE"})
- jarjarAndDepsHeaderJar = combinedJar
- if j.expandJarjarRules != nil {
- // Transform classes.jar into classes-jarjar.jar
- jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
- TransformJarJar(ctx, jarjarFile, jarjarAndDepsHeaderJar, j.expandJarjarRules)
- jarjarAndDepsHeaderJar = jarjarFile
- if ctx.Failed() {
- return nil, nil, nil
- }
- }
-
- if j.repackageJarjarRules != nil {
- repackagedJarjarFile := android.PathForModuleOut(ctx, "repackaged-turbine-jarjar", jarName)
- TransformJarJar(ctx, repackagedJarjarFile, jarjarAndDepsHeaderJar, j.repackageJarjarRules)
- jarjarAndDepsRepackagedHeaderJar = repackagedJarjarFile
- if ctx.Failed() {
- return nil, nil, nil
- }
- } else {
- jarjarAndDepsRepackagedHeaderJar = jarjarAndDepsHeaderJar
- }
-
- return headerJar, jarjarAndDepsHeaderJar, jarjarAndDepsRepackagedHeaderJar
+ return headerJar, combinedHeaderJarOutputPath
}
func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
@@ -1986,23 +1960,24 @@
return
}
- dep, _ := android.OtherModuleProvider(ctx, module, JavaInfoProvider)
- tag := ctx.OtherModuleDependencyTag(module)
- _, isUsesLibDep := tag.(usesLibraryDependencyTag)
- if tag == libTag || tag == r8LibraryJarTag || isUsesLibDep {
- directLibs = append(directLibs, dep.HeaderJars...)
- } else if tag == staticLibTag {
- directStaticLibs = append(directStaticLibs, dep.HeaderJars...)
- } else {
- // Don't propagate transitive libs for other kinds of dependencies.
- return
- }
+ if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
+ tag := ctx.OtherModuleDependencyTag(module)
+ _, isUsesLibDep := tag.(usesLibraryDependencyTag)
+ if tag == libTag || tag == r8LibraryJarTag || isUsesLibDep {
+ directLibs = append(directLibs, dep.HeaderJars...)
+ } else if tag == staticLibTag {
+ directStaticLibs = append(directStaticLibs, dep.HeaderJars...)
+ } else {
+ // Don't propagate transitive libs for other kinds of dependencies.
+ return
+ }
- if dep.TransitiveLibsHeaderJars != nil {
- transitiveLibs = append(transitiveLibs, dep.TransitiveLibsHeaderJars)
- }
- if dep.TransitiveStaticLibsHeaderJars != nil {
- transitiveStaticLibs = append(transitiveStaticLibs, dep.TransitiveStaticLibsHeaderJars)
+ if dep.TransitiveLibsHeaderJars != nil {
+ transitiveLibs = append(transitiveLibs, dep.TransitiveLibsHeaderJars)
+ }
+ if dep.TransitiveStaticLibsHeaderJars != nil {
+ transitiveStaticLibs = append(transitiveStaticLibs, dep.TransitiveStaticLibsHeaderJars)
+ }
}
})
j.transitiveLibsHeaderJars = android.NewDepSet(android.POSTORDER, directLibs, transitiveLibs)
@@ -2108,9 +2083,10 @@
ctx.VisitDirectDeps(func(module android.Module) {
tag := ctx.OtherModuleDependencyTag(module)
if tag == staticLibTag {
- depInfo, _ := android.OtherModuleProvider(ctx, module, JavaInfoProvider)
- if depInfo.TransitiveSrcFiles != nil {
- fromDeps = append(fromDeps, depInfo.TransitiveSrcFiles)
+ if depInfo, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
+ if depInfo.TransitiveSrcFiles != nil {
+ fromDeps = append(fromDeps, depInfo.TransitiveSrcFiles)
+ }
}
}
})
@@ -2730,11 +2706,21 @@
if j.repackageJarjarRules == nil {
return infile
}
- repackagedJarjarFile := android.PathForModuleOut(ctx, "repackaged-jarjar", info+jarName)
+ repackagedJarjarFile := android.PathForModuleOut(ctx, "repackaged-jarjar", info, jarName)
TransformJarJar(ctx, repackagedJarjarFile, infile, j.repackageJarjarRules)
return repackagedJarjarFile
}
+func (j *Module) jarjarIfNecessary(ctx android.ModuleContext, infile android.Path, jarName, info string) android.Path {
+ if j.expandJarjarRules == nil {
+ return infile
+ }
+ jarjarFile := android.PathForModuleOut(ctx, "jarjar", info, jarName)
+ TransformJarJar(ctx, jarjarFile, infile, j.expandJarjarRules)
+ return jarjarFile
+
+}
+
func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
deps.processorPath = append(deps.processorPath, pluginJars...)
deps.processorClasses = append(deps.processorClasses, pluginClasses...)
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index 3f8735c..90aeb4e 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -130,7 +130,7 @@
d.combinedHeaderJar = d.headerJars[0]
}
- android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
+ android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{
HeaderJars: d.headerJars,
ImplementationAndResourcesJars: d.implementationAndResourceJars,
ImplementationJars: d.implementationJars,
diff --git a/java/dex.go b/java/dex.go
index bb36871..d88e8f8 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -291,8 +291,9 @@
// See b/20667396
var proguardRaiseDeps classpath
ctx.VisitDirectDepsWithTag(proguardRaiseTag, func(m android.Module) {
- dep, _ := android.OtherModuleProvider(ctx, m, JavaInfoProvider)
- proguardRaiseDeps = append(proguardRaiseDeps, dep.RepackagedHeaderJars...)
+ if dep, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider); ok {
+ proguardRaiseDeps = append(proguardRaiseDeps, dep.RepackagedHeaderJars...)
+ }
})
r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars"))
diff --git a/java/hiddenapi.go b/java/hiddenapi.go
index 689c78f..b1a9deb 100644
--- a/java/hiddenapi.go
+++ b/java/hiddenapi.go
@@ -98,8 +98,9 @@
// processing.
classesJars := android.Paths{classesJar}
ctx.VisitDirectDepsWithTag(hiddenApiAnnotationsTag, func(dep android.Module) {
- javaInfo, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
- classesJars = append(classesJars, javaInfo.ImplementationJars...)
+ if javaInfo, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
+ classesJars = append(classesJars, javaInfo.ImplementationJars...)
+ }
})
h.classesJarPaths = classesJars
diff --git a/java/java.go b/java/java.go
index 1d4fa44..ebc4425 100644
--- a/java/java.go
+++ b/java/java.go
@@ -315,14 +315,14 @@
AconfigIntermediateCacheOutputPaths android.Paths
}
-var JavaInfoProvider = blueprint.NewProvider[JavaInfo]()
+var JavaInfoProvider = blueprint.NewProvider[*JavaInfo]()
// SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to
// the sysprop implementation library.
type SyspropPublicStubInfo struct {
// JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to
// the sysprop implementation library.
- JavaInfo JavaInfo
+ JavaInfo *JavaInfo
}
var SyspropPublicStubInfoProvider = blueprint.NewProvider[SyspropPublicStubInfo]()
@@ -2249,14 +2249,17 @@
}
srcFilesInfo = append(srcFilesInfo, provider)
case libTag:
- provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
- classPaths = append(classPaths, provider.HeaderJars...)
+ if provider, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
+ classPaths = append(classPaths, provider.HeaderJars...)
+ }
case bootClasspathTag:
- provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
- bootclassPaths = append(bootclassPaths, provider.HeaderJars...)
+ if provider, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
+ bootclassPaths = append(bootclassPaths, provider.HeaderJars...)
+ }
case staticLibTag:
- provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
- staticLibs = append(staticLibs, provider.HeaderJars...)
+ if provider, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
+ staticLibs = append(staticLibs, provider.HeaderJars...)
+ }
case systemModulesTag:
module := dep.(SystemModulesProvider)
systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...)
@@ -2358,7 +2361,7 @@
ctx.Phony(ctx.ModuleName(), al.stubsJar)
- android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
+ android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{
HeaderJars: android.PathsIfNonNil(al.stubsJar),
ImplementationAndResourcesJars: android.PathsIfNonNil(al.stubsJar),
ImplementationJars: android.PathsIfNonNil(al.stubsJar),
@@ -2787,7 +2790,7 @@
}
}
- android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
+ android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{
HeaderJars: android.PathsIfNonNil(j.combinedHeaderFile),
TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index 38553a6..d794e51 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -168,9 +168,10 @@
var transitiveSrcFiles android.Paths
for _, module := range allModules {
- depInfo, _ := android.OtherModuleProvider(ctx, module, JavaInfoProvider)
- if depInfo.TransitiveSrcFiles != nil {
- transitiveSrcFiles = append(transitiveSrcFiles, depInfo.TransitiveSrcFiles.ToList()...)
+ if depInfo, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
+ if depInfo.TransitiveSrcFiles != nil {
+ transitiveSrcFiles = append(transitiveSrcFiles, depInfo.TransitiveSrcFiles.ToList()...)
+ }
}
}
jarArgs := resourcePathsToJarArgs(transitiveSrcFiles)
diff --git a/java/robolectric.go b/java/robolectric.go
index 4cad5b1..26f4b71 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -214,12 +214,13 @@
}
handleLibDeps := func(dep android.Module, runtimeOnly bool) {
- m, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
if !runtimeOnly {
r.libs = append(r.libs, ctx.OtherModuleName(dep))
}
if !android.InList(ctx.OtherModuleName(dep), config.FrameworkLibraries) {
- combinedJarJars = append(combinedJarJars, m.ImplementationAndResourcesJars...)
+ if m, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
+ combinedJarJars = append(combinedJarJars, m.ImplementationAndResourcesJars...)
+ }
}
}
diff --git a/java/system_modules.go b/java/system_modules.go
index 8e2d5d8..500d7fa 100644
--- a/java/system_modules.go
+++ b/java/system_modules.go
@@ -162,8 +162,9 @@
var jars android.Paths
ctx.VisitDirectDepsWithTag(systemModulesLibsTag, func(module android.Module) {
- dep, _ := android.OtherModuleProvider(ctx, module, JavaInfoProvider)
- jars = append(jars, dep.HeaderJars...)
+ if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
+ jars = append(jars, dep.HeaderJars...)
+ }
})
system.headerJars = jars