Merge "Update linker.config.pb based on package dependency" into main
diff --git a/android/base_module_context.go b/android/base_module_context.go
index dd38a4e..9be3fad 100644
--- a/android/base_module_context.go
+++ b/android/base_module_context.go
@@ -305,6 +305,12 @@
AllowDisabledModuleDependency(target Module) bool
}
+type AlwaysAllowDisabledModuleDependencyTag struct{}
+
+func (t AlwaysAllowDisabledModuleDependencyTag) AllowDisabledModuleDependency(Module) bool {
+ return true
+}
+
func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool, ignoreBlueprint bool) Module {
aModule, _ := module.(Module)
diff --git a/android/license_metadata.go b/android/license_metadata.go
index 463fd07..eabb1b1 100644
--- a/android/license_metadata.go
+++ b/android/license_metadata.go
@@ -77,6 +77,11 @@
if ctx.OtherModuleDependencyTag(dep) == DefaultsDepTag {
return
}
+ // The required dependencies just say modules A and B should be installed together.
+ // It doesn't mean that one is built using the other.
+ if ctx.OtherModuleDependencyTag(dep) == RequiredDepTag {
+ return
+ }
if info, ok := OtherModuleProvider(ctx, dep, LicenseMetadataProvider); ok {
allDepMetadataFiles = append(allDepMetadataFiles, info.LicenseMetadataPath)
diff --git a/android/module.go b/android/module.go
index 000476c..cce4fa6 100644
--- a/android/module.go
+++ b/android/module.go
@@ -542,6 +542,15 @@
var teamDepTag = TeamDepTagType{}
+// Dependency tag for required, host_required, and target_required modules.
+var RequiredDepTag = struct {
+ blueprint.BaseDependencyTag
+ InstallAlwaysNeededDependencyTag
+ // Requiring disabled module has been supported (as a side effect of this being implemented
+ // in Make). We may want to make it an error, but for now, let's keep the existing behavior.
+ AlwaysAllowDisabledModuleDependencyTag
+}{}
+
// CommonTestOptions represents the common `test_options` properties in
// Android.bp.
type CommonTestOptions struct {
@@ -1007,6 +1016,87 @@
if m.Team() != "" {
ctx.AddDependency(ctx.Module(), teamDepTag, m.Team())
}
+
+ // TODO(jiyong): remove below case. This is to work around build errors happening
+ // on branches with reduced manifest like aosp_kernel-build-tools.
+ // In the branch, a build error occurs as follows.
+ // 1. aosp_kernel-build-tools is a reduced manifest branch. It doesn't have some git
+ // projects like external/bouncycastle
+ // 2. `boot_signer` is `required` by modules like `build_image` which is explicitly list as
+ // the top-level build goal (in the shell file that invokes Soong).
+ // 3. `boot_signer` depends on `bouncycastle-unbundled` which is in the missing git project.
+ // 4. aosp_kernel-build-tools invokes soong with `--skip-make`. Therefore, the absence of
+ // ALLOW_MISSING_DEPENDENCIES didn't cause a problem.
+ // 5. Now, since Soong understands `required` deps, it tries to build `boot_signer` and the
+ // absence of external/bouncycastle fails the build.
+ //
+ // Unfortunately, there's no way for Soong to correctly determine if it's running in a
+ // reduced manifest branch. Instead, here, we use the absence of DeviceArch or DeviceName as
+ // a strong signal, because that's very common across reduced manifest branches.
+ pv := ctx.Config().productVariables
+ fullManifest := pv.DeviceArch != nil && pv.DeviceName != nil
+ if fullManifest {
+ m.addRequiredDeps(ctx)
+ }
+}
+
+// addRequiredDeps adds required, target_required, and host_required as dependencies.
+func (m *ModuleBase) addRequiredDeps(ctx BottomUpMutatorContext) {
+ addDep := func(target Target, depName string) {
+ if !ctx.OtherModuleExists(depName) {
+ if ctx.Config().AllowMissingDependencies() {
+ return
+ }
+ }
+
+ // If Android native module requires another Android native module, ensure that
+ // they have the same bitness. This mimics the policy in select-bitness-of-required-modules
+ // in build/make/core/main.mk.
+ // TODO(jiyong): the Make-side does this only when the required module is a shared
+ // library or a native test.
+ bothInAndroid := m.Device() && target.Os.Class == Device
+ nativeArch := m.Arch().ArchType.Multilib != string(MultilibCommon)
+ sameBitness := m.Arch().ArchType.Multilib == target.Arch.ArchType.Multilib
+ if bothInAndroid && nativeArch && !sameBitness {
+ return
+ }
+
+ variation := target.Variations()
+ if ctx.OtherModuleFarDependencyVariantExists(variation, depName) {
+ ctx.AddFarVariationDependencies(variation, RequiredDepTag, depName)
+ }
+ }
+
+ if m.Device() {
+ for _, depName := range m.RequiredModuleNames() {
+ for _, target := range ctx.Config().Targets[Android] {
+ addDep(target, depName)
+ }
+ }
+ for _, depName := range m.HostRequiredModuleNames() {
+ for _, target := range ctx.Config().Targets[ctx.Config().BuildOS] {
+ addDep(target, depName)
+ }
+ }
+ }
+
+ if m.Host() {
+ for _, depName := range m.RequiredModuleNames() {
+ for _, target := range ctx.Config().Targets[ctx.Config().BuildOS] {
+ // When a host module requires another host module, don't make a
+ // dependency if they have different OSes (i.e. hostcross).
+ if m.Target().HostCross != target.HostCross {
+ continue
+ }
+ addDep(target, depName)
+ }
+ }
+ for _, depName := range m.TargetRequiredModuleNames() {
+ for _, target := range ctx.Config().Targets[Android] {
+ addDep(target, depName)
+ }
+ }
+ }
}
// AddProperties "registers" the provided props
diff --git a/apex/apex.go b/apex/apex.go
index ed2ca98..bc91407 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1820,6 +1820,9 @@
if dt, ok := depTag.(*dependencyTag); ok && !dt.payload {
return false
}
+ if depTag == android.RequiredDepTag {
+ return false
+ }
ai, _ := android.OtherModuleProvider(ctx, child, android.ApexInfoProvider)
externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
@@ -2319,6 +2322,8 @@
// nothing
} else if depTag == android.DarwinUniversalVariantTag {
// nothing
+ } else if depTag == android.RequiredDepTag {
+ // nothing
} else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index add6083..b7362b2 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -10047,7 +10047,6 @@
key: "myapex.key",
updatable: false,
java_libs: ["foo"],
- required: ["otherapex"],
}
apex_key {
diff --git a/cc/cc.go b/cc/cc.go
index 0fa3457..90185ea 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -2980,6 +2980,9 @@
if depTag == stubImplDepTag {
return false
}
+ if depTag == android.RequiredDepTag {
+ return false
+ }
// Even if target lib has no vendor variant, keep checking dependency
// graph in case it depends on vendor_available or product_available
@@ -3157,6 +3160,10 @@
return
}
+ if depTag == android.RequiredDepTag {
+ return
+ }
+
if dep.Target().Os != ctx.Os() {
ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
return
diff --git a/cc/lto.go b/cc/lto.go
index 05fa8ee..a084db7 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -90,10 +90,6 @@
} else if ctx.testBinary() || ctx.testLibrary() {
// Do not enable LTO for tests for better debugging.
ltoEnabled = false
- } else if ctx.isVndk() {
- // FIXME: ThinLTO for VNDK produces different output.
- // b/169217596
- ltoEnabled = false
}
lto.Properties.LtoDefault = ltoDefault
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go
index 6d62746..74c79e3 100644
--- a/filesystem/filesystem_test.go
+++ b/filesystem/filesystem_test.go
@@ -76,6 +76,11 @@
cc_library {
name: "libbar",
+ required: ["libbaz"],
+ }
+
+ cc_library {
+ name: "libbaz",
}
`)
@@ -87,6 +92,7 @@
"bin/foo",
"lib/libbar.so",
"lib64/libbar.so",
+ "lib64/libbaz.so",
"etc/bpf/bpf.o",
}
for _, e := range expected {
diff --git a/genrule/genrule.go b/genrule/genrule.go
index cf2a966..43f4fe5 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -317,7 +317,17 @@
// required relative locations of the tool and its dependencies, use those
// instead. They will be copied to those relative locations in the sbox
// sandbox.
- packagedTools = append(packagedTools, specs...)
+ // Care must be taken since TransitivePackagingSpec may return device-side
+ // paths via the required property. Filter them out.
+ for i, ps := range specs {
+ if ps.Partition() != "" {
+ if i == 0 {
+ panic("first PackagingSpec is assumed to be the host-side tool")
+ }
+ continue
+ }
+ packagedTools = append(packagedTools, ps)
+ }
// Assume that the first PackagingSpec of the module is the tool.
addLocationLabel(tag.label, packagedToolLocation{specs[0]})
} else {
diff --git a/java/aar.go b/java/aar.go
index 5061879..1734da9 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -387,11 +387,6 @@
// Add additional manifest files to transitive manifests.
additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
transitiveManifestPaths := append(android.Paths{manifestPath}, additionalManifests...)
- // TODO(b/288358614): Soong has historically not merged manifests from dependencies of android_library_import
- // modules. Merging manifests from dependencies could remove the need for pom2bp to generate the "-nodeps" copies
- // of androidx libraries, but doing so triggers errors due to errors introduced by existing dependencies of
- // android_library_import modules. If this is fixed, staticManifestsDepSet can be dropped completely in favor of
- // staticResourcesNodesDepSet.manifests()
transitiveManifestPaths = append(transitiveManifestPaths, staticManifestsDepSet.ToList()...)
if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
@@ -763,7 +758,8 @@
// reverse later.
// NOTE: this is legacy and probably incorrect behavior, for most other cases (e.g. conflicting classes in
// dependencies) the highest priority dependency is listed first, but for resources the highest priority
- // dependency has to be listed last.
+ // dependency has to be listed last. This is also inconsistent with the way manifests from the same
+ // transitive dependencies are merged.
staticResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil,
android.ReverseSliceInPlace(staticResourcesNodeDepSets))
sharedResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil,
@@ -978,7 +974,8 @@
properties AARImportProperties
- classpathFile android.WritablePath
+ headerJarFile android.WritablePath
+ implementationJarFile android.WritablePath
proguardFlags android.WritablePath
exportPackage android.WritablePath
transitiveAaptResourcePackagesFile android.Path
@@ -999,6 +996,9 @@
sdkVersion android.SdkSpec
minSdkVersion android.ApiLevel
+ usesLibrary
+ classLoaderContexts dexpreopt.ClassLoaderContextMap
+
// Single aconfig "cache file" merged from this module and all dependencies.
mergedAconfigFiles map[string]android.Paths
}
@@ -1011,7 +1011,7 @@
case ".aar":
return []android.Path{a.aarPath}, nil
case "":
- return []android.Path{a.classpathFile}, nil
+ return []android.Path{a.implementationJarFile}, nil
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
@@ -1094,6 +1094,8 @@
ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...)
ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...)
+
+ a.usesLibrary.deps(ctx, false)
}
type JniPackageInfo struct {
@@ -1152,7 +1154,7 @@
}
extractedAARDir := android.PathForModuleOut(ctx, "aar")
- a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar")
+ classpathFile := extractedAARDir.Join(ctx, "classes-combined.jar")
a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml")
a.rTxt = extractedAARDir.Join(ctx, "R.txt")
a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip")
@@ -1168,11 +1170,11 @@
ctx.Build(pctx, android.BuildParams{
Rule: unzipAAR,
Input: a.aarPath,
- Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage, a.rTxt},
+ Outputs: android.WritablePaths{classpathFile, a.proguardFlags, a.manifest, a.assetsPackage, a.rTxt},
Description: "unzip AAR",
Args: map[string]string{
"outDir": extractedAARDir.String(),
- "combinedClassesJar": a.classpathFile.String(),
+ "combinedClassesJar": classpathFile.String(),
"assetsPackage": a.assetsPackage.String(),
},
})
@@ -1245,13 +1247,7 @@
a.resourcesNodesDepSet = resourcesNodesDepSetBuilder.Build()
manifestDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(a.manifest)
- // TODO(b/288358614): Soong has historically not merged manifests from dependencies of android_library_import
- // modules. Merging manifests from dependencies could remove the need for pom2bp to generate the "-nodeps" copies
- // of androidx libraries, but doing so triggers errors due to errors introduced by existing dependencies of
- // android_library_import modules. If this is fixed, AndroidLibraryDependency.ManifestsDepSet can be dropped
- // completely in favor of AndroidLibraryDependency.ResourceNodesDepSet.manifest
- //manifestDepSetBuilder.Transitive(transitiveStaticDeps.manifests)
- _ = staticManifestsDepSet
+ manifestDepSetBuilder.Transitive(staticManifestsDepSet)
a.manifestsDepSet = manifestDepSetBuilder.Build()
transitiveAaptResourcePackages := staticDeps.resPackages().Strings()
@@ -1263,12 +1259,45 @@
a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile
a.collectTransitiveHeaderJars(ctx)
+
+ a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
+
+ var staticJars android.Paths
+ var staticHeaderJars android.Paths
+ ctx.VisitDirectDeps(func(module android.Module) {
+ if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
+ tag := ctx.OtherModuleDependencyTag(module)
+ switch tag {
+ case staticLibTag:
+ staticJars = append(staticJars, dep.ImplementationJars...)
+ staticHeaderJars = append(staticHeaderJars, dep.HeaderJars...)
+ }
+ }
+ addCLCFromDep(ctx, module, a.classLoaderContexts)
+ })
+
+ if len(staticJars) > 0 {
+ combineJars := append(android.Paths{classpathFile}, staticJars...)
+ a.implementationJarFile = android.PathForModuleOut(ctx, "combined", ctx.ModuleName()+".jar")
+ TransformJarsToJar(ctx, a.implementationJarFile, "combine", combineJars, android.OptionalPath{}, false, nil, nil)
+ } else {
+ a.implementationJarFile = classpathFile
+ }
+
+ if len(staticHeaderJars) > 0 {
+ combineJars := append(android.Paths{classpathFile}, staticHeaderJars...)
+ a.headerJarFile = android.PathForModuleOut(ctx, "turbine-combined", ctx.ModuleName()+".jar")
+ TransformJarsToJar(ctx, a.headerJarFile, "combine header jars", combineJars, android.OptionalPath{}, false, nil, nil)
+ } else {
+ a.headerJarFile = classpathFile
+ }
+
android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
- HeaderJars: android.PathsIfNonNil(a.classpathFile),
+ HeaderJars: android.PathsIfNonNil(a.headerJarFile),
TransitiveLibsHeaderJars: a.transitiveLibsHeaderJars,
TransitiveStaticLibsHeaderJars: a.transitiveStaticLibsHeaderJars,
- ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile),
- ImplementationJars: android.PathsIfNonNil(a.classpathFile),
+ ImplementationAndResourcesJars: android.PathsIfNonNil(a.implementationJarFile),
+ ImplementationJars: android.PathsIfNonNil(a.implementationJarFile),
StubsLinkType: Implementation,
// TransitiveAconfigFiles: // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
})
@@ -1301,15 +1330,15 @@
}
func (a *AARImport) HeaderJars() android.Paths {
- return android.Paths{a.classpathFile}
+ return android.Paths{a.headerJarFile}
}
func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
- return android.Paths{a.classpathFile}
+ return android.Paths{a.implementationJarFile}
}
-func (a *AARImport) DexJarBuildPath(ctx android.ModuleErrorfContext) android.Path {
- return nil
+func (a *AARImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
+ return OptionalDexJarPath{}
}
func (a *AARImport) DexJarInstallPath() android.Path {
@@ -1317,9 +1346,11 @@
}
func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
- return nil
+ return a.classLoaderContexts
}
+var _ UsesLibraryDependency = (*AARImport)(nil)
+
var _ android.ApexModule = (*AARImport)(nil)
// Implements android.ApexModule
@@ -1328,7 +1359,7 @@
}
// Implements android.ApexModule
-func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
+func (a *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
return nil
}
@@ -1342,7 +1373,10 @@
func AARImportFactory() android.Module {
module := &AARImport{}
- module.AddProperties(&module.properties)
+ module.AddProperties(
+ &module.properties,
+ &module.usesLibrary.usesLibraryProperties,
+ )
android.InitPrebuiltModule(module, &module.properties.Aars)
android.InitApexModule(module)
diff --git a/java/android_manifest_test.go b/java/android_manifest_test.go
index 5909b1e..7c91884 100644
--- a/java/android_manifest_test.go
+++ b/java/android_manifest_test.go
@@ -92,10 +92,9 @@
"out/soong/.intermediates/transitive/android_common/manifest_fixer/AndroidManifest.xml",
"transitive/AndroidManifest2.xml",
"out/soong/.intermediates/transitive_import/android_common/aar/AndroidManifest.xml",
+ "out/soong/.intermediates/transitive_import_dep/android_common/aar/AndroidManifest.xml",
"out/soong/.intermediates/direct_import/android_common/aar/AndroidManifest.xml",
- // TODO(b/288358614): Soong has historically not merged manifests from dependencies of
- // android_library_import modules.
-
+ "out/soong/.intermediates/direct_import_dep/android_common/aar/AndroidManifest.xml",
},
manifestMergerRule.Implicits)
}
diff --git a/java/androidmk.go b/java/androidmk.go
index 498962f..a52d439 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -211,7 +211,7 @@
return []android.AndroidMkEntries{android.AndroidMkEntries{
Class: "JAVA_LIBRARIES",
OverrideName: prebuilt.BaseModuleName(),
- OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
+ OutputFile: android.OptionalPathForPath(prebuilt.combinedImplementationFile),
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
@@ -219,8 +219,8 @@
if prebuilt.dexJarFile.IsSet() {
entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path())
}
- entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedClasspathFile)
- entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile)
+ entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedHeaderFile)
+ entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedImplementationFile)
entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
@@ -262,13 +262,13 @@
}
return []android.AndroidMkEntries{android.AndroidMkEntries{
Class: "JAVA_LIBRARIES",
- OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
+ OutputFile: android.OptionalPathForPath(prebuilt.implementationJarFile),
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
- entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.classpathFile)
- entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile)
+ entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.headerJarFile)
+ entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.implementationJarFile)
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage)
entries.SetPath("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackagesFile)
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
diff --git a/java/app_test.go b/java/app_test.go
index b75cb16..ca9d317 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -829,12 +829,12 @@
"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
"out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar",
"out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar",
},
appCombined: []string{
"out/soong/.intermediates/app/android_common/javac/app.jar",
"out/soong/.intermediates/direct/android_common/combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar",
},
directResources: nil,
@@ -849,12 +849,12 @@
directClasspath: []string{
"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
"out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar",
},
directCombined: []string{
"out/soong/.intermediates/direct/android_common/javac/direct.jar",
"out/soong/.intermediates/transitive/android_common/javac/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar",
},
transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"},
@@ -928,13 +928,13 @@
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar",
"out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar",
},
appCombined: []string{
"out/soong/.intermediates/app/android_common/javac/app.jar",
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/direct/android_common/combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar",
},
directResources: nil,
@@ -953,12 +953,12 @@
"out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar",
"out/soong/.intermediates/transitive_import/android_common/busybox/R.jar",
"out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar",
},
directCombined: []string{
"out/soong/.intermediates/direct/android_common/javac/direct.jar",
"out/soong/.intermediates/transitive/android_common/javac/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar",
},
transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"},
@@ -1034,13 +1034,13 @@
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar",
"out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar",
},
appCombined: []string{
"out/soong/.intermediates/app/android_common/javac/app.jar",
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/direct/android_common/combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar",
},
dontVerifyDirect: true,
@@ -1075,12 +1075,12 @@
"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
"out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar",
"out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar",
},
appCombined: []string{
"out/soong/.intermediates/app/android_common/javac/app.jar",
"out/soong/.intermediates/direct/android_common/combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar",
},
directResources: nil,
@@ -1098,12 +1098,12 @@
"out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar",
"out/soong/.intermediates/transitive_import/android_common/busybox/R.jar",
"out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar",
},
directCombined: []string{
"out/soong/.intermediates/direct/android_common/javac/direct.jar",
"out/soong/.intermediates/transitive/android_common/javac/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar",
},
dontVerifyTransitive: true,
@@ -1137,12 +1137,12 @@
"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
"out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar",
"out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar",
},
appCombined: []string{
"out/soong/.intermediates/app/android_common/javac/app.jar",
"out/soong/.intermediates/direct/android_common/combined/direct.jar",
- "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar",
},
directResources: nil,
@@ -1157,12 +1157,12 @@
directClasspath: []string{
"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
"out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar",
},
directCombined: []string{
"out/soong/.intermediates/direct/android_common/javac/direct.jar",
"out/soong/.intermediates/transitive/android_common/javac/transitive.jar",
- "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar",
},
transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"},
diff --git a/java/java.go b/java/java.go
index 97feb9b..72536cd 100644
--- a/java/java.go
+++ b/java/java.go
@@ -21,6 +21,7 @@
import (
"fmt"
"path/filepath"
+ "slices"
"sort"
"strings"
@@ -2337,6 +2338,9 @@
// List of shared java libs that this module has dependencies to
Libs []string
+ // List of static java libs that this module has dependencies to
+ Static_libs []string
+
// List of files to remove from the jar file(s)
Exclude_files []string
@@ -2389,9 +2393,10 @@
dexJarFileErr error
dexJarInstallFile android.Path
- combinedClasspathFile android.Path
- classLoaderContexts dexpreopt.ClassLoaderContextMap
- exportAidlIncludeDirs android.Paths
+ combinedImplementationFile android.Path
+ combinedHeaderFile android.Path
+ classLoaderContexts dexpreopt.ClassLoaderContextMap
+ exportAidlIncludeDirs android.Paths
hideApexVariantFromMake bool
@@ -2475,6 +2480,7 @@
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
+ ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
sdkDeps(ctx, android.SdkContext(j), j.dexer)
@@ -2504,23 +2510,13 @@
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.commonBuildActions(ctx)
- jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
-
- jarName := j.Stem() + ".jar"
- outputFile := android.PathForModuleOut(ctx, "combined", jarName)
- TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
- false, j.properties.Exclude_files, j.properties.Exclude_dirs)
- if Bool(j.properties.Jetifier) {
- inputFile := outputFile
- outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
- TransformJetifier(ctx, outputFile, inputFile)
- }
- j.combinedClasspathFile = outputFile
j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
var flags javaBuilderFlags
j.collectTransitiveHeaderJars(ctx)
+ var staticJars android.Paths
+ var staticHeaderJars android.Paths
ctx.VisitDirectDeps(func(module android.Module) {
tag := ctx.OtherModuleDependencyTag(module)
if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
@@ -2530,6 +2526,8 @@
flags.dexClasspath = append(flags.dexClasspath, dep.HeaderJars...)
case staticLibTag:
flags.classpath = append(flags.classpath, dep.HeaderJars...)
+ staticJars = append(staticJars, dep.ImplementationAndResourcesJars...)
+ staticHeaderJars = append(staticHeaderJars, dep.HeaderJars...)
case bootClasspathTag:
flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...)
}
@@ -2543,6 +2541,46 @@
addCLCFromDep(ctx, module, j.classLoaderContexts)
})
+ jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
+ jarName := j.Stem() + ".jar"
+
+ // Always pass the input jars to TransformJarsToJar, even if there is only a single jar, we need the output
+ // file of the module to be named jarName.
+ outputFile := android.PathForModuleOut(ctx, "combined", jarName)
+ implementationJars := append(slices.Clone(jars), staticJars...)
+ TransformJarsToJar(ctx, outputFile, "combine prebuilt implementation jars", implementationJars, android.OptionalPath{},
+ false, j.properties.Exclude_files, j.properties.Exclude_dirs)
+
+ // If no dependencies have separate header jars then there is no need to create a separate
+ // header jar for this module.
+ reuseImplementationJarAsHeaderJar := slices.Equal(staticJars, staticHeaderJars)
+
+ var headerOutputFile android.WritablePath
+ if reuseImplementationJarAsHeaderJar {
+ headerOutputFile = outputFile
+ } else {
+ headerJars := append(slices.Clone(jars), staticHeaderJars...)
+ headerOutputFile = android.PathForModuleOut(ctx, "turbine-combined", jarName)
+ TransformJarsToJar(ctx, headerOutputFile, "combine prebuilt header jars", headerJars, android.OptionalPath{},
+ false, j.properties.Exclude_files, j.properties.Exclude_dirs)
+ }
+
+ if Bool(j.properties.Jetifier) {
+ inputFile := outputFile
+ outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
+ TransformJetifier(ctx, outputFile, inputFile)
+
+ if !reuseImplementationJarAsHeaderJar {
+ headerInputFile := headerOutputFile
+ headerOutputFile = android.PathForModuleOut(ctx, "jetifier-headers", jarName)
+ TransformJetifier(ctx, headerOutputFile, headerInputFile)
+ } else {
+ headerOutputFile = outputFile
+ }
+ }
+ j.combinedHeaderFile = headerOutputFile
+ j.combinedImplementationFile = outputFile
+
j.maybeInstall(ctx, jarName, outputFile)
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
@@ -2626,11 +2664,11 @@
}
android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
- HeaderJars: android.PathsIfNonNil(j.combinedClasspathFile),
+ HeaderJars: android.PathsIfNonNil(j.combinedHeaderFile),
TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
- ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile),
- ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile),
+ ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedImplementationFile),
+ ImplementationJars: android.PathsIfNonNil(j.combinedImplementationFile),
AidlIncludeDirs: j.exportAidlIncludeDirs,
StubsLinkType: j.stubsLinkType,
// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
@@ -2658,7 +2696,7 @@
func (j *Import) OutputFiles(tag string) (android.Paths, error) {
switch tag {
case "", ".jar":
- return android.Paths{j.combinedClasspathFile}, nil
+ return android.Paths{j.combinedImplementationFile}, nil
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
@@ -2667,17 +2705,11 @@
var _ android.OutputFileProducer = (*Import)(nil)
func (j *Import) HeaderJars() android.Paths {
- if j.combinedClasspathFile == nil {
- return nil
- }
- return android.Paths{j.combinedClasspathFile}
+ return android.PathsIfNonNil(j.combinedHeaderFile)
}
func (j *Import) ImplementationAndResourcesJars() android.Paths {
- if j.combinedClasspathFile == nil {
- return nil
- }
- return android.Paths{j.combinedClasspathFile}
+ return android.PathsIfNonNil(j.combinedImplementationFile)
}
func (j *Import) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
diff --git a/java/java_test.go b/java/java_test.go
index 194f9d9..2676aa5 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -588,10 +588,11 @@
javac := fooModule.Rule("javac")
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
barModule := ctx.ModuleForTests("bar", "android_common")
- barJar := barModule.Rule("combineJar").Output
+ barJar := barModule.Output("combined/bar.jar").Output
bazModule := ctx.ModuleForTests("baz", "android_common")
bazJar := bazModule.Rule("combineJar").Output
- sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output
+ sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").
+ Output("combined/sdklib.stubs.jar").Output
fooLibrary := fooModule.Module().(*Library)
assertDeepEquals(t, "foo unique sources incorrect",
@@ -1035,7 +1036,7 @@
}
}
-func TestJavaLibrary(t *testing.T) {
+func TestJavaLibraryOutputFiles(t *testing.T) {
testJavaWithFS(t, "", map[string][]byte{
"libcore/Android.bp": []byte(`
java_library {
@@ -1052,7 +1053,7 @@
})
}
-func TestJavaImport(t *testing.T) {
+func TestJavaImportOutputFiles(t *testing.T) {
testJavaWithFS(t, "", map[string][]byte{
"libcore/Android.bp": []byte(`
java_import {
@@ -1068,6 +1069,85 @@
})
}
+func TestJavaImport(t *testing.T) {
+ bp := `
+ java_library {
+ name: "source_library",
+ srcs: ["source.java"],
+ }
+
+ java_import {
+ name: "import_with_no_deps",
+ jars: ["no_deps.jar"],
+ }
+
+ java_import {
+ name: "import_with_source_deps",
+ jars: ["source_deps.jar"],
+ static_libs: ["source_library"],
+ }
+
+ java_import {
+ name: "import_with_import_deps",
+ jars: ["import_deps.jar"],
+ static_libs: ["import_with_no_deps"],
+ }
+ `
+ ctx := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ ).RunTestWithBp(t, bp)
+
+ source := ctx.ModuleForTests("source_library", "android_common")
+ sourceJar := source.Output("javac/source_library.jar")
+ sourceHeaderJar := source.Output("turbine-combined/source_library.jar")
+ sourceJavaInfo, _ := android.SingletonModuleProvider(ctx, source.Module(), JavaInfoProvider)
+
+ // The source library produces separate implementation and header jars
+ android.AssertPathsRelativeToTopEquals(t, "source library implementation jar",
+ []string{sourceJar.Output.String()}, sourceJavaInfo.ImplementationAndResourcesJars)
+ android.AssertPathsRelativeToTopEquals(t, "source library header jar",
+ []string{sourceHeaderJar.Output.String()}, sourceJavaInfo.HeaderJars)
+
+ importWithNoDeps := ctx.ModuleForTests("import_with_no_deps", "android_common")
+ importWithNoDepsJar := importWithNoDeps.Output("combined/import_with_no_deps.jar")
+ importWithNoDepsJavaInfo, _ := android.SingletonModuleProvider(ctx, importWithNoDeps.Module(), JavaInfoProvider)
+
+ // An import with no deps produces a single jar used as both the header and implementation jar.
+ android.AssertPathsRelativeToTopEquals(t, "import with no deps implementation jar",
+ []string{importWithNoDepsJar.Output.String()}, importWithNoDepsJavaInfo.ImplementationAndResourcesJars)
+ android.AssertPathsRelativeToTopEquals(t, "import with no deps header jar",
+ []string{importWithNoDepsJar.Output.String()}, importWithNoDepsJavaInfo.HeaderJars)
+ android.AssertPathsRelativeToTopEquals(t, "import with no deps combined inputs",
+ []string{"no_deps.jar"}, importWithNoDepsJar.Inputs)
+
+ importWithSourceDeps := ctx.ModuleForTests("import_with_source_deps", "android_common")
+ importWithSourceDepsJar := importWithSourceDeps.Output("combined/import_with_source_deps.jar")
+ importWithSourceDepsHeaderJar := importWithSourceDeps.Output("turbine-combined/import_with_source_deps.jar")
+ importWithSourceDepsJavaInfo, _ := android.SingletonModuleProvider(ctx, importWithSourceDeps.Module(), JavaInfoProvider)
+
+ // An import with source deps produces separate header and implementation jars.
+ android.AssertPathsRelativeToTopEquals(t, "import with source deps implementation jar",
+ []string{importWithSourceDepsJar.Output.String()}, importWithSourceDepsJavaInfo.ImplementationAndResourcesJars)
+ android.AssertPathsRelativeToTopEquals(t, "import with source deps header jar",
+ []string{importWithSourceDepsHeaderJar.Output.String()}, importWithSourceDepsJavaInfo.HeaderJars)
+ android.AssertPathsRelativeToTopEquals(t, "import with source deps combined implementation jar inputs",
+ []string{"source_deps.jar", sourceJar.Output.String()}, importWithSourceDepsJar.Inputs)
+ android.AssertPathsRelativeToTopEquals(t, "import with source deps combined header jar inputs",
+ []string{"source_deps.jar", sourceHeaderJar.Output.String()}, importWithSourceDepsHeaderJar.Inputs)
+
+ importWithImportDeps := ctx.ModuleForTests("import_with_import_deps", "android_common")
+ importWithImportDepsJar := importWithImportDeps.Output("combined/import_with_import_deps.jar")
+ importWithImportDepsJavaInfo, _ := android.SingletonModuleProvider(ctx, importWithImportDeps.Module(), JavaInfoProvider)
+
+ // An import with only import deps produces a single jar used as both the header and implementation jar.
+ android.AssertPathsRelativeToTopEquals(t, "import with import deps implementation jar",
+ []string{importWithImportDepsJar.Output.String()}, importWithImportDepsJavaInfo.ImplementationAndResourcesJars)
+ android.AssertPathsRelativeToTopEquals(t, "import with import deps header jar",
+ []string{importWithImportDepsJar.Output.String()}, importWithImportDepsJavaInfo.HeaderJars)
+ android.AssertPathsRelativeToTopEquals(t, "import with import deps combined implementation jar inputs",
+ []string{"import_deps.jar", importWithNoDepsJar.Output.String()}, importWithImportDepsJar.Inputs)
+}
+
var compilerFlagsTestCases = []struct {
in string
out bool
diff --git a/rust/library.go b/rust/library.go
index 7f004fc..3560d73 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -54,9 +54,13 @@
Shared VariantLibraryProperties `android:"arch_variant"`
Static VariantLibraryProperties `android:"arch_variant"`
- // path to include directories to pass to cc_* modules, only relevant for static/shared variants.
+ // TODO: Remove this when all instances of Include_dirs have been removed from rust_ffi modules.
+ // path to include directories to pass to cc_* modules, only relevant for static/shared variants (deprecated, use export_include_dirs instead).
Include_dirs []string `android:"path,arch_variant"`
+ // path to include directories to export to cc_* modules, only relevant for static/shared variants.
+ Export_include_dirs []string `android:"path,arch_variant"`
+
// Whether this library is part of the Rust toolchain sysroot.
Sysroot *bool
}
@@ -465,6 +469,7 @@
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
if library.shared() || library.static() {
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
+ library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)...)
}
if library.shared() {
if ctx.Darwin() {
diff --git a/rust/library_test.go b/rust/library_test.go
index e03074d..7275b66 100644
--- a/rust/library_test.go
+++ b/rust/library_test.go
@@ -403,3 +403,22 @@
}
}
+
+func TestRustFFIExportedIncludes(t *testing.T) {
+ ctx := testRust(t, `
+ rust_ffi {
+ name: "libbar",
+ srcs: ["foo.rs"],
+ crate_name: "bar",
+ export_include_dirs: ["rust_includes"],
+ host_supported: true,
+ }
+ cc_library_static {
+ name: "libfoo",
+ srcs: ["foo.cpp"],
+ shared_libs: ["libbar"],
+ host_supported: true,
+ }`)
+ libfooStatic := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_static").Rule("cc")
+ android.AssertStringDoesContain(t, "cFlags for lib module", libfooStatic.Args["cFlags"], " -Irust_includes ")
+}
diff --git a/rust/vendor_snapshot_test.go b/rust/vendor_snapshot_test.go
index 7ebe66b..a6ed0e5 100644
--- a/rust/vendor_snapshot_test.go
+++ b/rust/vendor_snapshot_test.go
@@ -32,7 +32,7 @@
crate_name: "ffivendor_available",
srcs: ["lib.rs"],
vendor_available: true,
- include_dirs: ["rust_headers/"],
+ export_include_dirs: ["rust_headers/"],
}
rust_ffi {
@@ -40,7 +40,7 @@
crate_name: "ffivendor",
srcs: ["lib.rs"],
vendor: true,
- include_dirs: ["rust_headers/"],
+ export_include_dirs: ["rust_headers/"],
}
rust_library {
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index 2f25a8c..81c678d 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -94,7 +94,6 @@
"gcert": Allowed,
"gcertstatus": Allowed,
"gcloud": Allowed,
- "getopt": Allowed,
"git": Allowed,
"hexdump": Allowed,
"jar": Allowed,