Merge "Defer to clang for `--hash-style`." into main
diff --git a/android/config.go b/android/config.go
index 567ebd8..10c30d4 100644
--- a/android/config.go
+++ b/android/config.go
@@ -168,7 +168,10 @@
// Thus, verify_overlaps is disabled when RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE is set to false.
// TODO(b/308174018): Re-enable verify_overlaps for both builr from source/mainline prebuilts.
func (c Config) DisableVerifyOverlaps() bool {
- return c.IsEnvTrue("DISABLE_VERIFY_OVERLAPS") || !c.ReleaseDefaultModuleBuildFromSource()
+ if c.IsEnvFalse("DISABLE_VERIFY_OVERLAPS") && c.ReleaseDisableVerifyOverlaps() {
+ panic("The current release configuration does not support verify_overlaps. DISABLE_VERIFY_OVERLAPS cannot be set to false")
+ }
+ return c.IsEnvTrue("DISABLE_VERIFY_OVERLAPS") || c.ReleaseDisableVerifyOverlaps() || !c.ReleaseDefaultModuleBuildFromSource()
}
// MaxPageSizeSupported returns the max page size supported by the device. This
@@ -209,6 +212,10 @@
Bool(c.config.productVariables.ReleaseDefaultModuleBuildFromSource)
}
+func (c Config) ReleaseDisableVerifyOverlaps() bool {
+ return c.config.productVariables.GetBuildFlagBool("RELEASE_DISABLE_VERIFY_OVERLAPS_CHECK")
+}
+
// Enables flagged apis annotated with READ_WRITE aconfig flags to be included in the stubs
// and hiddenapi flags so that they are accessible at runtime
func (c Config) ReleaseExportRuntimeApis() bool {
diff --git a/android/filegroup.go b/android/filegroup.go
index bc881ed..86d7b4b 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -15,6 +15,7 @@
package android
import (
+ "maps"
"strings"
"github.com/google/blueprint"
@@ -97,6 +98,25 @@
}
SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: fg.srcs.Strings()})
CollectDependencyAconfigFiles(ctx, &fg.mergedAconfigFiles)
+
+ var aconfigDeclarations []string
+ var intermediateCacheOutputPaths Paths
+ var srcjars Paths
+ modeInfos := make(map[string]ModeInfo)
+ ctx.VisitDirectDeps(func(module Module) {
+ if dep, ok := OtherModuleProvider(ctx, module, CodegenInfoProvider); ok {
+ aconfigDeclarations = append(aconfigDeclarations, dep.AconfigDeclarations...)
+ intermediateCacheOutputPaths = append(intermediateCacheOutputPaths, dep.IntermediateCacheOutputPaths...)
+ srcjars = append(srcjars, dep.Srcjars...)
+ maps.Copy(modeInfos, dep.ModeInfos)
+ }
+ })
+ SetProvider(ctx, CodegenInfoProvider, CodegenInfo{
+ AconfigDeclarations: aconfigDeclarations,
+ IntermediateCacheOutputPaths: intermediateCacheOutputPaths,
+ Srcjars: srcjars,
+ ModeInfos: modeInfos,
+ })
}
func (fg *fileGroup) Srcs() Paths {
diff --git a/cc/genrule_test.go b/cc/genrule_test.go
index 05c644f..0896206 100644
--- a/cc/genrule_test.go
+++ b/cc/genrule_test.go
@@ -210,3 +210,47 @@
t.Errorf(`expected product variant, but does not exist in %v`, variants)
}
}
+
+// cc_genrule is initialized to android.InitAndroidArchModule
+// that is an architecture-specific Android module.
+// So testing properties tagged with `android:"arch_variant"`
+// for cc_genrule.
+func TestMultilibGenruleOut(t *testing.T) {
+ bp := `
+ cc_genrule {
+ name: "gen",
+ cmd: "cp $(in) $(out)",
+ srcs: ["foo"],
+ multilib: {
+ lib32: {
+ out: [
+ "subdir32/external-module32",
+ ],
+ },
+ lib64: {
+ out: [
+ "subdir64/external-module64",
+ ],
+ },
+ },
+ }
+ `
+ result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, bp)
+ gen_32bit := result.ModuleForTests("gen", "android_arm_armv7-a-neon").OutputFiles(t, "")
+ android.AssertPathsEndWith(t,
+ "genrule_out",
+ []string{
+ "subdir32/external-module32",
+ },
+ gen_32bit,
+ )
+
+ gen_64bit := result.ModuleForTests("gen", "android_arm64_armv8-a").OutputFiles(t, "")
+ android.AssertPathsEndWith(t,
+ "genrule_out",
+ []string{
+ "subdir64/external-module64",
+ },
+ gen_64bit,
+ )
+}
diff --git a/cmd/symbols_map/Android.bp b/cmd/symbols_map/Android.bp
index 0ba3b07..e3ae6ed 100644
--- a/cmd/symbols_map/Android.bp
+++ b/cmd/symbols_map/Android.bp
@@ -5,17 +5,16 @@
blueprint_go_binary {
name: "symbols_map",
srcs: [
- "elf.go",
"r8.go",
"symbols_map.go",
],
testSrcs: [
- "elf_test.go",
"r8_test.go",
],
deps: [
"blueprint-pathtools",
"golang-protobuf-encoding-prototext",
+ "soong-elf",
"soong-response",
"symbols_map_proto",
],
diff --git a/cmd/symbols_map/symbols_map.go b/cmd/symbols_map/symbols_map.go
index 938446d..c56cf93 100644
--- a/cmd/symbols_map/symbols_map.go
+++ b/cmd/symbols_map/symbols_map.go
@@ -22,6 +22,7 @@
"strings"
"android/soong/cmd/symbols_map/symbols_map_proto"
+ "android/soong/elf"
"android/soong/response"
"github.com/google/blueprint/pathtools"
@@ -116,7 +117,7 @@
if *elfFile != "" {
typ = symbols_map_proto.Mapping_ELF
location = *elfFile
- identifier, err = elfIdentifier(*elfFile, true)
+ identifier, err = elf.Identifier(*elfFile, true)
if err != nil {
fmt.Fprintf(os.Stderr, "error reading elf identifier: %s\n", err)
os.Exit(1)
diff --git a/elf/Android.bp b/elf/Android.bp
new file mode 100644
index 0000000..6450be1
--- /dev/null
+++ b/elf/Android.bp
@@ -0,0 +1,28 @@
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+bootstrap_go_package {
+ name: "soong-elf",
+ pkgPath: "android/soong/elf",
+ srcs: [
+ "elf.go",
+ ],
+ testSrcs: [
+ "elf_test.go",
+ ],
+}
diff --git a/cmd/symbols_map/elf.go b/elf/elf.go
similarity index 94%
rename from cmd/symbols_map/elf.go
rename to elf/elf.go
index 950e3b2..e84a8ae 100644
--- a/cmd/symbols_map/elf.go
+++ b/elf/elf.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package main
+package elf
import (
"debug/elf"
@@ -26,9 +26,9 @@
const gnuBuildID = "GNU\x00"
-// elfIdentifier extracts the elf build ID from an elf file. If allowMissing is true it returns
+// Identifier extracts the elf build ID from an elf file. If allowMissing is true it returns
// an empty identifier if the file exists but the build ID note does not.
-func elfIdentifier(filename string, allowMissing bool) (string, error) {
+func Identifier(filename string, allowMissing bool) (string, error) {
f, err := os.Open(filename)
if err != nil {
return "", fmt.Errorf("failed to open %s: %w", filename, err)
diff --git a/cmd/symbols_map/elf_test.go b/elf/elf_test.go
similarity index 99%
rename from cmd/symbols_map/elf_test.go
rename to elf/elf_test.go
index a94c87f..a220770 100644
--- a/cmd/symbols_map/elf_test.go
+++ b/elf/elf_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package main
+package elf
import (
"bytes"
diff --git a/genrule/genrule.go b/genrule/genrule.go
index a2a3f75..cf2a966 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -808,7 +808,7 @@
type genRuleProperties struct {
// names of the output files that will be generated
- Out []string
+ Out []string `android:"arch_variant"`
}
var Bool = proptools.Bool
diff --git a/java/aar.go b/java/aar.go
index 27dd38b..2835792 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -104,6 +104,9 @@
// Filter only specified product and ignore other products
Filter_product *string `blueprint:"mutated"`
+
+ // Names of aconfig_declarations modules that specify aconfig flags that the module depends on.
+ Flags_packages []string
}
type aapt struct {
@@ -804,6 +807,10 @@
a.aapt.deps(ctx, sdkDep)
}
a.usesLibrary.deps(ctx, false)
+
+ for _, aconfig_declaration := range a.aaptProperties.Flags_packages {
+ ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
+ }
}
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -817,13 +824,14 @@
sdkContext: android.SdkContext(a),
classLoaderContexts: a.classLoaderContexts,
enforceDefaultTargetSdkVersion: false,
+ aconfigTextFiles: getAconfigFilePaths(ctx),
},
)
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
a.hideApexVariantFromMake = !apexInfo.IsForPlatform()
- a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName())
+ a.stem = proptools.StringDefault(a.overridableProperties.Stem, ctx.ModuleName())
ctx.CheckbuildFile(a.aapt.proguardOptionsFile)
ctx.CheckbuildFile(a.aapt.exportPackage)
diff --git a/java/aar_test.go b/java/aar_test.go
index 4d4e5d0..6bd53f2 100644
--- a/java/aar_test.go
+++ b/java/aar_test.go
@@ -81,3 +81,50 @@
})
}
}
+
+func TestLibraryFlagsPackages(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForJavaTest,
+ ).RunTestWithBp(t, `
+ android_library {
+ name: "foo",
+ srcs: ["a.java"],
+ sdk_version: "current",
+ flags_packages: [
+ "bar",
+ "baz",
+ ],
+ }
+ aconfig_declarations {
+ name: "bar",
+ package: "com.example.package.bar",
+ srcs: [
+ "bar.aconfig",
+ ],
+ }
+ aconfig_declarations {
+ name: "baz",
+ package: "com.example.package.baz",
+ srcs: [
+ "baz.aconfig",
+ ],
+ }
+ `)
+
+ foo := result.ModuleForTests("foo", "android_common")
+
+ // android_library module depends on aconfig_declarations listed in flags_packages
+ android.AssertBoolEquals(t, "foo expected to depend on bar", true,
+ CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "bar"))
+
+ android.AssertBoolEquals(t, "foo expected to depend on baz", true,
+ CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "baz"))
+
+ aapt2LinkRule := foo.Rule("android/soong/java.aapt2Link")
+ linkInFlags := aapt2LinkRule.Args["inFlags"]
+ android.AssertStringDoesContain(t,
+ "aapt2 link command expected to pass feature flags arguments",
+ linkInFlags,
+ "--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt",
+ )
+}
diff --git a/java/app.go b/java/app.go
index 4f6f1f3..4656888 100755
--- a/java/app.go
+++ b/java/app.go
@@ -169,9 +169,6 @@
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES.
Overrides []string
-
- // Names of aconfig_declarations modules that specify aconfig flags that the app depends on.
- Flags_packages []string
}
type AndroidApp struct {
@@ -290,6 +287,10 @@
}
a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
+
+ for _, aconfig_declaration := range a.aaptProperties.Flags_packages {
+ ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
+ }
}
func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
@@ -317,10 +318,6 @@
`must be names of android_app_certificate modules in the form ":module"`)
}
}
-
- for _, aconfig_declaration := range a.overridableAppProperties.Flags_packages {
- ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
- }
}
func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -457,6 +454,21 @@
return proptools.BoolDefault(a.overridableAppProperties.Rename_resources_package, true)
}
+func getAconfigFilePaths(ctx android.ModuleContext) (aconfigTextFilePaths android.Paths) {
+ ctx.VisitDirectDepsWithTag(aconfigDeclarationTag, func(dep android.Module) {
+ if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok {
+ aconfigTextFilePaths = append(aconfigTextFilePaths, provider.IntermediateDumpOutputPath)
+ } else {
+ ctx.ModuleErrorf("Only aconfig_declarations module type is allowed for "+
+ "flags_packages property, but %s is not aconfig_declarations module type",
+ dep.Name(),
+ )
+ }
+ })
+
+ return aconfigTextFilePaths
+}
+
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis)
if ctx.Module().(android.SdkContext).SdkVersion(ctx).Kind == android.SdkModule {
@@ -507,18 +519,6 @@
a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion
}
- var aconfigTextFilePaths android.Paths
- ctx.VisitDirectDepsWithTag(aconfigDeclarationTag, func(dep android.Module) {
- if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok {
- aconfigTextFilePaths = append(aconfigTextFilePaths, provider.IntermediateDumpOutputPath)
- } else {
- ctx.ModuleErrorf("Only aconfig_declarations module type is allowed for "+
- "flags_packages property, but %s is not aconfig_declarations module type",
- dep.Name(),
- )
- }
- })
-
a.aapt.buildActions(ctx,
aaptBuildActionOptions{
sdkContext: android.SdkContext(a),
@@ -526,7 +526,7 @@
excludedLibs: a.usesLibraryProperties.Exclude_uses_libs,
enforceDefaultTargetSdkVersion: a.enforceDefaultTargetSdkVersion(),
extraLinkFlags: aaptLinkFlags,
- aconfigTextFiles: aconfigTextFilePaths,
+ aconfigTextFiles: getAconfigFilePaths(ctx),
},
)
@@ -755,7 +755,7 @@
// Unlike installApkName, a.stem should respect base module name for override_android_app.
// Therefore, use ctx.ModuleName() instead of a.Name().
- a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName())
+ a.stem = proptools.StringDefault(a.overridableProperties.Stem, ctx.ModuleName())
// Check if the install APK name needs to be overridden.
// Both android_app and override_android_app module are expected to possess
@@ -763,7 +763,7 @@
// from the base module. Therefore, use a.Name() which represents
// the module name for both android_app and override_android_app.
a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(
- proptools.StringDefault(a.overridableDeviceProperties.Stem, a.Name()))
+ proptools.StringDefault(a.overridableProperties.Stem, a.Name()))
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
@@ -1507,7 +1507,7 @@
func OverrideAndroidAppModuleFactory() android.Module {
m := &OverrideAndroidApp{}
m.AddProperties(
- &OverridableDeviceProperties{},
+ &OverridableProperties{},
&overridableAppProperties{},
)
diff --git a/java/app_test.go b/java/app_test.go
index 5d7b048..b75cb16 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -4401,3 +4401,20 @@
dexpreopt := result.ModuleForTests("app", "android_common").MaybeRule("dexpreopt").Rule
android.AssertBoolEquals(t, "dexpreopt should be disabled if optional_uses_libs does not have an implementation", true, dexpreopt == nil)
}
+
+func TestAppStem(t *testing.T) {
+ ctx := testApp(t, `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ stem: "foo-new",
+ sdk_version: "current",
+ }`)
+
+ foo := ctx.ModuleForTests("foo", "android_common")
+
+ outputs := fmt.Sprint(foo.AllOutputs())
+ if !strings.Contains(outputs, "foo-new.apk") {
+ t.Errorf("Module output does not contain expected apk %s", "foo-new.apk")
+ }
+}
diff --git a/java/base.go b/java/base.go
index 69f88be..be286fe 100644
--- a/java/base.go
+++ b/java/base.go
@@ -305,8 +305,8 @@
HiddenAPIFlagFileProperties
}
-// Device properties that can be overridden by overriding module (e.g. override_android_app)
-type OverridableDeviceProperties struct {
+// Properties that can be overridden by overriding module (e.g. override_android_app)
+type OverridableProperties struct {
// set the name of the output. If not set, `name` is used.
// To override a module with this property set, overriding module might need to set this as well.
// Otherwise, both the overridden and the overriding modules will have the same output name, which
@@ -434,7 +434,7 @@
protoProperties android.ProtoProperties
deviceProperties DeviceProperties
- overridableDeviceProperties OverridableDeviceProperties
+ overridableProperties OverridableProperties
// jar file containing header classes including static library dependencies, suitable for
// inserting into the bootclasspath/classpath of another compile
@@ -616,6 +616,7 @@
func (j *Module) addHostProperties() {
j.AddProperties(
&j.properties,
+ &j.overridableProperties,
&j.protoProperties,
&j.usesLibraryProperties,
)
@@ -625,7 +626,6 @@
j.addHostProperties()
j.AddProperties(
&j.deviceProperties,
- &j.overridableDeviceProperties,
&j.dexer.dexProperties,
&j.dexpreoptProperties,
&j.linter.properties,
@@ -1219,14 +1219,15 @@
}
android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
- HeaderJars: android.PathsIfNonNil(j.headerJarFile),
- TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
- TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
- AidlIncludeDirs: j.exportAidlIncludeDirs,
- ExportedPlugins: j.exportedPluginJars,
- ExportedPluginClasses: j.exportedPluginClasses,
- ExportedPluginDisableTurbine: j.exportedDisableTurbine,
- StubsLinkType: j.stubsLinkType,
+ HeaderJars: android.PathsIfNonNil(j.headerJarFile),
+ TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
+ TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
+ AidlIncludeDirs: j.exportAidlIncludeDirs,
+ ExportedPlugins: j.exportedPluginJars,
+ ExportedPluginClasses: j.exportedPluginClasses,
+ ExportedPluginDisableTurbine: j.exportedDisableTurbine,
+ StubsLinkType: j.stubsLinkType,
+ AconfigIntermediateCacheOutputPaths: deps.aconfigProtoFiles,
})
j.outputFile = j.headerJarFile
@@ -1729,22 +1730,23 @@
android.CollectDependencyAconfigFiles(ctx, &j.mergedAconfigFiles)
android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
- HeaderJars: android.PathsIfNonNil(j.headerJarFile),
- RepackagedHeaderJars: android.PathsIfNonNil(j.repackagedHeaderJarFile),
- TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
- TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
- ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar),
- ImplementationJars: android.PathsIfNonNil(j.implementationJarFile),
- ResourceJars: android.PathsIfNonNil(j.resourceJar),
- AidlIncludeDirs: j.exportAidlIncludeDirs,
- SrcJarArgs: j.srcJarArgs,
- SrcJarDeps: j.srcJarDeps,
- TransitiveSrcFiles: j.transitiveSrcFiles,
- ExportedPlugins: j.exportedPluginJars,
- ExportedPluginClasses: j.exportedPluginClasses,
- ExportedPluginDisableTurbine: j.exportedDisableTurbine,
- JacocoReportClassesFile: j.jacocoReportClassesFile,
- StubsLinkType: j.stubsLinkType,
+ HeaderJars: android.PathsIfNonNil(j.headerJarFile),
+ RepackagedHeaderJars: android.PathsIfNonNil(j.repackagedHeaderJarFile),
+ TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
+ TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
+ ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar),
+ ImplementationJars: android.PathsIfNonNil(j.implementationJarFile),
+ ResourceJars: android.PathsIfNonNil(j.resourceJar),
+ AidlIncludeDirs: j.exportAidlIncludeDirs,
+ SrcJarArgs: j.srcJarArgs,
+ SrcJarDeps: j.srcJarDeps,
+ TransitiveSrcFiles: j.transitiveSrcFiles,
+ ExportedPlugins: j.exportedPluginJars,
+ ExportedPluginClasses: j.exportedPluginClasses,
+ ExportedPluginDisableTurbine: j.exportedDisableTurbine,
+ JacocoReportClassesFile: j.jacocoReportClassesFile,
+ StubsLinkType: j.stubsLinkType,
+ AconfigIntermediateCacheOutputPaths: deps.aconfigProtoFiles,
})
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
@@ -2295,6 +2297,7 @@
// annotation processor that generates API is incompatible with the turbine
// optimization.
deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
+ deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.AconfigIntermediateCacheOutputPaths...)
case pluginTag:
if plugin, ok := module.(*Plugin); ok {
if plugin.pluginProperties.Processor_class != nil {
@@ -2353,6 +2356,8 @@
deps.staticJars = append(deps.staticJars, dep.Srcs()...)
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
}
+ } else if dep, ok := android.OtherModuleProvider(ctx, module, android.CodegenInfoProvider); ok {
+ deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.IntermediateCacheOutputPaths...)
} else {
switch tag {
case bootClasspathTag:
diff --git a/java/java.go b/java/java.go
index e606993..ad10cbd 100644
--- a/java/java.go
+++ b/java/java.go
@@ -309,6 +309,10 @@
// implementation jars. If the provider is set by java_sdk_library, the link type is "unknown"
// and selection between the stub jar vs implementation jar is deferred to SdkLibrary.sdkJars(...)
StubsLinkType StubsLinkType
+
+ // AconfigIntermediateCacheOutputPaths is a path to the cache files collected from the
+ // java_aconfig_library modules that are statically linked to this module.
+ AconfigIntermediateCacheOutputPaths android.Paths
}
var JavaInfoProvider = blueprint.NewProvider[JavaInfo]()
@@ -897,7 +901,7 @@
}
}
- j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName())
+ j.stem = proptools.StringDefault(j.overridableProperties.Stem, ctx.ModuleName())
proguardSpecInfo := j.collectProguardSpecInfo(ctx)
android.SetProvider(ctx, ProguardSpecInfoProvider, proguardSpecInfo)
@@ -1694,7 +1698,7 @@
}
func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName())
+ j.stem = proptools.StringDefault(j.overridableProperties.Stem, ctx.ModuleName())
if ctx.Arch().ArchType == android.Common {
// Compile the jar
@@ -3005,7 +3009,7 @@
module.AddProperties(
&CommonProperties{},
&DeviceProperties{},
- &OverridableDeviceProperties{},
+ &OverridableProperties{},
&DexProperties{},
&DexpreoptProperties{},
&android.ProtoProperties{},
diff --git a/java/java_test.go b/java/java_test.go
index 9a4f085..194f9d9 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -2757,3 +2757,38 @@
cmdline := String(android.RuleBuilderSboxProtoForTests(t, result.TestContext, manifest).Commands[0].Command)
android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "revert-annotations-exportable.txt")
}
+
+func TestJavaLibHostWithStem(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_library_host {
+ name: "foo",
+ srcs: ["a.java"],
+ stem: "foo-new",
+ }
+ `)
+
+ buildOS := ctx.Config().BuildOS.String()
+ foo := ctx.ModuleForTests("foo", buildOS+"_common")
+
+ outputs := fmt.Sprint(foo.AllOutputs())
+ if !strings.Contains(outputs, "foo-new.jar") {
+ t.Errorf("Module output does not contain expected jar %s", "foo-new.jar")
+ }
+}
+
+func TestJavaLibWithStem(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_library {
+ name: "foo",
+ srcs: ["a.java"],
+ stem: "foo-new",
+ }
+ `)
+
+ foo := ctx.ModuleForTests("foo", "android_common")
+
+ outputs := fmt.Sprint(foo.AllOutputs())
+ if !strings.Contains(outputs, "foo-new.jar") {
+ t.Errorf("Module output does not contain expected jar %s", "foo-new.jar")
+ }
+}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index cdd0448..bde5e7d 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,20 +1993,25 @@
if !Bool(module.sdkLibraryProperties.No_dist) {
// Dist the api txt and removed api txt artifacts for sdk builds.
distDir := proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
+ stubsTypeTagPrefix := ""
+ if mctx.Config().ReleaseHiddenApiExportableStubs() {
+ stubsTypeTagPrefix = ".exportable"
+ }
for _, p := range []struct {
tag string
pattern string
}{
// "exportable" api files are copied to the dist directory instead of the
- // "everything" api files.
- {tag: ".exportable.api.txt", pattern: "%s.txt"},
- {tag: ".exportable.removed-api.txt", pattern: "%s-removed.txt"},
+ // "everything" api files when "RELEASE_HIDDEN_API_EXPORTABLE_STUBS" build flag
+ // is set. Otherwise, the "everything" api files are copied to the dist directory.
+ {tag: "%s.api.txt", pattern: "%s.txt"},
+ {tag: "%s.removed-api.txt", pattern: "%s-removed.txt"},
} {
props.Dists = append(props.Dists, android.Dist{
Targets: []string{"sdk", "win_sdk"},
Dir: distDir,
Dest: proptools.StringPtr(fmt.Sprintf(p.pattern, module.distStem())),
- Tag: proptools.StringPtr(p.tag),
+ Tag: proptools.StringPtr(fmt.Sprintf(p.tag, stubsTypeTagPrefix)),
})
}
}
@@ -2079,7 +2084,7 @@
mctx.CreateModule(ApiLibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary())
}
-func (module *SdkLibrary) topLevelStubsLibraryProps(mctx android.DefaultableHookContext, apiScope *apiScope) libraryProperties {
+func (module *SdkLibrary) topLevelStubsLibraryProps(mctx android.DefaultableHookContext, apiScope *apiScope, doDist bool) libraryProperties {
props := libraryProperties{}
props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_library_visibility)
@@ -2095,13 +2100,22 @@
}
props.Compile_dex = compileDex
+ if !Bool(module.sdkLibraryProperties.No_dist) && doDist {
+ props.Dist.Targets = []string{"sdk", "win_sdk"}
+ props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.distStem()))
+ props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
+ props.Dist.Tag = proptools.StringPtr(".jar")
+ }
+
return props
}
func (module *SdkLibrary) createTopLevelStubsLibrary(
mctx android.DefaultableHookContext, apiScope *apiScope, contributesToApiSurface bool) {
- props := module.topLevelStubsLibraryProps(mctx, apiScope)
+ // Dist the "everything" stubs when the RELEASE_HIDDEN_API_EXPORTABLE_STUBS build flag is false
+ doDist := !mctx.Config().ReleaseHiddenApiExportableStubs()
+ props := module.topLevelStubsLibraryProps(mctx, apiScope, doDist)
props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
// Add the stub compiling java_library/java_api_library as static lib based on build config
@@ -2117,18 +2131,11 @@
func (module *SdkLibrary) createTopLevelExportableStubsLibrary(
mctx android.DefaultableHookContext, apiScope *apiScope) {
- props := module.topLevelStubsLibraryProps(mctx, apiScope)
+ // Dist the "exportable" stubs when the RELEASE_HIDDEN_API_EXPORTABLE_STUBS build flag is true
+ doDist := mctx.Config().ReleaseHiddenApiExportableStubs()
+ props := module.topLevelStubsLibraryProps(mctx, apiScope, doDist)
props.Name = proptools.StringPtr(module.exportableStubsLibraryModuleName(apiScope))
- // Dist the class jar artifact for sdk builds.
- // "exportable" stubs are copied to dist for sdk builds instead of the "everything" stubs.
- if !Bool(module.sdkLibraryProperties.No_dist) {
- props.Dist.Targets = []string{"sdk", "win_sdk"}
- props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.distStem()))
- props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
- props.Dist.Tag = proptools.StringPtr(".jar")
- }
-
staticLib := module.exportableSourceStubsLibraryModuleName(apiScope)
props.Static_libs = append(props.Static_libs, staticLib)
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index 93ef408..b622f98 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -1393,6 +1393,11 @@
"sdklib_group_foo",
"sdklib_owner_foo",
"foo"),
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.BuildFlags = map[string]string{
+ "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
+ }
+ }),
).RunTestWithBp(t, `
java_sdk_library {
name: "sdklib_no_group",
diff --git a/rust/compiler.go b/rust/compiler.go
index c1bdbeb..03fdf2b 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -75,6 +75,8 @@
strippedOutputFilePath() android.OptionalPath
checkedCrateRootPath() (android.Path, error)
+
+ Aliases() map[string]string
}
func (compiler *baseCompiler) edition() string {
@@ -140,6 +142,12 @@
// flags to pass to the linker
Ld_flags []string `android:"arch_variant"`
+ // Rust crate dependencies to rename. Each entry should be a string of the form "dependencyname:alias".
+ //
+ // "dependencyname" here should be the name of the crate, not the Android module. This is
+ // equivalent to writing `alias = { package = "dependencyname" }` in a `Cargo.toml`.
+ Aliases []string
+
// list of rust rlib crate dependencies
Rlibs []string `android:"arch_variant"`
@@ -281,6 +289,18 @@
return Bool(compiler.Properties.Prefer_rlib)
}
+func (compiler *baseCompiler) Aliases() map[string]string {
+ aliases := map[string]string{}
+ for _, entry := range compiler.Properties.Aliases {
+ dep, alias, found := strings.Cut(entry, ":")
+ if !found {
+ panic(fmt.Errorf("invalid aliases entry %q missing ':'", entry))
+ }
+ aliases[dep] = alias
+ }
+ return aliases
+}
+
func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage {
// For devices, we always link stdlibs in as dylibs by default.
if compiler.preferRlib() {
diff --git a/rust/rust.go b/rust/rust.go
index 668dd8f..7d81c72 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -1142,6 +1142,7 @@
}
}
}
+
func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps
@@ -1433,16 +1434,29 @@
mod.transitiveAndroidMkSharedLibs = android.NewDepSet[string](android.PREORDER, directAndroidMkSharedLibs, transitiveAndroidMkSharedLibs)
var rlibDepFiles RustLibraries
+ aliases := mod.compiler.Aliases()
for _, dep := range directRlibDeps {
- rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
+ crateName := dep.CrateName()
+ if alias, aliased := aliases[crateName]; aliased {
+ crateName = alias
+ }
+ rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: crateName})
}
var dylibDepFiles RustLibraries
for _, dep := range directDylibDeps {
- dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
+ crateName := dep.CrateName()
+ if alias, aliased := aliases[crateName]; aliased {
+ crateName = alias
+ }
+ dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: crateName})
}
var procMacroDepFiles RustLibraries
for _, dep := range directProcMacroDeps {
- procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
+ crateName := dep.CrateName()
+ if alias, aliased := aliases[crateName]; aliased {
+ crateName = alias
+ }
+ procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: crateName})
}
var staticLibDepFiles android.Paths
diff --git a/rust/rust_test.go b/rust/rust_test.go
index d609c2f..295a734 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -470,6 +470,35 @@
m.Output("libwaldo.dylib.so.bloaty.csv")
}
+// Test that aliases are respected.
+func TestRustAliases(t *testing.T) {
+ ctx := testRust(t, `
+ rust_library {
+ name: "libbar",
+ crate_name: "bar",
+ srcs: ["src/lib.rs"],
+ }
+ rust_library {
+ name: "libbaz",
+ crate_name: "baz",
+ srcs: ["src/lib.rs"],
+ }
+ rust_binary {
+ name: "foo",
+ srcs: ["src/main.rs"],
+ rustlibs: ["libbar", "libbaz"],
+ aliases: ["bar:bar_renamed"],
+ }`)
+
+ fooRustc := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Rule("rustc")
+ if !strings.Contains(fooRustc.Args["libFlags"], "--extern bar_renamed=out/soong/.intermediates/libbar/android_arm64_armv8-a_dylib/unstripped/libbar.dylib.so") {
+ t.Errorf("--extern bar_renamed=out/soong/.intermediates/libbar/android_arm64_armv8-a_dylib/unstripped/libbar.dylib.so flag not being passed to rustc for rust_binary with aliases. libFlags: %#v", fooRustc.Args["libFlags"])
+ }
+ if !strings.Contains(fooRustc.Args["libFlags"], "--extern baz=out/soong/.intermediates/libbaz/android_arm64_armv8-a_dylib/unstripped/libbaz.dylib.so") {
+ t.Errorf("--extern baz=out/soong/.intermediates/libbaz/android_arm64_armv8-a_dylib/unstripped/libbaz.dylib.so flag not being passed to rustc for rust_binary with aliases. libFlags: %#v", fooRustc.Args["libFlags"])
+ }
+}
+
func assertString(t *testing.T, got, expected string) {
t.Helper()
if got != expected {