Merge "Allow ramdisk targets to set cflags/exclude_srcs." into main
diff --git a/aconfig/init.go b/aconfig/init.go
index 3ed5faf..7e283ea 100644
--- a/aconfig/init.go
+++ b/aconfig/init.go
@@ -44,6 +44,7 @@
Command: `rm -rf ${out}.tmp` +
` && mkdir -p ${out}.tmp` +
` && ${aconfig} create-java-lib` +
+ ` --mode ${mode}` +
` --cache ${in}` +
` --out ${out}.tmp` +
` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
@@ -53,7 +54,7 @@
"$soong_zip",
},
Restat: true,
- })
+ }, "mode")
// For java_aconfig_library: Generate java file
cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
diff --git a/aconfig/java_aconfig_library.go b/aconfig/java_aconfig_library.go
index 53b2b10..53f8bd1 100644
--- a/aconfig/java_aconfig_library.go
+++ b/aconfig/java_aconfig_library.go
@@ -30,6 +30,9 @@
type JavaAconfigDeclarationsLibraryProperties struct {
// name of the aconfig_declarations module to generate a library for
Aconfig_declarations string
+
+ // whether to generate test mode version of the library
+ Test bool
}
type JavaAconfigDeclarationsLibraryCallbacks struct {
@@ -61,11 +64,20 @@
// Generate the action to build the srcjar
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
+ var mode string
+ if callbacks.properties.Test {
+ mode = "test"
+ } else {
+ mode = "production"
+ }
ctx.Build(pctx, android.BuildParams{
Rule: javaRule,
Input: declarations.IntermediatePath,
Output: srcJarPath,
Description: "aconfig.srcjar",
+ Args: map[string]string{
+ "mode": mode,
+ },
})
// Tell the java module about the .aconfig files, so they can be propagated up the dependency chain.
diff --git a/aconfig/java_aconfig_library_test.go b/aconfig/java_aconfig_library_test.go
index 1808290..af50848 100644
--- a/aconfig/java_aconfig_library_test.go
+++ b/aconfig/java_aconfig_library_test.go
@@ -15,6 +15,7 @@
package aconfig
import (
+ "fmt"
"strings"
"testing"
@@ -152,3 +153,39 @@
runJavaAndroidMkTest(t, bp)
}
+
+func testCodegenMode(t *testing.T, bpMode string, ruleMode string) {
+ result := android.GroupFixturePreparers(
+ PrepareForTestWithAconfigBuildComponents,
+ java.PrepareForTestWithJavaDefaultModules).
+ ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
+ RunTestWithBp(t, fmt.Sprintf(`
+ aconfig_declarations {
+ name: "my_aconfig_declarations",
+ package: "com.example.package",
+ srcs: ["foo.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library",
+ aconfig_declarations: "my_aconfig_declarations",
+ %s
+ }
+ `, bpMode))
+
+ module := result.ModuleForTests("my_java_aconfig_library", "android_common")
+ rule := module.Rule("java_aconfig_library")
+ android.AssertStringEquals(t, "rule must contain test mode", rule.Args["mode"], ruleMode)
+}
+
+func TestDefaultProdMode(t *testing.T) {
+ testCodegenMode(t, "", "production")
+}
+
+func TestProdMode(t *testing.T) {
+ testCodegenMode(t, "test: false,", "production")
+}
+
+func TestTestMode(t *testing.T) {
+ testCodegenMode(t, "test: true,", "test")
+}
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 8ccef8d..ee63bb4 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -434,6 +434,7 @@
"external/bazelbuild-rules_java":/* recursive = */ true,
"external/bazelbuild-rules_license":/* recursive = */ true,
"external/bazelbuild-rules_go":/* recursive = */ true,
+ "external/bazelbuild-rules_python":/* recursive = */ true,
"external/bazelbuild-kotlin-rules":/* recursive = */ true,
"external/bazel-skylib":/* recursive = */ true,
"external/protobuf":/* recursive = */ false,
@@ -917,7 +918,10 @@
"libart_headers", // depends on unconverted modules: art_libartbase_headers
"libartbase-art-gtest", // depends on unconverted modules: libgtest_isolated, libart, libart-compiler, libdexfile, libprofile
"libartbased-art-gtest", // depends on unconverted modules: libgtest_isolated, libartd, libartd-compiler, libdexfiled, libprofiled
+ "libart-runtime", // depends on unconverted modules: apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api, art_operator_srcs, libcpu_features, libodrstatslog, libelffile, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfile, libnativebridge, libnativeloader, libsigchain, libartbase, libprofile, cpp-define-generator-asm-support
+ "libart-runtime-for-test", // depends on unconverted modules: apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api, art_operator_srcs, libcpu_features, libodrstatslog, libelffile, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfile, libnativebridge, libnativeloader, libsigchain, libartbase, libprofile, cpp-define-generator-asm-support
"libartd", // depends on unconverted modules: art_operator_srcs, libcpu_features, libodrstatslog, libelffiled, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfiled, libnativebridge, libnativeloader, libsigchain, libartbased, libprofiled, cpp-define-generator-asm-support, apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api
+ "libartd-runtime", // depends on unconverted modules: art_operator_srcs, libcpu_features, libodrstatslog, libelffiled, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfiled, libnativebridge, libnativeloader, libsigchain, libartbased, libprofiled, cpp-define-generator-asm-support, apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api
"libartd-runtime-gtest", // depends on unconverted modules: libgtest_isolated, libartd-compiler, libdexfiled, libprofiled, libartbased, libartbased-art-gtest
"libdebuggerd", // depends on unconverted module: libdexfile
"libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core
@@ -1602,14 +1606,6 @@
"test_com.android.neuralnetworks",
"libneuralnetworks",
"libneuralnetworks_static",
- }
-
- // Staging-mode allowlist. Modules in this list are only built
- // by Bazel with --bazel-mode-staging. This list should contain modules
- // which will soon be added to the prod allowlist.
- // It is implicit that all modules in ProdMixedBuildsEnabledList will
- // also be built - do not add them to this list.
- StagingMixedBuildsEnabledList = []string{
// M13: media.swcodec launch
"com.android.media.swcodec",
"test_com.android.media.swcodec",
@@ -1617,20 +1613,26 @@
"libcodec2_hidl@1.0",
}
+ // Staging-mode allowlist. Modules in this list are only built
+ // by Bazel with --bazel-mode-staging. This list should contain modules
+ // which will soon be added to the prod allowlist.
+ // It is implicit that all modules in ProdMixedBuildsEnabledList will
+ // also be built - do not add them to this list.
+ StagingMixedBuildsEnabledList = []string{}
+
// These should be the libs that are included by the apexes in the ProdMixedBuildsEnabledList
ProdDclaMixedBuildsEnabledList = []string{
"libbase",
"libc++",
"libcrypto",
"libcutils",
- }
-
- // These should be the libs that are included by the apexes in the StagingMixedBuildsEnabledList
- StagingDclaMixedBuildsEnabledList = []string{
"libstagefright_flacdec",
"libutils",
}
+ // These should be the libs that are included by the apexes in the StagingMixedBuildsEnabledList
+ StagingDclaMixedBuildsEnabledList = []string{}
+
// TODO(b/269342245): Enable the rest of the DCLA libs
// "libssl",
diff --git a/android/config.go b/android/config.go
index 2a243ee..30be7d6 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1909,6 +1909,10 @@
return c.config.productVariables.RequiresInsecureExecmemForSwiftshader
}
+func (c *deviceConfig) Release_aidl_use_unfrozen() bool {
+ return Bool(c.config.productVariables.Release_aidl_use_unfrozen)
+}
+
func (c *config) SelinuxIgnoreNeverallows() bool {
return c.productVariables.SelinuxIgnoreNeverallows
}
diff --git a/android/module.go b/android/module.go
index 384776a..4c781f6 100644
--- a/android/module.go
+++ b/android/module.go
@@ -4029,43 +4029,26 @@
JavaBp2buildTargetName() string
}
-// PartitionXsdSrcs partitions srcs into xsd_config modules and others
-// Since xsd_config are soong modules, we cannot use file extension for partitioning
-func PartitionXsdSrcs(ctx BazelConversionPathContext, srcs []string) ([]string, []string) {
- //isXsd returns true if src is a soong module of type xsd_config
- isXsd := func(src string) bool {
- mod, exists := ctx.ModuleFromName(src)
+// XsdModuleToTargetName is a function that takes an XsdConfigBp2buildTarget
+type XsdModuleToTargetName func(xsd XsdConfigBp2buildTargets) string
+
+// XsdLabelMapper returns a bazel.LabelMapper for partitioning XSD sources/headers given an
+// XsdModuleToTargetName function.
+func XsdLabelMapper(targetName XsdModuleToTargetName) bazel.LabelMapper {
+ return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
+ mod, exists := ctx.ModuleFromName(label.OriginalModuleName)
if !exists {
- return false
+ return label.Label, false
}
- _, _isXsd := mod.(XsdConfigBp2buildTargets)
- return _isXsd
- }
- nonXsd := []string{}
- xsd := []string{}
-
- for _, src := range srcs {
- if isXsd(src) {
- xsd = append(xsd, src)
- } else {
- nonXsd = append(nonXsd, src)
+ xsdMod, isXsd := mod.(XsdConfigBp2buildTargets)
+ if !isXsd {
+ return label.Label, false
}
- }
- return nonXsd, xsd
-}
-
-// Replaces //a/b/my_xsd_config with //a/b/my_xsd_config-{cpp|java}
-// The new target name is provided by the `targetName` callback function
-func XsdConfigBp2buildTarget(ctx BazelConversionPathContext, mod blueprint.Module, targetName func(xsd XsdConfigBp2buildTargets) string) string {
- xsd, isXsd := mod.(XsdConfigBp2buildTargets)
- if !isXsd {
- ctx.ModuleErrorf("xsdConfigJavaTarget called on %v, which is not an xsd_config", mod)
+ // Remove the base module name
+ ret := strings.TrimSuffix(label.Label, mod.Name())
+ // Append the language specific target name
+ ret += targetName(xsdMod)
+ return ret, true
}
- ret := BazelModuleLabel(ctx, mod)
- // Remove the base module name
- ret = strings.TrimSuffix(ret, mod.Name())
- // Append the language specific target name
- ret += targetName(xsd)
- return ret
}
diff --git a/android/variable.go b/android/variable.go
index f07ab56..7fb81b9 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -184,6 +184,13 @@
Srcs []string `android:"arch_variant"`
Exclude_srcs []string `android:"arch_variant"`
} `android:"arch_variant"`
+
+ // release_aidl_use_unfrozen is "true" when a device can
+ // use the unfrozen versions of AIDL interfaces.
+ Release_aidl_use_unfrozen struct {
+ Cflags []string
+ Cmd *string
+ }
} `android:"arch_variant"`
}
@@ -462,6 +469,8 @@
SelinuxIgnoreNeverallows bool `json:",omitempty"`
+ Release_aidl_use_unfrozen *bool `json:",omitempty"`
+
SepolicyFreezeTestExtraDirs []string `json:",omitempty"`
SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"`
@@ -734,7 +743,9 @@
dst = append(dst, src...)
(*p)[propertyName][key] = dst
default:
- panic(fmt.Errorf("TODO: handle merging value %#v", existing))
+ if existing != propertyValue {
+ panic(fmt.Errorf("TODO: handle merging value %#v", existing))
+ }
}
} else {
(*p)[propertyName][key] = propertyValue
@@ -947,7 +958,7 @@
productConfigProperties.AddSoongConfigProperty(propertyName, namespace, soongConfigVariableName, soongConfigVariableValue, os.Name, property.Interface())
}
}
- } else {
+ } else if !archOrOsSpecificStruct.IsZero() {
// One problem with supporting additional fields is that if multiple branches of
// "target" overlap, we don't want them to be in the same select statement (aka
// configuration axis). "android" and "host" are disjoint, so it's ok that we only
diff --git a/apex/apex.go b/apex/apex.go
index 325ca00..b26d1d2 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -993,7 +993,7 @@
// the non-system APEXes because the VNDK libraries won't be included (and duped) in the
// APEX, but shared across APEXes via the VNDK APEX.
useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
- excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
+ excludeVndkLibs := useVndk && a.useVndkAsStable(mctx)
if proptools.Bool(a.properties.Use_vndk_as_stable) {
if !useVndk {
mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
@@ -2394,7 +2394,7 @@
// tags used below are private (e.g. `cc.sharedDepTag`).
if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
if ch, ok := child.(*cc.Module); ok {
- if ch.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && ch.IsVndk() {
+ if ch.UseVndk() && a.useVndkAsStable(ctx) && ch.IsVndk() {
vctx.requireNativeLibs = append(vctx.requireNativeLibs, ":vndk")
return false
}
@@ -3716,3 +3716,12 @@
func (a *apexBundle) IsTestApex() bool {
return a.testApex
}
+
+func (a *apexBundle) useVndkAsStable(ctx android.BaseModuleContext) bool {
+ // VNDK cannot be linked if it is deprecated
+ if ctx.Config().IsVndkDeprecated() {
+ return false
+ }
+
+ return proptools.Bool(a.properties.Use_vndk_as_stable)
+}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index df138e0..ed78033 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -3029,7 +3029,11 @@
vendor: true,
shared_libs: ["libvndk", "libvendor"],
}
- `)
+ `,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.TestProductVariables.KeepVndk = proptools.BoolPtr(true)
+ }),
+ )
vendorVariant := "android_vendor.29_arm64_armv8-a"
diff --git a/bazel/aquery.go b/bazel/aquery.go
index 3428328..2c080a1 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -459,7 +459,7 @@
// escapes the args received from aquery and creates a command string
func commandString(actionEntry *analysis_v2_proto.Action) string {
switch actionEntry.Mnemonic {
- case "GoCompilePkg":
+ case "GoCompilePkg", "GoStdlib":
argsEscaped := []string{}
for _, arg := range actionEntry.Arguments {
if arg == "" {
diff --git a/bazel/properties.go b/bazel/properties.go
index 15af09b..702c31c 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -288,6 +288,41 @@
return result
}
+// FirstUniqueBazelLabelListAttribute takes a LabelListAttribute and makes the LabelList for
+// each axis/configuration by keeping the first instance of a Label and omitting all subsequent
+// repetitions.
+func FirstUniqueBazelLabelListAttribute(attr LabelListAttribute) LabelListAttribute {
+ var result LabelListAttribute
+ result.Value = FirstUniqueBazelLabelList(attr.Value)
+ if attr.HasConfigurableValues() {
+ result.ConfigurableValues = make(configurableLabelLists)
+ }
+ for axis, configToLabels := range attr.ConfigurableValues {
+ for c, l := range configToLabels {
+ result.SetSelectValue(axis, c, FirstUniqueBazelLabelList(l))
+ }
+ }
+
+ return result
+}
+
+// SubtractBazelLabelListAttribute subtract needle from haystack for LabelList in each
+// axis/configuration.
+func SubtractBazelLabelListAttribute(haystack LabelListAttribute, needle LabelListAttribute) LabelListAttribute {
+ var result LabelListAttribute
+ result.Value = SubtractBazelLabelList(haystack.Value, needle.Value)
+ if haystack.HasConfigurableValues() {
+ result.ConfigurableValues = make(configurableLabelLists)
+ }
+ for axis, configToLabels := range haystack.ConfigurableValues {
+ for haystackConfig, haystackLabels := range configToLabels {
+ result.SetSelectValue(axis, haystackConfig, SubtractBazelLabelList(haystackLabels, needle.SelectValue(axis, haystackConfig)))
+ }
+ }
+
+ return result
+}
+
type Attribute interface {
HasConfigurableValues() bool
}
diff --git a/bazel/properties_test.go b/bazel/properties_test.go
index c56d11f..c98ae0e 100644
--- a/bazel/properties_test.go
+++ b/bazel/properties_test.go
@@ -125,6 +125,63 @@
}
}
}
+
+func TestSubtractBazelLabelListAttribute(t *testing.T) {
+ testCases := []struct {
+ haystack LabelListAttribute
+ needle LabelListAttribute
+ expected LabelListAttribute
+ }{
+ {
+ haystack: LabelListAttribute{
+ Value: makeLabelList(
+ []string{"a", "b", "a", "c"},
+ []string{"x", "x", "y", "z"},
+ ),
+ ConfigurableValues: configurableLabelLists{
+ ArchConfigurationAxis: labelListSelectValues{
+ "arm": makeLabelList([]string{"arm_1", "arm_2"}, []string{}),
+ "x86": makeLabelList([]string{"x86_3", "x86_4", "x86_5"}, []string{"x86_5"}),
+ },
+ },
+ },
+ needle: LabelListAttribute{
+ Value: makeLabelList(
+ []string{"d", "a"},
+ []string{"x", "y2", "z2"},
+ ),
+ ConfigurableValues: configurableLabelLists{
+ ArchConfigurationAxis: labelListSelectValues{
+ "arm": makeLabelList([]string{"arm_1", "arm_3"}, []string{}),
+ "x86": makeLabelList([]string{"x86_3", "x86_4"}, []string{"x86_6"}),
+ },
+ },
+ },
+ expected: LabelListAttribute{
+ Value: makeLabelList(
+ []string{"b", "c"},
+ []string{"x", "x", "y", "z"},
+ ),
+ ConfigurableValues: configurableLabelLists{
+ ArchConfigurationAxis: labelListSelectValues{
+ "arm": makeLabelList([]string{"arm_2"}, []string{}),
+ "x86": makeLabelList([]string{"x86_5"}, []string{"x86_5"}),
+ },
+ },
+ ForceSpecifyEmptyList: false,
+ EmitEmptyList: false,
+ Prepend: false,
+ },
+ },
+ }
+ for _, tc := range testCases {
+ got := SubtractBazelLabelListAttribute(tc.haystack, tc.needle)
+ if !reflect.DeepEqual(tc.expected, got) {
+ t.Fatalf("Expected\n%v, but got\n%v", tc.expected, got)
+ }
+ }
+}
+
func TestFirstUniqueBazelLabelList(t *testing.T) {
testCases := []struct {
originalLabelList LabelList
@@ -167,6 +224,46 @@
}
}
+func TestFirstUniqueBazelLabelListAttribute(t *testing.T) {
+ testCases := []struct {
+ originalLabelList LabelListAttribute
+ expectedUniqueLabelList LabelListAttribute
+ }{
+ {
+ originalLabelList: LabelListAttribute{
+ Value: makeLabelList(
+ []string{"a", "b", "a", "c"},
+ []string{"x", "x", "y", "z"},
+ ),
+ ConfigurableValues: configurableLabelLists{
+ ArchConfigurationAxis: labelListSelectValues{
+ "arm": makeLabelList([]string{"1", "2", "1"}, []string{}),
+ "x86": makeLabelList([]string{"3", "4", "4"}, []string{"5", "5"}),
+ },
+ },
+ },
+ expectedUniqueLabelList: LabelListAttribute{
+ Value: makeLabelList(
+ []string{"a", "b", "c"},
+ []string{"x", "y", "z"},
+ ),
+ ConfigurableValues: configurableLabelLists{
+ ArchConfigurationAxis: labelListSelectValues{
+ "arm": makeLabelList([]string{"1", "2"}, []string{}),
+ "x86": makeLabelList([]string{"3", "4"}, []string{"5"}),
+ },
+ },
+ },
+ },
+ }
+ for _, tc := range testCases {
+ actualUniqueLabelList := FirstUniqueBazelLabelListAttribute(tc.originalLabelList)
+ if !reflect.DeepEqual(tc.expectedUniqueLabelList, actualUniqueLabelList) {
+ t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabelList, actualUniqueLabelList)
+ }
+ }
+}
+
func TestUniqueSortedBazelLabelList(t *testing.T) {
testCases := []struct {
originalLabelList LabelList
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index f889693..4a3786f 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -46,6 +46,7 @@
"apex_conversion_test.go",
"apex_key_conversion_test.go",
"build_conversion_test.go",
+ "bp2build_product_config_test.go",
"bzl_conversion_test.go",
"cc_binary_conversion_test.go",
"cc_library_conversion_test.go",
diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go
index c8067af..f56e6d8 100644
--- a/bp2build/bp2build_product_config.go
+++ b/bp2build/bp2build_product_config.go
@@ -7,6 +7,7 @@
"fmt"
"os"
"path/filepath"
+ "reflect"
"strings"
"github.com/google/blueprint/proptools"
@@ -151,16 +152,17 @@
if err != nil {
return "", err
}
- result := "platforms:\n"
- result += platformMappingSingleProduct(mainProductLabel, mainProductVariables)
+ var result strings.Builder
+ result.WriteString("platforms:\n")
+ platformMappingSingleProduct(mainProductLabel, mainProductVariables, &result)
for product, productVariablesStarlark := range productsForTesting {
productVariables, err := starlarkMapToProductVariables(productVariablesStarlark)
if err != nil {
return "", err
}
- result += platformMappingSingleProduct("@//build/bazel/tests/products:"+product, &productVariables)
+ platformMappingSingleProduct("@//build/bazel/tests/products:"+product, &productVariables, &result)
}
- return result, nil
+ return result.String(), nil
}
var bazelPlatformSuffixes = []string{
@@ -177,42 +179,107 @@
"_windows_x86_64",
}
-func platformMappingSingleProduct(label string, productVariables *android.ProductVariables) string {
- buildSettings := ""
- buildSettings += fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride))
- buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ","))
- buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ","))
- buildSettings += fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true))
- buildSettings += fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ","))
- result := ""
- for _, suffix := range bazelPlatformSuffixes {
- result += " " + label + suffix + "\n" + buildSettings
+func platformMappingSingleProduct(label string, productVariables *android.ProductVariables, result *strings.Builder) {
+ targetBuildVariant := "user"
+ if proptools.Bool(productVariables.Eng) {
+ targetBuildVariant = "eng"
+ } else if proptools.Bool(productVariables.Debuggable) {
+ targetBuildVariant = "userdebug"
}
- return result
+
+ for _, suffix := range bazelPlatformSuffixes {
+ result.WriteString(" ")
+ result.WriteString(label)
+ result.WriteString(suffix)
+ result.WriteString("\n")
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:always_use_prebuilt_sdks=%t\n", proptools.Bool(productVariables.Always_use_prebuilt_sdks)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_id=%s\n", proptools.String(productVariables.BuildId)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_version_tags=%s\n", strings.Join(productVariables.BuildVersionTags, ",")))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:certificate_overrides=%s\n", strings.Join(productVariables.CertificateOverrides, ",")))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ",")))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ",")))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:compressed_apex=%t\n", proptools.Bool(productVariables.CompressedApex)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate=%s\n", proptools.String(productVariables.DefaultAppCertificate)))
+ 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_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:manifest_package_name_overrides=%s\n", strings.Join(productVariables.ManifestPackageNameOverrides, ",")))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_name=%s\n", proptools.String(productVariables.Platform_version_name)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:target_build_variant=%s\n", targetBuildVariant))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:tidy_checks=%s\n", proptools.String(productVariables.TidyChecks)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build=%t\n", proptools.Bool(productVariables.Unbundled_build)))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build_apps=%s\n", strings.Join(productVariables.Unbundled_build_apps, ",")))
+ }
}
func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) {
- var err error
result := android.ProductVariables{}
- result.ApexGlobalMinSdkVersionOverride, err = starlark_import.UnmarshalNoneable[string](in["ApexGlobalMinSdkVersionOverride"])
- if err != nil {
- return result, err
+ productVarsReflect := reflect.ValueOf(&result).Elem()
+ for i := 0; i < productVarsReflect.NumField(); i++ {
+ field := productVarsReflect.Field(i)
+ fieldType := productVarsReflect.Type().Field(i)
+ name := fieldType.Name
+ if name == "BootJars" || name == "ApexBootJars" || name == "VendorVars" ||
+ name == "VendorSnapshotModules" || name == "RecoverySnapshotModules" {
+ // These variables have more complicated types, and we don't need them right now
+ continue
+ }
+ if _, ok := in[name]; ok {
+ switch field.Type().Kind() {
+ case reflect.Bool:
+ val, err := starlark_import.Unmarshal[bool](in[name])
+ if err != nil {
+ return result, err
+ }
+ field.SetBool(val)
+ case reflect.String:
+ val, err := starlark_import.Unmarshal[string](in[name])
+ if err != nil {
+ return result, err
+ }
+ field.SetString(val)
+ case reflect.Slice:
+ if field.Type().Elem().Kind() != reflect.String {
+ return result, fmt.Errorf("slices of types other than strings are unimplemented")
+ }
+ val, err := starlark_import.UnmarshalReflect(in[name], field.Type())
+ if err != nil {
+ return result, err
+ }
+ field.Set(val)
+ case reflect.Pointer:
+ switch field.Type().Elem().Kind() {
+ case reflect.Bool:
+ val, err := starlark_import.UnmarshalNoneable[bool](in[name])
+ if err != nil {
+ return result, err
+ }
+ field.Set(reflect.ValueOf(val))
+ case reflect.String:
+ val, err := starlark_import.UnmarshalNoneable[string](in[name])
+ if err != nil {
+ return result, err
+ }
+ field.Set(reflect.ValueOf(val))
+ case reflect.Int:
+ val, err := starlark_import.UnmarshalNoneable[int](in[name])
+ if err != nil {
+ return result, err
+ }
+ field.Set(reflect.ValueOf(val))
+ default:
+ return result, fmt.Errorf("pointers of types other than strings/bools are unimplemented: %s", field.Type().Elem().Kind().String())
+ }
+ default:
+ return result, fmt.Errorf("unimplemented type: %s", field.Type().String())
+ }
+ }
}
- result.CFIIncludePaths, err = starlark_import.Unmarshal[[]string](in["CFIIncludePaths"])
- if err != nil {
- return result, err
- }
- result.CFIExcludePaths, err = starlark_import.Unmarshal[[]string](in["CFIExcludePaths"])
- if err != nil {
- return result, err
- }
- result.EnableCFI, err = starlark_import.UnmarshalNoneable[bool](in["EnableCFI"])
- if err != nil {
- return result, err
- }
- result.DeviceAbi, err = starlark_import.Unmarshal[[]string](in["DeviceAbi"])
- if err != nil {
- return result, err
- }
+
return result, nil
}
diff --git a/bp2build/bp2build_product_config_test.go b/bp2build/bp2build_product_config_test.go
new file mode 100644
index 0000000..3dd53ce
--- /dev/null
+++ b/bp2build/bp2build_product_config_test.go
@@ -0,0 +1,88 @@
+package bp2build
+
+import (
+ "android/soong/android"
+ "android/soong/starlark_import"
+ "encoding/json"
+ "reflect"
+ "testing"
+
+ "github.com/google/blueprint/proptools"
+ "go.starlark.net/starlark"
+)
+
+func createStarlarkValue(t *testing.T, code string) starlark.Value {
+ t.Helper()
+ result, err := starlark.ExecFile(&starlark.Thread{}, "main.bzl", "x = "+code, nil)
+ if err != nil {
+ t.Error(err)
+ }
+ return result["x"]
+}
+
+func createStarlarkProductVariablesMap(t *testing.T, code string) map[string]starlark.Value {
+ t.Helper()
+ rawValue := createStarlarkValue(t, code)
+ value, err := starlark_import.Unmarshal[map[string]starlark.Value](rawValue)
+ if err != nil {
+ t.Error(err)
+ }
+ return value
+}
+
+func TestStarlarkMapToProductVariables(t *testing.T) {
+ thirty := 30
+ cases := []struct {
+ starlark string
+ result android.ProductVariables
+ }{
+ {
+ starlark: `{"CompressedApex": True}`,
+ result: android.ProductVariables{CompressedApex: proptools.BoolPtr(true)},
+ },
+ {
+ starlark: `{"ApexGlobalMinSdkVersionOverride": "Tiramisu"}`,
+ result: android.ProductVariables{ApexGlobalMinSdkVersionOverride: proptools.StringPtr("Tiramisu")},
+ },
+ {
+ starlark: `{"ProductManufacturer": "Google"}`,
+ result: android.ProductVariables{ProductManufacturer: "Google"},
+ },
+ {
+ starlark: `{"Unbundled_build_apps": ["app1", "app2"]}`,
+ result: android.ProductVariables{Unbundled_build_apps: []string{"app1", "app2"}},
+ },
+ {
+ starlark: `{"Platform_sdk_version": 30}`,
+ result: android.ProductVariables{Platform_sdk_version: &thirty},
+ },
+ {
+ starlark: `{"HostFakeSnapshotEnabled": True}`,
+ result: android.ProductVariables{HostFakeSnapshotEnabled: true},
+ },
+ }
+
+ for _, testCase := range cases {
+ productVariables, err := starlarkMapToProductVariables(createStarlarkProductVariablesMap(t,
+ testCase.starlark))
+ if err != nil {
+ t.Error(err)
+ continue
+ }
+ if !reflect.DeepEqual(testCase.result, productVariables) {
+ expected, err := json.Marshal(testCase.result)
+ if err != nil {
+ t.Error(err)
+ continue
+ }
+ actual, err := json.Marshal(productVariables)
+ if err != nil {
+ t.Error(err)
+ continue
+ }
+ expectedStr := string(expected)
+ actualStr := string(actual)
+ t.Errorf("expected %q, but got %q", expectedStr, actualStr)
+ }
+ }
+}
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index 0e6596b..3de5213 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -353,7 +353,104 @@
Importpath bazel.StringAttribute
Srcs bazel.LabelListAttribute
Deps bazel.LabelListAttribute
+ Data bazel.LabelListAttribute
Target_compatible_with bazel.LabelListAttribute
+
+ // attributes for the dynamically generated go_test target
+ Embed bazel.LabelListAttribute
+}
+
+type goTestProperties struct {
+ name string
+ dir string
+ testSrcs []string
+ linuxTestSrcs []string
+ darwinTestSrcs []string
+ testData []string
+ // Name of the target that should be compiled together with the test
+ embedName string
+}
+
+// Creates a go_test target for bootstrap_go_package / blueprint_go_binary
+func generateBazelTargetsGoTest(ctx *android.Context, goModulesMap nameToGoLibraryModule, gp goTestProperties) (BazelTarget, error) {
+ ca := android.CommonAttributes{
+ Name: gp.name,
+ }
+ ga := goAttributes{
+ Srcs: goSrcLabels(ctx.Config(), gp.dir, gp.testSrcs, gp.linuxTestSrcs, gp.darwinTestSrcs),
+ Data: goSrcLabels(ctx.Config(), gp.dir, gp.testData, []string{}, []string{}),
+ Embed: bazel.MakeLabelListAttribute(
+ bazel.MakeLabelList(
+ []bazel.Label{bazel.Label{Label: ":" + gp.embedName}},
+ ),
+ ),
+ Target_compatible_with: targetNotCompatibleWithAndroid(),
+ }
+
+ libTest := goBazelTarget{
+ targetName: gp.name,
+ targetPackage: gp.dir,
+ bazelRuleClass: "go_test",
+ bazelRuleLoadLocation: "@io_bazel_rules_go//go:def.bzl",
+ bazelAttributes: []interface{}{&ca, &ga},
+ }
+ return generateBazelTarget(ctx, libTest)
+}
+
+// TODO - b/288491147: testSrcs of certain bootstrap_go_package/blueprint_go_binary are not hermetic and depend on
+// testdata checked into the filesystem.
+// Denylist the generation of go_test targets for these Soong modules.
+// The go_library/go_binary will still be generated, since those are hermitic.
+var (
+ goTestsDenylist = []string{
+ "android-archive-zip",
+ "bazel_notice_gen",
+ "blueprint-bootstrap-bpdoc",
+ "blueprint-microfactory",
+ "blueprint-pathtools",
+ "bssl_ar",
+ "compliance_checkmetadata",
+ "compliance_checkshare",
+ "compliance_dumpgraph",
+ "compliance_dumpresolutions",
+ "compliance_listshare",
+ "compliance-module",
+ "compliancenotice_bom",
+ "compliancenotice_shippedlibs",
+ "compliance_rtrace",
+ "compliance_sbom",
+ "golang-protobuf-internal-fuzz-jsonfuzz",
+ "golang-protobuf-internal-fuzz-textfuzz",
+ "golang-protobuf-internal-fuzz-wirefuzz",
+ "htmlnotice",
+ "protoc-gen-go",
+ "rbcrun-module",
+ "spdx-tools-builder",
+ "spdx-tools-builder2v1",
+ "spdx-tools-builder2v2",
+ "spdx-tools-builder2v3",
+ "spdx-tools-idsearcher",
+ "spdx-tools-spdx-json",
+ "spdx-tools-utils",
+ "soong-ui-build",
+ "textnotice",
+ "xmlnotice",
+ }
+)
+
+func testOfGoPackageIsIncompatible(g *bootstrap.GoPackage) bool {
+ return android.InList(g.Name(), goTestsDenylist) ||
+ // Denylist tests of soong_build
+ // Theses tests have a guard that prevent usage outside a test environment
+ // The guard (`ensureTestOnly`) looks for a `-test` in os.Args, which is present in soong's gotestrunner, but missing in `b test`
+ g.IsPluginFor("soong_build") ||
+ // soong-android is a dep of soong_build
+ // This dependency is created by soong_build by listing it in its deps explicitly in Android.bp, and not via `plugin_for` in `soong-android`
+ g.Name() == "soong-android"
+}
+
+func testOfGoBinaryIsIncompatible(g *bootstrap.GoBinary) bool {
+ return android.InList(g.Name(), goTestsDenylist)
}
func generateBazelTargetsGoPackage(ctx *android.Context, g *bootstrap.GoPackage, goModulesMap nameToGoLibraryModule) ([]BazelTarget, []error) {
@@ -390,12 +487,33 @@
bazelRuleLoadLocation: "@io_bazel_rules_go//go:def.bzl",
bazelAttributes: []interface{}{&ca, &ga},
}
- // TODO - b/284483729: Create go_test target from testSrcs
- libTarget, err := generateBazelTarget(ctx, lib)
- if err != nil {
- return []BazelTarget{}, []error{err}
+ retTargets := []BazelTarget{}
+ var retErrs []error
+ if libTarget, err := generateBazelTarget(ctx, lib); err == nil {
+ retTargets = append(retTargets, libTarget)
+ } else {
+ retErrs = []error{err}
}
- return []BazelTarget{libTarget}, nil
+
+ // If the library contains test srcs, create an additional go_test target
+ if !testOfGoPackageIsIncompatible(g) && (len(g.TestSrcs()) > 0 || len(g.LinuxTestSrcs()) > 0 || len(g.DarwinTestSrcs()) > 0) {
+ gp := goTestProperties{
+ name: g.Name() + "-test",
+ dir: ctx.ModuleDir(g),
+ testSrcs: g.TestSrcs(),
+ linuxTestSrcs: g.LinuxTestSrcs(),
+ darwinTestSrcs: g.DarwinTestSrcs(),
+ testData: g.TestData(),
+ embedName: g.Name(), // embed the source go_library in the test so that its .go files are included in the compilation unit
+ }
+ if libTestTarget, err := generateBazelTargetsGoTest(ctx, goModulesMap, gp); err == nil {
+ retTargets = append(retTargets, libTestTarget)
+ } else {
+ retErrs = append(retErrs, err)
+ }
+ }
+
+ return retTargets, retErrs
}
type goLibraryModule struct {
@@ -440,6 +558,9 @@
Name: g.Name(),
}
+ retTargets := []BazelTarget{}
+ var retErrs []error
+
// For this bootstrap_go_package dep chain,
// A --> B --> C ( ---> depends on)
// Soong provides the convenience of only listing B as deps of A even if a src file of A imports C
@@ -450,12 +571,70 @@
// bp2build does not have sufficient info on whether C is a direct dep of A or not, so for now collect all transitive deps and add them to deps
transitiveDeps := transitiveGoDeps(g.Deps(), goModulesMap)
+ goSource := ""
+ // If the library contains test srcs, create an additional go_test target
+ // The go_test target will embed a go_source containining the source .go files it tests
+ if !testOfGoBinaryIsIncompatible(g) && (len(g.TestSrcs()) > 0 || len(g.LinuxTestSrcs()) > 0 || len(g.DarwinTestSrcs()) > 0) {
+ // Create a go_source containing the source .go files of go_library
+ // This target will be an `embed` of the go_binary and go_test
+ goSource = g.Name() + "-source"
+ ca := android.CommonAttributes{
+ Name: goSource,
+ }
+ ga := goAttributes{
+ Srcs: goSrcLabels(ctx.Config(), ctx.ModuleDir(g), g.Srcs(), g.LinuxSrcs(), g.DarwinSrcs()),
+ Deps: goDepLabels(transitiveDeps, goModulesMap),
+ Target_compatible_with: targetNotCompatibleWithAndroid(),
+ }
+ libTestSource := goBazelTarget{
+ targetName: goSource,
+ targetPackage: ctx.ModuleDir(g),
+ bazelRuleClass: "go_source",
+ bazelRuleLoadLocation: "@io_bazel_rules_go//go:def.bzl",
+ bazelAttributes: []interface{}{&ca, &ga},
+ }
+ if libSourceTarget, err := generateBazelTarget(ctx, libTestSource); err == nil {
+ retTargets = append(retTargets, libSourceTarget)
+ } else {
+ retErrs = append(retErrs, err)
+ }
+
+ // Create a go_test target
+ gp := goTestProperties{
+ name: g.Name() + "-test",
+ dir: ctx.ModuleDir(g),
+ testSrcs: g.TestSrcs(),
+ linuxTestSrcs: g.LinuxTestSrcs(),
+ darwinTestSrcs: g.DarwinTestSrcs(),
+ testData: g.TestData(),
+ // embed the go_source in the test
+ embedName: g.Name() + "-source",
+ }
+ if libTestTarget, err := generateBazelTargetsGoTest(ctx, goModulesMap, gp); err == nil {
+ retTargets = append(retTargets, libTestTarget)
+ } else {
+ retErrs = append(retErrs, err)
+ }
+
+ }
+
+ // Create a go_binary target
ga := goAttributes{
- Srcs: goSrcLabels(ctx.Config(), ctx.ModuleDir(g), g.Srcs(), g.LinuxSrcs(), g.DarwinSrcs()),
Deps: goDepLabels(transitiveDeps, goModulesMap),
Target_compatible_with: targetNotCompatibleWithAndroid(),
}
+ // If the binary has testSrcs, embed the common `go_source`
+ if goSource != "" {
+ ga.Embed = bazel.MakeLabelListAttribute(
+ bazel.MakeLabelList(
+ []bazel.Label{bazel.Label{Label: ":" + goSource}},
+ ),
+ )
+ } else {
+ ga.Srcs = goSrcLabels(ctx.Config(), ctx.ModuleDir(g), g.Srcs(), g.LinuxSrcs(), g.DarwinSrcs())
+ }
+
bin := goBazelTarget{
targetName: g.Name(),
targetPackage: ctx.ModuleDir(g),
@@ -463,12 +642,14 @@
bazelRuleLoadLocation: "@io_bazel_rules_go//go:def.bzl",
bazelAttributes: []interface{}{&ca, &ga},
}
- // TODO - b/284483729: Create go_test target from testSrcs
- binTarget, err := generateBazelTarget(ctx, bin)
- if err != nil {
- return []BazelTarget{}, []error{err}
+
+ if binTarget, err := generateBazelTarget(ctx, bin); err == nil {
+ retTargets = append(retTargets, binTarget)
+ } else {
+ retErrs = []error{err}
}
- return []BazelTarget{binTarget}, nil
+
+ return retTargets, retErrs
}
func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (conversionResults, []error) {
diff --git a/bp2build/cc_test_conversion_test.go b/bp2build/cc_test_conversion_test.go
index 684fd03..3c037b4 100644
--- a/bp2build/cc_test_conversion_test.go
+++ b/bp2build/cc_test_conversion_test.go
@@ -120,8 +120,6 @@
"//build/bazel/platforms/os:windows": [":hostlib"],
"//conditions:default": [],
})`,
- "gtest": "True",
- "isolated": "True",
"local_includes": `["."]`,
"dynamic_deps": `[":cc_test_lib2"] + select({
"//build/bazel/platforms/os:android": [":foolib"],
@@ -158,7 +156,6 @@
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"gtest": "False",
- "isolated": "False",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
},
@@ -184,8 +181,6 @@
"tags": `["no-remote"]`,
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
- "gtest": "True",
- "isolated": "True",
"deps": `[
":libgtest_main",
":libgtest",
@@ -212,8 +207,6 @@
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
- "gtest": "True",
- "isolated": "True",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
@@ -243,8 +236,6 @@
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
- "gtest": "True",
- "isolated": "True",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
@@ -271,14 +262,13 @@
srcs: ["test.cpp"],
test_config_template: "test_config_template.xml",
auto_gen_config: true,
+ isolated: true,
}
-` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
- simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
+` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
+ simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"auto_generate_test_config": "True",
- "gtest": "True",
- "isolated": "True",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
@@ -288,10 +278,8 @@
]`,
"template_install_base": `"/data/local/tmp"`,
"template_test_config": `"test_config_template.xml"`,
- "deps": `[
- ":libgtest_main",
- ":libgtest",
- ]`,
+ "deps": `[":libgtest_isolated_main"]`,
+ "dynamic_deps": `[":liblog"]`,
},
},
},
@@ -311,8 +299,6 @@
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
- "gtest": "True",
- "isolated": "True",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
@@ -326,3 +312,63 @@
})
}
+
+func TestCcTest_WithIsolatedTurnedOn(t *testing.T) {
+ runCcTestTestCase(t, ccTestBp2buildTestCase{
+ description: "cc test that sets `isolated: true` should run with ligtest_isolated_main instead of libgtest_main",
+ blueprint: `
+cc_test {
+ name: "mytest",
+ srcs: ["test.cpp"],
+ isolated: true,
+}
+` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
+ simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
+ targets: []testBazelTarget{
+ {"cc_test", "mytest", AttrNameToString{
+ "local_includes": `["."]`,
+ "srcs": `["test.cpp"]`,
+ "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
+ "deps": `[":libgtest_isolated_main"]`,
+ "dynamic_deps": `[":liblog"]`,
+ },
+ },
+ },
+ })
+
+}
+
+func TestCcTest_GtestExplicitlySpecifiedInAndroidBp(t *testing.T) {
+ runCcTestTestCase(t, ccTestBp2buildTestCase{
+ description: "If `gtest` is explicit in Android.bp, it should be explicit in BUILD files as well",
+ blueprint: `
+cc_test {
+ name: "mytest_with_gtest",
+ gtest: true,
+}
+cc_test {
+ name: "mytest_with_no_gtest",
+ gtest: false,
+}
+` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
+ targets: []testBazelTarget{
+ {"cc_test", "mytest_with_gtest", AttrNameToString{
+ "local_includes": `["."]`,
+ "deps": `[
+ ":libgtest_main",
+ ":libgtest",
+ ]`,
+ "gtest": "True",
+ "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
+ },
+ },
+ {"cc_test", "mytest_with_no_gtest", AttrNameToString{
+ "local_includes": `["."]`,
+ "gtest": "False",
+ "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
+ },
+ },
+ },
+ })
+}
diff --git a/bp2build/go_conversion_test.go b/bp2build/go_conversion_test.go
index 507fbf0..2387641 100644
--- a/bp2build/go_conversion_test.go
+++ b/bp2build/go_conversion_test.go
@@ -45,11 +45,17 @@
srcs: [
"foo_linux.go",
],
+ testSrcs: [
+ "foo_linux_test.go",
+ ],
},
darwin: {
srcs: [
"foo_darwin.go",
],
+ testSrcs: [
+ "foo_darwin_test.go",
+ ],
},
testSrcs: [
"foo1_test.go",
@@ -84,7 +90,21 @@
})`,
},
android.HostSupported,
- )},
+ ),
+ makeBazelTargetHostOrDevice("go_test", "foo-test",
+ AttrNameToString{
+ "embed": `[":foo"]`,
+ "srcs": `[
+ "foo1_test.go",
+ "foo2_test.go",
+ ] + select({
+ "//build/bazel/platforms/os:darwin": ["foo_darwin_test.go"],
+ "//build/bazel/platforms/os:linux_glibc": ["foo_linux_test.go"],
+ "//conditions:default": [],
+ })`,
+ },
+ android.HostSupported,
+ )},
})
}
@@ -125,6 +145,44 @@
})
}
+func TestConvertGoBinaryWithTestSrcs(t *testing.T) {
+ bp := `
+blueprint_go_binary {
+ name: "foo",
+ srcs: ["main.go"],
+ testSrcs: ["main_test.go"],
+}
+`
+ t.Parallel()
+ runGoTests(t, Bp2buildTestCase{
+ Description: "Convert blueprint_go_binary with testSrcs",
+ Blueprint: bp,
+ ExpectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("go_binary", "foo",
+ AttrNameToString{
+ "deps": `[]`,
+ "embed": `[":foo-source"]`,
+ },
+ android.HostSupported,
+ ),
+ makeBazelTargetHostOrDevice("go_source", "foo-source",
+ AttrNameToString{
+ "deps": `[]`,
+ "srcs": `["main.go"]`,
+ },
+ android.HostSupported,
+ ),
+ makeBazelTargetHostOrDevice("go_test", "foo-test",
+ AttrNameToString{
+ "embed": `[":foo-source"]`,
+ "srcs": `["main_test.go"]`,
+ },
+ android.HostSupported,
+ ),
+ },
+ })
+}
+
func TestConvertGoBinaryWithSrcInDifferentPackage(t *testing.T) {
bp := `
blueprint_go_binary {
diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go
index 813773d..143597d 100644
--- a/bp2build/soong_config_module_type_conversion_test.go
+++ b/bp2build/soong_config_module_type_conversion_test.go
@@ -1406,3 +1406,111 @@
target_compatible_with = ["//build/bazel/platforms/os:android"],
)`}})
}
+
+// If we have
+// A. a soong_config_module_type with target.android_<arch>.* in properties
+// B. a module that uses this module type but does not set target.android_<arch>.* via soong config vars
+// Then we should not panic
+func TestPanicsIfSoongConfigModuleTypeHasArchSpecificProperties(t *testing.T) {
+ commonBp := `
+soong_config_bool_variable {
+ name: "my_bool_variable",
+}
+soong_config_module_type {
+ name: "special_cc_defaults",
+ module_type: "cc_defaults",
+ config_namespace: "my_namespace",
+ bool_variables: ["my_bool_variable"],
+ properties: [
+ "cflags",
+ "target.android_arm64.shared_libs",
+ ],
+}
+cc_binary {
+ name: "my_binary",
+ defaults: ["my_special_cc_defaults"],
+}
+`
+ testCases := []struct {
+ desc string
+ additionalBp string
+ isPanicExpected bool
+ }{
+ {
+ desc: "target.android_arm64 is not set, bp2build should not panic",
+ additionalBp: `
+special_cc_defaults {
+ name: "my_special_cc_defaults",
+ soong_config_variables: {
+ my_bool_variable: {
+ cflags: ["-DFOO"],
+ conditions_default: {
+ cflags: ["-DBAR"],
+ }
+ }
+ },
+}
+ `,
+ isPanicExpected: false,
+ },
+ {
+ desc: "target.android_arm64 is set using the bool soong config var, bp2build should panic",
+ additionalBp: `
+special_cc_defaults {
+ name: "my_special_cc_defaults",
+ soong_config_variables: {
+ my_bool_variable: {
+ cflags: ["-DFOO"],
+ target: {
+ android_arm64: {
+ shared_libs: ["liblog"],
+ },
+ },
+ conditions_default: {
+ cflags: ["-DBAR"],
+ }
+ }
+ },
+}
+ `,
+ isPanicExpected: true,
+ },
+ {
+ desc: "target.android_arm64 is set using conditions_default for the bool soong config var, bp2build should panic",
+ additionalBp: `
+special_cc_defaults {
+ name: "my_special_cc_defaults",
+ soong_config_variables: {
+ my_bool_variable: {
+ cflags: ["-DFOO"],
+ conditions_default: {
+ cflags: ["-DBAR"],
+ target: {
+ android_arm64: {
+ shared_libs: ["liblog"],
+ },
+ },
+ }
+ }
+ },
+}
+ `,
+ isPanicExpected: true,
+ },
+ }
+ for _, tc := range testCases {
+ bp2buildTestCase := Bp2buildTestCase{
+ Description: tc.desc,
+ ModuleTypeUnderTest: "cc_binary",
+ ModuleTypeUnderTestFactory: cc.BinaryFactory,
+ Blueprint: commonBp + tc.additionalBp,
+ // Check in `foo` dir so that we can check whether it panics or not and not trip over an empty `ExpectedBazelTargets`
+ Dir: "foo",
+ ExpectedBazelTargets: []string{},
+ }
+ if tc.isPanicExpected {
+ bp2buildTestCase.ExpectedErr = fmt.Errorf("TODO: support other target types in soong config variable structs: Android_arm64")
+ }
+ runSoongConfigModuleTypeTest(t, bp2buildTestCase)
+ }
+}
diff --git a/cc/afdo.go b/cc/afdo.go
index bc7cd52..23d196d 100644
--- a/cc/afdo.go
+++ b/cc/afdo.go
@@ -131,6 +131,10 @@
return
}
+ if !c.afdo.afdoEnabled() {
+ return
+ }
+
ctx.VisitDirectDepsWithTag(FdoProfileTag, func(m android.Module) {
if ctx.OtherModuleHasProvider(m, FdoProfileProvider) {
info := ctx.OtherModuleProvider(m, FdoProfileProvider).(FdoProfileInfo)
diff --git a/cc/api_level.go b/cc/api_level.go
index a5571f3..69a0d3a 100644
--- a/cc/api_level.go
+++ b/cc/api_level.go
@@ -31,7 +31,11 @@
case android.Arm64, android.X86_64:
return android.FirstLp64Version
case android.Riscv64:
- return android.FutureApiLevel
+ apiLevel, err := android.ApiLevelFromUser(ctx, "VanillaIceCream")
+ if err != nil {
+ panic(err)
+ }
+ return apiLevel
default:
panic(fmt.Errorf("Unknown arch %q", arch))
}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 6e00aa8..9895a20 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -43,6 +43,10 @@
rScriptSrcPartition = "renderScript"
+ xsdSrcPartition = "xsd"
+
+ hdrPartition = "hdr"
+
stubsSuffix = "_stub_libs_current"
)
@@ -155,6 +159,7 @@
lSrcPartition: bazel.LabelPartition{Extensions: []string{".l"}},
llSrcPartition: bazel.LabelPartition{Extensions: []string{".ll"}},
rScriptSrcPartition: bazel.LabelPartition{Extensions: []string{".fs", ".rscript"}},
+ xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(xsdConfigCppTarget)},
// C++ is the "catch-all" group, and comprises generated sources because we don't
// know the language of these sources until the genrule is executed.
cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
@@ -165,6 +170,14 @@
return bazel.PartitionLabelListAttribute(ctx, &srcs, labels)
}
+func partitionHeaders(ctx android.BazelConversionPathContext, hdrs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
+ labels := bazel.LabelPartitions{
+ xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(xsdConfigCppTarget)},
+ hdrPartition: bazel.LabelPartition{Keep_remainder: true},
+ }
+ return bazel.PartitionLabelListAttribute(ctx, &hdrs, labels)
+}
+
// bp2BuildParseLibProps returns the attributes for a variant of a cc_library.
func bp2BuildParseLibProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) staticOrSharedAttributes {
lib, ok := module.compiler.(*libraryDecorator)
@@ -403,7 +416,8 @@
srcs bazel.LabelListAttribute
// xsd config sources
- xsdInSrcs bazel.StringListAttribute
+ xsdSrcs bazel.LabelListAttribute
+ exportXsdSrcs bazel.LabelListAttribute
// Lex sources and options
lSrcs bazel.LabelListAttribute
@@ -494,14 +508,11 @@
func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, props *BaseCompilerProperties) {
// If there's arch specific srcs or exclude_srcs, generate a select entry for it.
// TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
- srcsList, xsdList, ok := parseSrcs(ctx, props)
+ srcsList, ok := parseSrcs(ctx, props)
if ok {
ca.srcs.SetSelectValue(axis, config, srcsList)
}
- if len(xsdList) > 0 {
- ca.xsdInSrcs.SetSelectValue(axis, config, xsdList)
- }
localIncludeDirs := props.Local_include_dirs
if axis == bazel.NoConfigAxis {
@@ -568,9 +579,11 @@
}
}
-func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs bazel.LabelListAttribute) {
+func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs, exportHdrs bazel.LabelListAttribute) {
ca.srcs.ResolveExcludes()
partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs)
+ partitionedImplHdrs := partitionHeaders(ctx, implementationHdrs)
+ partitionedHdrs := partitionHeaders(ctx, exportHdrs)
ca.protoSrcs = partitionedSrcs[protoSrcPartition]
ca.aidlSrcs = partitionedSrcs[aidlSrcPartition]
@@ -580,10 +593,19 @@
if lla.IsEmpty() {
continue
}
- lla.Append(implementationHdrs)
+ lla.Append(partitionedImplHdrs[hdrPartition])
partitionedSrcs[p] = lla
}
+ ca.hdrs = partitionedHdrs[hdrPartition]
+
+ ca.includesFromHeaders(ctx, partitionedImplHdrs[hdrPartition], partitionedHdrs[hdrPartition])
+
+ xsdSrcs := bazel.SubtractBazelLabelListAttribute(partitionedSrcs[xsdSrcPartition], partitionedHdrs[xsdSrcPartition])
+ xsdSrcs.Append(partitionedImplHdrs[xsdSrcPartition])
+ ca.exportXsdSrcs = partitionedHdrs[xsdSrcPartition]
+ ca.xsdSrcs = bazel.FirstUniqueBazelLabelListAttribute(xsdSrcs)
+
ca.srcs = partitionedSrcs[cppSrcPartition]
ca.cSrcs = partitionedSrcs[cSrcPartition]
ca.asSrcs = partitionedSrcs[asSrcPartition]
@@ -604,11 +626,11 @@
}
// Parse srcs from an arch or OS's props value.
-func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, []string, bool) {
+func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, bool) {
anySrcs := false
// Add srcs-like dependencies such as generated files.
// First create a LabelList containing these dependencies, then merge the values with srcs.
- genSrcs, xsd := android.PartitionXsdSrcs(ctx, props.Generated_sources)
+ genSrcs := props.Generated_sources
generatedSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, genSrcs, props.Exclude_generated_sources)
if len(props.Generated_sources) > 0 || len(props.Exclude_generated_sources) > 0 {
anySrcs = true
@@ -620,7 +642,7 @@
anySrcs = true
}
- return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), xsd, anySrcs
+ return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
}
func bp2buildStdVal(std *string, prefix string, useGnu bool) *string {
@@ -667,8 +689,43 @@
return split[0][2:], true
}
-// includesFromLabelList extracts relative/absolute includes from a bazel.LabelList>
-func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []string) {
+// includesFromHeaders gets the include directories needed from generated headers
+func (ca *compilerAttributes) includesFromHeaders(ctx android.BazelConversionPathContext, implHdrs, hdrs bazel.LabelListAttribute) {
+ local, absolute := includesFromLabelListAttribute(implHdrs, ca.localIncludes, ca.absoluteIncludes)
+ localExport, absoluteExport := includesFromLabelListAttribute(hdrs, ca.includes.Includes, ca.includes.AbsoluteIncludes)
+
+ ca.localIncludes = local
+ ca.absoluteIncludes = absolute
+
+ ca.includes.Includes = localExport
+ ca.includes.AbsoluteIncludes = absoluteExport
+}
+
+// includesFromLabelList extracts the packages from a LabelListAttribute that should be includes and
+// combines them with existing local/absolute includes.
+func includesFromLabelListAttribute(attr bazel.LabelListAttribute, existingLocal, existingAbsolute bazel.StringListAttribute) (bazel.StringListAttribute, bazel.StringListAttribute) {
+ localAttr := existingLocal.Clone()
+ absoluteAttr := existingAbsolute.Clone()
+ if !attr.Value.IsEmpty() {
+ l, a := includesFromLabelList(attr.Value, existingLocal.Value, existingAbsolute.Value)
+ localAttr.SetSelectValue(bazel.NoConfigAxis, "", l)
+ absoluteAttr.SetSelectValue(bazel.NoConfigAxis, "", a)
+ }
+ for axis, configToLabels := range attr.ConfigurableValues {
+ for c, labels := range configToLabels {
+ local := existingLocal.SelectValue(axis, c)
+ absolute := existingAbsolute.SelectValue(axis, c)
+ l, a := includesFromLabelList(labels, local, absolute)
+ localAttr.SetSelectValue(axis, c, l)
+ absoluteAttr.SetSelectValue(axis, c, a)
+ }
+ }
+ return *localAttr, *absoluteAttr
+}
+
+// includesFromLabelList extracts relative/absolute includes from a bazel.LabelList.
+func includesFromLabelList(labelList bazel.LabelList, existingRel, existingAbs []string) ([]string, []string) {
+ var relative, absolute []string
for _, hdr := range labelList.Includes {
if pkg, hasPkg := packageFromLabel(hdr.Label); hasPkg {
absolute = append(absolute, pkg)
@@ -676,6 +733,12 @@
relative = append(relative, pkg)
}
}
+ if len(relative)+len(existingRel) != 0 {
+ relative = android.FirstUniqueStrings(append(append([]string{}, existingRel...), relative...))
+ }
+ if len(absolute)+len(existingAbs) != 0 {
+ absolute = android.FirstUniqueStrings(append(append([]string{}, existingAbs...), absolute...))
+ }
return relative, absolute
}
@@ -740,8 +803,6 @@
archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{})
archVariantLibraryProperties := module.GetArchVariantProperties(ctx, &LibraryProperties{})
- var implementationHdrs bazel.LabelListAttribute
-
axisToConfigs := map[bazel.ConfigurationAxis]map[string]bool{}
allAxesAndConfigs := func(cp android.ConfigurationAxisToArchVariantProperties) {
for axis, configMap := range cp {
@@ -761,6 +822,7 @@
linkerAttrs := linkerAttributes{}
var aidlLibs bazel.LabelList
+ var implementationHdrs, exportHdrs bazel.LabelListAttribute
// Iterate through these axes in a deterministic order. This is required
// because processing certain dependencies may result in concatenating
@@ -770,9 +832,9 @@
for _, axis := range bazel.SortedConfigurationAxes(axisToConfigs) {
configs := axisToConfigs[axis]
for cfg := range configs {
- var allHdrs, allHdrsXsd []string
+ var allHdrs []string
if baseCompilerProps, ok := archVariantCompilerProps[axis][cfg].(*BaseCompilerProperties); ok {
- allHdrs, allHdrsXsd = android.PartitionXsdSrcs(ctx, baseCompilerProps.Generated_headers)
+ allHdrs = baseCompilerProps.Generated_headers
if baseCompilerProps.Lex != nil {
compilerAttrs.lexopts.SetSelectValue(axis, cfg, baseCompilerProps.Lex.Flags)
@@ -786,36 +848,17 @@
aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs))
}
- var exportHdrs, exportHdrsXsd []string
+ var exportedHdrs []string
if baseLinkerProps, ok := archVariantLinkerProps[axis][cfg].(*BaseLinkerProperties); ok {
- exportHdrs, exportHdrsXsd = android.PartitionXsdSrcs(ctx, baseLinkerProps.Export_generated_headers)
+ exportedHdrs = baseLinkerProps.Export_generated_headers
(&linkerAttrs).bp2buildForAxisAndConfig(ctx, module, axis, cfg, baseLinkerProps)
}
- // in the synthetic bp2build workspace, xsd sources are compiled to a static library
- xsdList := compilerAttrs.xsdInSrcs.SelectValue(axis, cfg)
- allHdrsXsd = android.FirstUniqueStrings(append(xsdList, allHdrsXsd...))
- headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportHdrs, android.BazelLabelForModuleDeps)
- xsdConfigLibs := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrsXsd, exportHdrsXsd, bazelLabelForXsdConfig)
+ headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportedHdrs, android.BazelLabelForModuleDeps)
implementationHdrs.SetSelectValue(axis, cfg, headers.implementation)
- compilerAttrs.hdrs.SetSelectValue(axis, cfg, headers.export)
-
- exportIncludes, exportAbsoluteIncludes := includesFromLabelList(headers.export)
- compilerAttrs.includes.Includes.SetSelectValue(axis, cfg, exportIncludes)
- compilerAttrs.includes.AbsoluteIncludes.SetSelectValue(axis, cfg, exportAbsoluteIncludes)
-
- includes, absoluteIncludes := includesFromLabelList(headers.implementation)
- currAbsoluteIncludes := compilerAttrs.absoluteIncludes.SelectValue(axis, cfg)
- currAbsoluteIncludes = android.FirstUniqueStrings(append(currAbsoluteIncludes, absoluteIncludes...))
-
- compilerAttrs.absoluteIncludes.SetSelectValue(axis, cfg, currAbsoluteIncludes)
-
- currIncludes := compilerAttrs.localIncludes.SelectValue(axis, cfg)
- currIncludes = android.FirstUniqueStrings(append(currIncludes, includes...))
-
- compilerAttrs.localIncludes.SetSelectValue(axis, cfg, currIncludes)
+ exportHdrs.SetSelectValue(axis, cfg, headers.export)
if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok {
if axis == bazel.NoConfigAxis {
@@ -835,14 +878,6 @@
}
}
- if len(allHdrsXsd) > 0 {
- wholeStaticLibs := linkerAttrs.implementationWholeArchiveDeps.SelectValue(axis, cfg)
- (&wholeStaticLibs).Append(xsdConfigLibs.implementation)
- linkerAttrs.implementationWholeArchiveDeps.SetSelectValue(axis, cfg, wholeStaticLibs)
- wholeStaticLibs = linkerAttrs.wholeArchiveDeps.SelectValue(axis, cfg)
- (&wholeStaticLibs).Append(xsdConfigLibs.export)
- linkerAttrs.wholeArchiveDeps.SetSelectValue(axis, cfg, wholeStaticLibs)
- }
}
}
@@ -860,11 +895,14 @@
(&compilerAttrs).convertProductVariables(ctx, productVariableProps)
(&linkerAttrs).convertProductVariables(ctx, productVariableProps)
- (&compilerAttrs).finalize(ctx, implementationHdrs)
+ (&compilerAttrs).finalize(ctx, implementationHdrs, exportHdrs)
(&linkerAttrs).finalize(ctx)
(&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs))
+ (&linkerAttrs).wholeArchiveDeps.Append(compilerAttrs.exportXsdSrcs)
+ (&linkerAttrs).implementationWholeArchiveDeps.Append(compilerAttrs.xsdSrcs)
+
protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs)
// bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know
@@ -1748,16 +1786,8 @@
return label
}
-// Replaces //a/b/my_xsd_config with //a/b/my_xsd_config-cpp
-func xsdConfigCppTarget(ctx android.BazelConversionPathContext, mod blueprint.Module) string {
- callback := func(xsd android.XsdConfigBp2buildTargets) string {
- return xsd.CppBp2buildTargetName()
- }
- return android.XsdConfigBp2buildTarget(ctx, mod, callback)
-}
-
-func bazelLabelForXsdConfig(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
- return android.BazelLabelForModuleDepsWithFn(ctx, modules, xsdConfigCppTarget)
+func xsdConfigCppTarget(xsd android.XsdConfigBp2buildTargets) string {
+ return xsd.CppBp2buildTargetName()
}
func bazelLabelForWholeDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
diff --git a/cc/config/global.go b/cc/config/global.go
index 266d278..ff5ab05 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -149,6 +149,7 @@
commonGlobalLldflags = []string{
"-fuse-ld=lld",
"-Wl,--icf=safe",
+ "-Wl,--no-demangle",
}
deviceGlobalCppflags = []string{
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 626005b..6c38355 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -675,12 +675,6 @@
s.Integer_overflow = nil
}
- // TODO(b/254713216): CFI doesn't work for riscv64 yet because LTO doesn't work.
- if ctx.Arch().ArchType == android.Riscv64 {
- s.Cfi = nil
- s.Diag.Cfi = nil
- }
-
// Disable CFI for musl
if ctx.toolchain().Musl() {
s.Cfi = nil
diff --git a/cc/stl.go b/cc/stl.go
index ffc7c76..8f92dcb 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -80,8 +80,7 @@
return ""
}
s = deduplicateStlInput(s)
- archHasNDKStl := ctx.Arch().ArchType != android.Riscv64
- if ctx.useSdk() && ctx.Device() && archHasNDKStl {
+ if ctx.useSdk() && ctx.Device() {
switch s {
case "", "system":
return "ndk_system"
diff --git a/cc/test.go b/cc/test.go
index 3bba003..0be2301 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -267,7 +267,7 @@
return BoolDefault(test.LinkerProperties.Gtest, true)
}
-func (test *testDecorator) isolated(ctx BaseModuleContext) bool {
+func (test *testDecorator) isolated(ctx android.EarlyModuleContext) bool {
return BoolDefault(test.LinkerProperties.Isolated, false)
}
@@ -682,8 +682,7 @@
type testBinaryAttributes struct {
binaryAttributes
- Gtest bool
- Isolated bool
+ Gtest *bool
tidyAttributes
tradefed.TestConfigAttributes
@@ -721,15 +720,15 @@
m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes)
- for _, propIntf := range m.GetProperties() {
- if testLinkerProps, ok := propIntf.(*TestLinkerProperties); ok {
- testBinaryAttrs.Gtest = proptools.BoolDefault(testLinkerProps.Gtest, true)
- testBinaryAttrs.Isolated = proptools.BoolDefault(testLinkerProps.Isolated, true)
- break
- }
- }
+ testBinary := m.linker.(*testBinary)
+ gtest := testBinary.gtest()
+ gtestIsolated := testBinary.isolated(ctx)
+ // Use the underling bool pointer for Gtest in attrs
+ // This ensures that if this property is not set in Android.bp file, it will not be set in BUILD file either
+ // cc_test macro will default gtest to True
+ testBinaryAttrs.Gtest = testBinary.LinkerProperties.Gtest
- addImplicitGtestDeps(ctx, &testBinaryAttrs)
+ addImplicitGtestDeps(ctx, &testBinaryAttrs, gtest, gtestIsolated)
for _, testProps := range m.GetProperties() {
if p, ok := testProps.(*TestBinaryProperties); ok {
@@ -742,7 +741,7 @@
p.Auto_gen_config,
p.Test_options.Test_suite_tag,
p.Test_config_template,
- getTradefedConfigOptions(ctx, p, testBinaryAttrs.Isolated),
+ getTradefedConfigOptions(ctx, p, gtestIsolated),
&testInstallBase,
)
testBinaryAttrs.TestConfigAttributes = testConfigAttributes
@@ -765,18 +764,25 @@
// cc_test that builds using gtest needs some additional deps
// addImplicitGtestDeps makes these deps explicit in the generated BUILD files
-func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes) {
- if attrs.Gtest {
- gtestDeps := android.BazelLabelForModuleDeps(
- ctx,
- []string{
+func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes, gtest, gtestIsolated bool) {
+ addDepsAndDedupe := func(lla *bazel.LabelListAttribute, modules []string) {
+ moduleLabels := android.BazelLabelForModuleDeps(ctx, modules)
+ lla.Value.Append(moduleLabels)
+ // Dedupe
+ lla.Value = bazel.FirstUniqueBazelLabelList(lla.Value)
+ }
+ // this must be kept in sync with Soong's implementation in:
+ // https://cs.android.com/android/_/android/platform/build/soong/+/460fb2d6d546b5ab493a7e5479998c4933a80f73:cc/test.go;l=300-313;drc=ec7314336a2b35ea30ce5438b83949c28e3ac429;bpv=1;bpt=0
+ if gtest {
+ // TODO - b/244433197: Handle canUseSdk
+ if gtestIsolated {
+ addDepsAndDedupe(&attrs.Deps, []string{"libgtest_isolated_main"})
+ addDepsAndDedupe(&attrs.Dynamic_deps, []string{"liblog"})
+ } else {
+ addDepsAndDedupe(&attrs.Deps, []string{
"libgtest_main",
"libgtest",
- },
- )
- attrs.Deps.Value.Append(gtestDeps)
- // Dedupe
- attrs.Deps.Value = bazel.FirstUniqueBazelLabelList(attrs.Deps.Value)
+ })
+ }
}
- // TODO(b/244432609): handle `isolated` property.
}
diff --git a/java/aar.go b/java/aar.go
index a682e3a..180e1d7 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -88,28 +88,40 @@
// do not include AndroidManifest from dependent libraries
Dont_merge_manifests *bool
+ // If use_resource_processor is set, use Bazel's resource processor instead of aapt2 to generate R.class files.
+ // The resource processor produces more optimal R.class files that only list resources in the package of the
+ // library that provided them, as opposed to aapt2 which produces R.java files for every package containing
+ // every resource. Using the resource processor can provide significant build time speedups, but requires
+ // fixing the module to use the correct package to reference each resource, and to avoid having any other
+ // libraries in the tree that use the same package name. Defaults to false, but will default to true in the
+ // future.
+ Use_resource_processor *bool
+
// true if RRO is enforced for any of the dependent modules
RROEnforcedForDependent bool `blueprint:"mutated"`
}
type aapt struct {
- aaptSrcJar android.Path
- exportPackage android.Path
- manifestPath android.Path
- proguardOptionsFile android.Path
- rTxt android.Path
- extraAaptPackagesFile android.Path
- mergedManifestFile android.Path
- noticeFile android.OptionalPath
- assetPackage android.OptionalPath
- isLibrary bool
- defaultManifestVersion string
- useEmbeddedNativeLibs bool
- useEmbeddedDex bool
- usesNonSdkApis bool
- hasNoCode bool
- LoggingParent string
- resourceFiles android.Paths
+ aaptSrcJar android.Path
+ transitiveAaptRJars android.Paths
+ transitiveAaptResourcePackages android.Paths
+ exportPackage android.Path
+ manifestPath android.Path
+ proguardOptionsFile android.Path
+ rTxt android.Path
+ rJar android.Path
+ extraAaptPackagesFile android.Path
+ mergedManifestFile android.Path
+ noticeFile android.OptionalPath
+ assetPackage android.OptionalPath
+ isLibrary bool
+ defaultManifestVersion string
+ useEmbeddedNativeLibs bool
+ useEmbeddedDex bool
+ usesNonSdkApis bool
+ hasNoCode bool
+ LoggingParent string
+ resourceFiles android.Paths
splitNames []string
splits []split
@@ -139,6 +151,10 @@
}
}
+func (a *aapt) useResourceProcessorBusyBox() bool {
+ return BoolDefault(a.aaptProperties.Use_resource_processor, false)
+}
+
func (a *aapt) ExportPackage() android.Path {
return a.exportPackage
}
@@ -175,8 +191,6 @@
// Flags specified in Android.bp
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
- linkFlags = append(linkFlags, "--no-static-lib-packages")
-
// Find implicit or explicit asset and resource dirs
assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets")
resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res")
@@ -348,6 +362,19 @@
linkFlags = append(linkFlags, "--static-lib")
}
+ if a.isLibrary && a.useResourceProcessorBusyBox() {
+ // When building an android_library using ResourceProcessorBusyBox the resources are merged into
+ // package-res.apk with --merge-only, but --no-static-lib-packages is not used so that R.txt only
+ // contains resources from this library.
+ linkFlags = append(linkFlags, "--merge-only")
+ } else {
+ // When building and app or when building an android_library without ResourceProcessorBusyBox
+ // --no-static-lib-packages is used to put all the resources into the app. If ResourceProcessorBusyBox
+ // is used then the app's R.txt will be post-processed along with the R.txt files from dependencies to
+ // sort resources into the right packages in R.class.
+ linkFlags = append(linkFlags, "--no-static-lib-packages")
+ }
+
packageRes := android.PathForModuleOut(ctx, "package-res.apk")
// the subdir "android" is required to be filtered by package names
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
@@ -355,6 +382,7 @@
rTxt := android.PathForModuleOut(ctx, "R.txt")
// This file isn't used by Soong, but is generated for exporting
extraPackages := android.PathForModuleOut(ctx, "extra_packages")
+ var transitiveRJars android.Paths
var compiledResDirs []android.Paths
for _, dir := range resDirs {
@@ -374,7 +402,23 @@
// of transitiveStaticLibs.
transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages())
- compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
+ if a.isLibrary && a.useResourceProcessorBusyBox() {
+ // When building an android_library with ResourceProcessorBusyBox enabled treat static library dependencies
+ // as imports. The resources from dependencies will not be merged into this module's package-res.apk, and
+ // instead modules depending on this module will reference package-res.apk from all transitive static
+ // dependencies.
+ for _, staticDep := range staticDeps {
+ linkDeps = append(linkDeps, staticDep.resPackage)
+ linkFlags = append(linkFlags, "-I "+staticDep.resPackage.String())
+ if staticDep.usedResourceProcessor {
+ transitiveRJars = append(transitiveRJars, staticDep.rJar)
+ }
+ }
+ } else {
+ // When building an app or building a library without ResourceProcessorBusyBox enabled all static
+ // dependencies are compiled into this module's package-res.apk as overlays.
+ compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
+ }
if len(transitiveStaticLibs) > 0 {
// If we are using static android libraries, every source file becomes an overlay.
@@ -437,7 +481,16 @@
a.assetPackage = android.OptionalPathForPath(assets)
}
+ if a.useResourceProcessorBusyBox() {
+ rJar := android.PathForModuleOut(ctx, "busybox/R.jar")
+ resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary)
+ transitiveRJars = append(transitiveRJars, rJar)
+ a.rJar = rJar
+ }
+
a.aaptSrcJar = srcJar
+ a.transitiveAaptRJars = transitiveRJars
+ a.transitiveAaptResourcePackages = staticDeps.resPackages()
a.exportPackage = packageRes
a.manifestPath = manifestPath
a.proguardOptionsFile = proguardOptionsFile
@@ -449,7 +502,11 @@
resPackage: a.exportPackage,
manifest: a.manifestPath,
additionalManifests: additionalManifests,
+ rTxt: a.rTxt,
+ rJar: a.rJar,
assets: a.assetPackage,
+
+ usedResourceProcessor: a.useResourceProcessorBusyBox(),
}).
Transitive(staticResourcesNodesDepSet).Build()
a.rroDirsDepSet = android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL).
@@ -461,34 +518,93 @@
Transitive(staticManifestsDepSet).Build()
}
+var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox",
+ blueprint.RuleParams{
+ Command: "${config.JavaCmd} -cp ${config.ResourceProcessorBusyBox} " +
+ "com.google.devtools.build.android.ResourceProcessorBusyBox --tool=GENERATE_BINARY_R -- @${out}.args && " +
+ "if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out}; fi",
+ CommandDeps: []string{"${config.ResourceProcessorBusyBox}"},
+ Rspfile: "${out}.args",
+ RspfileContent: "--primaryRTxt ${rTxt} --primaryManifest ${manifest} --classJarOutput ${out}.tmp ${args}",
+ Restat: true,
+ }, "rTxt", "manifest", "args")
+
+// resourceProcessorBusyBoxGenerateBinaryR converts the R.txt file produced by aapt2 into R.class files
+// using Bazel's ResourceProcessorBusyBox tool, which is faster than compiling the R.java files and
+// supports producing classes for static dependencies that only include resources from that dependency.
+func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, manifest android.Path,
+ rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool) {
+
+ var args []string
+ var deps android.Paths
+
+ if !isLibrary {
+ // When compiling an app, pass all R.txt and AndroidManifest.xml from transitive static library dependencies
+ // to ResourceProcessorBusyBox so that it can regenerate R.class files with the final resource IDs for each
+ // package.
+ args, deps = transitiveDeps.resourceProcessorDeps()
+ } else {
+ // When compiling a library don't pass any dependencies as it only needs to generate an R.class file for this
+ // library. Pass --finalFields=false so that the R.class file contains non-final fields so they don't get
+ // inlined into the library before the final IDs are assigned during app compilation.
+ args = append(args, "--finalFields=false")
+ }
+
+ deps = append(deps, rTxt, manifest)
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: resourceProcessorBusyBox,
+ Output: rJar,
+ Implicits: deps,
+ Description: "ResourceProcessorBusyBox",
+ Args: map[string]string{
+ "rTxt": rTxt.String(),
+ "manifest": manifest.String(),
+ "args": strings.Join(args, " "),
+ },
+ })
+}
+
type resourcesNode struct {
resPackage android.Path
manifest android.Path
additionalManifests android.Paths
+ rTxt android.Path
+ rJar android.Path
assets android.OptionalPath
+
+ usedResourceProcessor bool
}
type transitiveAarDeps []*resourcesNode
func (t transitiveAarDeps) resPackages() android.Paths {
- var paths android.Paths
+ paths := make(android.Paths, 0, len(t))
for _, dep := range t {
paths = append(paths, dep.resPackage)
}
- return android.FirstUniquePaths(paths)
+ return paths
}
func (t transitiveAarDeps) manifests() android.Paths {
- var paths android.Paths
+ paths := make(android.Paths, 0, len(t))
for _, dep := range t {
paths = append(paths, dep.manifest)
paths = append(paths, dep.additionalManifests...)
}
- return android.FirstUniquePaths(paths)
+ return paths
+}
+
+func (t transitiveAarDeps) resourceProcessorDeps() (args []string, deps android.Paths) {
+ for _, dep := range t {
+ args = append(args, "--library="+dep.rTxt.String()+","+dep.manifest.String())
+ deps = append(deps, dep.rTxt, dep.manifest)
+ }
+ return args, deps
}
func (t transitiveAarDeps) assets() android.Paths {
- var paths android.Paths
+ paths := make(android.Paths, 0, len(t))
for _, dep := range t {
if dep.assets.Valid() {
paths = append(paths, dep.assets.Path())
@@ -613,9 +729,12 @@
a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName())
- ctx.CheckbuildFile(a.proguardOptionsFile)
- ctx.CheckbuildFile(a.exportPackage)
- ctx.CheckbuildFile(a.aaptSrcJar)
+ ctx.CheckbuildFile(a.aapt.proguardOptionsFile)
+ ctx.CheckbuildFile(a.aapt.exportPackage)
+ ctx.CheckbuildFile(a.aapt.aaptSrcJar)
+ if a.useResourceProcessorBusyBox() {
+ ctx.CheckbuildFile(a.aapt.rJar)
+ }
// apps manifests are handled by aapt, don't let Module see them
a.properties.Manifest = nil
@@ -627,7 +746,22 @@
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
a.proguardOptionsFile)
- a.Module.compile(ctx, a.aaptSrcJar)
+ var extraSrcJars android.Paths
+ var extraCombinedJars android.Paths
+ var extraClasspathJars android.Paths
+ if a.useResourceProcessorBusyBox() {
+ // When building a library with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox for this
+ // library and each of the transitive static android_library dependencies has already created an
+ // R.class file for the appropriate package. Add all of those R.class files to the classpath.
+ extraClasspathJars = a.transitiveAaptRJars
+ } else {
+ // When building a library without ResourceProcessorBusyBox the aapt2 rule creates R.srcjar containing
+ // R.java files for the library's package and the packages from all transitive static android_library
+ // dependencies. Compile the srcjar alongside the rest of the sources.
+ extraSrcJars = android.Paths{a.aapt.aaptSrcJar}
+ }
+
+ a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars)
a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar")
var res android.Paths
@@ -729,12 +863,15 @@
properties AARImportProperties
- classpathFile android.WritablePath
- proguardFlags android.WritablePath
- exportPackage android.WritablePath
- extraAaptPackagesFile android.WritablePath
- manifest android.WritablePath
- assetsPackage android.WritablePath
+ classpathFile android.WritablePath
+ proguardFlags android.WritablePath
+ exportPackage android.WritablePath
+ transitiveAaptResourcePackages android.Paths
+ extraAaptPackagesFile android.WritablePath
+ manifest android.WritablePath
+ assetsPackage android.WritablePath
+ rTxt android.WritablePath
+ rJar android.WritablePath
resourcesNodesDepSet *android.DepSet[*resourcesNode]
manifestsDepSet *android.DepSet[android.Path]
@@ -903,12 +1040,13 @@
a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar")
a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt")
a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml")
+ aarRTxt := extractedAARDir.Join(ctx, "R.txt")
a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip")
ctx.Build(pctx, android.BuildParams{
Rule: unzipAAR,
Input: a.aarPath,
- Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage},
+ Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage, aarRTxt},
Description: "unzip AAR",
Args: map[string]string{
"outDir": extractedAARDir.String(),
@@ -928,14 +1066,14 @@
// the subdir "android" is required to be filtered by package names
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
- rTxt := android.PathForModuleOut(ctx, "R.txt")
+ a.rTxt = android.PathForModuleOut(ctx, "R.txt")
a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
var linkDeps android.Paths
linkFlags := []string{
"--static-lib",
- "--no-static-lib-packages",
+ "--merge-only",
"--auto-add-overlay",
}
@@ -948,25 +1086,35 @@
_ = staticRRODirsDepSet
staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList())
- // AAPT2 overlays are in lowest to highest priority order, reverse the topological order
- // of transitiveStaticLibs.
- transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages())
-
linkDeps = append(linkDeps, sharedLibs...)
- linkDeps = append(linkDeps, transitiveStaticLibs...)
+ linkDeps = append(linkDeps, staticDeps.resPackages()...)
linkFlags = append(linkFlags, libFlags...)
- overlayRes := append(android.Paths{flata}, transitiveStaticLibs...)
+ overlayRes := android.Paths{flata}
+
+ // Treat static library dependencies of static libraries as imports.
+ transitiveStaticLibs := staticDeps.resPackages()
+ linkDeps = append(linkDeps, transitiveStaticLibs...)
+ for _, staticLib := range transitiveStaticLibs {
+ linkFlags = append(linkFlags, "-I "+staticLib.String())
+ }
transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets())
- aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
+ aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, a.rTxt, a.extraAaptPackagesFile,
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
+ a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar")
+ resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true)
+
resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL)
resourcesNodesDepSetBuilder.Direct(&resourcesNode{
resPackage: a.exportPackage,
manifest: a.manifest,
+ rTxt: a.rTxt,
+ rJar: a.rJar,
assets: android.OptionalPathForPath(a.assetsPackage),
+
+ usedResourceProcessor: true,
})
resourcesNodesDepSetBuilder.Transitive(staticResourcesNodesDepSet)
a.resourcesNodesDepSet = resourcesNodesDepSetBuilder.Build()
@@ -981,6 +1129,8 @@
_ = staticManifestsDepSet
a.manifestsDepSet = manifestDepSetBuilder.Build()
+ a.transitiveAaptResourcePackages = staticDeps.resPackages()
+
a.collectTransitiveHeaderJars(ctx)
ctx.SetProvider(JavaInfoProvider, JavaInfo{
HeaderJars: android.PathsIfNonNil(a.classpathFile),
diff --git a/java/androidmk.go b/java/androidmk.go
index 36271dd..82505e9 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -269,6 +269,7 @@
entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage)
+ entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackages)
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
@@ -521,6 +522,7 @@
}
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.exportPackage)
+ entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", a.transitiveAaptResourcePackages)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile)
entries.AddStrings("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.exportedProguardFlagFiles.Strings()...)
diff --git a/java/app.go b/java/app.go
index f1992c9..224bc88 100755
--- a/java/app.go
+++ b/java/app.go
@@ -521,7 +521,23 @@
a.dexpreopter.preventInstall = a.appProperties.PreventInstall
if ctx.ModuleName() != "framework-res" {
- a.Module.compile(ctx, a.aaptSrcJar)
+ var extraSrcJars android.Paths
+ var extraClasspathJars android.Paths
+ var extraCombinedJars android.Paths
+ if a.useResourceProcessorBusyBox() {
+ // When building an app with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox has already
+ // created R.class files that provide IDs for resources in busybox/R.jar. Pass that file in the
+ // classpath when compiling everything else, and add it to the final classes jar.
+ extraClasspathJars = android.Paths{a.aapt.rJar}
+ extraCombinedJars = android.Paths{a.aapt.rJar}
+ } else {
+ // When building an app without ResourceProcessorBusyBox the aapt2 rule creates R.srcjar containing
+ // R.java files for the app's package and the packages from all transitive static android_library
+ // dependencies. Compile the srcjar alongside the rest of the sources.
+ extraSrcJars = android.Paths{a.aapt.aaptSrcJar}
+ }
+
+ a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars)
}
return a.dexJarFile.PathOrNil()
@@ -1039,7 +1055,6 @@
module.Module.dexProperties.Optimize.EnabledByDefault = true
module.Module.dexProperties.Optimize.Shrink = proptools.BoolPtr(true)
- module.Module.dexProperties.Optimize.Proguard_compatibility = proptools.BoolPtr(false)
module.Module.properties.Instrument = true
module.Module.properties.Supports_static_instrumentation = true
diff --git a/java/app_builder.go b/java/app_builder.go
index d20a6bf..e241adb 100644
--- a/java/app_builder.go
+++ b/java/app_builder.go
@@ -225,8 +225,6 @@
})
}
-const jniJarOutputPathString = "jniJarOutput.zip"
-
func TransformJniLibsToJar(
ctx android.ModuleContext,
outputFile android.WritablePath,
@@ -258,7 +256,10 @@
rule = zipRE
args["implicits"] = strings.Join(deps.Strings(), ",")
}
- jniJarPath := android.PathForModuleOut(ctx, jniJarOutputPathString)
+ var jniJarPath android.WritablePath = android.PathForModuleOut(ctx, "jniJarOutput.zip")
+ if len(prebuiltJniPackages) == 0 {
+ jniJarPath = outputFile
+ }
ctx.Build(pctx, android.BuildParams{
Rule: rule,
Description: "zip jni libs",
@@ -266,12 +267,14 @@
Implicits: deps,
Args: args,
})
- ctx.Build(pctx, android.BuildParams{
- Rule: mergeAssetsRule,
- Description: "merge prebuilt JNI packages",
- Inputs: append(prebuiltJniPackages, jniJarPath),
- Output: outputFile,
- })
+ if len(prebuiltJniPackages) > 0 {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: mergeAssetsRule,
+ Description: "merge prebuilt JNI packages",
+ Inputs: append(prebuiltJniPackages, jniJarPath),
+ Output: outputFile,
+ })
+ }
}
func (a *AndroidApp) generateJavaUsedByApex(ctx android.ModuleContext) {
diff --git a/java/app_test.go b/java/app_test.go
index c438b6c..8474ea7 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -722,7 +722,10 @@
func TestAndroidResourceProcessor(t *testing.T) {
testCases := []struct {
- name string
+ name string
+ appUsesRP bool
+ directLibUsesRP bool
+ transitiveLibUsesRP bool
dontVerifyApp bool
appResources []string
@@ -759,7 +762,12 @@
transitiveImportImports []string
}{
{
- name: "legacy",
+ // Test with all modules set to use_resource_processor: false (except android_library_import modules,
+ // which always use resource processor).
+ name: "legacy",
+ appUsesRP: false,
+ directLibUsesRP: false,
+ transitiveLibUsesRP: false,
appResources: nil,
appOverlays: []string{
@@ -771,7 +779,6 @@
"out/soong/.intermediates/direct_import/android_common/package-res.apk",
"out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat",
},
-
appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"},
appClasspath: []string{
@@ -792,7 +799,6 @@
"out/soong/.intermediates/transitive_import/android_common/package-res.apk",
"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat",
},
-
directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"},
directClasspath: []string{
@@ -814,18 +820,256 @@
transitiveCombined: nil,
directImportResources: nil,
- directImportOverlays: []string{
- "out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata",
+ directImportOverlays: []string{"out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata"},
+ directImportImports: []string{
+ "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk",
"out/soong/.intermediates/direct_import_dep/android_common/package-res.apk",
},
- directImportImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
transitiveImportResources: nil,
- transitiveImportOverlays: []string{
- "out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata",
+ transitiveImportOverlays: []string{"out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata"},
+ transitiveImportImports: []string{
+ "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk",
"out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
},
- transitiveImportImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ },
+ {
+ // Test with all modules set to use_resource_processor: true.
+ name: "resource_processor",
+ appUsesRP: true,
+ directLibUsesRP: true,
+ transitiveLibUsesRP: true,
+
+ appResources: nil,
+ appOverlays: []string{
+ "out/soong/.intermediates/transitive/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import/android_common/package-res.apk",
+ "out/soong/.intermediates/direct/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import/android_common/package-res.apk",
+ "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat",
+ },
+ appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ appSrcJars: nil,
+ appClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/app/android_common/busybox/R.jar",
+ "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+ appCombined: []string{
+ "out/soong/.intermediates/app/android_common/busybox/R.jar",
+ "out/soong/.intermediates/app/android_common/javac/app.jar",
+ "out/soong/.intermediates/direct/android_common/combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+
+ directResources: nil,
+ directOverlays: []string{"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat"},
+ directImports: []string{
+ "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive/android_common/package-res.apk",
+ },
+ directSrcJars: nil,
+ directClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar",
+ "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar",
+ "out/soong/.intermediates/transitive/android_common/busybox/R.jar",
+ "out/soong/.intermediates/direct/android_common/busybox/R.jar",
+ "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar",
+ "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ },
+ directCombined: []string{
+ "out/soong/.intermediates/direct/android_common/javac/direct.jar",
+ "out/soong/.intermediates/transitive/android_common/javac/transitive.jar",
+ "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ },
+
+ transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"},
+ transitiveOverlays: nil,
+ transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ transitiveSrcJars: nil,
+ transitiveClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/transitive/android_common/busybox/R.jar",
+ },
+ transitiveCombined: nil,
+
+ directImportResources: nil,
+ directImportOverlays: []string{"out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata"},
+ directImportImports: []string{
+ "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk",
+ },
+
+ transitiveImportResources: nil,
+ transitiveImportOverlays: []string{"out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata"},
+ transitiveImportImports: []string{
+ "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ },
+ }, {
+ // Test an app building with resource processor enabled but with dependencies built without
+ // resource processor.
+ name: "app_resource_processor",
+ appUsesRP: true,
+ directLibUsesRP: false,
+ transitiveLibUsesRP: false,
+
+ appResources: nil,
+ appOverlays: []string{
+ "out/soong/.intermediates/transitive/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import/android_common/package-res.apk",
+ "out/soong/.intermediates/direct/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import/android_common/package-res.apk",
+ "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat",
+ },
+ appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ appSrcJars: nil,
+ appClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ // R.jar has to come before direct.jar
+ "out/soong/.intermediates/app/android_common/busybox/R.jar",
+ "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+ appCombined: []string{
+ "out/soong/.intermediates/app/android_common/busybox/R.jar",
+ "out/soong/.intermediates/app/android_common/javac/app.jar",
+ "out/soong/.intermediates/direct/android_common/combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+
+ dontVerifyDirect: true,
+ dontVerifyTransitive: true,
+ dontVerifyDirectImport: true,
+ dontVerifyTransitiveImport: true,
+ },
+ {
+ // Test an app building without resource processor enabled but with a dependency built with
+ // resource processor.
+ name: "app_dependency_lib_resource_processor",
+ appUsesRP: false,
+ directLibUsesRP: true,
+ transitiveLibUsesRP: false,
+
+ appOverlays: []string{
+ "out/soong/.intermediates/transitive/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import/android_common/package-res.apk",
+ "out/soong/.intermediates/direct/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import/android_common/package-res.apk",
+ "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat",
+ },
+ appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"},
+ appClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+ appCombined: []string{
+ "out/soong/.intermediates/app/android_common/javac/app.jar",
+ "out/soong/.intermediates/direct/android_common/combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+
+ directResources: nil,
+ directOverlays: []string{"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat"},
+ directImports: []string{
+ "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive/android_common/package-res.apk",
+ },
+ directSrcJars: nil,
+ directClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar",
+ "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar",
+ "out/soong/.intermediates/direct/android_common/busybox/R.jar",
+ "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar",
+ "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ },
+ directCombined: []string{
+ "out/soong/.intermediates/direct/android_common/javac/direct.jar",
+ "out/soong/.intermediates/transitive/android_common/javac/transitive.jar",
+ "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ },
+
+ dontVerifyTransitive: true,
+ dontVerifyDirectImport: true,
+ dontVerifyTransitiveImport: true,
+ },
+ {
+ // Test a library building without resource processor enabled but with a dependency built with
+ // resource processor.
+ name: "lib_dependency_lib_resource_processor",
+ appUsesRP: false,
+ directLibUsesRP: false,
+ transitiveLibUsesRP: true,
+
+ appOverlays: []string{
+ "out/soong/.intermediates/transitive/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import/android_common/package-res.apk",
+ "out/soong/.intermediates/direct/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/direct_import/android_common/package-res.apk",
+ "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat",
+ },
+ appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"},
+ appClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+ appCombined: []string{
+ "out/soong/.intermediates/app/android_common/javac/app.jar",
+ "out/soong/.intermediates/direct/android_common/combined/direct.jar",
+ "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
+ },
+
+ directResources: nil,
+ directOverlays: []string{
+ "out/soong/.intermediates/transitive/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
+ "out/soong/.intermediates/transitive_import/android_common/package-res.apk",
+ "out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat",
+ },
+ directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"},
+ directClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar",
+ "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ },
+ directCombined: []string{
+ "out/soong/.intermediates/direct/android_common/javac/direct.jar",
+ "out/soong/.intermediates/transitive/android_common/javac/transitive.jar",
+ "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar",
+ },
+
+ transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"},
+ transitiveOverlays: nil,
+ transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
+ transitiveSrcJars: nil,
+ transitiveClasspath: []string{
+ "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar",
+ "out/soong/.intermediates/transitive/android_common/busybox/R.jar",
+ },
+ transitiveCombined: nil,
+
+ dontVerifyDirectImport: true,
+ dontVerifyTransitiveImport: true,
},
}
@@ -839,6 +1083,7 @@
resource_dirs: ["app/res"],
manifest: "app/AndroidManifest.xml",
static_libs: ["direct", "direct_import"],
+ use_resource_processor: %v,
}
android_library {
@@ -848,6 +1093,7 @@
resource_dirs: ["direct/res"],
manifest: "direct/AndroidManifest.xml",
static_libs: ["transitive", "transitive_import"],
+ use_resource_processor: %v,
}
android_library {
@@ -856,6 +1102,7 @@
srcs: ["transitive/transitive.java"],
resource_dirs: ["transitive/res"],
manifest: "transitive/AndroidManifest.xml",
+ use_resource_processor: %v,
}
android_library_import {
@@ -883,7 +1130,7 @@
sdk_version: "current",
aars: ["transitive_import_dep.aar"],
}
- `)
+ `, testCase.appUsesRP, testCase.directLibUsesRP, testCase.transitiveLibUsesRP)
fs := android.MockFS{
"app/res/values/strings.xml": nil,
@@ -1495,7 +1742,7 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.Output(jniJarOutputPathString)
+ jniLibZip := app.Output("jnilibs.zip")
var abis []string
args := strings.Fields(jniLibZip.Args["jarArgs"])
for i := 0; i < len(args); i++ {
@@ -1628,7 +1875,7 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.MaybeOutput(jniJarOutputPathString)
+ jniLibZip := app.MaybeOutput("jnilibs.zip")
if g, w := (jniLibZip.Rule != nil), test.packaged; g != w {
t.Errorf("expected jni packaged %v, got %v", w, g)
}
@@ -1719,7 +1966,7 @@
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.MaybeOutput(jniJarOutputPathString)
+ jniLibZip := app.MaybeOutput("jnilibs.zip")
if len(jniLibZip.Implicits) != 1 {
t.Fatalf("expected exactly one jni library, got %q", jniLibZip.Implicits.Strings())
}
@@ -2739,7 +2986,7 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.Output(jniJarOutputPathString)
+ jniLibZip := app.Output("jnilibs.zip")
var jnis []string
args := strings.Fields(jniLibZip.Args["jarArgs"])
for i := 0; i < len(args); i++ {
diff --git a/java/base.go b/java/base.go
index 2293f64..f5eb01c 100644
--- a/java/base.go
+++ b/java/base.go
@@ -1065,7 +1065,7 @@
module.properties.Generated_srcjars = append(module.properties.Generated_srcjars, path)
}
-func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
+func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspathJars, extraCombinedJars android.Paths) {
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
deps := j.collectDeps(ctx)
@@ -1103,9 +1103,7 @@
srcJars := srcFiles.FilterByExt(".srcjar")
srcJars = append(srcJars, deps.srcJars...)
- if aaptSrcJar != nil {
- srcJars = append(srcJars, aaptSrcJar)
- }
+ srcJars = append(srcJars, extraSrcJars...)
srcJars = append(srcJars, j.properties.Generated_srcjars...)
srcFiles = srcFiles.FilterOutByExt(".srcjar")
@@ -1148,6 +1146,11 @@
var kotlinJars android.Paths
var kotlinHeaderJars android.Paths
+ // Prepend extraClasspathJars to classpath so that the resource processor R.jar comes before
+ // any dependencies so that it can override any non-final R classes from dependencies with the
+ // final R classes from the app.
+ flags.classpath = append(android.CopyOf(extraClasspathJars), flags.classpath...)
+
if srcFiles.HasExt(".kt") {
// When using kotlin sources turbine is used to generate annotation processor sources,
// including for annotation processors that generate API, so we can use turbine for
@@ -1241,8 +1244,9 @@
// allow for the use of annotation processors that do function correctly
// with sharding enabled. See: b/77284273.
}
+ extraJars := append(android.CopyOf(extraCombinedJars), kotlinHeaderJars...)
headerJarFileWithoutDepsOrJarjar, j.headerJarFile =
- j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, kotlinHeaderJars)
+ j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars)
if ctx.Failed() {
return
}
@@ -1393,6 +1397,8 @@
jars = append(jars, servicesJar)
}
+ jars = append(android.CopyOf(extraCombinedJars), jars...)
+
// Combine the classes built from sources, any manifests, and any static libraries into
// classes.jar. If there is only one input jar this step will be skipped.
var outputFile android.OutputPath
diff --git a/java/builder.go b/java/builder.go
index afbd69e..debf49a 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -55,7 +55,7 @@
`$zipTemplate${config.SoongZipCmd} -jar -o $out.tmp -C $outDir -D $outDir && ` +
`if ! cmp -s "$out.tmp" "$out"; then mv "$out.tmp" "$out"; fi && ` +
`if ! cmp -s "$annoSrcJar.tmp" "$annoSrcJar"; then mv "$annoSrcJar.tmp" "$annoSrcJar"; fi && ` +
- `rm -rf "$srcJarDir"`,
+ `rm -rf "$srcJarDir" "$outDir"`,
CommandDeps: []string{
"${config.JavacCmd}",
"${config.SoongZipCmd}",
diff --git a/java/config/config.go b/java/config/config.go
index 195dae1..83c27d3 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -148,6 +148,8 @@
pctx.SourcePathVariable("JavaKytheExtractorJar", "prebuilts/build-tools/common/framework/javac_extractor.jar")
pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")
+ pctx.SourcePathVariable("ResourceProcessorBusyBox", "prebuilts/bazel/common/android_tools/android_tools/all_android_tools_deploy.jar")
+
pctx.HostBinToolVariable("GenKotlinBuildFileCmd", "gen-kotlin-build-file")
pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
diff --git a/java/dex.go b/java/dex.go
index 7dd14bd..7e7da00 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -45,8 +45,8 @@
// Whether to continue building even if warnings are emitted. Defaults to true.
Ignore_warnings *bool
- // If true, runs R8 in Proguard compatibility mode, otherwise runs R8 in full mode.
- // Defaults to false for apps, true for libraries and tests.
+ // If true, runs R8 in Proguard compatibility mode (default).
+ // Otherwise, runs R8 in full mode.
Proguard_compatibility *bool
// If true, optimize for size by removing unused code. Defaults to true for apps,
diff --git a/java/java.go b/java/java.go
index 20d9afc..f29f738 100644
--- a/java/java.go
+++ b/java/java.go
@@ -699,7 +699,7 @@
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
j.classLoaderContexts = j.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
}
- j.compile(ctx, nil)
+ j.compile(ctx, nil, nil, nil)
// Collect the module directory for IDE info in java/jdeps.go.
j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
@@ -2819,12 +2819,8 @@
hasKotlin bool
}
-// Replaces //a/b/my_xsd_config with //a/b/my_xsd_config-java
-func xsdConfigJavaTarget(ctx android.BazelConversionPathContext, mod blueprint.Module) string {
- callback := func(xsd android.XsdConfigBp2buildTargets) string {
- return xsd.JavaBp2buildTargetName()
- }
- return android.XsdConfigBp2buildTarget(ctx, mod, callback)
+func javaXsdTargetName(xsd android.XsdConfigBp2buildTargets) string {
+ return xsd.JavaBp2buildTargetName()
}
// convertLibraryAttrsBp2Build returns a javaCommonAttributes struct with
@@ -2835,21 +2831,14 @@
func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) (*javaCommonAttributes, *bp2BuildJavaInfo) {
var srcs bazel.LabelListAttribute
var deps bazel.LabelListAttribute
- var staticDeps bazel.LabelList
+ var staticDeps bazel.LabelListAttribute
archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
for axis, configToProps := range archVariantProps {
for config, _props := range configToProps {
if archProps, ok := _props.(*CommonProperties); ok {
- srcsNonXsd, srcsXsd := android.PartitionXsdSrcs(ctx, archProps.Srcs)
- excludeSrcsNonXsd, _ := android.PartitionXsdSrcs(ctx, archProps.Exclude_srcs)
- archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, srcsNonXsd, excludeSrcsNonXsd)
+ archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs)
srcs.SetSelectValue(axis, config, archSrcs)
-
- // Add to static deps
- xsdJavaConfigLibraryLabels := android.BazelLabelForModuleDepsWithFn(ctx, srcsXsd, xsdConfigJavaTarget)
- staticDeps.Append(xsdJavaConfigLibraryLabels)
-
}
}
}
@@ -2857,6 +2846,7 @@
javaSrcPartition := "java"
protoSrcPartition := "proto"
+ xsdSrcPartition := "xsd"
logtagSrcPartition := "logtag"
aidlSrcPartition := "aidl"
kotlinPartition := "kotlin"
@@ -2865,6 +2855,7 @@
logtagSrcPartition: bazel.LabelPartition{Extensions: []string{".logtags", ".logtag"}},
protoSrcPartition: android.ProtoSrcLabelPartition,
aidlSrcPartition: android.AidlSrcLabelPartition,
+ xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(javaXsdTargetName)},
kotlinPartition: bazel.LabelPartition{Extensions: []string{".kt"}},
})
@@ -2872,6 +2863,8 @@
kotlinSrcs := srcPartitions[kotlinPartition]
javaSrcs.Append(kotlinSrcs)
+ staticDeps.Append(srcPartitions[xsdSrcPartition])
+
if !srcPartitions[logtagSrcPartition].IsEmpty() {
logtagsLibName := m.Name() + "_logtags"
ctx.CreateBazelTargetModule(
@@ -2925,7 +2918,7 @@
},
)
- staticDeps.Add(&bazel.Label{Label: ":" + javaAidlLibName})
+ staticDeps.Append(bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + javaAidlLibName}))
}
var javacopts bazel.StringListAttribute //[]string
@@ -2980,7 +2973,9 @@
// by protoc are included directly in the resulting JAR. Thus upstream dependencies
// that depend on a java_library with proto sources can link directly to the protobuf API,
// and so this should be a static dependency.
- staticDeps.Add(protoDepLabel)
+ if protoDepLabel != nil {
+ staticDeps.Append(bazel.MakeSingleLabelListAttribute(*protoDepLabel))
+ }
depLabels := &javaDependencyLabels{}
depLabels.Deps = deps
@@ -2995,7 +2990,7 @@
}
}
}
- depLabels.StaticDeps.Value.Append(staticDeps)
+ depLabels.StaticDeps.Append(staticDeps)
hasKotlin := !kotlinSrcs.IsEmpty()
commonAttrs.kotlinAttributes = &kotlinAttributes{
diff --git a/java/kotlin.go b/java/kotlin.go
index f28d6c7..3637e2e 100644
--- a/java/kotlin.go
+++ b/java/kotlin.go
@@ -42,7 +42,7 @@
` -P plugin:org.jetbrains.kotlin.jvm.abi:outputDir=$headerClassesDir && ` +
`${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir -write_if_changed && ` +
`${config.SoongZipCmd} -jar -o $headerJar -C $headerClassesDir -D $headerClassesDir -write_if_changed && ` +
- `rm -rf "$srcJarDir"`,
+ `rm -rf "$srcJarDir" "$classesDir" "$headerClassesDir"`,
CommandDeps: []string{
"${config.KotlincCmd}",
"${config.KotlinCompilerJar}",
diff --git a/rust/config/arm64_device.go b/rust/config/arm64_device.go
index ae783e8..08ac2ef 100644
--- a/rust/config/arm64_device.go
+++ b/rust/config/arm64_device.go
@@ -26,11 +26,18 @@
Arm64LinkFlags = []string{}
Arm64ArchVariantRustFlags = map[string][]string{
- "armv8-a": []string{},
- "armv8-a-branchprot": []string{},
- "armv8-2a": []string{},
- "armv8-2a-dotprod": []string{},
- "armv9-a": []string{},
+ "armv8-a": []string{},
+ "armv8-a-branchprot": []string{
+ // branch-protection=bti,pac-ret is equivalent to Clang's mbranch-protection=standard
+ "-Z branch-protection=bti,pac-ret",
+ },
+ "armv8-2a": []string{},
+ "armv8-2a-dotprod": []string{},
+ "armv9-a": []string{
+ // branch-protection=bti,pac-ret is equivalent to Clang's mbranch-protection=standard
+ "-Z branch-protection=bti,pac-ret",
+ "-Z stack-protector=none",
+ },
}
)
diff --git a/starlark_import/unmarshal.go b/starlark_import/unmarshal.go
index 33c0cd9..b243471 100644
--- a/starlark_import/unmarshal.go
+++ b/starlark_import/unmarshal.go
@@ -34,6 +34,9 @@
return reflect.ValueOf(value), nil
}
zero := reflect.Zero(ty)
+ if value == nil {
+ panic("nil value")
+ }
var result reflect.Value
if ty.Kind() == reflect.Interface {
var err error
diff --git a/ui/build/config.go b/ui/build/config.go
index fb5f7dd..e5c9a50 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -374,6 +374,11 @@
if err := loadEnvConfig(ctx, ret, bc); err != nil {
ctx.Fatalln("Failed to parse env config files: %v", err)
}
+ if !ret.canSupportRBE() {
+ // Explicitly set USE_RBE env variable to false when we cannot run
+ // an RBE build to avoid ninja local execution pool issues.
+ ret.environ.Set("USE_RBE", "false")
+ }
}
if distDir, ok := ret.environ.Get("DIST_DIR"); ok {
@@ -1374,18 +1379,26 @@
return true
}
+func (c *configImpl) canSupportRBE() bool {
+ // Do not use RBE with prod credentials in scenarios when stubby doesn't exist, since
+ // its unlikely that we will be able to obtain necessary creds without stubby.
+ authType, _ := c.rbeAuth()
+ if !c.StubbyExists() && strings.Contains(authType, "use_google_prod_creds") {
+ return false
+ }
+ return true
+}
+
func (c *configImpl) UseRBE() bool {
// These alternate modes of running Soong do not use RBE / reclient.
if c.Bp2Build() || c.Queryview() || c.ApiBp2build() || c.JsonModuleGraph() {
return false
}
- authType, _ := c.rbeAuth()
- // Do not use RBE with prod credentials in scenarios when stubby doesn't exist, since
- // its unlikely that we will be able to obtain necessary creds without stubby.
- if !c.StubbyExists() && strings.Contains(authType, "use_google_prod_creds") {
+ if !c.canSupportRBE() {
return false
}
+
if v, ok := c.Environment().Get("USE_RBE"); ok {
v = strings.TrimSpace(v)
if v != "" && v != "false" {