Merge "Delete the noisy error message"
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index 1ecb0af..e151521 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -496,13 +496,15 @@
if err != nil {
reportPathError(ctx, err)
}
- relativeRootPath := filepath.Join("execroot", "__main__", relativeRoot)
- if pathComponents := strings.Split(path, "/"); len(pathComponents) >= 3 &&
+ var relativeRootPath string
+ if pathComponents := strings.SplitN(path, "/", 4); len(pathComponents) >= 3 &&
pathComponents[0] == "bazel-out" && pathComponents[2] == "bin" {
// If the path starts with something like: bazel-out/linux_x86_64-fastbuild-ST-b4ef1c4402f9/bin/
// make it relative to that folder. bazel-out/volatile-status.txt is an example
// of something that starts with bazel-out but is not relative to the bin folder
relativeRootPath = filepath.Join("execroot", "__main__", pathComponents[0], pathComponents[1], pathComponents[2], relativeRoot)
+ } else {
+ relativeRootPath = filepath.Join("execroot", "__main__", relativeRoot)
}
var relPath string
diff --git a/android/mutator.go b/android/mutator.go
index d92b87c..4e55609 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -409,7 +409,7 @@
return &bottomUpMutatorContext{
bp: ctx,
- baseModuleContext: a.base().baseModuleContextFactory(ctx),
+ baseModuleContext: moduleContext,
finalPhase: finalPhase,
}
}
diff --git a/android/sdk_version.go b/android/sdk_version.go
index d73c912..8953eae 100644
--- a/android/sdk_version.go
+++ b/android/sdk_version.go
@@ -51,6 +51,7 @@
SdkModule
SdkSystemServer
SdkPrivate
+ SdkToolchain // API surface provided by ART to compile other API domains
)
// String returns the string representation of this SdkKind
@@ -76,6 +77,8 @@
return "module-lib"
case SdkSystemServer:
return "system-server"
+ case SdkToolchain:
+ return "toolchain"
default:
return "invalid"
}
diff --git a/android/soong_config_modules.go b/android/soong_config_modules.go
index c1e92b8..9f5440d 100644
--- a/android/soong_config_modules.go
+++ b/android/soong_config_modules.go
@@ -20,7 +20,9 @@
import (
"fmt"
"path/filepath"
+ "reflect"
"strings"
+ "sync"
"text/scanner"
"github.com/google/blueprint"
@@ -31,12 +33,18 @@
)
func init() {
- RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
+ RegisterSoongConfigModuleBuildComponents(InitRegistrationContext)
}
+func RegisterSoongConfigModuleBuildComponents(ctx RegistrationContext) {
+ ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
+ ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
+ ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
+ ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
+}
+
+var PrepareForTestWithSoongConfigModuleBuildComponents = FixtureRegisterWithContext(RegisterSoongConfigModuleBuildComponents)
+
type soongConfigModuleTypeImport struct {
ModuleBase
properties soongConfigModuleTypeImportProperties
@@ -416,13 +424,43 @@
// configModuleFactory takes an existing soongConfigModuleFactory and a
// ModuleType to create a new ModuleFactory that uses a custom loadhook.
func configModuleFactory(factory blueprint.ModuleFactory, moduleType *soongconfig.ModuleType, bp2build bool) blueprint.ModuleFactory {
- conditionalFactoryProps := soongconfig.CreateProperties(factory, moduleType)
- if !conditionalFactoryProps.IsValid() {
- return factory
+ // Defer creation of conditional properties struct until the first call from the factory
+ // method. That avoids having to make a special call to the factory to create the properties
+ // structs from which the conditional properties struct is created. This is needed in order to
+ // allow singleton modules to be customized by soong_config_module_type as the
+ // SingletonModuleFactoryAdaptor factory registers a load hook for the singleton module
+ // everytime that it is called. Calling the factory twice causes a build failure as the load
+ // hook is called twice, the first time it updates the singleton module to indicate that it has
+ // been registered as a module, and the second time it fails because it thinks it has been
+ // registered again and a singleton module can only be registered once.
+ //
+ // This is an issue for singleton modules because:
+ // * Load hooks are registered on the module object and are only called when the module object
+ // is created by Blueprint while processing the Android.bp file.
+ // * The module factory for a singleton module returns the same module object each time it is
+ // called, and registers its load hook on that same module object.
+ // * When the module factory is called by Blueprint it then calls all the load hooks that have
+ // been registered for every call to that module factory.
+ //
+ // It is not an issue for normal modules because they return a new module object each time the
+ // factory is called and so any load hooks registered on module objects which are discarded will
+ // not be run.
+ once := &sync.Once{}
+ conditionalFactoryProps := reflect.Value{}
+ getConditionalFactoryProps := func(props []interface{}) reflect.Value {
+ once.Do(func() {
+ conditionalFactoryProps = soongconfig.CreateProperties(props, moduleType)
+ })
+ return conditionalFactoryProps
}
return func() (blueprint.Module, []interface{}) {
module, props := factory()
+ conditionalFactoryProps := getConditionalFactoryProps(props)
+ if !conditionalFactoryProps.IsValid() {
+ return module, props
+ }
+
conditionalProps := proptools.CloneEmptyProperties(conditionalFactoryProps)
props = append(props, conditionalProps.Interface())
diff --git a/android/soong_config_modules_test.go b/android/soong_config_modules_test.go
index ceb8e45..cab3e2d 100644
--- a/android/soong_config_modules_test.go
+++ b/android/soong_config_modules_test.go
@@ -15,12 +15,10 @@
package android
import (
+ "fmt"
"testing"
)
-type soongConfigTestDefaultsModuleProperties struct {
-}
-
type soongConfigTestDefaultsModule struct {
ModuleBase
DefaultsModuleBase
@@ -53,6 +51,11 @@
func (t soongConfigTestModule) GenerateAndroidBuildActions(ModuleContext) {}
+var prepareForSoongConfigTestModule = FixtureRegisterWithContext(func(ctx RegistrationContext) {
+ ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
+ ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
+})
+
func TestSoongConfigModule(t *testing.T) {
configBp := `
soong_config_module_type {
@@ -309,14 +312,8 @@
result := GroupFixturePreparers(
tc.preparer,
PrepareForTestWithDefaults,
- FixtureRegisterWithContext(func(ctx RegistrationContext) {
- ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
- ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
- ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
- }),
+ PrepareForTestWithSoongConfigModuleBuildComponents,
+ prepareForSoongConfigTestModule,
fs.AddToFixture(),
FixtureWithRootAndroidBp(bp),
).RunTest(t)
@@ -371,14 +368,8 @@
GroupFixturePreparers(
fixtureForVendorVars(map[string]map[string]string{"acme": {"feature1": "1"}}),
PrepareForTestWithDefaults,
- FixtureRegisterWithContext(func(ctx RegistrationContext) {
- ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
- ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
- ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
- }),
+ PrepareForTestWithSoongConfigModuleBuildComponents,
+ prepareForSoongConfigTestModule,
FixtureWithRootAndroidBp(bp),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
// TODO(b/171232169): improve the error message for non-existent properties
@@ -411,14 +402,8 @@
GroupFixturePreparers(
fixtureForVendorVars(map[string]map[string]string{"acme": {"feature1": "1"}}),
PrepareForTestWithDefaults,
- FixtureRegisterWithContext(func(ctx RegistrationContext) {
- ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
- ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
- ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
- }),
+ PrepareForTestWithSoongConfigModuleBuildComponents,
+ prepareForSoongConfigTestModule,
FixtureWithRootAndroidBp(bp),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
// TODO(b/171232169): improve the error message for non-existent properties
@@ -426,10 +411,95 @@
})).RunTest(t)
}
-func testConfigWithVendorVars(buildDir, bp string, fs map[string][]byte, vendorVars map[string]map[string]string) Config {
- config := TestConfig(buildDir, nil, bp, fs)
+type soongConfigTestSingletonModule struct {
+ SingletonModuleBase
+ props soongConfigTestSingletonModuleProperties
+}
- config.TestProductVariables.VendorVars = vendorVars
+type soongConfigTestSingletonModuleProperties struct {
+ Fragments []struct {
+ Apex string
+ Module string
+ }
+}
- return config
+func soongConfigTestSingletonModuleFactory() SingletonModule {
+ m := &soongConfigTestSingletonModule{}
+ m.AddProperties(&m.props)
+ InitAndroidModule(m)
+ return m
+}
+
+func (t *soongConfigTestSingletonModule) GenerateAndroidBuildActions(ModuleContext) {}
+
+func (t *soongConfigTestSingletonModule) GenerateSingletonBuildActions(SingletonContext) {}
+
+var prepareForSoongConfigTestSingletonModule = FixtureRegisterWithContext(func(ctx RegistrationContext) {
+ ctx.RegisterSingletonModuleType("test_singleton", soongConfigTestSingletonModuleFactory)
+})
+
+func TestSoongConfigModuleSingletonModule(t *testing.T) {
+ bp := `
+ soong_config_module_type {
+ name: "acme_test_singleton",
+ module_type: "test_singleton",
+ config_namespace: "acme",
+ bool_variables: ["coyote"],
+ properties: ["fragments"],
+ }
+
+ acme_test_singleton {
+ name: "wiley",
+ fragments: [
+ {
+ apex: "com.android.acme",
+ module: "road-runner",
+ },
+ ],
+ soong_config_variables: {
+ coyote: {
+ fragments: [
+ {
+ apex: "com.android.acme",
+ module: "wiley",
+ },
+ ],
+ },
+ },
+ }
+ `
+
+ for _, test := range []struct {
+ coyote bool
+ expectedFragments string
+ }{
+ {
+ coyote: false,
+ expectedFragments: "[{Apex:com.android.acme Module:road-runner}]",
+ },
+ {
+ coyote: true,
+ expectedFragments: "[{Apex:com.android.acme Module:road-runner} {Apex:com.android.acme Module:wiley}]",
+ },
+ } {
+ t.Run(fmt.Sprintf("coyote:%t", test.coyote), func(t *testing.T) {
+ result := GroupFixturePreparers(
+ PrepareForTestWithSoongConfigModuleBuildComponents,
+ prepareForSoongConfigTestSingletonModule,
+ FixtureWithRootAndroidBp(bp),
+ FixtureModifyProductVariables(func(variables FixtureProductVariables) {
+ variables.VendorVars = map[string]map[string]string{
+ "acme": {
+ "coyote": fmt.Sprintf("%t", test.coyote),
+ },
+ }
+ }),
+ ).RunTest(t)
+
+ // Make sure that the singleton was created.
+ result.SingletonForTests("test_singleton")
+ m := result.ModuleForTests("wiley", "").module.(*soongConfigTestSingletonModule)
+ AssertStringEquals(t, "fragments", test.expectedFragments, fmt.Sprintf("%+v", m.props.Fragments))
+ })
+ }
}
diff --git a/android/soongconfig/modules.go b/android/soongconfig/modules.go
index 1519f60..ed4888d 100644
--- a/android/soongconfig/modules.go
+++ b/android/soongconfig/modules.go
@@ -22,7 +22,6 @@
"strings"
"sync"
- "github.com/google/blueprint"
"github.com/google/blueprint/parser"
"github.com/google/blueprint/proptools"
@@ -363,10 +362,9 @@
// },
// },
// }
-func CreateProperties(factory blueprint.ModuleFactory, moduleType *ModuleType) reflect.Value {
+func CreateProperties(factoryProps []interface{}, moduleType *ModuleType) reflect.Value {
var fields []reflect.StructField
- _, factoryProps := factory()
affectablePropertiesType := createAffectablePropertiesType(moduleType.affectableProperties, factoryProps)
if affectablePropertiesType == nil {
return reflect.Value{}
diff --git a/apex/apex.go b/apex/apex.go
index b9a3c8f..e99823b 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1905,9 +1905,15 @@
return
}
a.installDir = android.PathForModuleInstall(ctx, "apex")
- a.outputApexFile = android.PathForBazelOut(ctx, outputs.SignedOutput)
- a.outputFile = a.outputApexFile
+
+ // Set the output file to .apex or .capex depending on the compression configuration.
a.setCompression(ctx)
+ if a.isCompressed {
+ a.outputApexFile = android.PathForBazelOut(ctx, outputs.SignedCompressedOutput)
+ } else {
+ a.outputApexFile = android.PathForBazelOut(ctx, outputs.SignedOutput)
+ }
+ a.outputFile = a.outputApexFile
// TODO(b/257829940): These are used by the apex_keys_text singleton; would probably be a clearer
// interface if these were set in a provider rather than the module itself
diff --git a/apex/bp2build_test.go b/apex/bp2build_test.go
index 58f30bd..01afa52 100644
--- a/apex/bp2build_test.go
+++ b/apex/bp2build_test.go
@@ -42,15 +42,16 @@
OutputBaseDir: outputBaseDir,
LabelToApexInfo: map[string]cquery.ApexInfo{
"//:foo": cquery.ApexInfo{
- SignedOutput: "signed_out.apex",
- UnsignedOutput: "unsigned_out.apex",
- BundleKeyInfo: []string{"public_key", "private_key"},
- ContainerKeyInfo: []string{"container_cert", "container_private"},
- SymbolsUsedByApex: "foo_using.txt",
- JavaSymbolsUsedByApex: "foo_using.xml",
- BundleFile: "apex_bundle.zip",
- InstalledFiles: "installed-files.txt",
- RequiresLibs: []string{"//path/c:c", "//path/d:d"},
+ SignedOutput: "signed_out.apex",
+ SignedCompressedOutput: "signed_out.capex",
+ UnsignedOutput: "unsigned_out.apex",
+ BundleKeyInfo: []string{"public_key", "private_key"},
+ ContainerKeyInfo: []string{"container_cert", "container_private"},
+ SymbolsUsedByApex: "foo_using.txt",
+ JavaSymbolsUsedByApex: "foo_using.xml",
+ BundleFile: "apex_bundle.zip",
+ InstalledFiles: "installed-files.txt",
+ RequiresLibs: []string{"//path/c:c", "//path/d:d"},
// unused
PackageName: "pkg_name",
@@ -115,6 +116,68 @@
}
}
+func TestCompressedApexImageInMixedBuilds(t *testing.T) {
+ bp := `
+apex_key{
+ name: "foo_key",
+}
+apex {
+ name: "foo",
+ key: "foo_key",
+ updatable: true,
+ min_sdk_version: "31",
+ file_contexts: ":myapex-file_contexts",
+ bazel_module: { label: "//:foo" },
+ test_only_force_compression: true, // force compression
+}`
+
+ outputBaseDir := "out/bazel"
+ result := android.GroupFixturePreparers(
+ prepareForApexTest,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.BazelContext = android.MockBazelContext{
+ OutputBaseDir: outputBaseDir,
+ LabelToApexInfo: map[string]cquery.ApexInfo{
+ "//:foo": cquery.ApexInfo{
+ SignedOutput: "signed_out.apex",
+ SignedCompressedOutput: "signed_out.capex",
+ BundleKeyInfo: []string{"public_key", "private_key"},
+ ContainerKeyInfo: []string{"container_cert", "container_private"},
+ },
+ },
+ }
+ }),
+ ).RunTestWithBp(t, bp)
+
+ m := result.ModuleForTests("foo", "android_common_foo_image").Module()
+ ab, ok := m.(*apexBundle)
+ if !ok {
+ t.Fatalf("Expected module to be an apexBundle, was not")
+ }
+
+ if w, g := "out/bazel/execroot/__main__/signed_out.capex", ab.outputFile.String(); w != g {
+ t.Errorf("Expected output file to be compressed apex %q, got %q", w, g)
+ }
+
+ mkData := android.AndroidMkDataForTest(t, result.TestContext, m)
+ var builder strings.Builder
+ mkData.Custom(&builder, "foo", "BAZEL_TARGET_", "", mkData)
+
+ data := builder.String()
+
+ expectedAndroidMk := []string{
+ "LOCAL_PREBUILT_MODULE_FILE := out/bazel/execroot/__main__/signed_out.capex",
+
+ // Check that the source install file is the capex. The dest is not important.
+ "LOCAL_SOONG_INSTALL_PAIRS := out/bazel/execroot/__main__/signed_out.capex:",
+ }
+ for _, androidMk := range expectedAndroidMk {
+ if !strings.Contains(data, androidMk) {
+ t.Errorf("Expected %q in androidmk data, but did not find %q", androidMk, data)
+ }
+ }
+}
+
func TestOverrideApexImageInMixedBuilds(t *testing.T) {
bp := `
apex_key{
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go
index 7c9ae3b..81c60d9 100644
--- a/bazel/cquery/request_type.go
+++ b/bazel/cquery/request_type.go
@@ -232,8 +232,14 @@
fail("%s did not provide ApexInfo" % id_string)
bundle_key_info = info.bundle_key_info
container_key_info = info.container_key_info
+
+signed_compressed_output = "" # no .capex if the apex is not compressible, cannot be None as it needs to be json encoded.
+if info.signed_compressed_output:
+ signed_compressed_output = info.signed_compressed_output.path
+
return json_encode({
"signed_output": info.signed_output.path,
+ "signed_compressed_output": signed_compressed_output,
"unsigned_output": info.unsigned_output.path,
"provides_native_libs": [str(lib) for lib in info.provides_native_libs],
"requires_native_libs": [str(lib) for lib in info.requires_native_libs],
@@ -249,18 +255,19 @@
}
type ApexInfo struct {
- SignedOutput string `json:"signed_output"`
- UnsignedOutput string `json:"unsigned_output"`
- ProvidesLibs []string `json:"provides_native_libs"`
- RequiresLibs []string `json:"requires_native_libs"`
- BundleKeyInfo []string `json:"bundle_key_info"`
- ContainerKeyInfo []string `json:"container_key_info"`
- PackageName string `json:"package_name"`
- SymbolsUsedByApex string `json:"symbols_used_by_apex"`
- JavaSymbolsUsedByApex string `json:"java_symbols_used_by_apex"`
- BackingLibs string `json:"backing_libs"`
- BundleFile string `json:"bundle_file"`
- InstalledFiles string `json:"installed_files"`
+ SignedOutput string `json:"signed_output"`
+ SignedCompressedOutput string `json:"signed_compressed_output"`
+ UnsignedOutput string `json:"unsigned_output"`
+ ProvidesLibs []string `json:"provides_native_libs"`
+ RequiresLibs []string `json:"requires_native_libs"`
+ BundleKeyInfo []string `json:"bundle_key_info"`
+ ContainerKeyInfo []string `json:"container_key_info"`
+ PackageName string `json:"package_name"`
+ SymbolsUsedByApex string `json:"symbols_used_by_apex"`
+ JavaSymbolsUsedByApex string `json:"java_symbols_used_by_apex"`
+ BackingLibs string `json:"backing_libs"`
+ BundleFile string `json:"bundle_file"`
+ InstalledFiles string `json:"installed_files"`
}
// ParseResult returns a value obtained by parsing the result of the request's Starlark function.
diff --git a/bazel/properties.go b/bazel/properties.go
index f9cabf2..76450dc 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -674,6 +674,11 @@
// specific select statements where an empty list for a non-default select
// key has a meaning.
EmitEmptyList bool
+
+ // If a property has struct tag "variant_prepend", this value should
+ // be set to True, so that when bp2build generates BUILD.bazel, variant
+ // properties(select ...) come before general properties.
+ Prepend bool
}
type configurableLabelLists map[ConfigurationAxis]labelListSelectValues
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 714b848..1c0e563 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -1146,6 +1146,76 @@
}})
}
+func TestApexWithStubLib(t *testing.T) {
+ runApexTestCase(t, Bp2buildTestCase{
+ Description: "apex - static variant of stub lib should not have apex_available tag",
+ ModuleTypeUnderTest: "apex",
+ ModuleTypeUnderTestFactory: apex.BundleFactory,
+ Filesystem: map[string]string{},
+ Blueprint: `
+cc_library{
+ name: "foo",
+ stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] },
+ apex_available: ["myapex"],
+}
+
+cc_binary{
+ name: "bar",
+ static_libs: ["foo"],
+ apex_available: ["myapex"],
+}
+
+apex {
+ name: "myapex",
+ manifest: "myapex_manifest.json",
+ file_contexts: ":myapex-file_contexts",
+ binaries: ["bar"],
+ native_shared_libs: ["foo"],
+}
+` + simpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"),
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_binary", "bar", AttrNameToString{
+ "local_includes": `["."]`,
+ "deps": `[":foo_bp2build_cc_library_static"]`,
+ "tags": `["apex_available=myapex"]`,
+ }),
+ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "local_includes": `["."]`,
+ }),
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "stubs_symbol_file": `"foo.map.txt"`,
+ "tags": `["apex_available=myapex"]`,
+ }),
+ MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
+ "soname": `"foo.so"`,
+ "source_library": `":foo"`,
+ "symbol_file": `"foo.map.txt"`,
+ "versions": `[
+ "28",
+ "29",
+ "current",
+ ]`,
+ }),
+ MakeBazelTarget("apex", "myapex", AttrNameToString{
+ "file_contexts": `":myapex-file_contexts"`,
+ "manifest": `"myapex_manifest.json"`,
+ "binaries": `[":bar"]`,
+ "native_shared_libs_32": `select({
+ "//build/bazel/platforms/arch:arm": [":foo"],
+ "//build/bazel/platforms/arch:x86": [":foo"],
+ "//conditions:default": [],
+ })`,
+ "native_shared_libs_64": `select({
+ "//build/bazel/platforms/arch:arm64": [":foo"],
+ "//build/bazel/platforms/arch:x86_64": [":foo"],
+ "//conditions:default": [],
+ })`,
+ }),
+ },
+ })
+}
+
func TestApexCertificateIsSrc(t *testing.T) {
runApexTestCase(t, Bp2buildTestCase{
Description: "apex - certificate is src",
diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go
index 32500a0..072f5b3 100644
--- a/bp2build/cc_library_headers_conversion_test.go
+++ b/bp2build/cc_library_headers_conversion_test.go
@@ -186,6 +186,8 @@
})
}
+// header_libs has "variant_prepend" tag. In bp2build output,
+// variant info(select) should go before general info.
func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers test with os-specific header_libs props",
@@ -247,14 +249,14 @@
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
- "deps": `[":base-lib"] + select({
+ "deps": `select({
"//build/bazel/platforms/os:android": [":android-lib"],
"//build/bazel/platforms/os:darwin": [":darwin-lib"],
"//build/bazel/platforms/os:linux_bionic": [":linux_bionic-lib"],
"//build/bazel/platforms/os:linux_glibc": [":linux-lib"],
"//build/bazel/platforms/os:windows": [":windows-lib"],
"//conditions:default": [],
- })`,
+ }) + [":base-lib"]`,
}),
},
})
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 5a1260f..767f4ad 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1003,6 +1003,8 @@
})
}
+// generated_headers has "variant_prepend" tag. In bp2build output,
+// variant info(select) should go before general info.
func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Description: "cc_library_static arch srcs/exclude_srcs with generated files",
@@ -1066,13 +1068,13 @@
"//build/bazel/platforms/os:android": [":generated_src_android"],
"//conditions:default": [],
})`,
- "hdrs": `["//dep:generated_hdr_other_pkg"] + select({
- "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
- "//conditions:default": [],
- }) + select({
+ "hdrs": `select({
"//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"],
"//conditions:default": [],
- })`,
+ }) + select({
+ "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
+ "//conditions:default": [],
+ }) + ["//dep:generated_hdr_other_pkg"]`,
"local_includes": `["."]`,
"export_absolute_includes": `["dep"]`,
}),
diff --git a/bp2build/configurability.go b/bp2build/configurability.go
index c630965..987c903 100644
--- a/bp2build/configurability.go
+++ b/bp2build/configurability.go
@@ -106,8 +106,9 @@
return value, []selects{ret}
}
-func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects) {
+func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects, bool) {
value := reflect.ValueOf(list.Value.Includes)
+ prepend := list.Prepend
var ret []selects
for _, axis := range list.SortedConfigurationAxes() {
configToLabels := list.ConfigurableValues[axis]
@@ -133,7 +134,7 @@
}
}
- return value, ret
+ return value, ret, prepend
}
func labelListSelectValue(selectKey string, list bazel.LabelList, emitEmptyList bool) (bool, reflect.Value) {
@@ -173,7 +174,7 @@
value, configurableAttrs, prepend = getStringListValues(list)
defaultSelectValue = &emptyBazelList
case bazel.LabelListAttribute:
- value, configurableAttrs = getLabelListValues(list)
+ value, configurableAttrs, prepend = getLabelListValues(list)
emitZeroValues = list.EmitEmptyList
defaultSelectValue = &emptyBazelList
if list.ForceSpecifyEmptyList && (!value.IsNil() || list.HasConfigurableValues()) {
diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go
index 7029b93..dcd1f85 100644
--- a/bp2build/soong_config_module_type_conversion_test.go
+++ b/bp2build/soong_config_module_type_conversion_test.go
@@ -29,10 +29,7 @@
func registerSoongConfigModuleTypes(ctx android.RegistrationContext) {
cc.RegisterCCBuildComponents(ctx)
- ctx.RegisterModuleType("soong_config_module_type_import", android.SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", android.SoongConfigBoolVariableDummyFactory)
+ android.RegisterSoongConfigModuleBuildComponents(ctx)
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index a7ee5d1..d331d89 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -804,6 +804,12 @@
(&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs))
}
+ linkerAttrs.wholeArchiveDeps.Prepend = true
+ linkerAttrs.deps.Prepend = true
+ compilerAttrs.localIncludes.Prepend = true
+ compilerAttrs.absoluteIncludes.Prepend = true
+ compilerAttrs.hdrs.Prepend = true
+
features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module))
features.DeduplicateAxesFromBase()
diff --git a/cc/library.go b/cc/library.go
index 4b47515..787de44 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -436,17 +436,23 @@
Bzl_load_location: "//build/bazel/rules/cc:cc_library_shared.bzl",
}
- tags := android.ApexAvailableTags(m)
+ var tagsForStaticVariant bazel.StringListAttribute
+ if compilerAttrs.stubsSymbolFile == nil && len(compilerAttrs.stubsVersions.Value) == 0 {
+ tagsForStaticVariant = android.ApexAvailableTags(m)
+ }
+
+ tagsForSharedVariant := android.ApexAvailableTags(m)
+
ctx.CreateBazelTargetModuleWithRestrictions(staticProps,
android.CommonAttributes{
Name: m.Name() + "_bp2build_cc_library_static",
- Tags: tags,
+ Tags: tagsForStaticVariant,
},
staticTargetAttrs, staticAttrs.Enabled)
ctx.CreateBazelTargetModuleWithRestrictions(sharedProps,
android.CommonAttributes{
Name: m.Name(),
- Tags: tags,
+ Tags: tagsForSharedVariant,
},
sharedTargetAttrs, sharedAttrs.Enabled)
diff --git a/cc/object.go b/cc/object.go
index c3a198d..6cb1a30 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -78,7 +78,7 @@
Static_libs []string `android:"arch_variant,variant_prepend"`
// list of shared library modules should only provide headers for this module.
- Shared_libs []string `android:"arch_variant"`
+ Shared_libs []string `android:"arch_variant,variant_prepend"`
// list of modules that should only provide headers for this module.
Header_libs []string `android:"arch_variant,variant_prepend"`
@@ -178,6 +178,8 @@
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Static_libs))
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Shared_libs))
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Header_libs))
+ // static_libs, shared_libs, and header_libs have variant_prepend tag
+ deps.Prepend = true
}
}
}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 577e980..25b8fe8 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -70,10 +70,11 @@
// TODO(jiyong): allow apex_key to be specified here
Avb_private_key *string `android:"path"`
- // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
+ // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Avb_algorithm *string
- // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
+ // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
+ // avbtool. Default used by avbtool is sha1.
Avb_hash_algorithm *string
// Name of the partition stored in vbmeta desc. Defaults to the name of this module.
diff --git a/java/app.go b/java/app.go
index df6698d..845f850 100755
--- a/java/app.go
+++ b/java/app.go
@@ -315,10 +315,6 @@
}
}
- if Bool(a.appProperties.Enforce_default_target_sdk_version) {
- a.SetEnforceDefaultTargetSdkVersion(true)
- }
-
a.checkPlatformAPI(ctx)
a.checkSdkVersions(ctx)
}
@@ -639,6 +635,11 @@
a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath)
}
+ // For apps targeting latest target_sdk_version
+ if Bool(a.appProperties.Enforce_default_target_sdk_version) {
+ a.SetEnforceDefaultTargetSdkVersion(true)
+ }
+
// Process all building blocks, from AAPT to certificates.
a.aaptBuildActions(ctx)
@@ -800,6 +801,8 @@
unstrippedFile: dep.UnstrippedOutputFile(),
partition: dep.Partition(),
})
+ } else if ctx.Config().AllowMissingDependencies() {
+ ctx.AddMissingDependencies([]string{otherName})
} else {
ctx.ModuleErrorf("dependency %q missing output file", otherName)
}
diff --git a/java/app_test.go b/java/app_test.go
index bc971e3..cd88864 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -3203,7 +3203,7 @@
updatable: true,
},
{
- name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion",
+ name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion",
enforceDefaultTargetSdkVersion: true,
platform_sdk_final: false,
targetSdkVersionInBp: "current",
@@ -3259,6 +3259,76 @@
}
}
+func TestEnforceDefaultAppTargetSdkVersionFlagForTests(t *testing.T) {
+ platform_sdk_codename := "Tiramisu"
+ platform_sdk_version := 33
+ testCases := []struct {
+ name string
+ enforceDefaultTargetSdkVersion bool
+ expectedError string
+ platform_sdk_final bool
+ targetSdkVersionInBp string
+ targetSdkVersionExpected string
+ }{
+ {
+ name: "Not enforcing Target SDK Version: Android.bp has older targetSdkVersion",
+ enforceDefaultTargetSdkVersion: false,
+ targetSdkVersionInBp: "29",
+ targetSdkVersionExpected: "29",
+ },
+ {
+ name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion",
+ enforceDefaultTargetSdkVersion: true,
+ platform_sdk_final: true,
+ targetSdkVersionInBp: "current",
+ targetSdkVersionExpected: "33",
+ },
+ {
+ name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion",
+ enforceDefaultTargetSdkVersion: true,
+ platform_sdk_final: false,
+ targetSdkVersionInBp: "current",
+ targetSdkVersionExpected: "10000",
+ },
+ }
+ for _, testCase := range testCases {
+ errExpected := testCase.expectedError != ""
+ bp := fmt.Sprintf(`
+ android_test {
+ name: "foo",
+ enforce_default_target_sdk_version: %t,
+ min_sdk_version: "29",
+ target_sdk_version: "%v",
+ }
+ `, testCase.enforceDefaultTargetSdkVersion, testCase.targetSdkVersionInBp)
+
+ fixture := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ android.PrepareForTestWithAllowMissingDependencies,
+ android.PrepareForTestWithAndroidMk,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ // explicitly set following platform variables to make the test deterministic
+ variables.Platform_sdk_final = &testCase.platform_sdk_final
+ variables.Platform_sdk_version = &platform_sdk_version
+ variables.Platform_sdk_codename = &platform_sdk_codename
+ variables.Unbundled_build_apps = []string{"sampleModule"}
+ }),
+ )
+
+ errorHandler := android.FixtureExpectsNoErrors
+ if errExpected {
+ errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.expectedError)
+ }
+ result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp)
+
+ if !errExpected {
+ foo := result.ModuleForTests("foo", "android_common")
+ manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
+ android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected)
+ }
+ }
+}
+
func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) {
result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 066f0d6..4bbe70a 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -877,6 +877,7 @@
"module_lib": android.SdkModule,
"module-lib": android.SdkModule,
"test": android.SdkTest,
+ "toolchain": android.SdkToolchain,
}
)
diff --git a/java/jdeps.go b/java/jdeps.go
index 3734335..a52b867 100644
--- a/java/jdeps.go
+++ b/java/jdeps.go
@@ -52,6 +52,11 @@
return
}
+ // Prevent including both prebuilts and matching source modules when one replaces the other.
+ if !android.IsModulePreferred(module) {
+ return
+ }
+
ideInfoProvider, ok := module.(android.IDEInfo)
if !ok {
return
diff --git a/tests/apex_cc_module_arch_variant_tests.sh b/tests/apex_cc_module_arch_variant_tests.sh
new file mode 100755
index 0000000..97e6576
--- /dev/null
+++ b/tests/apex_cc_module_arch_variant_tests.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+set -uo pipefail
+
+# Integration test for verifying arch variant cflags set on cc modules included
+# in Bazel-built apexes in the real source tree.
+
+if [ ! -e "build/make/core/Makefile" ]; then
+ echo "$0 must be run from the top of the Android source tree."
+ exit 1
+fi
+
+############
+# Test Setup
+############
+
+OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)"
+BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel"
+
+export TARGET_PRODUCT="aosp_arm64"
+[ "$#" -ge 1 ] && export TARGET_PRODUCT="$1"
+ARCH_VARIANT_CFLAG="armv8-a"
+[ "$#" -ge 2 ] && ARCH_VARIANT_CFLAG="$2"
+CPU_VARIANT_CFLAG=""
+[ "$#" -ge 3 ] && CPU_VARIANT_CFLAG="$3"
+
+function call_bazel() {
+ build/bazel/bin/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
+}
+
+function cleanup {
+ # call bazel clean because some bazel outputs don't have w bits.
+ call_bazel clean
+ rm -rf "${OUTPUT_DIR}"
+}
+trap cleanup EXIT
+
+######################
+# Run bp2build / Bazel
+######################
+build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build
+
+# Number of CppCompile actions with arch variant flag
+actions_with_arch_variant_num=$(call_bazel aquery --config=bp2build --config=ci --config=android \
+ 'mnemonic("CppCompile", deps(//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal.apex))' | grep -c "\-march=$ARCH_VARIANT_CFLAG")
+
+# Number of all CppCompile actions
+all_cppcompile_actions_num=0
+aquery_summary=$(call_bazel aquery --config=bp2build --config=ci --config=android --output=summary \
+ 'mnemonic("CppCompile", deps(//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal.apex))' \
+ | egrep -o '.*opt-ST.*: ([0-9]+)$' \
+ | cut -d: -f2 -)
+
+while read -r num;
+do
+ all_cppcompile_actions_num=$(($all_cppcompile_actions_num + $num))
+done <<< "$aquery_summary"
+
+if [ $actions_with_arch_variant_num -eq $all_cppcompile_actions_num ]
+then
+ echo "Pass: arch variant is set."
+else
+ echo "Error: number of CppCompile actions with arch variant set: actual=$actions_with_arch_variant_num, expected=$all_cppcompile_actions_num"
+ exit 1
+fi
+
+if [ $CPU_VARIANT_CFLAG ]
+then
+ # Number of CppCompiler actions with cpu variant flag
+ actions_with_cpu_variant_num=$(call_bazel aquery --config=bp2build --config=ci --config=android \
+ 'mnemonic("CppCompile", deps(//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal.apex))' | grep -c "\-mcpu=$CPU_VARIANT_CFLAG")
+
+ if [ $actions_with_cpu_variant_num -eq $all_cppcompile_actions_num ]
+ then
+ echo "Pass: cpu variant is set."
+ else
+ echo "Error: number of CppCompile actions with cpu variant set: actual=$actions_with_cpu_variant_num, expected=$all_cppcompile_actions_num"
+ exit 1
+ fi
+fi
\ No newline at end of file
diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh
index 7a71b27..eb76a46 100755
--- a/tests/run_integration_tests.sh
+++ b/tests/run_integration_tests.sh
@@ -14,3 +14,7 @@
# mock client.
"$TOP/build/soong/tests/apex_comparison_tests.sh"
"$TOP/build/soong/tests/apex_comparison_tests.sh" "module_arm64only"
+
+"$TOP/build/soong/tests/apex_cc_module_arch_variant_tests.sh"
+"$TOP/build/soong/tests/apex_cc_module_arch_variant_tests.sh" "aosp_arm" "armv7-a"
+"$TOP/build/soong/tests/apex_cc_module_arch_variant_tests.sh" "aosp_cf_arm64_phone" "armv8-a" "cortex-a53"
\ No newline at end of file
diff --git a/ui/build/config.go b/ui/build/config.go
index 61f6b1c..b928faa 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -204,16 +204,11 @@
return nil
}
-func loadEnvConfig(ctx Context, config *configImpl) error {
- bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
+func loadEnvConfig(ctx Context, config *configImpl, bc string) error {
if bc == "" {
return nil
}
- if err := fetchEnvConfig(ctx, config, bc); err != nil {
- ctx.Verbosef("Failed to fetch config file: %v\n", err)
- }
-
configDirs := []string{
config.OutDir(),
os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG_DIR"),
@@ -262,6 +257,12 @@
environ: OsEnvironment(),
sandboxConfig: &SandboxConfig{},
}
+ srcDir := absPath(ctx, ".")
+ bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
+ if err := loadEnvConfig(ctx, ret, bc); err != nil {
+ ctx.Fatalln("Failed to parse env config files: %v", err)
+ }
+ ret.metricsUploader = GetMetricsUploader(srcDir, ret.environ)
return Config{ret}
}
@@ -294,8 +295,15 @@
// loadEnvConfig needs to know what the OUT_DIR is, so it should
// be called after we determine the appropriate out directory.
- if err := loadEnvConfig(ctx, ret); err != nil {
- ctx.Fatalln("Failed to parse env config files: %v", err)
+ bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
+
+ if bc != "" {
+ if err := fetchEnvConfig(ctx, ret, bc); err != nil {
+ ctx.Verbosef("Failed to fetch config file: %v\n", err)
+
+ } else if err := loadEnvConfig(ctx, ret, bc); err != nil {
+ ctx.Fatalln("Failed to parse env config files: %v", err)
+ }
}
if distDir, ok := ret.environ.Get("DIST_DIR"); ok {