Merge "rust: Add support for host fuzzers." into main
diff --git a/aconfig/Android.bp b/aconfig/Android.bp
index 6927765..d2ddfdf 100644
--- a/aconfig/Android.bp
+++ b/aconfig/Android.bp
@@ -14,6 +14,7 @@
"soong-bazel",
"soong-android",
"soong-java",
+ "soong-rust",
],
srcs: [
"aconfig_declarations.go",
@@ -24,6 +25,7 @@
"init.go",
"java_aconfig_library.go",
"testing.go",
+ "rust_aconfig_library.go",
],
testSrcs: [
"aconfig_declarations_test.go",
diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go
index 565d185..4e199dd 100644
--- a/aconfig/aconfig_declarations.go
+++ b/aconfig/aconfig_declarations.go
@@ -17,8 +17,9 @@
import (
"android/soong/android"
"fmt"
- "github.com/google/blueprint"
"strings"
+
+ "github.com/google/blueprint"
)
type DeclarationsModule struct {
@@ -96,6 +97,15 @@
return sb.String()
}
+func optionalVariable(prefix string, value string) string {
+ var sb strings.Builder
+ if value != "" {
+ sb.WriteString(prefix)
+ sb.WriteString(value)
+ }
+ return sb.String()
+}
+
// Provider published by aconfig_value_set
type declarationsProviderData struct {
Package string
@@ -123,15 +133,17 @@
// Intermediate format
inputFiles := android.PathsForModuleSrc(ctx, module.properties.Srcs)
intermediatePath := android.PathForModuleOut(ctx, "intermediate.pb")
+ defaultPermission := ctx.Config().ReleaseAconfigFlagDefaultPermission()
ctx.Build(pctx, android.BuildParams{
Rule: aconfigRule,
Output: intermediatePath,
Description: "aconfig_declarations",
Args: map[string]string{
- "release_version": ctx.Config().ReleaseVersion(),
- "package": module.properties.Package,
- "declarations": android.JoinPathsWithPrefix(inputFiles, "--declarations "),
- "values": joinAndPrefix(" --values ", module.properties.Values),
+ "release_version": ctx.Config().ReleaseVersion(),
+ "package": module.properties.Package,
+ "declarations": android.JoinPathsWithPrefix(inputFiles, "--declarations "),
+ "values": joinAndPrefix(" --values ", module.properties.Values),
+ "default-permission": optionalVariable(" --default-permission ", defaultPermission),
},
})
diff --git a/aconfig/init.go b/aconfig/init.go
index 37167aa..797388d 100644
--- a/aconfig/init.go
+++ b/aconfig/init.go
@@ -16,6 +16,7 @@
import (
"android/soong/android"
+
"github.com/google/blueprint"
)
@@ -29,6 +30,7 @@
` --package ${package}` +
` ${declarations}` +
` ${values}` +
+ ` ${default-permission}` +
` --cache ${out}.tmp` +
` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
// ` --build-id ${release_version}` +
@@ -36,7 +38,7 @@
"${aconfig}",
},
Restat: true,
- }, "release_version", "package", "declarations", "values")
+ }, "release_version", "package", "declarations", "values", "default-permission")
// For java_aconfig_library: Generate java file
javaRule = pctx.AndroidStaticRule("java_aconfig_library",
@@ -70,6 +72,20 @@
},
}, "gendir")
+ rustRule = pctx.AndroidStaticRule("rust_aconfig_library",
+ blueprint.RuleParams{
+ Command: `rm -rf ${gendir}` +
+ ` && mkdir -p ${gendir}` +
+ ` && ${aconfig} create-rust-lib` +
+ ` --mode ${mode}` +
+ ` --cache ${in}` +
+ ` --out ${gendir}`,
+ CommandDeps: []string{
+ "$aconfig",
+ "$soong_zip",
+ },
+ }, "gendir", "mode")
+
// For all_aconfig_declarations
allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
blueprint.RuleParams{
@@ -92,5 +108,6 @@
ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
+ ctx.RegisterModuleType("rust_aconfig_library", RustAconfigLibraryFactory)
ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
}
diff --git a/aconfig/rust_aconfig_library.go b/aconfig/rust_aconfig_library.go
new file mode 100644
index 0000000..8b16372
--- /dev/null
+++ b/aconfig/rust_aconfig_library.go
@@ -0,0 +1,83 @@
+package aconfig
+
+import (
+ "android/soong/android"
+ "android/soong/rust"
+ "fmt"
+
+ "github.com/google/blueprint"
+)
+
+type rustDeclarationsTagType struct {
+ blueprint.BaseDependencyTag
+}
+
+var rustDeclarationsTag = rustDeclarationsTagType{}
+
+type RustAconfigLibraryProperties struct {
+ // name of the aconfig_declarations module to generate a library for
+ Aconfig_declarations string
+}
+
+type aconfigDecorator struct {
+ *rust.BaseSourceProvider
+
+ Properties RustAconfigLibraryProperties
+}
+
+func NewRustAconfigLibrary(hod android.HostOrDeviceSupported) (*rust.Module, *aconfigDecorator) {
+ aconfig := &aconfigDecorator{
+ BaseSourceProvider: rust.NewSourceProvider(),
+ Properties: RustAconfigLibraryProperties{},
+ }
+
+ module := rust.NewSourceProviderModule(android.HostAndDeviceSupported, aconfig, false, false)
+ return module, aconfig
+}
+
+// rust_aconfig_library generates aconfig rust code from the provided aconfig declaration. This module type will
+// create library variants that can be used as a crate dependency by adding it to the rlibs, dylibs, and rustlibs
+// properties of other modules.
+func RustAconfigLibraryFactory() android.Module {
+ module, _ := NewRustAconfigLibrary(android.HostAndDeviceSupported)
+ return module.Init()
+}
+
+func (a *aconfigDecorator) SourceProviderProps() []interface{} {
+ return append(a.BaseSourceProvider.SourceProviderProps(), &a.Properties)
+}
+
+func (a *aconfigDecorator) GenerateSource(ctx rust.ModuleContext, deps rust.PathDeps) android.Path {
+ generatedDir := android.PathForModuleGen(ctx)
+ generatedSource := android.PathForModuleGen(ctx, "src", "lib.rs")
+
+ declarationsModules := ctx.GetDirectDepsWithTag(rustDeclarationsTag)
+
+ if len(declarationsModules) != 1 {
+ panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
+ }
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: rustRule,
+ Input: declarations.IntermediatePath,
+ Outputs: []android.WritablePath{
+ generatedSource,
+ },
+ Description: "rust_aconfig_library",
+ Args: map[string]string{
+ "gendir": generatedDir.String(),
+ // TODO: Add test mode
+ "mode": "production",
+ },
+ })
+ a.BaseSourceProvider.OutputFiles = android.Paths{generatedSource}
+ return generatedSource
+}
+
+func (a *aconfigDecorator) SourceProviderDeps(ctx rust.DepsContext, deps rust.Deps) rust.Deps {
+ deps = a.BaseSourceProvider.SourceProviderDeps(ctx, deps)
+ deps.Rustlibs = append(deps.Rustlibs, "libflags_rust")
+ ctx.AddDependency(ctx.Module(), rustDeclarationsTag, a.Properties.Aconfig_declarations)
+ return deps
+}
diff --git a/aconfig/rust_aconfig_library_test.go b/aconfig/rust_aconfig_library_test.go
new file mode 100644
index 0000000..17385c3
--- /dev/null
+++ b/aconfig/rust_aconfig_library_test.go
@@ -0,0 +1,60 @@
+package aconfig
+
+import (
+ "android/soong/android"
+ "android/soong/rust"
+ "fmt"
+ "testing"
+)
+
+func TestRustAconfigLibrary(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ PrepareForTestWithAconfigBuildComponents,
+ rust.PrepareForTestWithRustIncludeVndk,
+ android.PrepareForTestWithArchMutator,
+ android.PrepareForTestWithDefaults,
+ android.PrepareForTestWithPrebuilts,
+ ).
+ ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
+ RunTestWithBp(t, fmt.Sprintf(`
+ rust_library {
+ name: "libflags_rust", // test mock
+ crate_name: "flags_rust",
+ srcs: ["lib.rs"],
+ }
+ aconfig_declarations {
+ name: "my_aconfig_declarations",
+ package: "com.example.package",
+ srcs: ["foo.aconfig"],
+ }
+
+ rust_aconfig_library {
+ name: "libmy_rust_aconfig_library",
+ crate_name: "my_rust_aconfig_library",
+ aconfig_declarations: "my_aconfig_declarations",
+ }
+ `))
+
+ sourceVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_source")
+ rule := sourceVariant.Rule("rust_aconfig_library")
+ android.AssertStringEquals(t, "rule must contain production mode", rule.Args["mode"], "production")
+
+ dylibVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_dylib")
+ rlibRlibStdVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_rlib_rlib-std")
+ rlibDylibStdVariant := result.ModuleForTests("libmy_rust_aconfig_library", "android_arm64_armv8-a_rlib_dylib-std")
+
+ variants := []android.TestingModule{
+ dylibVariant,
+ rlibDylibStdVariant,
+ rlibRlibStdVariant,
+ }
+
+ for _, variant := range variants {
+ android.AssertStringEquals(
+ t,
+ "dylib variant builds from generated rust code",
+ "out/soong/.intermediates/libmy_rust_aconfig_library/android_arm64_armv8-a_source/gen/src/lib.rs",
+ variant.Rule("rustc").Inputs[0].RelativeToTop().String(),
+ )
+ }
+}
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 6bfa05d..71c8d0e 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -440,6 +440,7 @@
"external/bazelbuild-rules_license":/* recursive = */ true,
"external/bazelbuild-rules_go":/* recursive = */ true,
"external/bazelbuild-rules_python":/* recursive = */ true,
+ "external/bazelbuild-rules_rust":/* recursive = */ true,
"external/bazelbuild-kotlin-rules":/* recursive = */ true,
"external/bazel-skylib":/* recursive = */ true,
"external/protobuf":/* recursive = */ false,
@@ -467,6 +468,7 @@
"prebuilts/sdk/tools":/* recursive = */ false,
"prebuilts/r8":/* recursive = */ false,
"prebuilts/runtime":/* recursive = */ false,
+ "prebuilts/rust":/* recursive = */ true,
// not recursive due to conflicting workspace paths in tools/atest/bazel/rules
"tools/asuite/atest":/* recursive = */ false,
@@ -480,6 +482,32 @@
}
Bp2buildModuleAlwaysConvertList = []string{
+ // ext
+ "tagsoup",
+
+ // framework-res
+ "remote-color-resources-compile-public",
+ "remote-color-resources-compile-colors",
+
+ // framework-minus-apex
+ "android.mime.types.minimized",
+ "debian.mime.types.minimized",
+ "framework-javastream-protos",
+ "libview-inspector-annotation-processor",
+
+ // services
+ "apache-commons-math",
+ "cbor-java",
+ "icu4j_calendar_astronomer",
+ "json",
+ "remote-color-resources-compile-public",
+ "statslog-art-java-gen",
+ "statslog-framework-java-gen",
+
+ "AndroidCommonLint",
+ "ImmutabilityAnnotation",
+ "ImmutabilityAnnotationProcessorHostLibrary",
+
"libidmap2_policies",
"libSurfaceFlingerProp",
"toolbox_input_labels",
@@ -938,7 +966,6 @@
"libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core
"libdebuggerd_handler_core", "libdebuggerd_handler_fallback", // depends on unconverted module libdebuggerd
"libdexfiled", // depends on unconverted modules: dexfile_operator_srcs, libartbased, libartpalette
- "libfastdeploy_host", // depends on unconverted modules: libandroidfw, libusb, AdbWinApi
"libgmock_main_ndk", // depends on unconverted modules: libgtest_ndk_c++
"libgmock_ndk", // depends on unconverted modules: libgtest_ndk_c++
"libnativehelper_lazy_mts_jni", "libnativehelper_mts_jni", // depends on unconverted modules: libnativetesthelper_jni, libgmock_ndk
@@ -992,8 +1019,6 @@
"svcenc", "svcdec",
// Failing host cc_tests
- "libprocinfo_test",
- "ziparchive-tests",
"gtest_isolated_tests",
"libunwindstack_unit_test",
"power_tests", // failing test on server, but not on host
@@ -1012,7 +1037,7 @@
"libnativebridge6-test-case",
"libnativebridge6prezygotefork",
- "libandroidfw_tests", "aapt2_tests", // failing due to data path issues
+ "libandroidfw_tests", // failing due to data path issues
// error: overriding commands for target
// `out/host/linux-x86/nativetest64/gmock_tests/gmock_tests__cc_runner_test',
@@ -1070,6 +1095,7 @@
"ion-unit-tests",
"jemalloc5_integrationtests",
"jemalloc5_unittests",
+ "jemalloc5_stresstests", // run by run_jemalloc_tests.sh and will be deleted after V
"ld_config_test_helper",
"ld_preload_test_helper",
"libBionicCtsGtestMain", // depends on unconverted modules: libgtest_isolated
@@ -1099,7 +1125,6 @@
"memunreachable_binder_test", // depends on unconverted modules: libbinder
"memunreachable_test",
"metadata_tests",
- "minijail0_cli_unittest_gtest",
"mpeg2dec",
"mvcdec",
"ns_hidden_child_helper",
@@ -1111,14 +1136,12 @@
"rappor-tests", // depends on unconverted modules: jsr305, guava
"scudo_unit_tests",
"stats-log-api-gen-test", // depends on unconverted modules: libstats_proto_host
- "syscall_filter_unittest_gtest",
"thread_exit_cb_helper",
"tls_properties_helper",
"ulp",
"vec_test",
"yuvconstants",
"yuvconvert",
- "zipalign_tests",
// cc_test_library
"clang_diagnostic_tests",
@@ -1526,6 +1549,10 @@
"libart_generated_headers",
"libart-runtime-gtest",
"libartd-runtime-gtest",
+ "libart-unstripped",
+
+ // depends on libart-unstripped and new module type llvm_prebuilt_build_tool
+ "check_cfi",
}
// Bazel prod-mode allowlist. Modules in this list are built by Bazel
diff --git a/android/bazel.go b/android/bazel.go
index df30ff2..e4fada0 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -21,6 +21,7 @@
"strings"
"android/soong/ui/metrics/bp2build_metrics_proto"
+
"github.com/google/blueprint"
"github.com/google/blueprint/bootstrap"
"github.com/google/blueprint/proptools"
@@ -153,8 +154,8 @@
HasHandcraftedLabel() bool
HandcraftedLabel() string
GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string
- ShouldConvertWithBp2build(ctx BazelConversionContext) bool
- shouldConvertWithBp2build(ctx bazelOtherModuleContext, module blueprint.Module) bool
+ ShouldConvertWithBp2build(ctx ShouldConvertWithBazelContext) bool
+ shouldConvertWithBp2build(shouldConvertModuleContext, shouldConvertParams) bool
// ConvertWithBp2build either converts the module to a Bazel build target or
// declares the module as unconvertible (for logging and metrics).
@@ -448,12 +449,32 @@
if !ok {
return false
}
- return b.shouldConvertWithBp2build(ctx, module) || b.HasHandcraftedLabel()
+
+ return b.HasHandcraftedLabel() || b.shouldConvertWithBp2build(ctx, shouldConvertParams{
+ module: module,
+ moduleDir: ctx.OtherModuleDir(module),
+ moduleName: ctx.OtherModuleName(module),
+ moduleType: ctx.OtherModuleType(module),
+ })
+}
+
+type ShouldConvertWithBazelContext interface {
+ ModuleErrorf(format string, args ...interface{})
+ Module() Module
+ Config() Config
+ ModuleType() string
+ ModuleName() string
+ ModuleDir() string
}
// ShouldConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build
-func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx BazelConversionContext) bool {
- return b.shouldConvertWithBp2build(ctx, ctx.Module())
+func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx ShouldConvertWithBazelContext) bool {
+ return b.shouldConvertWithBp2build(ctx, shouldConvertParams{
+ module: ctx.Module(),
+ moduleDir: ctx.ModuleDir(),
+ moduleName: ctx.ModuleName(),
+ moduleType: ctx.ModuleType(),
+ })
}
type bazelOtherModuleContext interface {
@@ -471,11 +492,24 @@
arch == Riscv64 // TODO(b/262192655) Riscv64 toolchains are not currently supported.
}
-func (b *BazelModuleBase) shouldConvertWithBp2build(ctx bazelOtherModuleContext, module blueprint.Module) bool {
+type shouldConvertModuleContext interface {
+ ModuleErrorf(format string, args ...interface{})
+ Config() Config
+}
+
+type shouldConvertParams struct {
+ module blueprint.Module
+ moduleType string
+ moduleDir string
+ moduleName string
+}
+
+func (b *BazelModuleBase) shouldConvertWithBp2build(ctx shouldConvertModuleContext, p shouldConvertParams) bool {
if !b.bazelProps().Bazel_module.CanConvertToBazel {
return false
}
+ module := p.module
// In api_bp2build mode, all soong modules that can provide API contributions should be converted
// This is irrespective of its presence/absence in bp2build allowlists
if ctx.Config().BuildMode == ApiBp2build {
@@ -484,7 +518,7 @@
}
propValue := b.bazelProperties.Bazel_module.Bp2build_available
- packagePath := moduleDirWithPossibleOverride(ctx, module)
+ packagePath := moduleDirWithPossibleOverride(ctx, module, p.moduleDir)
// Modules in unit tests which are enabled in the allowlist by type or name
// trigger this conditional because unit tests run under the "." package path
@@ -493,10 +527,10 @@
return true
}
- moduleName := moduleNameWithPossibleOverride(ctx, module)
+ moduleName := moduleNameWithPossibleOverride(ctx, module, p.moduleName)
allowlist := ctx.Config().Bp2buildPackageConfig
moduleNameAllowed := allowlist.moduleAlwaysConvert[moduleName]
- moduleTypeAllowed := allowlist.moduleTypeAlwaysConvert[ctx.OtherModuleType(module)]
+ moduleTypeAllowed := allowlist.moduleTypeAlwaysConvert[p.moduleType]
allowlistConvert := moduleNameAllowed || moduleTypeAllowed
if moduleNameAllowed && moduleTypeAllowed {
ctx.ModuleErrorf("A module cannot be in moduleAlwaysConvert and also be in moduleTypeAlwaysConvert")
@@ -588,8 +622,21 @@
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
return
}
+ // There may be cases where the target is created by a macro rather than in a BUILD file, those
+ // should be captured as well.
+ if bModule.HasHandcraftedLabel() {
+ // Defer to the BUILD target. Generating an additional target would
+ // cause a BUILD file conflict.
+ ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE, "")
+ return
+ }
// TODO: b/285631638 - Differentiate between denylisted modules and missing bp2build capabilities.
- if !bModule.shouldConvertWithBp2build(ctx, ctx.Module()) {
+ if !bModule.shouldConvertWithBp2build(ctx, shouldConvertParams{
+ module: ctx.Module(),
+ moduleDir: ctx.ModuleDir(),
+ moduleName: ctx.ModuleName(),
+ moduleType: ctx.ModuleType(),
+ }) {
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "")
return
}
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index b08a4ca..7992564 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -88,6 +88,8 @@
EarlyModulePathContext
BazelConversionContext
+ ModuleName() string
+ ModuleType() string
ModuleErrorf(fmt string, args ...interface{})
PropertyErrorf(property, fmt string, args ...interface{})
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
@@ -459,8 +461,8 @@
}
func bp2buildModuleLabel(ctx BazelConversionContext, module blueprint.Module) string {
- moduleName := moduleNameWithPossibleOverride(ctx, module)
- moduleDir := moduleDirWithPossibleOverride(ctx, module)
+ moduleName := moduleNameWithPossibleOverride(ctx, module, ctx.OtherModuleName(module))
+ moduleDir := moduleDirWithPossibleOverride(ctx, module, ctx.OtherModuleDir(module))
if moduleDir == Bp2BuildTopLevel {
moduleDir = ""
}
diff --git a/android/bazel_paths_test.go b/android/bazel_paths_test.go
index 60c0a14..75b77a3 100644
--- a/android/bazel_paths_test.go
+++ b/android/bazel_paths_test.go
@@ -19,6 +19,7 @@
"testing"
"android/soong/bazel"
+
"github.com/google/blueprint"
"github.com/google/blueprint/pathtools"
)
@@ -157,6 +158,14 @@
return ctx.moduleDir
}
+func (ctx *TestBazelConversionPathContext) ModuleName() string {
+ panic("Unimplemented")
+}
+
+func (ctx *TestBazelConversionPathContext) ModuleType() string {
+ panic("Unimplemented")
+}
+
func TestTransformSubpackagePath(t *testing.T) {
cfg := NullConfig("out", "out/soong")
cfg.fs = pathtools.MockFs(map[string][]byte{
diff --git a/android/bazel_test.go b/android/bazel_test.go
index 13fd408..194a6b3 100644
--- a/android/bazel_test.go
+++ b/android/bazel_test.go
@@ -373,7 +373,14 @@
allowlist: test.allowlist,
}
- shouldConvert := test.module.shouldConvertWithBp2build(bcc, test.module.TestModuleInfo)
+ shouldConvert := test.module.shouldConvertWithBp2build(bcc,
+ shouldConvertParams{
+ module: test.module.TestModuleInfo,
+ moduleDir: test.module.TestModuleInfo.Dir,
+ moduleType: test.module.TestModuleInfo.Typ,
+ moduleName: test.module.TestModuleInfo.ModuleName,
+ },
+ )
if test.shouldConvert != shouldConvert {
t.Errorf("Module shouldConvert expected to be: %v, but was: %v", test.shouldConvert, shouldConvert)
}
diff --git a/android/config.go b/android/config.go
index eb89493..3e7bb14 100644
--- a/android/config.go
+++ b/android/config.go
@@ -190,6 +190,12 @@
return String(c.config.productVariables.DeviceMaxPageSizeSupported)
}
+// PageSizeAgnostic returns true when AOSP is page size agnostic,
+// othersise it returns false.
+func (c Config) PageSizeAgnostic() bool {
+ return Bool(c.config.productVariables.DevicePageSizeAgnostic)
+}
+
// The release version passed to aconfig, derived from RELEASE_VERSION
func (c Config) ReleaseVersion() string {
return c.config.productVariables.ReleaseVersion
@@ -200,6 +206,12 @@
return c.config.productVariables.ReleaseAconfigValueSets
}
+// The flag default permission value passed to aconfig
+// derived from RELEASE_ACONFIG_FLAG_DEFAULT_PERMISSION
+func (c Config) ReleaseAconfigFlagDefaultPermission() string {
+ return c.config.productVariables.ReleaseAconfigFlagDefaultPermission
+}
+
// A DeviceConfig object represents the configuration for a particular device
// being built. For now there will only be one of these, but in the future there
// may be multiple devices being built.
@@ -433,10 +445,6 @@
t := reflect.TypeOf(p.Product_variables)
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
- if f.Name == "Pdk" {
- // Pdk is deprecated and has no effect as of aosp/1319667
- continue
- }
archVariant := proptools.HasTag(f, "android", "arch_variant")
if mainProductVariablesStructField, ok := allProductVariablesType.FieldByName(f.Name); ok {
productVariablesInfo[f.Name] = productVariableStarlarkRepresentation{
diff --git a/android/override_module.go b/android/override_module.go
index a4b7431..9e0de6f 100644
--- a/android/override_module.go
+++ b/android/override_module.go
@@ -353,26 +353,26 @@
// variant of this OverridableModule, or ctx.ModuleName() if this module is not an OverridableModule
// or if this variant is not overridden.
func ModuleNameWithPossibleOverride(ctx BazelConversionContext) string {
- return moduleNameWithPossibleOverride(ctx, ctx.Module())
+ return moduleNameWithPossibleOverride(ctx, ctx.Module(), ctx.OtherModuleName(ctx.Module()))
}
-func moduleNameWithPossibleOverride(ctx bazelOtherModuleContext, module blueprint.Module) string {
+func moduleNameWithPossibleOverride(ctx shouldConvertModuleContext, module blueprint.Module, name string) string {
if overridable, ok := module.(OverridableModule); ok {
if o := overridable.GetOverriddenBy(); o != "" {
return o
}
}
- return ctx.OtherModuleName(module)
+ return name
}
// moduleDirWithPossibleOverride returns the dir of the OverrideModule that overrides the current
// variant of the given OverridableModule, or ctx.OtherModuleName() if the module is not an
// OverridableModule or if the variant is not overridden.
-func moduleDirWithPossibleOverride(ctx bazelOtherModuleContext, module blueprint.Module) string {
+func moduleDirWithPossibleOverride(ctx shouldConvertModuleContext, module blueprint.Module, dir string) string {
if overridable, ok := module.(OverridableModule); ok {
if o := overridable.GetOverriddenByModuleDir(); o != "" {
return o
}
}
- return ctx.OtherModuleDir(module)
+ return dir
}
diff --git a/android/proto.go b/android/proto.go
index aad521b..b21efd6 100644
--- a/android/proto.go
+++ b/android/proto.go
@@ -230,6 +230,7 @@
name := m.Name() + "_proto"
depsFromFilegroup := protoLibraries
+ var canonicalPathFromRoot bool
if len(directProtoSrcs.Includes) > 0 {
pkgToSrcs := partitionSrcsByPackage(ctx.ModuleDir(), directProtoSrcs)
@@ -250,7 +251,8 @@
if axis == bazel.NoConfigAxis {
info.Type = props.Proto.Type
- if !proptools.BoolDefault(props.Proto.Canonical_path_from_root, canonicalPathFromRootDefault) {
+ canonicalPathFromRoot = proptools.BoolDefault(props.Proto.Canonical_path_from_root, canonicalPathFromRootDefault)
+ if !canonicalPathFromRoot {
// an empty string indicates to strips the package path
path := ""
attrs.Strip_import_prefix = &path
@@ -271,13 +273,25 @@
tags := ApexAvailableTagsWithoutTestApexes(ctx.(TopDownMutatorContext), ctx.Module())
- // Since we are creating the proto_library in a subpackage, create an import_prefix relative to the current package
- if rel, err := filepath.Rel(ctx.ModuleDir(), pkg); err != nil {
- ctx.ModuleErrorf("Could not get relative path for %v %v", pkg, err)
- } else if rel != "." {
- attrs.Import_prefix = &rel
+ moduleDir := ctx.ModuleDir()
+ if !canonicalPathFromRoot {
+ // Since we are creating the proto_library in a subpackage, set the import_prefix relative to the current package
+ if rel, err := filepath.Rel(moduleDir, pkg); err != nil {
+ ctx.ModuleErrorf("Could not get relative path for %v %v", pkg, err)
+ } else if rel != "." {
+ attrs.Import_prefix = &rel
+ }
}
+ // TODO - b/246997908: Handle potential orphaned proto_library targets
+ // To create proto_library targets in the same package, we split the .proto files
+ // This means that if a proto_library in a subpackage imports another proto_library from the parent package
+ // (or a different subpackage), it will not find it.
+ // The CcProtoGen action itself runs fine because we construct the correct ProtoInfo,
+ // but the FileDescriptorSet of each proto_library might not be compile-able
+ if pkg != ctx.ModuleDir() {
+ tags.Append(bazel.MakeStringListAttribute([]string{"manual"}))
+ }
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
CommonAttributes{Name: name, Dir: proptools.StringPtr(pkg), Tags: tags},
@@ -285,7 +299,7 @@
)
l := ""
- if pkg == ctx.ModuleDir() { // same package that the original module lives in
+ if pkg == moduleDir { // same package that the original module lives in
l = ":" + name
} else {
l = "//" + pkg + ":" + name
diff --git a/android/variable.go b/android/variable.go
index 03a80c1..ca9a221 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -95,10 +95,6 @@
Cflags []string
}
- Device_page_size_agnostic struct {
- Cflags []string `android:"arch_variant"`
- } `android:"arch_variant"`
-
Override_rs_driver struct {
Cflags []string
}
@@ -142,6 +138,7 @@
Srcs []string
Exclude_srcs []string
+ Cmd *string
}
// eng is true for -eng builds, and can be used to turn on additional heavyweight debugging
@@ -160,11 +157,6 @@
}
}
- // Deprecated, has no effect as of aosp/1319667
- Pdk struct {
- Enabled *bool `android:"arch_variant"`
- } `android:"arch_variant"`
-
Uml struct {
Cppflags []string
}
@@ -232,6 +224,7 @@
DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"`
DeviceSystemSdkVersions []string `json:",omitempty"`
DeviceMaxPageSizeSupported *string `json:",omitempty"`
+ DevicePageSizeAgnostic *bool `json:",omitempty"`
RecoverySnapshotVersion *string `json:",omitempty"`
@@ -287,7 +280,6 @@
Safestack *bool `json:",omitempty"`
HostStaticBinaries *bool `json:",omitempty"`
Binder32bit *bool `json:",omitempty"`
- Device_page_size_agnostic *bool `json:",omitempty"`
UseGoma *bool `json:",omitempty"`
UseRBE *bool `json:",omitempty"`
UseRBEJAVAC *bool `json:",omitempty"`
@@ -491,6 +483,8 @@
ReleaseVersion string `json:",omitempty"`
ReleaseAconfigValueSets []string `json:",omitempty"`
+ ReleaseAconfigFlagDefaultPermission string `json:",omitempty"`
+
KeepVndk *bool `json:",omitempty"`
}
@@ -532,6 +526,7 @@
DeviceSecondaryCpuVariant: stringPtr("generic"),
DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"},
DeviceMaxPageSizeSupported: stringPtr("4096"),
+ DevicePageSizeAgnostic: boolPtr(false),
AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
AAPTPreferredConfig: stringPtr("xhdpi"),
@@ -544,7 +539,6 @@
Safestack: boolPtr(false),
TrimmedApex: boolPtr(false),
Build_from_text_stub: boolPtr(false),
- Device_page_size_agnostic: boolPtr(false),
BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
@@ -684,11 +678,16 @@
if moduleBase.variableProperties != nil {
productVariablesProperty := proptools.FieldNameForProperty("product_variables")
- for /* axis */ _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) {
- for config, props := range configToProps {
- variableValues := reflect.ValueOf(props).Elem().FieldByName(productVariablesProperty)
- productConfigProperties.AddProductConfigProperties(variableValues, config)
+ if moduleBase.ArchSpecific() {
+ for /* axis */ _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) {
+ for config, props := range configToProps {
+ variableValues := reflect.ValueOf(props).Elem().FieldByName(productVariablesProperty)
+ productConfigProperties.AddProductConfigProperties(variableValues, config)
+ }
}
+ } else {
+ variableValues := reflect.ValueOf(moduleBase.variableProperties).Elem().FieldByName(productVariablesProperty)
+ productConfigProperties.AddProductConfigProperties(variableValues, "")
}
}
diff --git a/apex/apex.go b/apex/apex.go
index b26d1d2..8c21d3d 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1685,6 +1685,7 @@
if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
}
+ dirInApex = filepath.Join(dirInApex, rustm.RelativeInstallPath())
fileToCopy := android.OutputFileForModule(ctx, rustm, "")
androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
@@ -1704,6 +1705,7 @@
if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
}
+ dirInApex = filepath.Join(dirInApex, rustm.RelativeInstallPath())
fileToCopy := android.OutputFileForModule(ctx, rustm, "")
androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 9dba08e..8368db1 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -390,7 +390,7 @@
name: "foo.rust",
srcs: ["foo.rs"],
rlibs: ["libfoo.rlib.rust"],
- dylibs: ["libfoo.dylib.rust"],
+ rustlibs: ["libfoo.dylib.rust"],
apex_available: ["myapex"],
}
@@ -2794,7 +2794,7 @@
name: "myapex",
key: "myapex.key",
native_shared_libs: ["mylib"],
- binaries: ["mybin"],
+ binaries: ["mybin", "mybin.rust"],
prebuilts: ["myetc"],
compile_multilib: "both",
updatable: false,
@@ -2829,6 +2829,13 @@
stl: "none",
apex_available: [ "myapex" ],
}
+
+ rust_binary {
+ name: "mybin.rust",
+ srcs: ["foo.rs"],
+ relative_install_path: "rust_subdir",
+ apex_available: [ "myapex" ],
+ }
`)
generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
@@ -2847,6 +2854,7 @@
ensureContains(t, cmd, "/bin ")
ensureContains(t, cmd, "/bin/foo ")
ensureContains(t, cmd, "/bin/foo/bar ")
+ ensureContains(t, cmd, "/bin/rust_subdir ")
}
func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) {
diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go
index 12a9b15..e8c2ef7 100644
--- a/bp2build/bp2build_product_config.go
+++ b/bp2build/bp2build_product_config.go
@@ -256,7 +256,7 @@
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ",")))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_max_page_size_supported=%s\n", proptools.String(productVariables.DeviceMaxPageSizeSupported)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_name=%s\n", proptools.String(productVariables.DeviceName)))
- result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_page_size_agnostic=%t\n", proptools.Bool(productVariables.Device_page_size_agnostic)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_page_size_agnostic=%t\n", proptools.Bool(productVariables.DevicePageSizeAgnostic)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_product=%s\n", proptools.String(productVariables.DeviceProduct)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enforce_vintf_manifest=%t\n", proptools.Bool(productVariables.Enforce_vintf_manifest)))
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index 6ca4bb4..cd1bc7f 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -686,6 +686,9 @@
//
// bp2build converters are used for the majority of modules.
if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() {
+ if aModule, ok := m.(android.Module); ok && aModule.IsConvertedByBp2build() {
+ panic(fmt.Errorf("module %q [%s] [%s] was both converted with bp2build and has a handcrafted label", bpCtx.ModuleName(m), moduleType, dir))
+ }
// Handle modules converted to handcrafted targets.
//
// Since these modules are associated with some handcrafted
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index e425b36..622ec4a 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -4930,6 +4930,9 @@
"bar/bar.proto", // Different package because there is a bar/Android.bp
"baz/subbaz/baz.proto", // Different package because there is baz/subbaz/Android.bp
],
+ proto: {
+ canonical_path_from_root: true,
+ }
}
` + simpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
Filesystem: map[string]string{
@@ -4963,8 +4966,8 @@
tc.Dir = "bar"
tc.ExpectedBazelTargets = []string{
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
- "srcs": `["//bar:bar.proto"]`,
- "import_prefix": `"bar"`,
+ "srcs": `["//bar:bar.proto"]`,
+ "tags": `["manual"]`,
}),
}
runCcLibraryTestCase(t, tc)
@@ -4973,8 +4976,80 @@
tc.Dir = "baz/subbaz"
tc.ExpectedBazelTargets = []string{
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
- "srcs": `["//baz/subbaz:baz.proto"]`,
- "import_prefix": `"baz/subbaz"`,
+ "srcs": `["//baz/subbaz:baz.proto"]`,
+ "tags": `["manual"]`,
+ }),
+ }
+ runCcLibraryTestCase(t, tc)
+}
+
+// Bazel enforces that proto_library and the .proto file are in the same bazel package
+func TestGenerateProtoLibraryInSamePackageNotCanonicalFromRoot(t *testing.T) {
+ tc := Bp2buildTestCase{
+ Description: "cc_library depends on .proto files from multiple packages",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `
+cc_library_static {
+ name: "foo",
+ srcs: [
+ "foo.proto",
+ "bar/bar.proto", // Different package because there is a bar/Android.bp
+ "baz/subbaz/baz.proto", // Different package because there is baz/subbaz/Android.bp
+ ],
+ proto: {
+ canonical_path_from_root: false,
+ }
+}
+` + simpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
+ Filesystem: map[string]string{
+ "bar/Android.bp": "",
+ "baz/subbaz/Android.bp": "",
+ },
+ }
+
+ // We will run the test 3 times and check in the root, bar and baz/subbaz directories
+ // Root dir
+ tc.ExpectedBazelTargets = []string{
+ MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "deps": `[":libprotobuf-cpp-lite"]`,
+ "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
+ }),
+ MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
+ "srcs": `["foo.proto"]`,
+ "strip_import_prefix": `""`,
+ }),
+ MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
+ "deps": `[
+ ":foo_proto",
+ "//bar:foo_proto",
+ "//baz/subbaz:foo_proto",
+ ]`,
+ }),
+ }
+ runCcLibraryTestCase(t, tc)
+
+ // bar dir
+ tc.Dir = "bar"
+ tc.ExpectedBazelTargets = []string{
+ MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
+ "srcs": `["//bar:bar.proto"]`,
+ "strip_import_prefix": `""`,
+ "import_prefix": `"bar"`,
+ "tags": `["manual"]`,
+ }),
+ }
+ runCcLibraryTestCase(t, tc)
+
+ // baz/subbaz dir
+ tc.Dir = "baz/subbaz"
+ tc.ExpectedBazelTargets = []string{
+ MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
+ "srcs": `["//baz/subbaz:baz.proto"]`,
+ "strip_import_prefix": `""`,
+ "import_prefix": `"baz/subbaz"`,
+ "tags": `["manual"]`,
}),
}
runCcLibraryTestCase(t, tc)
diff --git a/bp2build/genrule_conversion_test.go b/bp2build/genrule_conversion_test.go
index 5a73969..5ca8bd7 100644
--- a/bp2build/genrule_conversion_test.go
+++ b/bp2build/genrule_conversion_test.go
@@ -772,3 +772,144 @@
})
}
}
+
+func TestGenruleWithSoongConfigVariableConfiguredCmd(t *testing.T) {
+ testCases := []struct {
+ moduleType string
+ factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
+ }{
+ {
+ moduleType: "genrule",
+ factory: genrule.GenRuleFactory,
+ },
+ {
+ moduleType: "cc_genrule",
+ factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
+ },
+ {
+ moduleType: "java_genrule",
+ factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
+ },
+ {
+ moduleType: "java_genrule_host",
+ factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
+ },
+ }
+
+ bp := `
+soong_config_module_type {
+ name: "my_genrule",
+ module_type: "%s",
+ config_namespace: "my_namespace",
+ bool_variables: ["my_variable"],
+ properties: ["cmd"],
+}
+
+my_genrule {
+ name: "foo",
+ out: ["foo.txt"],
+ cmd: "echo 'no variable' > $(out)",
+ soong_config_variables: {
+ my_variable: {
+ cmd: "echo 'with variable' > $(out)",
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}
+`
+
+ for _, tc := range testCases {
+ moduleAttrs := AttrNameToString{
+ "cmd": `select({
+ "//build/bazel/product_config/config_settings:my_namespace__my_variable": "echo 'with variable' > $(OUTS)",
+ "//conditions:default": "echo 'no variable' > $(OUTS)",
+ })`,
+ "outs": `["foo.txt"]`,
+ }
+
+ expectedBazelTargets := []string{
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
+ }
+
+ t.Run(tc.moduleType, func(t *testing.T) {
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
+ Bp2buildTestCase{
+ Blueprint: fmt.Sprintf(bp, tc.moduleType),
+ ModuleTypeUnderTest: tc.moduleType,
+ ModuleTypeUnderTestFactory: tc.factory,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ })
+ }
+}
+
+func TestGenruleWithProductVariableConfiguredCmd(t *testing.T) {
+ testCases := []struct {
+ moduleType string
+ factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
+ }{
+ {
+ moduleType: "genrule",
+ factory: genrule.GenRuleFactory,
+ },
+ {
+ moduleType: "cc_genrule",
+ factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
+ },
+ {
+ moduleType: "java_genrule",
+ factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
+ },
+ {
+ moduleType: "java_genrule_host",
+ factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
+ },
+ }
+
+ bp := `
+
+%s {
+ name: "foo",
+ out: ["foo.txt"],
+ cmd: "echo 'no variable' > $(out)",
+ product_variables: {
+ debuggable: {
+ cmd: "echo 'with variable' > $(out)",
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}
+`
+
+ for _, tc := range testCases {
+ moduleAttrs := AttrNameToString{
+ "cmd": `select({
+ "//build/bazel/product_config/config_settings:debuggable": "echo 'with variable' > $(OUTS)",
+ "//conditions:default": "echo 'no variable' > $(OUTS)",
+ })`,
+ "outs": `["foo.txt"]`,
+ }
+
+ expectedBazelTargets := []string{
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
+ }
+
+ t.Run(tc.moduleType, func(t *testing.T) {
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
+ Bp2buildTestCase{
+ Blueprint: fmt.Sprintf(bp, tc.moduleType),
+ ModuleTypeUnderTest: tc.moduleType,
+ ModuleTypeUnderTestFactory: tc.factory,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ })
+ }
+}
diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go
index ca2e05f..12722a7 100644
--- a/cc/config/arm64_device.go
+++ b/cc/config/arm64_device.go
@@ -100,7 +100,15 @@
return strings.Join(flags, " ")
})
- exportedVars.ExportStringListStaticVariable("Arm64Cflags", arm64Cflags)
+ exportedVars.ExportStringList("Arm64Cflags", arm64Cflags)
+ pctx.VariableFunc("Arm64Cflags", func(ctx android.PackageVarContext) string {
+ flags := arm64Cflags
+ if ctx.Config().PageSizeAgnostic() {
+ flags = append(flags, "-D__BIONIC_NO_PAGE_SIZE_MACRO")
+ }
+ return strings.Join(flags, " ")
+ })
+
exportedVars.ExportStringListStaticVariable("Arm64Cppflags", arm64Cppflags)
exportedVars.ExportVariableReferenceDict("Arm64ArchVariantCflags", arm64ArchVariantCflagsVar)
diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go
index 3397e3d..3d6890c 100644
--- a/cc/config/arm_device.go
+++ b/cc/config/arm_device.go
@@ -183,12 +183,7 @@
exportedVars.ExportString("ArmClangTriple", clangTriple)
exportedVars.ExportStringListStaticVariable("ArmLdflags", armLdflags)
- exportedVars.ExportStringList("ArmLldflags", armLldflags)
- pctx.VariableFunc("ArmLldflags", func(ctx android.PackageVarContext) string {
- maxPageSizeFlag := "-Wl,-z,max-page-size=" + ctx.Config().MaxPageSizeSupported()
- flags := append(armLldflags, maxPageSizeFlag)
- return strings.Join(flags, " ")
- })
+ exportedVars.ExportStringListStaticVariable("ArmLldflags", armLldflags)
exportedVars.ExportStringListStaticVariable("ArmFixCortexA8LdFlags", armFixCortexA8LdFlags)
exportedVars.ExportStringListStaticVariable("ArmNoFixCortexA8LdFlags", armNoFixCortexA8LdFlags)
diff --git a/cc/lto.go b/cc/lto.go
index df9ca0a..820c1f0 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -162,7 +162,7 @@
}
func GlobalThinLTO(ctx android.BaseModuleContext) bool {
- return !ctx.Config().IsEnvFalse("GLOBAL_THINLTO")
+ return ctx.Config().IsEnvTrue("GLOBAL_THINLTO")
}
// Propagate lto requirements down from binaries
diff --git a/cc/orderfile.go b/cc/orderfile.go
index cc1ab29..b64c1c7 100644
--- a/cc/orderfile.go
+++ b/cc/orderfile.go
@@ -121,9 +121,9 @@
}
func (props *OrderfileProperties) addInstrumentationProfileGatherFlags(ctx ModuleContext, flags Flags) Flags {
- flags.Local.CFlags = append(flags.Local.CFlags, props.Orderfile.Cflags...)
flags.Local.CFlags = append(flags.Local.CFlags, orderfileProfileFlag)
flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm -enable-order-file-instrumentation")
+ flags.Local.CFlags = append(flags.Local.CFlags, props.Orderfile.Cflags...)
flags.Local.LdFlags = append(flags.Local.LdFlags, orderfileProfileFlag)
return flags
}
@@ -140,7 +140,6 @@
orderFilePath := orderFile.Path()
loadFlags := props.loadOrderfileFlags(ctx, orderFilePath.String())
- flags.Local.CFlags = append(flags.Local.CFlags, loadFlags...)
flags.Local.LdFlags = append(flags.Local.LdFlags, loadFlags...)
// Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
diff --git a/cc/orderfile_test.go b/cc/orderfile_test.go
index 9e30bd2..f68457d 100644
--- a/cc/orderfile_test.go
+++ b/cc/orderfile_test.go
@@ -79,12 +79,6 @@
libTest := result.ModuleForTests("libTest", "android_arm64_armv8-a_shared")
- // Check cFlags of orderfile-enabled module
- cFlags := libTest.Rule("cc").Args["cFlags"]
- if !strings.Contains(cFlags, expectedCFlag) {
- t.Errorf("Expected 'libTest' to load orderfile, but did not find %q in cflags %q", expectedCFlag, cFlags)
- }
-
// Check ldFlags of orderfile-enabled module
ldFlags := libTest.Rule("ld").Args["ldFlags"]
if !strings.Contains(ldFlags, expectedCFlag) {
@@ -150,12 +144,6 @@
test := result.ModuleForTests("test", "android_arm64_armv8-a")
- // Check cFlags of orderfile-enabled module
- cFlags := test.Rule("cc").Args["cFlags"]
- if !strings.Contains(cFlags, expectedCFlag) {
- t.Errorf("Expected 'test' to load orderfile, but did not find %q in cflags %q", expectedCFlag, cFlags)
- }
-
// Check ldFlags of orderfile-enabled module
ldFlags := test.Rule("ld").Args["ldFlags"]
if !strings.Contains(ldFlags, expectedCFlag) {
@@ -285,28 +273,17 @@
expectedCFlag := "-Wl,--symbol-ordering-file=toolchain/pgo-profiles/orderfiles/test.orderfile"
- // Check cFlags of orderfile-enabled module
+ // Check ldFlags of orderfile-enabled module
libTest := result.ModuleForTests("libTest", "android_arm64_armv8-a_shared")
- cFlags := libTest.Rule("cc").Args["cFlags"]
- if !strings.Contains(cFlags, expectedCFlag) {
- t.Errorf("Expected 'libTest' to load orderfile, but did not find %q in cflags %q", expectedCFlag, cFlags)
+ ldFlags := libTest.Rule("ld").Args["ldFlags"]
+ if !strings.Contains(ldFlags, expectedCFlag) {
+ t.Errorf("Expected 'libTest' to load orderfile, but did not find %q in ldFlags %q", expectedCFlag, ldFlags)
}
- // Check cFlags of the non-orderfile variant static libraries
libFoo := result.ModuleForTests("libFoo", "android_arm64_armv8-a_static")
libBar := result.ModuleForTests("libBar", "android_arm64_armv8-a_static")
- cFlags = libFoo.Rule("cc").Args["cFlags"]
- if strings.Contains(cFlags, expectedCFlag) {
- t.Errorf("Expected 'libFoo' not load orderfile, but did find %q in cflags %q", expectedCFlag, cFlags)
- }
-
- cFlags = libBar.Rule("cc").Args["cFlags"]
- if strings.Contains(cFlags, expectedCFlag) {
- t.Errorf("Expected 'libBar' not load orderfile, but did find %q in cflags %q", expectedCFlag, cFlags)
- }
-
// Check dependency edge from orderfile-enabled module to non-orderfile variant static libraries
if !hasDirectDep(result, libTest.Module(), libFoo.Module()) {
t.Errorf("libTest missing dependency on non-orderfile variant of libFoo")
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 8a8d605..aa4295d 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -869,7 +869,7 @@
Srcs bazel.LabelListAttribute
Output_extension *string
Tools bazel.LabelListAttribute
- Cmd string
+ Cmd bazel.StringAttribute
Data bazel.LabelListAttribute
}
@@ -917,7 +917,7 @@
Srcs bazel.LabelListAttribute
Outs []string
Tools bazel.LabelListAttribute
- Cmd string
+ Cmd bazel.StringAttribute
}
// ConvertWithBp2build converts a Soong module -> Bazel target.
@@ -967,14 +967,13 @@
}
}
- // Replace in and out variables with $< and $@
- var cmd string
- if m.properties.Cmd != nil {
+ replaceVariables := func(cmd string) string {
+ // Replace in and out variables with $< and $@
if ctx.ModuleType() == "gensrcs" {
- cmd = strings.ReplaceAll(*m.properties.Cmd, "$(in)", "$(SRC)")
+ cmd = strings.ReplaceAll(cmd, "$(in)", "$(SRC)")
cmd = strings.ReplaceAll(cmd, "$(out)", "$(OUT)")
} else {
- cmd = strings.Replace(*m.properties.Cmd, "$(in)", "$(SRCS)", -1)
+ cmd = strings.Replace(cmd, "$(in)", "$(SRCS)", -1)
cmd = strings.Replace(cmd, "$(out)", "$(OUTS)", -1)
}
cmd = strings.Replace(cmd, "$(genDir)", "$(RULEDIR)", -1)
@@ -990,6 +989,21 @@
cmd = strings.Replace(cmd, bpLoc, bazelLoc, -1)
cmd = strings.Replace(cmd, bpLocs, bazelLocs, -1)
}
+ return cmd
+ }
+
+ var cmdProp bazel.StringAttribute
+ cmdProp.SetValue(replaceVariables(proptools.String(m.properties.Cmd)))
+ allProductVariableProps := android.ProductVariableProperties(ctx, m)
+ if productVariableProps, ok := allProductVariableProps["Cmd"]; ok {
+ for productVariable, value := range productVariableProps {
+ var cmd string
+ if strValue, ok := value.(*string); ok && strValue != nil {
+ cmd = *strValue
+ }
+ cmd = replaceVariables(cmd)
+ cmdProp.SetSelectValue(productVariable.ConfigurationAxis(), productVariable.SelectKey(), &cmd)
+ }
}
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
@@ -1003,7 +1017,7 @@
attrs := &bazelGensrcsAttributes{
Srcs: srcs,
Output_extension: outputExtension,
- Cmd: cmd,
+ Cmd: cmdProp,
Tools: tools,
Data: data,
}
@@ -1026,7 +1040,7 @@
attrs := &bazelGenruleAttributes{
Srcs: srcs,
Outs: outs,
- Cmd: cmd,
+ Cmd: cmdProp,
Tools: tools,
}
props := bazel.BazelTargetModuleProperties{
@@ -1056,7 +1070,6 @@
Name: m.Name() + genruleHeaderLibrarySuffix,
Tags: tags,
}, attrs)
-
}
}
diff --git a/java/droiddoc.go b/java/droiddoc.go
index d4ead12..3ba3065 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -699,7 +699,6 @@
cmd := rule.Command().
BuiltTool("soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
Flag(config.JavacVmFlags).
- FlagWithArg("-encoding ", "UTF-8").
FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "javadoc.rsp"), srcs).
FlagWithInput("@", srcJarList)
diff --git a/java/droidstubs.go b/java/droidstubs.go
index bb2388f..f05ef1f 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -512,17 +512,16 @@
cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")).
Flag(config.JavacVmFlags).
Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED").
- FlagWithArg("-encoding ", "UTF-8").
- FlagWithArg("-source ", javaVersion.String()).
+ FlagWithArg("--java-source ", javaVersion.String()).
FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "metalava.rsp"), srcs).
FlagWithInput("@", srcJarList)
- if len(bootclasspath) > 0 {
- cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
- }
-
- if len(classpath) > 0 {
- cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
+ // Metalava does not differentiate between bootclasspath and classpath and has not done so for
+ // years, so it is unlikely to change any time soon.
+ combinedPaths := append(([]android.Path)(nil), bootclasspath.Paths()...)
+ combinedPaths = append(combinedPaths, classpath.Paths()...)
+ if len(combinedPaths) > 0 {
+ cmd.FlagWithInputList("--classpath ", combinedPaths, ":")
}
cmd.Flag("--color").
@@ -695,6 +694,13 @@
cmd.FlagWithArg("--error-message:compatibility:released ", msg)
}
+ if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") {
+ // Pass the current API file into metalava so it can use it as the basis for determining how to
+ // generate the output signature files (both api and removed).
+ currentApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
+ cmd.FlagWithInput("--use-same-format-as ", currentApiFile)
+ }
+
if generateStubs {
rule.Command().
BuiltTool("soong_zip").
diff --git a/java/java.go b/java/java.go
index f11debf..70aba8e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1683,6 +1683,9 @@
// extracting the compiled class files provided by the
// full_api_surface_stub module.
Full_api_surface_stub *string
+
+ // Version of previously released API file for compatibility check.
+ Previous_api *string `android:"path"`
}
func ApiLibraryFactory() android.Module {
@@ -1726,7 +1729,6 @@
cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")).
Flag(config.JavacVmFlags).
Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED").
- FlagWithArg("-encoding ", "UTF-8").
FlagWithInputList("--source-files ", srcs, " ")
cmd.Flag("--color").
@@ -1813,6 +1815,28 @@
}
}
+// API signature file names sorted from
+// the narrowest api scope to the widest api scope
+var scopeOrderedSourceFileNames = allApiScopes.Strings(
+ func(s *apiScope) string { return s.apiFilePrefix + "current.txt" })
+
+func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFiles android.Paths) android.Paths {
+ sortedSrcFiles := android.Paths{}
+
+ for _, scopeSourceFileName := range scopeOrderedSourceFileNames {
+ for _, sourceFileName := range srcFiles {
+ if sourceFileName.Base() == scopeSourceFileName {
+ sortedSrcFiles = append(sortedSrcFiles, sourceFileName)
+ }
+ }
+ }
+ if len(srcFiles) != len(sortedSrcFiles) {
+ ctx.ModuleErrorf("Unrecognizable source file found within %s", srcFiles)
+ }
+
+ return sortedSrcFiles
+}
+
func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
rule := android.NewRuleBuilder(pctx, ctx)
@@ -1863,10 +1887,18 @@
ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName())
}
+ srcFiles = al.sortApiFilesByApiScope(ctx, srcFiles)
+
cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir)
al.stubsFlags(ctx, cmd, stubsDir)
+ migratingNullability := String(al.properties.Previous_api) != ""
+ if migratingNullability {
+ previousApi := android.PathForModuleSrc(ctx, String(al.properties.Previous_api))
+ cmd.FlagWithInput("--migrate-nullness ", previousApi)
+ }
+
al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar")
al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, "metalava", "stubs.jar")
al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName()))
diff --git a/java/java_test.go b/java/java_test.go
index dd98677..6110e21 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1864,12 +1864,12 @@
provider_bp_a := `
java_api_contribution {
name: "foo1",
- api_file: "foo1.txt",
+ api_file: "current.txt",
}
`
provider_bp_b := `java_api_contribution {
name: "foo2",
- api_file: "foo2.txt",
+ api_file: "current.txt",
}
`
ctx, _ := testJavaWithFS(t, `
@@ -1897,11 +1897,11 @@
}{
{
moduleName: "bar1",
- sourceTextFileDirs: []string{"a/foo1.txt"},
+ sourceTextFileDirs: []string{"a/current.txt"},
},
{
moduleName: "bar2",
- sourceTextFileDirs: []string{"a/foo1.txt", "b/foo2.txt", "api1/current.txt", "api2/current.txt"},
+ sourceTextFileDirs: []string{"a/current.txt", "b/current.txt", "api1/current.txt", "api2/current.txt"},
},
}
for _, c := range testcases {
@@ -1918,25 +1918,25 @@
provider_bp_a := `
java_api_contribution {
name: "foo1",
- api_file: "foo1.txt",
+ api_file: "current.txt",
}
`
provider_bp_b := `
java_api_contribution {
name: "foo2",
- api_file: "foo2.txt",
+ api_file: "current.txt",
}
`
provider_bp_c := `
java_api_contribution {
name: "foo3",
- api_file: "foo3.txt",
+ api_file: "current.txt",
}
`
provider_bp_d := `
java_api_contribution {
name: "foo4",
- api_file: "foo4.txt",
+ api_file: "current.txt",
}
`
ctx, _ := testJavaWithFS(t, `
@@ -1985,15 +1985,15 @@
}{
{
moduleName: "bar1",
- sourceTextFileDirs: []string{"a/foo1.txt"},
+ sourceTextFileDirs: []string{"a/current.txt"},
},
{
moduleName: "bar2",
- sourceTextFileDirs: []string{"a/foo1.txt", "b/foo2.txt"},
+ sourceTextFileDirs: []string{"a/current.txt", "b/current.txt"},
},
{
moduleName: "bar3",
- sourceTextFileDirs: []string{"c/foo3.txt", "a/foo1.txt", "b/foo2.txt", "d/foo4.txt", "api1/current.txt", "api2/current.txt"},
+ sourceTextFileDirs: []string{"c/current.txt", "a/current.txt", "b/current.txt", "d/current.txt", "api1/current.txt", "api2/current.txt"},
},
}
for _, c := range testcases {
@@ -2010,13 +2010,13 @@
provider_bp_a := `
java_api_contribution {
name: "foo1",
- api_file: "foo1.txt",
+ api_file: "current.txt",
}
`
provider_bp_b := `
java_api_contribution {
name: "foo2",
- api_file: "foo2.txt",
+ api_file: "current.txt",
}
`
ctx, _ := testJavaWithFS(t, `
@@ -2063,13 +2063,13 @@
provider_bp_a := `
java_api_contribution {
name: "foo1",
- api_file: "foo1.txt",
+ api_file: "current.txt",
}
`
provider_bp_b := `
java_api_contribution {
name: "foo2",
- api_file: "foo2.txt",
+ api_file: "current.txt",
}
`
lib_bp_a := `
@@ -2138,13 +2138,13 @@
provider_bp_a := `
java_api_contribution {
name: "foo1",
- api_file: "foo1.txt",
+ api_file: "current.txt",
}
`
provider_bp_b := `
java_api_contribution {
name: "foo2",
- api_file: "foo2.txt",
+ api_file: "current.txt",
}
`
lib_bp_a := `
@@ -2212,13 +2212,13 @@
provider_bp_a := `
java_api_contribution {
name: "foo1",
- api_file: "foo1.txt",
+ api_file: "current.txt",
}
`
provider_bp_b := `
java_api_contribution {
name: "foo2",
- api_file: "foo2.txt",
+ api_file: "current.txt",
}
`
lib_bp_a := `
diff --git a/java/sdk_library.go b/java/sdk_library.go
index dbb2f02..b1ddde0 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -387,6 +387,23 @@
apiScopeModuleLib,
apiScopeSystemServer,
}
+ apiLibraryAdditionalProperties = map[string]struct {
+ FullApiSurfaceStubLib string
+ AdditionalApiContribution string
+ }{
+ "legacy.i18n.module.platform.api": {
+ FullApiSurfaceStubLib: "legacy.core.platform.api.stubs",
+ AdditionalApiContribution: "i18n.module.public.api.stubs.source.api.contribution",
+ },
+ "stable.i18n.module.platform.api": {
+ FullApiSurfaceStubLib: "stable.core.platform.api.stubs",
+ AdditionalApiContribution: "i18n.module.public.api.stubs.source.api.contribution",
+ },
+ "conscrypt.module.platform.api": {
+ FullApiSurfaceStubLib: "stable.core.platform.api.stubs",
+ AdditionalApiContribution: "conscrypt.module.public.api.stubs.source.api.contribution",
+ },
+ }
)
var (
@@ -1513,6 +1530,29 @@
return exists
}
+// The listed modules are the special java_sdk_libraries where apiScope.kind do not match the
+// api surface that the module contribute to. For example, the public droidstubs and java_library
+// do not contribute to the public api surface, but contributes to the core platform api surface.
+// This method returns the full api surface stub lib that
+// the generated java_api_library should depend on.
+func (module *SdkLibrary) alternativeFullApiSurfaceStubLib() string {
+ if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok {
+ return val.FullApiSurfaceStubLib
+ }
+ return ""
+}
+
+// The listed modules' stubs contents do not match the corresponding txt files,
+// but require additional api contributions to generate the full stubs.
+// This method returns the name of the additional api contribution module
+// for corresponding sdk_library modules.
+func (module *SdkLibrary) apiLibraryAdditionalApiContribution() string {
+ if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok {
+ return val.AdditionalApiContribution
+ }
+ return ""
+}
+
func childModuleVisibility(childVisibility []string) []string {
if childVisibility == nil {
// No child visibility set. The child will use the visibility of the sdk_library.
@@ -1778,7 +1818,7 @@
mctx.CreateModule(DroidstubsFactory, &props).(*Droidstubs).CallHookIfAvailable(mctx)
}
-func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
+func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, apiScope *apiScope, alternativeFullApiSurfaceStub string) {
props := struct {
Name *string
Visibility []string
@@ -1801,13 +1841,22 @@
apiContributions = append(apiContributions, module.stubsSourceModuleName(scope)+".api.contribution")
scope = scope.extends
}
+ if apiScope == apiScopePublic {
+ additionalApiContribution := module.apiLibraryAdditionalApiContribution()
+ if additionalApiContribution != "" {
+ apiContributions = append(apiContributions, additionalApiContribution)
+ }
+ }
props.Api_contributions = apiContributions
props.Libs = module.properties.Libs
props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...)
props.Libs = append(props.Libs, "stub-annotations")
props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs
- props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName() + ".from-text")
+ props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName())
+ if alternativeFullApiSurfaceStub != "" {
+ props.Full_api_surface_stub = proptools.StringPtr(alternativeFullApiSurfaceStub)
+ }
// android_module_lib_stubs_current.from-text only comprises api contributions from art, conscrypt and i18n.
// Thus, replace with android_module_lib_stubs_current_full.from-text, which comprises every api domains.
@@ -2062,9 +2111,13 @@
module.createStubsLibrary(mctx, scope)
- contributesToApiSurface := module.contributesToApiSurface(mctx.Config())
+ alternativeFullApiSurfaceStubLib := ""
+ if scope == apiScopePublic {
+ alternativeFullApiSurfaceStubLib = module.alternativeFullApiSurfaceStubLib()
+ }
+ contributesToApiSurface := module.contributesToApiSurface(mctx.Config()) || alternativeFullApiSurfaceStubLib != ""
if contributesToApiSurface {
- module.createApiLibrary(mctx, scope)
+ module.createApiLibrary(mctx, scope, alternativeFullApiSurfaceStubLib)
}
module.createTopLevelStubsLibrary(mctx, scope, contributesToApiSurface)
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index c22b980..118f8b6 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -1449,17 +1449,17 @@
{
scope: apiScopePublic,
apiContributions: []string{"foo.stubs.source.api.contribution"},
- fullApiSurfaceStub: "android_stubs_current.from-text",
+ fullApiSurfaceStub: "android_stubs_current",
},
{
scope: apiScopeSystem,
apiContributions: []string{"foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
- fullApiSurfaceStub: "android_system_stubs_current.from-text",
+ fullApiSurfaceStub: "android_system_stubs_current",
},
{
scope: apiScopeTest,
apiContributions: []string{"foo.stubs.source.test.api.contribution", "foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
- fullApiSurfaceStub: "android_test_stubs_current.from-text",
+ fullApiSurfaceStub: "android_test_stubs_current",
},
{
scope: apiScopeModuleLib,
diff --git a/rust/binary_test.go b/rust/binary_test.go
index dd4f993..fc4c560 100644
--- a/rust/binary_test.go
+++ b/rust/binary_test.go
@@ -21,6 +21,27 @@
"android/soong/android"
)
+// Test that rustlibs default linkage is always rlib for host binaries.
+func TestBinaryHostLinkage(t *testing.T) {
+ ctx := testRust(t, `
+ rust_binary_host {
+ name: "fizz-buzz",
+ srcs: ["foo.rs"],
+ rustlibs: ["libfoo"],
+ }
+ rust_library {
+ name: "libfoo",
+ srcs: ["foo.rs"],
+ crate_name: "foo",
+ host_supported: true,
+ }
+ `)
+ fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
+ if !android.InList("libfoo.rlib-std", fizzBuzz.Properties.AndroidMkRlibs) {
+ t.Errorf("rustlibs dependency libfoo should be an rlib dep for host binaries")
+ }
+}
+
// Test that rustlibs default linkage is correct for binaries.
func TestBinaryLinkage(t *testing.T) {
ctx := testRust(t, `
@@ -54,6 +75,12 @@
if !android.InList("libfoo", fizzBuzzDevice.Properties.AndroidMkDylibs) {
t.Errorf("rustlibs dependency libfoo should be an dylib dep for device modules")
}
+
+ rlibLinkDevice := ctx.ModuleForTests("rlib_linked", "android_arm64_armv8-a").Module().(*Module)
+
+ if !android.InList("libfoo.rlib-std", rlibLinkDevice.Properties.AndroidMkRlibs) {
+ t.Errorf("rustlibs dependency libfoo should be an rlib dep for device modules when prefer_rlib is set")
+ }
}
// Test that prefer_rlib links in libstd statically as well as rustlibs.
diff --git a/rust/bindgen.go b/rust/bindgen.go
index c2bf6af..407f275 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -294,7 +294,7 @@
// rust_bindgen generates Rust FFI bindings to C libraries using bindgen given a wrapper header as the primary input.
// Bindgen has a number of flags to control the generated source, and additional flags can be passed to clang to ensure
// the header and generated source is appropriately handled. It is recommended to add it as a dependency in the
-// rlibs, dylibs or rustlibs property. It may also be added in the srcs property for external crates, using the ":"
+// rlibs or rustlibs property. It may also be added in the srcs property for external crates, using the ":"
// prefix.
func RustBindgenFactory() android.Module {
module, _ := NewRustBindgen(android.HostAndDeviceSupported)
diff --git a/rust/builder.go b/rust/builder.go
index fbceecc..b1f049d 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -45,9 +45,9 @@
"rustcFlags", "libFlags", "envVars")
rustLink = pctx.AndroidStaticRule("rustLink",
blueprint.RuleParams{
- Command: "${config.RustLinker} -o $out ${crtBegin} ${config.RustLinkerArgs} @$in ${linkFlags} ${crtEnd}",
+ Command: "${config.RustLinker} -o $out ${crtBegin} ${earlyLinkFlags} @$in ${linkFlags} ${crtEnd}",
},
- "linkFlags", "crtBegin", "crtEnd")
+ "earlyLinkFlags", "linkFlags", "crtBegin", "crtEnd")
_ = pctx.SourcePathVariable("rustdocCmd", "${config.RustBin}/rustdoc")
rustdoc = pctx.AndroidStaticRule("rustdoc",
@@ -244,6 +244,10 @@
envVars = append(envVars, "AR=${cc_config.ClangBin}/llvm-ar")
+ if ctx.Darwin() {
+ envVars = append(envVars, "ANDROID_RUST_DARWIN=true")
+ }
+
return envVars
}
@@ -254,6 +258,7 @@
var implicits, linkImplicits, linkOrderOnly android.Paths
var output buildOutput
var rustcFlags, linkFlags []string
+ var earlyLinkFlags string
output.outputFile = outputFile
crateName := ctx.RustModule().CrateName()
@@ -292,6 +297,10 @@
}
// Collect linker flags
+ if !ctx.Darwin() {
+ earlyLinkFlags = "-Wl,--as-needed"
+ }
+
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
linkFlags = append(linkFlags, flags.LinkFlags...)
@@ -391,9 +400,10 @@
Implicits: linkImplicits,
OrderOnly: linkOrderOnly,
Args: map[string]string{
- "linkFlags": strings.Join(linkFlags, " "),
- "crtBegin": strings.Join(deps.CrtBegin.Strings(), " "),
- "crtEnd": strings.Join(deps.CrtEnd.Strings(), " "),
+ "earlyLinkFlags": earlyLinkFlags,
+ "linkFlags": strings.Join(linkFlags, " "),
+ "crtBegin": strings.Join(deps.CrtBegin.Strings(), " "),
+ "crtEnd": strings.Join(deps.CrtEnd.Strings(), " "),
},
})
}
diff --git a/rust/compiler.go b/rust/compiler.go
index 8d89c48..e6a7a93 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -91,10 +91,8 @@
// list of rust rlib crate dependencies
Rlibs []string `android:"arch_variant"`
- // list of rust dylib crate dependencies
- Dylibs []string `android:"arch_variant"`
-
- // list of rust automatic crate dependencies
+ // list of rust automatic crate dependencies.
+ // Rustlibs linkage is rlib for host targets and dylib for device targets.
Rustlibs []string `android:"arch_variant"`
// list of rust proc_macro crate dependencies
@@ -368,7 +366,6 @@
func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...)
- deps.Dylibs = append(deps.Dylibs, compiler.Properties.Dylibs...)
deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs...)
deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...)
deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
diff --git a/rust/config/global.go b/rust/config/global.go
index c39341e..86eb2d1 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -102,7 +102,6 @@
pctx.ImportAs("cc_config", "android/soong/cc/config")
pctx.StaticVariable("RustLinker", "${cc_config.ClangBin}/clang++")
- pctx.StaticVariable("RustLinkerArgs", "-Wl,--as-needed")
pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))
diff --git a/rust/protobuf.go b/rust/protobuf.go
index 0cf6e8c..a14ebea 100644
--- a/rust/protobuf.go
+++ b/rust/protobuf.go
@@ -243,7 +243,7 @@
// rust_protobuf generates protobuf rust code from the provided proto file. This uses the protoc-gen-rust plugin for
// protoc. Additional flags to the protoc command can be passed via the proto_flags property. This module type will
-// create library variants that can be used as a crate dependency by adding it to the rlibs, dylibs, and rustlibs
+// create library variants that can be used as a crate dependency by adding it to the rlibs and rustlibs
// properties of other modules.
func RustProtobufFactory() android.Module {
module, _ := NewRustProtobuf(android.HostAndDeviceSupported)
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 3f4e296..704bfe7 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -232,11 +232,6 @@
srcs: ["foo.rs"],
crate_name: "shared",
}
- rust_library_host_dylib {
- name: "libdylib",
- srcs: ["foo.rs"],
- crate_name: "dylib",
- }
rust_library_host_rlib {
name: "librlib",
srcs: ["foo.rs"],
@@ -252,7 +247,6 @@
}
rust_binary_host {
name: "fizz-buzz",
- dylibs: ["libdylib"],
rlibs: ["librlib"],
proc_macros: ["libpm"],
static_libs: ["libstatic"],
@@ -265,10 +259,6 @@
rustLink := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Rule("rustLink")
// Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up.
- if !android.InList("libdylib", module.Properties.AndroidMkDylibs) {
- t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)")
- }
-
if !android.InList("librlib.rlib-std", module.Properties.AndroidMkRlibs) {
t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)")
}
diff --git a/scripts/mkcratersp.py b/scripts/mkcratersp.py
index 86b4aa3..6ef01eb 100755
--- a/scripts/mkcratersp.py
+++ b/scripts/mkcratersp.py
@@ -48,6 +48,8 @@
linkdirs.append(sys.argv[i+1])
if arg.startswith('-l') or arg == '-shared':
libs.append(arg)
+ if os.getenv('ANDROID_RUST_DARWIN') and (arg == '-dylib' or arg == '-dynamiclib'):
+ libs.append(arg)
if arg.startswith('-Wl,--version-script='):
version_script = arg[21:]
if arg[0] == '-':
@@ -64,9 +66,13 @@
create_archive(f'{out}.a', [], temp_archives)
with open(out, 'w') as f:
- print(f'-Wl,--whole-archive', file=f)
- print(f'{out}.whole.a', file=f)
- print(f'-Wl,--no-whole-archive', file=f)
+ if os.getenv("ANDROID_RUST_DARWIN"):
+ print(f'-force_load', file=f)
+ print(f'{out}.whole.a', file=f)
+ else:
+ print(f'-Wl,--whole-archive', file=f)
+ print(f'{out}.whole.a', file=f)
+ print(f'-Wl,--no-whole-archive', file=f)
print(f'{out}.a', file=f)
for a in archives:
print(a, file=f)
diff --git a/sysprop/sysprop_library.go b/sysprop/sysprop_library.go
index 0edbb7c..a2c0fb7 100644
--- a/sysprop/sysprop_library.go
+++ b/sysprop/sysprop_library.go
@@ -24,6 +24,7 @@
"sync"
"android/soong/bazel"
+
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -410,7 +411,7 @@
Apex_available []string
Min_sdk_version *string
Bazel_module struct {
- Bp2build_available *bool
+ Label *string
}
}
@@ -428,6 +429,9 @@
SyspropPublicStub string
Apex_available []string
Min_sdk_version *string
+ Bazel_module struct {
+ Bp2build_available *bool
+ }
}
func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
@@ -473,6 +477,14 @@
"Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
}
+ var label *string
+ if b, ok := ctx.Module().(android.Bazelable); ok && b.ShouldConvertWithBp2build(ctx) {
+ // TODO: b/295566168 - this will need to change once build files are checked in to account for
+ // checked in modules in mixed builds
+ label = proptools.StringPtr(
+ fmt.Sprintf("//%s:%s", ctx.ModuleDir(), m.CcImplementationModuleName()))
+ }
+
// Generate a C++ implementation library.
// cc_library can receive *.sysprop files as their srcs, generating sources itself.
ccProps := ccLibraryProperties{}
@@ -492,11 +504,7 @@
ccProps.Host_supported = m.properties.Host_supported
ccProps.Apex_available = m.ApexProperties.Apex_available
ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
- // A Bazel macro handles this, so this module does not need to be handled
- // in bp2build
- // TODO(b/237810289) perhaps do something different here so that we aren't
- // also disabling these modules in mixed builds
- ccProps.Bazel_module.Bp2build_available = proptools.BoolPtr(false)
+ ccProps.Bazel_module.Label = label
ctx.CreateModule(cc.LibraryFactory, &ccProps)
scope := "internal"
@@ -541,6 +549,11 @@
SyspropPublicStub: publicStub,
Apex_available: m.ApexProperties.Apex_available,
Min_sdk_version: m.properties.Java.Min_sdk_version,
+ Bazel_module: struct {
+ Bp2build_available *bool
+ }{
+ Bp2build_available: proptools.BoolPtr(false),
+ },
})
if publicStub != "" {
@@ -558,6 +571,11 @@
Sdk_version: proptools.StringPtr("core_current"),
Libs: []string{javaSyspropStub},
Stem: proptools.StringPtr(m.BaseModuleName()),
+ Bazel_module: struct {
+ Bp2build_available *bool
+ }{
+ Bp2build_available: proptools.BoolPtr(false),
+ },
})
}
diff --git a/tests/sbom_test.sh b/tests/sbom_test.sh
index 2534b20..9801a8e 100755
--- a/tests/sbom_test.sh
+++ b/tests/sbom_test.sh
@@ -85,34 +85,18 @@
lz4=$out_dir/host/linux-x86/bin/lz4
declare -A diff_excludes
- diff_excludes[product]="\
- -I /product/etc/aconfig_flags.textproto \
- -I /product/etc/build_flags.json"
diff_excludes[vendor]="\
-I /vendor/lib64/libkeystore2_crypto.so \
- -I /vendor/etc/aconfig_flags.textproto \
- -I /vendor/etc/build_flags.json"
+ -I /vendor/lib64/libvsock_utils.so"
diff_excludes[system]="\
- -I /bin \
- -I /bugreports \
- -I /cache \
- -I /d \
- -I /etc \
- -I /init \
- -I /odm/app \
- -I /odm/bin \
- -I /odm_dlkm/etc \
- -I /odm/etc \
- -I /odm/firmware \
- -I /odm/framework \
- -I /odm/lib \
- -I /odm/lib64 \
- -I /odm/overlay \
- -I /odm/priv-app \
- -I /odm/usr \
- -I /sdcard \
- -I /system/etc/aconfig_flags.textproto \
- -I /system/etc/build_flags.json \
+ -I /system/bin/assemble_cvd \
+ -I /system/bin/console_forwarder \
+ -I /system/bin/kernel_log_monitor \
+ -I /system/bin/logcat_receiver \
+ -I /system/bin/mkenvimage_slim \
+ -I /system/bin/run_cvd \
+ -I /system/bin/simg2img \
+ -I /system/bin/log_tee \
-I /system/lib64/android.hardware.confirmationui@1.0.so \
-I /system/lib64/android.hardware.confirmationui-V1-ndk.so \
-I /system/lib64/android.hardware.keymaster@4.1.so \
@@ -140,11 +124,7 @@
-I /system/lib64/vndk-sp-29 \
-I /system/lib/vndk-29 \
-I /system/lib/vndk-sp-29 \
- -I /system/usr/icu \
- -I /vendor_dlkm/etc"
- diff_excludes[system_ext]="\
- -I /system_ext/etc/aconfig_flags.textproto \
- -I /system_ext/etc/build_flags.json"
+ -I /system/usr/icu"
# Example output of dump.erofs is as below, and the data used in the test start
# at line 11. Column 1 is inode id, column 2 is inode type and column 3 is name.
diff --git a/ui/build/config.go b/ui/build/config.go
index cecc8fa..5d1505a 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -437,6 +437,11 @@
ret.environ.Set("ANDROID_JAVA11_HOME", java11Home)
ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
+ // b/286885495, https://bugzilla.redhat.com/show_bug.cgi?id=2227130: some versions of Fedora include patches
+ // to unzip to enable zipbomb detection that incorrectly handle zip64 and data descriptors and fail on large
+ // zip files produced by soong_zip. Disable zipbomb detection.
+ ret.environ.Set("UNZIP_DISABLE_ZIPBOMB_DETECTION", "TRUE")
+
if ret.MultitreeBuild() {
ret.environ.Set("MULTITREE_BUILD", "true")
}