Merge "Add android.hardware.wifi.supplicant-V1-ndk to VNDK list."
diff --git a/android/androidmk.go b/android/androidmk.go
index feaef1f..f48c06b 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -29,6 +29,7 @@
"os"
"path/filepath"
"reflect"
+ "runtime"
"sort"
"strings"
@@ -902,6 +903,13 @@
return true
}
+ // On Mac, only expose host darwin modules to Make, as that's all we claim to support.
+ // In reality, some of them depend on device-built (Java) modules, so we can't disable all
+ // device modules in Soong, but we can hide them from Make (and thus the build user interface)
+ if runtime.GOOS == "darwin" && module.Os() != Darwin {
+ return true
+ }
+
return !module.Enabled() ||
module.commonProperties.HideFromMake ||
// Make does not understand LinuxBionic
diff --git a/android/androidmk_test.go b/android/androidmk_test.go
index 8eda9b2..ecfb008 100644
--- a/android/androidmk_test.go
+++ b/android/androidmk_test.go
@@ -18,6 +18,7 @@
"fmt"
"io"
"reflect"
+ "runtime"
"strings"
"testing"
@@ -155,6 +156,11 @@
}
func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
+ if runtime.GOOS == "darwin" {
+ // Device modules are not exported on Mac, so this test doesn't work.
+ t.SkipNow()
+ }
+
bp := `
custom {
name: "foo",
diff --git a/android/bazel.go b/android/bazel.go
index e4eaa37..5dda655 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -243,11 +243,20 @@
"brotli-fuzzer-corpus", // b/202015218: outputs are in location incompatible with bazel genrule handling.
+ // b/203369847: multiple genrules in the same package creating the same file
+ // //development/sdk/...
+ "platform_tools_properties",
+ "build_tools_source_properties",
+
// //external/libcap/...
"libcap", // http://b/198595332, depends on _makenames, a cc_binary
"cap_names.h", // http://b/198596102, depends on _makenames, a cc_binary
"libminijail", // depends on unconverted modules: libcap
+ "getcap", // depends on unconverted modules: libcap
+ "setcap", // depends on unconverted modules: libcap
+ "minijail0", // depends on unconverted modules: libcap, libminijail
+ "drop_privs", // depends on unconverted modules: libminijail
// Tests. Handle later.
"libbionic_tests_headers_posix", // http://b/186024507, cc_library_static, sched.h, time.h not found
@@ -274,6 +283,20 @@
"libgtest_ndk_c++", // b/201816222: Requires sdk_version support.
"libgtest_main_ndk_c++", // b/201816222: Requires sdk_version support.
+
+ "abb", // depends on unconverted modules: libadbd_core, libadbd_services, libcmd, libbinder, libutils, libselinux
+ "adb", // depends on unconverted modules: bin2c_fastdeployagent, libadb_crypto, libadb_host, libadb_pairing_connection, libadb_protos, libandroidfw, libapp_processes_protos_full, libfastdeploy_host, libmdnssd, libopenscreen-discovery, libopenscreen-platform-impl, libusb, libutils, libziparchive, libzstd, AdbWinApi
+ "adbd", // depends on unconverted modules: libadb_crypto, libadb_pairing_connection, libadb_protos, libadbd, libadbd_core, libapp_processes_protos_lite, libmdnssd, libzstd, libadbd_services, libcap, libminijail, libselinux
+ "bionic_tests_zipalign", // depends on unconverted modules: libziparchive, libutils
+ "linker", // depends on unconverted modules: liblinker_debuggerd_stub, libdebuggerd_handler_fallback, libziparchive, liblinker_main, liblinker_malloc
+ "linker_reloc_bench_main", // depends on unconverted modules: liblinker_reloc_bench_*
+ "sefcontext_compile", // depends on unconverted modules: libsepol
+ "versioner", // depends on unconverted modules: libclang_cxx_host, libLLVM_host
+
+ "linkerconfig", // http://b/202876379 has arch-variant static_executable
+ "mdnsd", // http://b/202876379 has arch-variant static_executable
+
+ "acvp_modulewrapper", // disabled for android x86/x86_64
}
// Per-module denylist of cc_library modules to only generate the static
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 06712a1..80e127c 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -48,11 +48,17 @@
StarlarkFunctionBody() string
}
+// Portion of cquery map key to describe target configuration.
+type configKey struct {
+ archType ArchType
+ osType OsType
+}
+
// Map key to describe bazel cquery requests.
type cqueryKey struct {
label string
requestType cqueryRequest
- archType ArchType
+ configKey configKey
}
// bazelHandler is the interface for a helper object related to deferring to Bazel for
@@ -72,14 +78,14 @@
// has been queued to be run later.
// Returns result files built by building the given bazel target label.
- GetOutputFiles(label string, archType ArchType) ([]string, bool)
+ GetOutputFiles(label string, cfgKey configKey) ([]string, bool)
// TODO(cparsons): Other cquery-related methods should be added here.
// Returns the results of GetOutputFiles and GetCcObjectFiles in a single query (in that order).
- GetCcInfo(label string, archType ArchType) (cquery.CcInfo, bool, error)
+ GetCcInfo(label string, cfgKey configKey) (cquery.CcInfo, bool, error)
// Returns the executable binary resultant from building together the python sources
- GetPythonBinary(label string, archType ArchType) (string, bool)
+ GetPythonBinary(label string, cfgKey configKey) (string, bool)
// ** End cquery methods
@@ -140,17 +146,17 @@
LabelToPythonBinary map[string]string
}
-func (m MockBazelContext) GetOutputFiles(label string, archType ArchType) ([]string, bool) {
+func (m MockBazelContext) GetOutputFiles(label string, cfgKey configKey) ([]string, bool) {
result, ok := m.LabelToOutputFiles[label]
return result, ok
}
-func (m MockBazelContext) GetCcInfo(label string, archType ArchType) (cquery.CcInfo, bool, error) {
+func (m MockBazelContext) GetCcInfo(label string, cfgKey configKey) (cquery.CcInfo, bool, error) {
result, ok := m.LabelToCcInfo[label]
return result, ok, nil
}
-func (m MockBazelContext) GetPythonBinary(label string, archType ArchType) (string, bool) {
+func (m MockBazelContext) GetPythonBinary(label string, cfgKey configKey) (string, bool) {
result, ok := m.LabelToPythonBinary[label]
return result, ok
}
@@ -171,8 +177,8 @@
var _ BazelContext = MockBazelContext{}
-func (bazelCtx *bazelContext) GetOutputFiles(label string, archType ArchType) ([]string, bool) {
- rawString, ok := bazelCtx.cquery(label, cquery.GetOutputFiles, archType)
+func (bazelCtx *bazelContext) GetOutputFiles(label string, cfgKey configKey) ([]string, bool) {
+ rawString, ok := bazelCtx.cquery(label, cquery.GetOutputFiles, cfgKey)
var ret []string
if ok {
bazelOutput := strings.TrimSpace(rawString)
@@ -181,8 +187,8 @@
return ret, ok
}
-func (bazelCtx *bazelContext) GetCcInfo(label string, archType ArchType) (cquery.CcInfo, bool, error) {
- result, ok := bazelCtx.cquery(label, cquery.GetCcInfo, archType)
+func (bazelCtx *bazelContext) GetCcInfo(label string, cfgKey configKey) (cquery.CcInfo, bool, error) {
+ result, ok := bazelCtx.cquery(label, cquery.GetCcInfo, cfgKey)
if !ok {
return cquery.CcInfo{}, ok, nil
}
@@ -192,8 +198,8 @@
return ret, ok, err
}
-func (bazelCtx *bazelContext) GetPythonBinary(label string, archType ArchType) (string, bool) {
- rawString, ok := bazelCtx.cquery(label, cquery.GetPythonBinary, archType)
+func (bazelCtx *bazelContext) GetPythonBinary(label string, cfgKey configKey) (string, bool) {
+ rawString, ok := bazelCtx.cquery(label, cquery.GetPythonBinary, cfgKey)
var ret string
if ok {
bazelOutput := strings.TrimSpace(rawString)
@@ -202,15 +208,15 @@
return ret, ok
}
-func (n noopBazelContext) GetOutputFiles(label string, archType ArchType) ([]string, bool) {
+func (n noopBazelContext) GetOutputFiles(label string, cfgKey configKey) ([]string, bool) {
panic("unimplemented")
}
-func (n noopBazelContext) GetCcInfo(label string, archType ArchType) (cquery.CcInfo, bool, error) {
+func (n noopBazelContext) GetCcInfo(label string, cfgKey configKey) (cquery.CcInfo, bool, error) {
panic("unimplemented")
}
-func (n noopBazelContext) GetPythonBinary(label string, archType ArchType) (string, bool) {
+func (n noopBazelContext) GetPythonBinary(label string, cfgKey configKey) (string, bool) {
panic("unimplemented")
}
@@ -303,8 +309,8 @@
// returns (result, true). If the request is queued but no results are available,
// then returns ("", false).
func (context *bazelContext) cquery(label string, requestType cqueryRequest,
- archType ArchType) (string, bool) {
- key := cqueryKey{label, requestType, archType}
+ cfgKey configKey) (string, bool) {
+ key := cqueryKey{label, requestType, cfgKey}
if result, ok := context.results[key]; ok {
return result, true
} else {
@@ -419,7 +425,7 @@
def _config_node_transition_impl(settings, attr):
return {
- "//command_line_option:platforms": "@//build/bazel/platforms:android_%s" % attr.arch,
+ "//command_line_option:platforms": "@//build/bazel/platforms:%s_%s" % (attr.os, attr.arch),
}
_config_node_transition = transition(
@@ -437,7 +443,8 @@
implementation = _passthrough_rule_impl,
attrs = {
"arch" : attr.string(mandatory = True),
- "deps" : attr.label_list(cfg = _config_node_transition),
+ "os" : attr.string(mandatory = True),
+ "deps" : attr.label_list(cfg = _config_node_transition, allow_files = True),
"_allowlist_function_transition": attr.label(default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
},
)
@@ -488,38 +495,32 @@
configNodeFormatString := `
config_node(name = "%s",
arch = "%s",
+ os = "%s",
deps = [%s],
)
`
- commonArchFilegroupString := `
-filegroup(name = "common",
- srcs = [%s],
-)
-`
-
configNodesSection := ""
- labelsByArch := map[string][]string{}
+ labelsByConfig := map[string][]string{}
for val, _ := range context.requests {
labelString := fmt.Sprintf("\"@%s\"", val.label)
- archString := getArchString(val)
- labelsByArch[archString] = append(labelsByArch[archString], labelString)
+ configString := getConfigString(val)
+ labelsByConfig[configString] = append(labelsByConfig[configString], labelString)
}
allLabels := []string{}
- for archString, labels := range labelsByArch {
- if archString == "common" {
- // arch-less labels (e.g. filegroups) don't need a config_node
- allLabels = append(allLabels, "\":common\"")
- labelsString := strings.Join(labels, ",\n ")
- configNodesSection += fmt.Sprintf(commonArchFilegroupString, labelsString)
- } else {
- // Create a config_node, and add the config_node's label to allLabels
- allLabels = append(allLabels, fmt.Sprintf("\":%s\"", archString))
- labelsString := strings.Join(labels, ",\n ")
- configNodesSection += fmt.Sprintf(configNodeFormatString, archString, archString, labelsString)
+ for configString, labels := range labelsByConfig {
+ configTokens := strings.Split(configString, "|")
+ if len(configTokens) != 2 {
+ panic(fmt.Errorf("Unexpected config string format: %s", configString))
}
+ archString := configTokens[0]
+ osString := configTokens[1]
+ targetString := fmt.Sprintf("%s_%s", osString, archString)
+ allLabels = append(allLabels, fmt.Sprintf("\":%s\"", targetString))
+ labelsString := strings.Join(labels, ",\n ")
+ configNodesSection += fmt.Sprintf(configNodeFormatString, targetString, archString, osString, labelsString)
}
return []byte(fmt.Sprintf(formatString, configNodesSection, strings.Join(allLabels, ",\n ")))
@@ -587,11 +588,15 @@
%s
def get_arch(target):
+ # TODO(b/199363072): filegroups and file targets aren't associated with any
+ # specific platform architecture in mixed builds. This is consistent with how
+ # Soong treats filegroups, but it may not be the case with manually-written
+ # filegroup BUILD targets.
buildoptions = build_options(target)
if buildoptions == None:
# File targets do not have buildoptions. File targets aren't associated with
- # any specific platform architecture in mixed builds.
- return "common"
+ # any specific platform architecture in mixed builds, so use the host.
+ return "x86_64|linux"
platforms = build_options(target)["//command_line_option:platforms"]
if len(platforms) != 1:
# An individual configured target should have only one platform architecture.
@@ -601,10 +606,12 @@
platform_name = build_options(target)["//command_line_option:platforms"][0].name
if platform_name == "host":
return "HOST"
+ elif platform_name.startswith("linux_glibc_"):
+ return platform_name[len("linux_glibc_"):] + "|" + platform_name[:len("linux_glibc_")-1]
elif platform_name.startswith("android_"):
- return platform_name[len("android_"):]
+ return platform_name[len("android_"):] + "|" + platform_name[:len("android_")-1]
elif platform_name.startswith("linux_"):
- return platform_name[len("linux_"):]
+ return platform_name[len("linux_"):] + "|" + platform_name[:len("linux_")-1]
else:
fail("expected platform name of the form 'android_<arch>' or 'linux_<arch>', but was " + str(platforms))
return "UNKNOWN"
@@ -852,14 +859,23 @@
}
func getCqueryId(key cqueryKey) string {
- return key.label + "|" + getArchString(key)
+ return key.label + "|" + getConfigString(key)
}
-func getArchString(key cqueryKey) string {
- arch := key.archType.Name
- if len(arch) > 0 {
- return arch
- } else {
- return "x86_64"
+func getConfigString(key cqueryKey) string {
+ arch := key.configKey.archType.Name
+ if len(arch) == 0 || arch == "common" {
+ // Use host platform, which is currently hardcoded to be x86_64.
+ arch = "x86_64"
}
+ os := key.configKey.osType.Name
+ if len(os) == 0 || os == "common_os" {
+ // Use host OS, which is currently hardcoded to be linux.
+ os = "linux"
+ }
+ return arch + "|" + os
+}
+
+func GetConfigKey(ctx ModuleContext) configKey {
+ return configKey{archType: ctx.Arch().ArchType, osType: ctx.Os()}
}
diff --git a/android/bazel_handler_test.go b/android/bazel_handler_test.go
index fe66a90..ad5b63b 100644
--- a/android/bazel_handler_test.go
+++ b/android/bazel_handler_test.go
@@ -9,11 +9,11 @@
func TestRequestResultsAfterInvokeBazel(t *testing.T) {
label := "//foo:bar"
- arch := Arm64
+ cfg := configKey{Arm64, Android}
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
- bazelCommand{command: "cquery", expression: "deps(@soong_injection//mixed_builds:buildroot, 2)"}: `//foo:bar|arm64>>out/foo/bar.txt`,
+ bazelCommand{command: "cquery", expression: "deps(@soong_injection//mixed_builds:buildroot, 2)"}: `//foo:bar|arm64|android>>out/foo/bar.txt`,
})
- g, ok := bazelContext.GetOutputFiles(label, arch)
+ g, ok := bazelContext.GetOutputFiles(label, cfg)
if ok {
t.Errorf("Did not expect cquery results prior to running InvokeBazel(), but got %s", g)
}
@@ -21,7 +21,7 @@
if err != nil {
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
}
- g, ok = bazelContext.GetOutputFiles(label, arch)
+ g, ok = bazelContext.GetOutputFiles(label, cfg)
if !ok {
t.Errorf("Expected cquery results after running InvokeBazel(), but got none")
} else if w := []string{"out/foo/bar.txt"}; !reflect.DeepEqual(w, g) {
diff --git a/android/config.go b/android/config.go
index c8d7cfd..6060bce 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1578,6 +1578,10 @@
return c.config.productVariables.SepolicyFreezeTestExtraPrebuiltDirs
}
+func (c *deviceConfig) GenerateAidlNdkPlatformBackend() bool {
+ return c.config.productVariables.GenerateAidlNdkPlatformBackend
+}
+
// The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs.
// Such lists are used in the build system for things like bootclasspath jars or system server jars.
// The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a
diff --git a/android/filegroup.go b/android/filegroup.go
index f8f0955..a79374d 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -118,14 +118,16 @@
}
archVariant := ctx.Arch().ArchType
+ osVariant := ctx.Os()
if len(fg.Srcs()) == 1 && fg.Srcs()[0].Base() == fg.Name() {
// This will be a regular file target, not filegroup, in Bazel.
// See FilegroupBp2Build for more information.
archVariant = Common
+ osVariant = CommonOS
}
bazelCtx := ctx.Config().BazelContext
- filePaths, ok := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), archVariant)
+ filePaths, ok := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), configKey{archVariant, osVariant})
if !ok {
return
}
diff --git a/android/soong_config_modules_test.go b/android/soong_config_modules_test.go
index b2f8eaa..0ec9bcb 100644
--- a/android/soong_config_modules_test.go
+++ b/android/soong_config_modules_test.go
@@ -60,7 +60,7 @@
module_type: "test",
config_namespace: "acme",
variables: ["board", "feature1", "FEATURE3", "unused_string_var"],
- bool_variables: ["feature2", "unused_feature"],
+ bool_variables: ["feature2", "unused_feature", "always_true"],
value_variables: ["size", "unused_size"],
properties: ["cflags", "srcs", "defaults"],
}
@@ -148,6 +148,11 @@
cflags: ["DEFAULT_B"],
}
+ test_defaults {
+ name: "foo_defaults_always_true",
+ cflags: ["DEFAULT_ALWAYS_TRUE"],
+ }
+
acme_test {
name: "foo_with_defaults",
cflags: ["-DGENERIC"],
@@ -176,6 +181,15 @@
FEATURE3: {
cflags: ["-DFEATURE3"],
},
+ always_true: {
+ defaults: ["foo_defaults_always_true"],
+ conditions_default: {
+ // verify that conditions_default is skipped if the
+ // soong config variable is true by specifying a
+ // non-existent module in conditions_default
+ defaults: ["//nonexistent:defaults"],
+ }
+ },
},
}
`
@@ -205,6 +219,7 @@
"unused_feature": "true", // unused
"unused_size": "1", // unused
"unused_string_var": "a", // unused
+ "always_true": "true",
},
}),
fooExpectedFlags: []string{
@@ -217,6 +232,7 @@
},
fooDefaultsExpectedFlags: []string{
"DEFAULT_A",
+ "DEFAULT_ALWAYS_TRUE",
"DEFAULT",
"-DGENERIC",
"-DSIZE=42",
@@ -227,7 +243,10 @@
{
name: "empty_prop_for_string_var",
preparer: fixtureForVendorVars(map[string]map[string]string{
- "acme": {"board": "soc_c"}}),
+ "acme": {
+ "board": "soc_c",
+ "always_true": "true",
+ }}),
fooExpectedFlags: []string{
"DEFAULT",
"-DGENERIC",
@@ -236,6 +255,7 @@
"-DF1_CONDITIONS_DEFAULT",
},
fooDefaultsExpectedFlags: []string{
+ "DEFAULT_ALWAYS_TRUE",
"DEFAULT",
"-DGENERIC",
},
@@ -243,7 +263,10 @@
{
name: "unused_string_var",
preparer: fixtureForVendorVars(map[string]map[string]string{
- "acme": {"board": "soc_d"}}),
+ "acme": {
+ "board": "soc_d",
+ "always_true": "true",
+ }}),
fooExpectedFlags: []string{
"DEFAULT",
"-DGENERIC",
@@ -253,14 +276,18 @@
"-DF1_CONDITIONS_DEFAULT",
},
fooDefaultsExpectedFlags: []string{
+ "DEFAULT_ALWAYS_TRUE",
"DEFAULT",
"-DGENERIC",
},
},
{
- name: "conditions_default",
- preparer: fixtureForVendorVars(map[string]map[string]string{}),
+ name: "conditions_default",
+ preparer: fixtureForVendorVars(map[string]map[string]string{
+ "acme": {
+ "always_true": "true",
+ }}),
fooExpectedFlags: []string{
"DEFAULT",
"-DGENERIC",
@@ -270,6 +297,7 @@
"-DF1_CONDITIONS_DEFAULT",
},
fooDefaultsExpectedFlags: []string{
+ "DEFAULT_ALWAYS_TRUE",
"DEFAULT",
"-DGENERIC",
},
diff --git a/android/variable.go b/android/variable.go
index 5c54e94..baa6dfa 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -419,6 +419,8 @@
SepolicyFreezeTestExtraDirs []string `json:",omitempty"`
SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"`
+
+ GenerateAidlNdkPlatformBackend bool `json:",omitempty"`
}
func boolPtr(v bool) *bool {
diff --git a/android_sdk/sdk_repo_host.go b/android_sdk/sdk_repo_host.go
index a76da8b..d64eb7a 100644
--- a/android_sdk/sdk_repo_host.go
+++ b/android_sdk/sdk_repo_host.go
@@ -241,11 +241,10 @@
func (s *sdkRepoHost) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
- // TODO: per-OS PHONY
fmt.Fprintln(w, ".PHONY:", name, "sdk_repo", "sdk-repo-"+name)
fmt.Fprintln(w, "sdk_repo", "sdk-repo-"+name+":", strings.Join(s.FilesToInstall().Strings(), " "))
- fmt.Fprintf(w, "$(call dist-for-goals,sdk_repo sdk-repo-%s,%s:new_%s-$(FILE_NAME_TAG).zip)\n\n", s.BaseModuleName(), s.outputFile.String(), s.outputBaseName)
+ fmt.Fprintf(w, "$(call dist-for-goals,sdk_repo sdk-repo-%s,%s:%s-$(FILE_NAME_TAG).zip)\n\n", s.BaseModuleName(), s.outputFile.String(), s.outputBaseName)
},
}
}
diff --git a/apex/apex.go b/apex/apex.go
index 9c2c679..1f06187 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -348,7 +348,6 @@
// Flags for special variants of APEX
testApex bool
vndkApex bool
- artApex bool
// Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
// one gets installed to the device.
@@ -754,13 +753,6 @@
ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
- if a.artApex {
- // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
- if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
- ctx.AddFarVariationDependencies(commonVariation, javaLibTag, "jacocoagent")
- }
- }
-
// Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
// This field currently isn't used.
// TODO(jiyong): consider dropping this feature
@@ -1151,8 +1143,8 @@
zipApexType = "zip"
flattenedApexType = "flattened"
- ext4FsType = "ext4"
- f2fsFsType = "f2fs"
+ ext4FsType = "ext4"
+ f2fsFsType = "f2fs"
erofsFsType = "erofs"
)
@@ -1683,6 +1675,9 @@
if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
return false
}
+ if mod, ok := child.(android.Module); ok && !mod.Enabled() {
+ return false
+ }
depName := ctx.OtherModuleName(child)
if _, isDirectDep := parent.(*apexBundle); isDirectDep {
switch depTag {
@@ -2200,10 +2195,9 @@
return module
}
-func ApexBundleFactory(testApex bool, artApex bool) android.Module {
+func ApexBundleFactory(testApex bool) android.Module {
bundle := newApexBundle()
bundle.testApex = testApex
- bundle.artApex = artApex
return bundle
}
diff --git a/apex/builder.go b/apex/builder.go
index 702b6fc..772f789 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -716,12 +716,10 @@
}
}
apisBackedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_backing.txt")
- ndkLibraryList := android.PathForSource(ctx, "system/core/rootdir/etc/public.libraries.android.txt")
rule := android.NewRuleBuilder(pctx, ctx)
rule.Command().
Tool(android.PathForSource(ctx, "build/soong/scripts/gen_ndk_backedby_apex.sh")).
Output(apisBackedbyOutputFile).
- Input(ndkLibraryList).
Flags(libNames)
rule.Build("ndk_backedby_list", "Generate API libraries backed by Apex")
a.apisBackedByModuleFile = apisBackedbyOutputFile
diff --git a/bazel/aquery.go b/bazel/aquery.go
index 8741afb..0dedcf4 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -246,7 +246,8 @@
outDir := proptools.ShellEscapeIncludingSpaces(filepath.Dir(out))
out = proptools.ShellEscapeIncludingSpaces(out)
in := proptools.ShellEscapeIncludingSpaces(inputPaths[0])
- buildStatement.Command = fmt.Sprintf("mkdir -p %[1]s && rm -f %[2]s && ln -rsf %[3]s %[2]s", outDir, out, in)
+ // Use hard links, because some soong actions expect real files (for example, `cp -d`).
+ buildStatement.Command = fmt.Sprintf("mkdir -p %[1]s && rm -f %[2]s && ln -f %[3]s %[2]s", outDir, out, in)
buildStatement.SymlinkPaths = outputPaths[:]
} else if len(actionEntry.Arguments) < 1 {
return nil, fmt.Errorf("received action with no command: [%v]", buildStatement)
diff --git a/bazel/aquery_test.go b/bazel/aquery_test.go
index 43e4155..88066c8 100644
--- a/bazel/aquery_test.go
+++ b/bazel/aquery_test.go
@@ -859,7 +859,7 @@
BuildStatement{
Command: "mkdir -p one/symlink_subdir && " +
"rm -f one/symlink_subdir/symlink && " +
- "ln -rsf one/file_subdir/file one/symlink_subdir/symlink",
+ "ln -f one/file_subdir/file one/symlink_subdir/symlink",
InputPaths: []string{"one/file_subdir/file"},
OutputPaths: []string{"one/symlink_subdir/symlink"},
SymlinkPaths: []string{"one/symlink_subdir/symlink"},
@@ -923,7 +923,7 @@
BuildStatement{
Command: "mkdir -p 'one/symlink subdir' && " +
"rm -f 'one/symlink subdir/symlink' && " +
- "ln -rsf 'one/file subdir/file' 'one/symlink subdir/symlink'",
+ "ln -f 'one/file subdir/file' 'one/symlink subdir/symlink'",
InputPaths: []string{"one/file subdir/file"},
OutputPaths: []string{"one/symlink subdir/symlink"},
SymlinkPaths: []string{"one/symlink subdir/symlink"},
diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go
index 45a3cb6..b0c3899 100644
--- a/bp2build/bp2build.go
+++ b/bp2build/bp2build.go
@@ -15,11 +15,12 @@
package bp2build
import (
- "android/soong/android"
- "android/soong/bazel"
"fmt"
"os"
"strings"
+
+ "android/soong/android"
+ "android/soong/bazel"
)
// Codegen is the backend of bp2build. The code generator is responsible for
@@ -43,7 +44,7 @@
writeFiles(ctx, bp2buildDir, bp2buildFiles)
soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName)
- writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.metrics))
+ writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(ctx.Config(), res.metrics))
return res.metrics
}
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
new file mode 100644
index 0000000..3a07128
--- /dev/null
+++ b/bp2build/cc_binary_conversion_test.go
@@ -0,0 +1,415 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package bp2build
+
+import (
+ "android/soong/android"
+ "android/soong/cc"
+ "fmt"
+ "strings"
+ "testing"
+)
+
+const (
+ ccBinaryTypePlaceHolder = "{rule_name}"
+ compatibleWithPlaceHolder = "{target_compatible_with}"
+)
+
+func registerCcBinaryModuleTypes(ctx android.RegistrationContext) {
+ cc.RegisterCCBuildComponents(ctx)
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
+ ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
+}
+
+var binaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary", compatibleWithPlaceHolder, "")
+var hostBinaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary_host", compatibleWithPlaceHolder, `
+ target_compatible_with = select({
+ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
+ "//conditions:default": [],
+ }),`)
+
+func runCcBinaryTests(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
+ runCcBinaryTestCase(t, tc)
+ runCcHostBinaryTestCase(t, tc)
+}
+
+func runCcBinaryTestCase(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
+ testCase := tc
+ testCase.expectedBazelTargets = append([]string{}, tc.expectedBazelTargets...)
+ testCase.moduleTypeUnderTest = "cc_binary"
+ testCase.moduleTypeUnderTestFactory = cc.BinaryFactory
+ testCase.moduleTypeUnderTestBp2BuildMutator = cc.BinaryBp2build
+ testCase.description = fmt.Sprintf("%s %s", testCase.moduleTypeUnderTest, testCase.description)
+ testCase.blueprint = binaryReplacer.Replace(testCase.blueprint)
+ for i, et := range testCase.expectedBazelTargets {
+ testCase.expectedBazelTargets[i] = binaryReplacer.Replace(et)
+ }
+ t.Run(testCase.description, func(t *testing.T) {
+ runBp2BuildTestCase(t, registerCcBinaryModuleTypes, testCase)
+ })
+}
+
+func runCcHostBinaryTestCase(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
+ testCase := tc
+ testCase.expectedBazelTargets = append([]string{}, tc.expectedBazelTargets...)
+ testCase.moduleTypeUnderTest = "cc_binary_host"
+ testCase.moduleTypeUnderTestFactory = cc.BinaryHostFactory
+ testCase.moduleTypeUnderTestBp2BuildMutator = cc.BinaryHostBp2build
+ testCase.description = fmt.Sprintf("%s %s", testCase.moduleTypeUnderTest, testCase.description)
+ testCase.blueprint = hostBinaryReplacer.Replace(testCase.blueprint)
+ for i, et := range testCase.expectedBazelTargets {
+ testCase.expectedBazelTargets[i] = hostBinaryReplacer.Replace(et)
+ }
+ t.Run(testCase.description, func(t *testing.T) {
+ runBp2BuildTestCase(t, registerCcBinaryModuleTypes, testCase)
+ })
+}
+
+func TestBasicCcBinary(t *testing.T) {
+ runCcBinaryTests(t, bp2buildTestCase{
+ description: "basic -- properties -> attrs with little/no transformation",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ srcs: ["a.cc"],
+ local_include_dirs: ["dir"],
+ include_dirs: ["absolute_dir"],
+ cflags: ["-Dcopt"],
+ cppflags: ["-Dcppflag"],
+ conlyflags: ["-Dconlyflag"],
+ asflags: ["-Dasflag"],
+ ldflags: ["ld-flag"],
+ rtti: true,
+ strip: {
+ all: true,
+ keep_symbols: true,
+ keep_symbols_and_debug_frame: true,
+ keep_symbols_list: ["symbol"],
+ none: true,
+ },
+}
+`,
+ expectedBazelTargets: []string{`cc_binary(
+ name = "foo",
+ absolute_includes = ["absolute_dir"],
+ asflags = ["-Dasflag"],
+ conlyflags = ["-Dconlyflag"],
+ copts = ["-Dcopt"],
+ cppflags = ["-Dcppflag"],
+ linkopts = ["ld-flag"],
+ local_includes = [
+ "dir",
+ ".",
+ ],
+ rtti = True,
+ srcs = ["a.cc"],
+ strip = {
+ "all": True,
+ "keep_symbols": True,
+ "keep_symbols_and_debug_frame": True,
+ "keep_symbols_list": ["symbol"],
+ "none": True,
+ },{target_compatible_with}
+)`},
+ })
+}
+
+func TestCcBinaryWithSharedLdflagDisableFeature(t *testing.T) {
+ runCcBinaryTests(t, bp2buildTestCase{
+ description: `ldflag "-shared" disables static_flag feature`,
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ ldflags: ["-shared"],
+ include_build_directory: false,
+}
+`,
+ expectedBazelTargets: []string{`cc_binary(
+ name = "foo",
+ features = ["-static_flag"],
+ linkopts = ["-shared"],{target_compatible_with}
+)`},
+ })
+}
+
+func TestCcBinaryWithLinkStatic(t *testing.T) {
+ runCcBinaryTests(t, bp2buildTestCase{
+ description: "link static",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ static_executable: true,
+ include_build_directory: false,
+}
+`,
+ expectedBazelTargets: []string{`cc_binary(
+ name = "foo",
+ linkshared = False,{target_compatible_with}
+)`},
+ })
+}
+
+func TestCcBinaryVersionScript(t *testing.T) {
+ runCcBinaryTests(t, bp2buildTestCase{
+ description: `version script`,
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ include_build_directory: false,
+ version_script: "vs",
+}
+`,
+ expectedBazelTargets: []string{`cc_binary(
+ name = "foo",
+ additional_linker_inputs = ["vs"],
+ linkopts = ["-Wl,--version-script,$(location vs)"],{target_compatible_with}
+)`},
+ })
+}
+
+func TestCcBinarySplitSrcsByLang(t *testing.T) {
+ runCcHostBinaryTestCase(t, bp2buildTestCase{
+ description: "split srcs by lang",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ srcs: [
+ "asonly.S",
+ "conly.c",
+ "cpponly.cpp",
+ ":fg_foo",
+ ],
+ include_build_directory: false,
+}
+` + simpleModuleDoNotConvertBp2build("filegroup", "fg_foo"),
+ expectedBazelTargets: []string{`cc_binary(
+ name = "foo",
+ srcs = [
+ "cpponly.cpp",
+ ":fg_foo_cpp_srcs",
+ ],
+ srcs_as = [
+ "asonly.S",
+ ":fg_foo_as_srcs",
+ ],
+ srcs_c = [
+ "conly.c",
+ ":fg_foo_c_srcs",
+ ],{target_compatible_with}
+)`},
+ })
+}
+
+func TestCcBinaryDoNotDistinguishBetweenDepsAndImplementationDeps(t *testing.T) {
+ runCcBinaryTestCase(t, bp2buildTestCase{
+ description: "no implementation deps",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ shared_libs: ["implementation_shared_dep", "shared_dep"],
+ export_shared_lib_headers: ["shared_dep"],
+ static_libs: ["implementation_static_dep", "static_dep"],
+ export_static_lib_headers: ["static_dep", "whole_static_dep"],
+ whole_static_libs: ["not_explicitly_exported_whole_static_dep", "whole_static_dep"],
+ include_build_directory: false,
+}
+` +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep") +
+ simpleModuleDoNotConvertBp2build("cc_library", "shared_dep") +
+ simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"),
+ expectedBazelTargets: []string{`cc_binary(
+ name = "foo",
+ deps = [
+ ":implementation_static_dep",
+ ":static_dep",
+ ],
+ dynamic_deps = [
+ ":implementation_shared_dep",
+ ":shared_dep",
+ ],{target_compatible_with}
+ whole_archive_deps = [
+ ":not_explicitly_exported_whole_static_dep",
+ ":whole_static_dep",
+ ],
+)`},
+ })
+}
+
+func TestCcBinaryNocrtTests(t *testing.T) {
+ baseTestCases := []struct {
+ description string
+ soongProperty string
+ bazelAttr string
+ }{
+ {
+ description: "nocrt: true",
+ soongProperty: `nocrt: true,`,
+ bazelAttr: ` link_crt = False,`,
+ },
+ {
+ description: "nocrt: false",
+ soongProperty: `nocrt: false,`,
+ },
+ {
+ description: "nocrt: not set",
+ },
+ }
+
+ baseBlueprint := `{rule_name} {
+ name: "foo",%s
+ include_build_directory: false,
+}
+`
+
+ baseBazelTarget := `cc_binary(
+ name = "foo",%s{target_compatible_with}
+)`
+
+ for _, btc := range baseTestCases {
+ prop := btc.soongProperty
+ if len(prop) > 0 {
+ prop = "\n" + prop
+ }
+ attr := btc.bazelAttr
+ if len(attr) > 0 {
+ attr = "\n" + attr
+ }
+ runCcBinaryTests(t, bp2buildTestCase{
+ description: btc.description,
+ blueprint: fmt.Sprintf(baseBlueprint, prop),
+ expectedBazelTargets: []string{
+ fmt.Sprintf(baseBazelTarget, attr),
+ },
+ })
+ }
+}
+
+func TestCcBinaryNo_libcrtTests(t *testing.T) {
+ baseTestCases := []struct {
+ description string
+ soongProperty string
+ bazelAttr string
+ }{
+ {
+ description: "no_libcrt: true",
+ soongProperty: `no_libcrt: true,`,
+ bazelAttr: ` use_libcrt = False,`,
+ },
+ {
+ description: "no_libcrt: false",
+ soongProperty: `no_libcrt: false,`,
+ bazelAttr: ` use_libcrt = True,`,
+ },
+ {
+ description: "no_libcrt: not set",
+ },
+ }
+
+ baseBlueprint := `{rule_name} {
+ name: "foo",%s
+ include_build_directory: false,
+}
+`
+
+ baseBazelTarget := `cc_binary(
+ name = "foo",{target_compatible_with}%s
+)`
+
+ for _, btc := range baseTestCases {
+ prop := btc.soongProperty
+ if len(prop) > 0 {
+ prop = "\n" + prop
+ }
+ attr := btc.bazelAttr
+ if len(attr) > 0 {
+ attr = "\n" + attr
+ }
+ runCcBinaryTests(t, bp2buildTestCase{
+ description: btc.description,
+ blueprint: fmt.Sprintf(baseBlueprint, prop),
+ expectedBazelTargets: []string{
+ fmt.Sprintf(baseBazelTarget, attr),
+ },
+ })
+ }
+}
+
+func TestCcBinaryPropertiesToFeatures(t *testing.T) {
+ baseTestCases := []struct {
+ description string
+ soongProperty string
+ bazelAttr string
+ }{
+ {
+ description: "pack_relocation: true",
+ soongProperty: `pack_relocations: true,`,
+ },
+ {
+ description: "pack_relocations: false",
+ soongProperty: `pack_relocations: false,`,
+ bazelAttr: ` features = ["disable_pack_relocations"],`,
+ },
+ {
+ description: "pack_relocations: not set",
+ },
+ {
+ description: "pack_relocation: true",
+ soongProperty: `allow_undefined_symbols: true,`,
+ bazelAttr: ` features = ["-no_undefined_symbols"],`,
+ },
+ {
+ description: "allow_undefined_symbols: false",
+ soongProperty: `allow_undefined_symbols: false,`,
+ },
+ {
+ description: "allow_undefined_symbols: not set",
+ },
+ }
+
+ baseBlueprint := `{rule_name} {
+ name: "foo",%s
+ include_build_directory: false,
+}
+`
+
+ baseBazelTarget := `cc_binary(
+ name = "foo",%s{target_compatible_with}
+)`
+
+ for _, btc := range baseTestCases {
+ prop := btc.soongProperty
+ if len(prop) > 0 {
+ prop = "\n" + prop
+ }
+ attr := btc.bazelAttr
+ if len(attr) > 0 {
+ attr = "\n" + attr
+ }
+ runCcBinaryTests(t, bp2buildTestCase{
+ description: btc.description,
+ blueprint: fmt.Sprintf(baseBlueprint, prop),
+ expectedBazelTargets: []string{
+ fmt.Sprintf(baseBazelTarget, attr),
+ },
+ })
+ }
+}
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 9f6f450..ef2ec32 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -986,6 +986,41 @@
})
}
+func TestCcLibraryStaticGeneratedHeadersAllPartitions(t *testing.T) {
+ runCcLibraryStaticTestCase(t, bp2buildTestCase{
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
+ blueprint: soongCcLibraryStaticPreamble + `
+genrule {
+ name: "generated_hdr",
+ cmd: "nothing to see here",
+}
+
+cc_library_static {
+ name: "foo_static",
+ srcs: ["cpp_src.cpp", "as_src.S", "c_src.c"],
+ generated_headers: ["generated_hdr"],
+ include_build_directory: false,
+}`,
+ expectedBazelTargets: []string{`cc_library_static(
+ name = "foo_static",
+ srcs = [
+ "cpp_src.cpp",
+ ":generated_hdr",
+ ],
+ srcs_as = [
+ "as_src.S",
+ ":generated_hdr",
+ ],
+ srcs_c = [
+ "c_src.c",
+ ":generated_hdr",
+ ],
+)`},
+ })
+}
+
func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
runCcLibraryStaticTestCase(t, bp2buildTestCase{
description: "cc_library_static arch srcs/exclude_srcs with generated files",
@@ -1067,10 +1102,10 @@
name = "foo_static3",
srcs = [
"common.cpp",
- ":generated_hdr",
- "//dep:generated_hdr_other_pkg",
":generated_src",
"//dep:generated_src_other_pkg",
+ ":generated_hdr",
+ "//dep:generated_hdr_other_pkg",
] + select({
"//build/bazel/platforms/arch:x86": [
"for-x86.cpp",
@@ -1082,8 +1117,8 @@
],
}) + select({
"//build/bazel/platforms/os:android": [
- "//dep:generated_hdr_other_pkg_android",
":generated_src_android",
+ "//dep:generated_hdr_other_pkg_android",
],
"//conditions:default": [],
}),
diff --git a/bp2build/conversion.go b/bp2build/conversion.go
index d34a4ba..944cb83 100644
--- a/bp2build/conversion.go
+++ b/bp2build/conversion.go
@@ -17,11 +17,11 @@
Contents string
}
-func CreateSoongInjectionFiles(metrics CodegenMetrics) []BazelFile {
+func CreateSoongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []BazelFile {
var files []BazelFile
files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
- files = append(files, newFile("cc_toolchain", "constants.bzl", config.BazelCcToolchainVars()))
+ files = append(files, newFile("cc_toolchain", "constants.bzl", config.BazelCcToolchainVars(cfg)))
files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.convertedModules, "\n")))
diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go
index dfa1a9e..d09238a 100644
--- a/bp2build/conversion_test.go
+++ b/bp2build/conversion_test.go
@@ -17,6 +17,8 @@
import (
"sort"
"testing"
+
+ "android/soong/android"
)
type bazelFilepath struct {
@@ -80,7 +82,7 @@
}
func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
- files := CreateSoongInjectionFiles(CodegenMetrics{})
+ files := CreateSoongInjectionFiles(android.Config{}, CodegenMetrics{})
expectedFilePaths := []bazelFilepath{
{
diff --git a/cc/binary.go b/cc/binary.go
index b423c50..4d1301b 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -20,6 +20,7 @@
"github.com/google/blueprint"
"android/soong/android"
+ "android/soong/bazel"
)
type BinaryLinkerProperties struct {
@@ -62,7 +63,7 @@
func RegisterBinaryBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("cc_binary", BinaryFactory)
- ctx.RegisterModuleType("cc_binary_host", binaryHostFactory)
+ ctx.RegisterModuleType("cc_binary_host", BinaryHostFactory)
}
// cc_binary produces a binary that is runnable on a device.
@@ -72,7 +73,7 @@
}
// cc_binary_host produces a binary that is runnable on a host.
-func binaryHostFactory() android.Module {
+func BinaryHostFactory() android.Module {
module, _ := NewBinary(android.HostSupported)
return module.Init()
}
@@ -541,3 +542,125 @@
},
})
}
+
+func init() {
+ android.RegisterBp2BuildMutator("cc_binary", BinaryBp2build)
+ android.RegisterBp2BuildMutator("cc_binary_host", BinaryHostBp2build)
+}
+
+func BinaryBp2build(ctx android.TopDownMutatorContext) {
+ binaryBp2build(ctx, "cc_binary")
+}
+
+func BinaryHostBp2build(ctx android.TopDownMutatorContext) {
+ binaryBp2build(ctx, "cc_binary_host")
+}
+
+func binaryBp2build(ctx android.TopDownMutatorContext, typ string) {
+ m, ok := ctx.Module().(*Module)
+ if !ok {
+ // Not a cc module
+ return
+ }
+ if !m.ConvertWithBp2build(ctx) {
+ return
+ }
+
+ if ctx.ModuleType() != typ {
+ return
+ }
+
+ var compatibleWith bazel.StringListAttribute
+ if typ == "cc_binary_host" {
+ //incompatible with android OS
+ compatibleWith.SetSelectValue(bazel.OsConfigurationAxis, android.Android.Name, []string{"@platforms//:incompatible"})
+ compatibleWith.SetSelectValue(bazel.OsConfigurationAxis, bazel.ConditionsDefaultConfigKey, []string{})
+ }
+
+ compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
+ linkerAttrs := bp2BuildParseLinkerProps(ctx, m)
+
+ attrs := &binaryAttributes{
+ binaryLinkerAttrs: bp2buildBinaryLinkerProps(ctx, m),
+
+ Srcs: compilerAttrs.srcs,
+ Srcs_c: compilerAttrs.cSrcs,
+ Srcs_as: compilerAttrs.asSrcs,
+
+ Copts: compilerAttrs.copts,
+ Cppflags: compilerAttrs.cppFlags,
+ Conlyflags: compilerAttrs.conlyFlags,
+ Asflags: compilerAttrs.asFlags,
+
+ Deps: linkerAttrs.implementationDeps,
+ Dynamic_deps: linkerAttrs.implementationDynamicDeps,
+ Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
+ System_deps: linkerAttrs.systemDynamicDeps,
+
+ Local_includes: compilerAttrs.localIncludes,
+ Absolute_includes: compilerAttrs.absoluteIncludes,
+ Linkopts: linkerAttrs.linkopts,
+ Link_crt: linkerAttrs.linkCrt,
+ Use_libcrt: linkerAttrs.useLibcrt,
+ Rtti: compilerAttrs.rtti,
+ Stl: compilerAttrs.stl,
+ Cpp_std: compilerAttrs.cppStd,
+
+ Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
+
+ Strip: stripAttributes{
+ Keep_symbols: linkerAttrs.stripKeepSymbols,
+ Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame,
+ Keep_symbols_list: linkerAttrs.stripKeepSymbolsList,
+ All: linkerAttrs.stripAll,
+ None: linkerAttrs.stripNone,
+ },
+
+ Target_compatible_with: compatibleWith,
+ Features: linkerAttrs.features,
+ }
+
+ ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_binary",
+ Bzl_load_location: "//build/bazel/rules:cc_binary.bzl",
+ },
+ android.CommonAttributes{Name: m.Name()},
+ attrs)
+}
+
+// binaryAttributes contains Bazel attributes corresponding to a cc binary
+type binaryAttributes struct {
+ binaryLinkerAttrs
+ Srcs bazel.LabelListAttribute
+ Srcs_c bazel.LabelListAttribute
+ Srcs_as bazel.LabelListAttribute
+
+ Copts bazel.StringListAttribute
+ Cppflags bazel.StringListAttribute
+ Conlyflags bazel.StringListAttribute
+ Asflags bazel.StringListAttribute
+
+ Deps bazel.LabelListAttribute
+ Dynamic_deps bazel.LabelListAttribute
+ Whole_archive_deps bazel.LabelListAttribute
+ System_deps bazel.LabelListAttribute
+
+ Local_includes bazel.StringListAttribute
+ Absolute_includes bazel.StringListAttribute
+
+ Linkopts bazel.StringListAttribute
+ Additional_linker_inputs bazel.LabelListAttribute
+
+ Link_crt bazel.BoolAttribute
+ Use_libcrt bazel.BoolAttribute
+
+ Rtti bazel.BoolAttribute
+ Stl *string
+ Cpp_std *string
+
+ Strip stripAttributes
+
+ Features bazel.StringListAttribute
+
+ Target_compatible_with bazel.StringListAttribute
+}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index c078096..3c238b5 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -26,6 +26,12 @@
"github.com/google/blueprint/proptools"
)
+const (
+ cSrcPartition = "c"
+ asSrcPartition = "as"
+ cppSrcPartition = "cpp"
+)
+
// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
// properties which apply to either the shared or static version of a cc_library module.
type staticOrSharedAttributes struct {
@@ -43,7 +49,7 @@
System_dynamic_deps bazel.LabelListAttribute
}
-func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) {
+func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
// Check that a module is a filegroup type named <label>.
isFilegroupNamed := func(m android.Module, fullLabel string) bool {
if ctx.OtherModuleType(m) != "filegroup" {
@@ -75,17 +81,14 @@
// TODO(b/190006308): Handle language detection of sources in a Bazel rule.
partitioned := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
- "c": bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
- "as": bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
+ cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
+ asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
// 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.
- "cpp": bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
+ cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
})
- cSrcs = partitioned["c"]
- asSrcs = partitioned["as"]
- cppSrcs = partitioned["cpp"]
- return
+ return partitioned
}
// bp2BuildParseLibProps returns the attributes for a variant of a cc_library.
@@ -114,7 +117,13 @@
type bazelLabelForDepsFn func(android.TopDownMutatorContext, []string) bazel.LabelList
-func partitionExportedAndImplementationsDeps(ctx android.TopDownMutatorContext, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition {
+func maybePartitionExportedAndImplementationsDeps(ctx android.TopDownMutatorContext, exportsDeps bool, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition {
+ if !exportsDeps {
+ return depsPartition{
+ implementation: fn(ctx, allDeps),
+ }
+ }
+
implementation, export := android.FilterList(allDeps, exportedDeps)
return depsPartition{
@@ -125,7 +134,12 @@
type bazelLabelForDepsExcludesFn func(android.TopDownMutatorContext, []string, []string) bazel.LabelList
-func partitionExportedAndImplementationsDepsExcludes(ctx android.TopDownMutatorContext, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition {
+func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.TopDownMutatorContext, exportsDeps bool, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition {
+ if !exportsDeps {
+ return depsPartition{
+ implementation: fn(ctx, allDeps, excludes),
+ }
+ }
implementation, export := android.FilterList(allDeps, exportedDeps)
return depsPartition{
@@ -142,11 +156,11 @@
attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs))
- staticDeps := partitionExportedAndImplementationsDeps(ctx, props.Static_libs, props.Export_static_lib_headers, bazelLabelForStaticDeps)
+ staticDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Static_libs, props.Export_static_lib_headers, bazelLabelForStaticDeps)
attrs.Deps.SetSelectValue(axis, config, staticDeps.export)
attrs.Implementation_deps.SetSelectValue(axis, config, staticDeps.implementation)
- sharedDeps := partitionExportedAndImplementationsDeps(ctx, props.Shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDeps)
+ sharedDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDeps)
attrs.Dynamic_deps.SetSelectValue(axis, config, sharedDeps.export)
attrs.Implementation_dynamic_deps.SetSelectValue(axis, config, sharedDeps.implementation)
@@ -175,10 +189,10 @@
}
}
- cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
- attrs.Srcs = cppSrcs
- attrs.Srcs_c = cSrcs
- attrs.Srcs_as = asSrcs
+ partitionedSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
+ attrs.Srcs = partitionedSrcs[cppSrcPartition]
+ attrs.Srcs_c = partitionedSrcs[cSrcPartition]
+ attrs.Srcs_as = partitionedSrcs[asSrcPartition]
return attrs
}
@@ -239,6 +253,7 @@
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
var srcs bazel.LabelListAttribute
+ var implementationHdrs bazel.LabelListAttribute
var copts bazel.StringListAttribute
var asFlags bazel.StringListAttribute
var conlyFlags bazel.StringListAttribute
@@ -265,10 +280,8 @@
anySrcs := false
// Add srcs-like dependencies such as generated files.
// First create a LabelList containing these dependencies, then merge the values with srcs.
- generatedHdrsAndSrcs := props.Generated_headers
- generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, props.Generated_sources...)
- generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, generatedHdrsAndSrcs, props.Exclude_generated_sources)
- if len(generatedHdrsAndSrcs) > 0 || len(props.Exclude_generated_sources) > 0 {
+ generatedSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, props.Generated_sources, props.Exclude_generated_sources)
+ if len(props.Generated_sources) > 0 || len(props.Exclude_generated_sources) > 0 {
anySrcs = true
}
@@ -276,7 +289,7 @@
if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
anySrcs = true
}
- return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList), anySrcs
+ return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
}
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
@@ -288,6 +301,9 @@
if srcsList, ok := parseSrcs(baseCompilerProps); ok {
srcs.SetSelectValue(axis, config, srcsList)
}
+ if len(baseCompilerProps.Generated_headers) > 0 {
+ implementationHdrs.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Generated_headers))
+ }
if axis == bazel.NoConfigAxis {
// If cpp_std is not specified, don't generate it in the
@@ -329,6 +345,21 @@
}
srcs.ResolveExcludes()
+ partitionedSrcs := groupSrcsByExtension(ctx, srcs)
+
+ for p, lla := range partitionedSrcs {
+ // if there are no sources, there is no need for headers
+ if lla.IsEmpty() {
+ continue
+ }
+ lla.Append(implementationHdrs)
+ partitionedSrcs[p] = lla
+ }
+
+ srcs = partitionedSrcs[cppSrcPartition]
+ cSrcs := partitionedSrcs[cSrcPartition]
+ asSrcs := partitionedSrcs[asSrcPartition]
+
absoluteIncludes.DeduplicateAxesFromBase()
localIncludes.DeduplicateAxesFromBase()
@@ -351,8 +382,6 @@
}
}
- srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs)
-
stlPropsByArch := module.GetArchVariantProperties(ctx, &StlProperties{})
for _, configToProps := range stlPropsByArch {
for _, props := range configToProps {
@@ -447,6 +476,7 @@
// Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module
var disallowedArchVariantCrt bool
+ isBinary := module.Binary()
for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
for config, props := range configToProps {
@@ -456,7 +486,7 @@
// Excludes to parallel Soong:
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
staticLibs := android.FirstUniqueStrings(baseLinkerProps.Static_libs)
- staticDeps := partitionExportedAndImplementationsDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs, baseLinkerProps.Export_static_lib_headers, bazelLabelForStaticDepsExcludes)
+ staticDeps := maybePartitionExportedAndImplementationsDepsExcludes(ctx, !isBinary, staticLibs, baseLinkerProps.Exclude_static_libs, baseLinkerProps.Export_static_lib_headers, bazelLabelForStaticDepsExcludes)
deps.SetSelectValue(axis, config, staticDeps.export)
implementationDeps.SetSelectValue(axis, config, staticDeps.implementation)
@@ -473,12 +503,12 @@
systemSharedDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
sharedLibs := android.FirstUniqueStrings(baseLinkerProps.Shared_libs)
- sharedDeps := partitionExportedAndImplementationsDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs, baseLinkerProps.Export_shared_lib_headers, bazelLabelForSharedDepsExcludes)
+ sharedDeps := maybePartitionExportedAndImplementationsDepsExcludes(ctx, !isBinary, sharedLibs, baseLinkerProps.Exclude_shared_libs, baseLinkerProps.Export_shared_lib_headers, bazelLabelForSharedDepsExcludes)
dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs)
- hDeps := partitionExportedAndImplementationsDeps(ctx, headerLibs, baseLinkerProps.Export_header_lib_headers, bazelLabelForHeaderDeps)
+ hDeps := maybePartitionExportedAndImplementationsDeps(ctx, !isBinary, headerLibs, baseLinkerProps.Export_header_lib_headers, bazelLabelForHeaderDeps)
headerDeps.SetSelectValue(axis, config, hDeps.export)
implementationHeaderDeps.SetSelectValue(axis, config, hDeps.implementation)
@@ -494,6 +524,10 @@
var linkerFlags []string
if len(baseLinkerProps.Ldflags) > 0 {
linkerFlags = append(linkerFlags, baseLinkerProps.Ldflags...)
+ // binaries remove static flag if -shared is in the linker flags
+ if module.Binary() && android.InList("-shared", linkerFlags) {
+ axisFeatures = append(axisFeatures, "-static_flag")
+ }
}
if baseLinkerProps.Version_script != nil {
label := android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
@@ -728,3 +762,29 @@
func bazelLabelForSharedDepsExcludes(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList {
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
}
+
+type binaryLinkerAttrs struct {
+ Linkshared *bool
+}
+
+func bp2buildBinaryLinkerProps(ctx android.TopDownMutatorContext, m *Module) binaryLinkerAttrs {
+ attrs := binaryLinkerAttrs{}
+ archVariantProps := m.GetArchVariantProperties(ctx, &BinaryLinkerProperties{})
+ for axis, configToProps := range archVariantProps {
+ for _, p := range configToProps {
+ props := p.(*BinaryLinkerProperties)
+ staticExecutable := props.Static_executable
+ if axis == bazel.NoConfigAxis {
+ if linkBinaryShared := !proptools.Bool(staticExecutable); !linkBinaryShared {
+ attrs.Linkshared = &linkBinaryShared
+ }
+ } else if staticExecutable != nil {
+ // TODO(b/202876379): Static_executable is arch-variant; however, linkshared is a
+ // nonconfigurable attribute. Only 4 AOSP modules use this feature, defer handling
+ ctx.ModuleErrorf("bp2build cannot migrate a module with arch/target-specific static_executable values")
+ }
+ }
+ }
+
+ return attrs
+}
diff --git a/cc/config/bp2build.go b/cc/config/bp2build.go
index d19f5ac..4797acc 100644
--- a/cc/config/bp2build.go
+++ b/cc/config/bp2build.go
@@ -16,9 +16,13 @@
import (
"fmt"
+ "reflect"
"regexp"
"sort"
"strings"
+
+ "android/soong/android"
+ "github.com/google/blueprint"
)
const (
@@ -26,18 +30,27 @@
)
type bazelVarExporter interface {
- asBazel(exportedStringVariables, exportedStringListVariables) []bazelConstant
+ asBazel(android.Config, exportedStringVariables, exportedStringListVariables, exportedConfigDependingVariables) []bazelConstant
}
// Helpers for exporting cc configuration information to Bazel.
var (
- // Map containing toolchain variables that are independent of the
+ // Maps containing toolchain variables that are independent of the
// environment variables of the build.
exportedStringListVars = exportedStringListVariables{}
exportedStringVars = exportedStringVariables{}
exportedStringListDictVars = exportedStringListDictVariables{}
+
+ /// Maps containing variables that are dependent on the build config.
+ exportedConfigDependingVars = exportedConfigDependingVariables{}
)
+type exportedConfigDependingVariables map[string]interface{}
+
+func (m exportedConfigDependingVariables) Set(k string, v interface{}) {
+ m[k] = v
+}
+
// Ensure that string s has no invalid characters to be generated into the bzl file.
func validateCharacters(s string) string {
for _, c := range []string{`\n`, `"`, `\`} {
@@ -74,10 +87,14 @@
return strings.Join(list, "\n")
}
-func (m exportedStringVariables) asBazel(stringScope exportedStringVariables, stringListScope exportedStringListVariables) []bazelConstant {
+func (m exportedStringVariables) asBazel(config android.Config,
+ stringVars exportedStringVariables, stringListVars exportedStringListVariables, cfgDepVars exportedConfigDependingVariables) []bazelConstant {
ret := make([]bazelConstant, 0, len(m))
for k, variableValue := range m {
- expandedVar := expandVar(variableValue, exportedStringVars, exportedStringListVars)
+ expandedVar, err := expandVar(config, variableValue, stringVars, stringListVars, cfgDepVars)
+ if err != nil {
+ panic(fmt.Errorf("error expanding config variable %s: %s", k, err))
+ }
if len(expandedVar) > 1 {
panic(fmt.Errorf("%s expands to more than one string value: %s", variableValue, expandedVar))
}
@@ -101,7 +118,9 @@
m[k] = v
}
-func (m exportedStringListVariables) asBazel(stringScope exportedStringVariables, stringListScope exportedStringListVariables) []bazelConstant {
+func (m exportedStringListVariables) asBazel(config android.Config,
+ stringScope exportedStringVariables, stringListScope exportedStringListVariables,
+ exportedVars exportedConfigDependingVariables) []bazelConstant {
ret := make([]bazelConstant, 0, len(m))
// For each exported variable, recursively expand elements in the variableValue
// list to ensure that interpolated variables are expanded according to their values
@@ -109,7 +128,11 @@
for k, variableValue := range m {
var expandedVars []string
for _, v := range variableValue {
- expandedVars = append(expandedVars, expandVar(v, stringScope, stringListScope)...)
+ expandedVar, err := expandVar(config, v, stringScope, stringListScope, exportedVars)
+ if err != nil {
+ panic(fmt.Errorf("Error expanding config variable %s=%s: %s", k, v, err))
+ }
+ expandedVars = append(expandedVars, expandedVar...)
}
// Assign the list as a bzl-private variable; this variable will be exported
// out through a constants struct later.
@@ -121,6 +144,18 @@
return ret
}
+// Convenience function to declare a static "source path" variable and export it to Bazel's cc_toolchain.
+func exportVariableConfigMethod(name string, method interface{}) blueprint.Variable {
+ exportedConfigDependingVars.Set(name, method)
+ return pctx.VariableConfigMethod(name, method)
+}
+
+// Convenience function to declare a static "source path" variable and export it to Bazel's cc_toolchain.
+func exportSourcePathVariable(name string, value string) {
+ pctx.SourcePathVariable(name, value)
+ exportedStringVars.Set(name, value)
+}
+
// Convenience function to declare a static variable and export it to Bazel's cc_toolchain.
func exportStringListStaticVariable(name string, value []string) {
pctx.StaticVariable(name, strings.Join(value, " "))
@@ -145,7 +180,8 @@
}
// Since dictionaries are not supported in Ninja, we do not expand variables for dictionaries
-func (m exportedStringListDictVariables) asBazel(_ exportedStringVariables, _ exportedStringListVariables) []bazelConstant {
+func (m exportedStringListDictVariables) asBazel(_ android.Config, _ exportedStringVariables,
+ _ exportedStringListVariables, _ exportedConfigDependingVariables) []bazelConstant {
ret := make([]bazelConstant, 0, len(m))
for k, dict := range m {
ret = append(ret, bazelConstant{
@@ -158,19 +194,20 @@
// BazelCcToolchainVars generates bzl file content containing variables for
// Bazel's cc_toolchain configuration.
-func BazelCcToolchainVars() string {
+func BazelCcToolchainVars(config android.Config) string {
return bazelToolchainVars(
+ config,
exportedStringListDictVars,
exportedStringListVars,
exportedStringVars)
}
-func bazelToolchainVars(vars ...bazelVarExporter) string {
+func bazelToolchainVars(config android.Config, vars ...bazelVarExporter) string {
ret := "# GENERATED FOR BAZEL FROM SOONG. DO NOT EDIT.\n\n"
results := []bazelConstant{}
for _, v := range vars {
- results = append(results, v.asBazel(exportedStringVars, exportedStringListVars)...)
+ results = append(results, v.asBazel(config, exportedStringVars, exportedStringListVars, exportedConfigDependingVars)...)
}
sort.Slice(results, func(i, j int) bool { return results[i].variableName < results[j].variableName })
@@ -201,34 +238,35 @@
// string slice than to handle a pass-by-referenced map, which would make it
// quite complex to track depth-first interpolations. It's also unlikely the
// interpolation stacks are deep (n > 1).
-func expandVar(toExpand string, stringScope exportedStringVariables, stringListScope exportedStringListVariables) []string {
+func expandVar(config android.Config, toExpand string, stringScope exportedStringVariables,
+ stringListScope exportedStringListVariables, exportedVars exportedConfigDependingVariables) ([]string, error) {
// e.g. "${ExternalCflags}"
r := regexp.MustCompile(`\${([a-zA-Z0-9_]+)}`)
// Internal recursive function.
- var expandVarInternal func(string, map[string]bool) []string
- expandVarInternal = func(toExpand string, seenVars map[string]bool) []string {
- var ret []string
- for _, v := range strings.Split(toExpand, " ") {
- matches := r.FindStringSubmatch(v)
+ var expandVarInternal func(string, map[string]bool) (string, error)
+ expandVarInternal = func(toExpand string, seenVars map[string]bool) (string, error) {
+ var ret string
+ remainingString := toExpand
+ for len(remainingString) > 0 {
+ matches := r.FindStringSubmatch(remainingString)
if len(matches) == 0 {
- return []string{v}
+ return ret + remainingString, nil
}
-
if len(matches) != 2 {
- panic(fmt.Errorf(
- "Expected to only match 1 subexpression in %s, got %d",
- v,
- len(matches)-1))
+ panic(fmt.Errorf("Expected to only match 1 subexpression in %s, got %d", remainingString, len(matches)-1))
}
+ matchIndex := strings.Index(remainingString, matches[0])
+ ret += remainingString[:matchIndex]
+ remainingString = remainingString[matchIndex+len(matches[0]):]
// Index 1 of FindStringSubmatch contains the subexpression match
// (variable name) of the capture group.
variable := matches[1]
// toExpand contains a variable.
if _, ok := seenVars[variable]; ok {
- panic(fmt.Errorf(
- "Unbounded recursive interpolation of variable: %s", variable))
+ return ret, fmt.Errorf(
+ "Unbounded recursive interpolation of variable: %s", variable)
}
// A map is passed-by-reference. Create a new map for
// this scope to prevent variables seen in one depth-first expansion
@@ -239,15 +277,65 @@
}
newSeenVars[variable] = true
if unexpandedVars, ok := stringListScope[variable]; ok {
+ expandedVars := []string{}
for _, unexpandedVar := range unexpandedVars {
- ret = append(ret, expandVarInternal(unexpandedVar, newSeenVars)...)
+ expandedVar, err := expandVarInternal(unexpandedVar, newSeenVars)
+ if err != nil {
+ return ret, err
+ }
+ expandedVars = append(expandedVars, expandedVar)
}
+ ret += strings.Join(expandedVars, " ")
} else if unexpandedVar, ok := stringScope[variable]; ok {
- ret = append(ret, expandVarInternal(unexpandedVar, newSeenVars)...)
+ expandedVar, err := expandVarInternal(unexpandedVar, newSeenVars)
+ if err != nil {
+ return ret, err
+ }
+ ret += expandedVar
+ } else if unevaluatedVar, ok := exportedVars[variable]; ok {
+ evalFunc := reflect.ValueOf(unevaluatedVar)
+ validateVariableMethod(variable, evalFunc)
+ evaluatedResult := evalFunc.Call([]reflect.Value{reflect.ValueOf(config)})
+ evaluatedValue := evaluatedResult[0].Interface().(string)
+ expandedVar, err := expandVarInternal(evaluatedValue, newSeenVars)
+ if err != nil {
+ return ret, err
+ }
+ ret += expandedVar
+ } else {
+ return "", fmt.Errorf("Unbound config variable %s", variable)
}
}
- return ret
+ return ret, nil
+ }
+ var ret []string
+ for _, v := range strings.Split(toExpand, " ") {
+ val, err := expandVarInternal(v, map[string]bool{})
+ if err != nil {
+ return ret, err
+ }
+ ret = append(ret, val)
}
- return expandVarInternal(toExpand, map[string]bool{})
+ return ret, nil
+}
+
+func validateVariableMethod(name string, methodValue reflect.Value) {
+ methodType := methodValue.Type()
+ if methodType.Kind() != reflect.Func {
+ panic(fmt.Errorf("method given for variable %s is not a function",
+ name))
+ }
+ if n := methodType.NumIn(); n != 1 {
+ panic(fmt.Errorf("method for variable %s has %d inputs (should be 1)",
+ name, n))
+ }
+ if n := methodType.NumOut(); n != 1 {
+ panic(fmt.Errorf("method for variable %s has %d outputs (should be 1)",
+ name, n))
+ }
+ if kind := methodType.Out(0).Kind(); kind != reflect.String {
+ panic(fmt.Errorf("method for variable %s does not return a string",
+ name))
+ }
}
diff --git a/cc/config/bp2build_test.go b/cc/config/bp2build_test.go
index 883597a..3118df1 100644
--- a/cc/config/bp2build_test.go
+++ b/cc/config/bp2build_test.go
@@ -16,13 +16,21 @@
import (
"testing"
+
+ "android/soong/android"
)
func TestExpandVars(t *testing.T) {
+ android_arm64_config := android.TestConfig("out", nil, "", nil)
+ android_arm64_config.BuildOS = android.Android
+ android_arm64_config.BuildArch = android.Arm64
+
testCases := []struct {
description string
+ config android.Config
stringScope exportedStringVariables
stringListScope exportedStringListVariables
+ configVars exportedConfigDependingVariables
toExpand string
expectedValues []string
}{
@@ -57,7 +65,7 @@
"bar": []string{"baz", "${qux}"},
},
toExpand: "${foo}",
- expectedValues: []string{"baz", "hello"},
+ expectedValues: []string{"baz hello"},
},
{
description: "double level expansion",
@@ -75,7 +83,7 @@
"b": []string{"d"},
},
toExpand: "${a}",
- expectedValues: []string{"d", "c"},
+ expectedValues: []string{"d c"},
},
{
description: "double level expansion, with two variables in a string",
@@ -85,7 +93,7 @@
"c": []string{"e"},
},
toExpand: "${a}",
- expectedValues: []string{"d", "e"},
+ expectedValues: []string{"d e"},
},
{
description: "triple level expansion with two variables in a string",
@@ -96,13 +104,38 @@
"d": []string{"foo"},
},
toExpand: "${a}",
- expectedValues: []string{"foo", "foo", "foo"},
+ expectedValues: []string{"foo foo foo"},
+ },
+ {
+ description: "expansion with config depending vars",
+ configVars: exportedConfigDependingVariables{
+ "a": func(c android.Config) string { return c.BuildOS.String() },
+ "b": func(c android.Config) string { return c.BuildArch.String() },
+ },
+ config: android_arm64_config,
+ toExpand: "${a}-${b}",
+ expectedValues: []string{"android-arm64"},
+ },
+ {
+ description: "double level multi type expansion",
+ stringListScope: exportedStringListVariables{
+ "platform": []string{"${os}-${arch}"},
+ "const": []string{"const"},
+ },
+ configVars: exportedConfigDependingVariables{
+ "os": func(c android.Config) string { return c.BuildOS.String() },
+ "arch": func(c android.Config) string { return c.BuildArch.String() },
+ "foo": func(c android.Config) string { return "foo" },
+ },
+ config: android_arm64_config,
+ toExpand: "${const}/${platform}/${foo}",
+ expectedValues: []string{"const/android-arm64/foo"},
},
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
- output := expandVar(testCase.toExpand, testCase.stringScope, testCase.stringListScope)
+ output, _ := expandVar(testCase.config, testCase.toExpand, testCase.stringScope, testCase.stringListScope, testCase.configVars)
if len(output) != len(testCase.expectedValues) {
t.Errorf("Expected %d values, got %d", len(testCase.expectedValues), len(output))
}
@@ -119,6 +152,7 @@
func TestBazelToolchainVars(t *testing.T) {
testCases := []struct {
name string
+ config android.Config
vars []bazelVarExporter
expectedOut string
}{
@@ -248,7 +282,7 @@
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
- out := bazelToolchainVars(tc.vars...)
+ out := bazelToolchainVars(tc.config, tc.vars...)
if out != tc.expectedOut {
t.Errorf("Expected \n%s, got \n%s", tc.expectedOut, out)
}
diff --git a/cc/config/global.go b/cc/config/global.go
index 6108d3d..7abd2fc 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -404,7 +404,7 @@
pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
}
-var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
+var HostPrebuiltTag = exportVariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
func ClangPath(ctx android.PathContext, file string) android.SourcePath {
type clangToolKey string
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index ecdcbde..ad82b94 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -56,9 +56,7 @@
"10.13",
"10.14",
"10.15",
- "11.0",
- "11.1",
- "11.3",
+ "11",
}
darwinAvailableLibraries = append(
@@ -138,7 +136,7 @@
return ""
}
- bytes, err := exec.Command(xcrunTool, args...).Output()
+ bytes, err := exec.Command(xcrunTool, append([]string{"--sdk", "macosx"}, args...)...).Output()
if err != nil {
macTools.err = fmt.Errorf("xcrun %q failed with: %q", args, err)
return ""
@@ -147,27 +145,19 @@
return strings.TrimSpace(string(bytes))
}
- xcrunSdk := func(arg string) string {
- if selected := ctx.Config().Getenv("MAC_SDK_VERSION"); selected != "" {
- if !inList(selected, darwinSupportedSdkVersions) {
- macTools.err = fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
- return ""
- }
-
- return xcrun("--sdk", "macosx"+selected, arg)
+ sdkVersion := xcrun("--show-sdk-version")
+ sdkVersionSupported := false
+ for _, version := range darwinSupportedSdkVersions {
+ if version == sdkVersion || strings.HasPrefix(sdkVersion, version+".") {
+ sdkVersionSupported = true
}
-
- for _, sdk := range darwinSupportedSdkVersions {
- bytes, err := exec.Command(xcrunTool, "--sdk", "macosx"+sdk, arg).Output()
- if err == nil {
- return strings.TrimSpace(string(bytes))
- }
- }
- macTools.err = fmt.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
- return ""
+ }
+ if !sdkVersionSupported {
+ macTools.err = fmt.Errorf("Unsupported macOS SDK version %q not in %v", sdkVersion, darwinSupportedSdkVersions)
+ return
}
- macTools.sdkRoot = xcrunSdk("--show-sdk-path")
+ macTools.sdkRoot = xcrun("--show-sdk-path")
macTools.arPath = xcrun("--find", "ar")
macTools.stripPath = xcrun("--find", "strip")
diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go
index ac5d5f7..43333fa 100644
--- a/cc/config/x86_linux_host.go
+++ b/cc/config/x86_linux_host.go
@@ -120,40 +120,40 @@
)
func init() {
- pctx.StaticVariable("LinuxGccVersion", linuxGccVersion)
- pctx.StaticVariable("LinuxGlibcVersion", linuxGlibcVersion)
+ exportStringStaticVariable("LinuxGccVersion", linuxGccVersion)
+ exportStringStaticVariable("LinuxGlibcVersion", linuxGlibcVersion)
+
// Most places use the full GCC version. A few only use up to the first two numbers.
if p := strings.Split(linuxGccVersion, "."); len(p) > 2 {
- pctx.StaticVariable("ShortLinuxGccVersion", strings.Join(p[:2], "."))
+ exportStringStaticVariable("ShortLinuxGccVersion", strings.Join(p[:2], "."))
} else {
- pctx.StaticVariable("ShortLinuxGccVersion", linuxGccVersion)
+ exportStringStaticVariable("ShortLinuxGccVersion", linuxGccVersion)
}
- pctx.SourcePathVariable("LinuxGccRoot",
- "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-linux-glibc${LinuxGlibcVersion}-${ShortLinuxGccVersion}")
+ exportSourcePathVariable("LinuxGccRoot",
+ "prebuilts/gcc/linux-x86/host/x86_64-linux-glibc${LinuxGlibcVersion}-${ShortLinuxGccVersion}")
- pctx.StaticVariable("LinuxGccTriple", "x86_64-linux")
+ exportStringListStaticVariable("LinuxGccTriple", []string{"x86_64-linux"})
- pctx.StaticVariable("LinuxCflags", strings.Join(linuxCflags, " "))
- pctx.StaticVariable("LinuxLdflags", strings.Join(linuxLdflags, " "))
- pctx.StaticVariable("LinuxLldflags", strings.Join(linuxLdflags, " "))
+ exportStringListStaticVariable("LinuxCflags", linuxCflags)
+ exportStringListStaticVariable("LinuxLdflags", linuxLdflags)
+ exportStringListStaticVariable("LinuxLldflags", linuxLdflags)
+ exportStringListStaticVariable("LinuxGlibcCflags", linuxGlibcCflags)
+ exportStringListStaticVariable("LinuxGlibcLdflags", linuxGlibcLdflags)
+ exportStringListStaticVariable("LinuxGlibcLldflags", linuxGlibcLdflags)
+ exportStringListStaticVariable("LinuxMuslCflags", linuxMuslCflags)
+ exportStringListStaticVariable("LinuxMuslLdflags", linuxMuslLdflags)
+ exportStringListStaticVariable("LinuxMuslLldflags", linuxMuslLdflags)
- pctx.StaticVariable("LinuxX86Cflags", strings.Join(linuxX86Cflags, " "))
- pctx.StaticVariable("LinuxX8664Cflags", strings.Join(linuxX8664Cflags, " "))
- pctx.StaticVariable("LinuxX86Ldflags", strings.Join(linuxX86Ldflags, " "))
- pctx.StaticVariable("LinuxX86Lldflags", strings.Join(linuxX86Ldflags, " "))
- pctx.StaticVariable("LinuxX8664Ldflags", strings.Join(linuxX8664Ldflags, " "))
- pctx.StaticVariable("LinuxX8664Lldflags", strings.Join(linuxX8664Ldflags, " "))
+ exportStringListStaticVariable("LinuxX86Cflags", linuxX86Cflags)
+ exportStringListStaticVariable("LinuxX8664Cflags", linuxX8664Cflags)
+ exportStringListStaticVariable("LinuxX86Ldflags", linuxX86Ldflags)
+ exportStringListStaticVariable("LinuxX86Lldflags", linuxX86Ldflags)
+ exportStringListStaticVariable("LinuxX8664Ldflags", linuxX8664Ldflags)
+ exportStringListStaticVariable("LinuxX8664Lldflags", linuxX8664Ldflags)
// Yasm flags
- pctx.StaticVariable("LinuxX86YasmFlags", "-f elf32 -m x86")
- pctx.StaticVariable("LinuxX8664YasmFlags", "-f elf64 -m amd64")
-
- pctx.StaticVariable("LinuxGlibcCflags", strings.Join(linuxGlibcCflags, " "))
- pctx.StaticVariable("LinuxGlibcLdflags", strings.Join(linuxGlibcLdflags, " "))
- pctx.StaticVariable("LinuxGlibcLldflags", strings.Join(linuxGlibcLdflags, " "))
- pctx.StaticVariable("LinuxMuslCflags", strings.Join(linuxMuslCflags, " "))
- pctx.StaticVariable("LinuxMuslLdflags", strings.Join(linuxMuslLdflags, " "))
- pctx.StaticVariable("LinuxMuslLldflags", strings.Join(linuxMuslLdflags, " "))
+ exportStringListStaticVariable("LinuxX86YasmFlags", []string{"-f elf32 -m x86"})
+ exportStringListStaticVariable("LinuxX8664YasmFlags", []string{"-f elf64 -m amd64"})
}
type toolchainLinux struct {
diff --git a/cc/installer.go b/cc/installer.go
index f95b493..2522610 100644
--- a/cc/installer.go
+++ b/cc/installer.go
@@ -29,6 +29,9 @@
// Install output directly in {partition}/, not in any subdir. This is only intended for use by
// init_first_stage.
Install_in_root *bool `android:"arch_variant"`
+
+ // Install output directly in {partition}/xbin
+ Install_in_xbin *bool `android:"arch_vvariant"`
}
type installLocation int
@@ -73,6 +76,8 @@
if installer.installInRoot() {
dir = ""
+ } else if installer.installInXbin() {
+ dir = "xbin"
}
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
@@ -123,3 +128,7 @@
func (installer *baseInstaller) installInRoot() bool {
return Bool(installer.Properties.Install_in_root)
}
+
+func (installer *baseInstaller) installInXbin() bool {
+ return Bool(installer.Properties.Install_in_xbin)
+}
diff --git a/cc/library.go b/cc/library.go
index ed4d3d2..d63acfb 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -639,7 +639,7 @@
func (handler *ccLibraryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool {
bazelCtx := ctx.Config().BazelContext
- ccInfo, ok, err := bazelCtx.GetCcInfo(label, ctx.Arch().ArchType)
+ ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx))
if err != nil {
ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err)
return false
diff --git a/cc/library_headers.go b/cc/library_headers.go
index 51c1eb8..b2b3dbc 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -57,7 +57,7 @@
func (h *libraryHeaderBazelHander) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool {
bazelCtx := ctx.Config().BazelContext
- ccInfo, ok, err := bazelCtx.GetCcInfo(label, ctx.Arch().ArchType)
+ ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx))
if err != nil {
ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err)
return false
diff --git a/cc/lto.go b/cc/lto.go
index 6d55579..99598a9 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -137,8 +137,9 @@
func (lto *lto) DefaultThinLTO(ctx BaseModuleContext) bool {
host := ctx.Host()
+ test := ctx.testBinary()
vndk := ctx.isVndk() // b/169217596
- return GlobalThinLTO(ctx) && !lto.Never() && !host && !vndk
+ return GlobalThinLTO(ctx) && !lto.Never() && !host && !test && !vndk
}
func (lto *lto) FullLTO() bool {
diff --git a/cc/object.go b/cc/object.go
index d8bb08f..43abb3a 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -54,7 +54,7 @@
func (handler *objectBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool {
bazelCtx := ctx.Config().BazelContext
- objPaths, ok := bazelCtx.GetOutputFiles(label, ctx.Arch().ArchType)
+ objPaths, ok := bazelCtx.GetOutputFiles(label, android.GetConfigKey(ctx))
if ok {
if len(objPaths) != 1 {
ctx.ModuleErrorf("expected exactly one object file for '%s', but got %s", label, objPaths)
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index d324241..62f3938 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -330,7 +330,7 @@
func (h *prebuiltStaticLibraryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool {
bazelCtx := ctx.Config().BazelContext
- ccInfo, ok, err := bazelCtx.GetCcInfo(label, ctx.Arch().ArchType)
+ ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx))
if err != nil {
ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err)
}
diff --git a/cmd/multiproduct_kati/Android.bp b/cmd/multiproduct_kati/Android.bp
index e5be6c0..20ca2a3 100644
--- a/cmd/multiproduct_kati/Android.bp
+++ b/cmd/multiproduct_kati/Android.bp
@@ -31,4 +31,14 @@
testSrcs: [
"main_test.go",
],
+ linux: {
+ srcs: [
+ "main_linux.go",
+ ],
+ },
+ darwin: {
+ srcs: [
+ "main_darwin.go",
+ ],
+ },
}
diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go
index 3c9cac1..0577c86 100644
--- a/cmd/multiproduct_kati/main.go
+++ b/cmd/multiproduct_kati/main.go
@@ -166,15 +166,6 @@
MainLogsDir string
}
-func detectTotalRAM() uint64 {
- var info syscall.Sysinfo_t
- err := syscall.Sysinfo(&info)
- if err != nil {
- panic(err)
- }
- return info.Totalram * uint64(info.Unit)
-}
-
func findNamedProducts(soongUi string, log logger.Logger) []string {
cmd := exec.Command(soongUi, "--dumpvars-mode", "--vars=all_named_products")
output, err := cmd.Output()
@@ -301,7 +292,7 @@
jobs = runtime.NumCPU() / 4
ramGb := int(detectTotalRAM() / (1024 * 1024 * 1024))
- if ramJobs := ramGb / 25; ramGb > 0 && jobs > ramJobs {
+ if ramJobs := ramGb / 30; ramGb > 0 && jobs > ramJobs {
jobs = ramJobs
}
diff --git a/cmd/multiproduct_kati/main_darwin.go b/cmd/multiproduct_kati/main_darwin.go
new file mode 100644
index 0000000..3d1b12a
--- /dev/null
+++ b/cmd/multiproduct_kati/main_darwin.go
@@ -0,0 +1,20 @@
+// Copyright 2017 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+func detectTotalRAM() uint64 {
+ // unimplemented stub on darwin
+ return 0
+}
diff --git a/cmd/multiproduct_kati/main_linux.go b/cmd/multiproduct_kati/main_linux.go
new file mode 100644
index 0000000..db74496
--- /dev/null
+++ b/cmd/multiproduct_kati/main_linux.go
@@ -0,0 +1,28 @@
+// Copyright 2017 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "syscall"
+)
+
+func detectTotalRAM() uint64 {
+ var info syscall.Sysinfo_t
+ err := syscall.Sysinfo(&info)
+ if err != nil {
+ panic(err)
+ }
+ return info.Totalram * uint64(info.Unit)
+}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 4dd2135..b9c2b10 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -248,7 +248,7 @@
// Returns true if information was available from Bazel, false if bazel invocation still needs to occur.
func (c *Module) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool {
bazelCtx := ctx.Config().BazelContext
- filePaths, ok := bazelCtx.GetOutputFiles(label, ctx.Arch().ArchType)
+ filePaths, ok := bazelCtx.GetOutputFiles(label, android.GetConfigKey(ctx))
if ok {
var bazelOutputFiles android.Paths
exportIncludeDirs := map[string]bool{}
diff --git a/java/proto.go b/java/proto.go
index 8731822..2fa22b6 100644
--- a/java/proto.go
+++ b/java/proto.go
@@ -24,7 +24,7 @@
func genProto(ctx android.ModuleContext, protoFiles android.Paths, flags android.ProtoFlags) android.Paths {
// Shard proto files into groups of 100 to avoid having to recompile all of them if one changes and to avoid
// hitting command line length limits.
- shards := android.ShardPaths(protoFiles, 100)
+ shards := android.ShardPaths(protoFiles, 50)
srcJarFiles := make(android.Paths, 0, len(shards))
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index 3ae8ab9..b377fd8 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -1162,17 +1162,21 @@
}
// Either pattern or text should be const, and the
// non-const one should be varRefExpr
- if xInList, ok = xPattern.(*stringLiteralExpr); ok {
+ if xInList, ok = xPattern.(*stringLiteralExpr); ok && !strings.ContainsRune(xInList.literal, '%') && xText.typ() == starlarkTypeList {
expr = xText
} else if xInList, ok = xText.(*stringLiteralExpr); ok {
expr = xPattern
} else {
- return &callExpr{
+ expr = &callExpr{
object: nil,
name: filterFuncCall.name,
args: filterFuncCall.args,
returnType: starlarkTypeBool,
}
+ if negate {
+ expr = ¬Expr{expr: expr}
+ }
+ return expr
}
case *variableRefExpr:
if v, ok := xPattern.(*variableRefExpr); ok {
diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go
index 434500b..fe1fa08 100644
--- a/mk2rbc/mk2rbc_test.go
+++ b/mk2rbc/mk2rbc_test.go
@@ -360,20 +360,27 @@
endif
ifneq (,$(filter true, $(v1)$(v2)))
endif
+ifeq (,$(filter barbet coral%,$(TARGET_PRODUCT)))
+else ifneq (,$(filter barbet%,$(TARGET_PRODUCT)))
+endif
`,
expected: `load("//build/make/core:product_config.rbc", "rblf")
def init(g, handle):
cfg = rblf.cfg(handle)
- if g["TARGET_BUILD_VARIANT"] not in ["userdebug", "eng"]:
+ if not rblf.filter("userdebug eng", g["TARGET_BUILD_VARIANT"]):
pass
- if g["TARGET_BUILD_VARIANT"] == "userdebug":
+ if rblf.filter("userdebug", g["TARGET_BUILD_VARIANT"]):
pass
if "plaf" in g.get("PLATFORM_LIST", []):
pass
if g["TARGET_BUILD_VARIANT"] in ["userdebug", "eng"]:
pass
- if "%s%s" % (_v1, _v2) == "true":
+ if rblf.filter("true", "%s%s" % (_v1, _v2)):
+ pass
+ if not rblf.filter("barbet coral%", g["TARGET_PRODUCT"]):
+ pass
+ elif rblf.filter("barbet%", g["TARGET_PRODUCT"]):
pass
`,
},
diff --git a/mk2rbc/version_defaults.go b/mk2rbc/version_defaults.go
index 27e8198..64645d7 100644
--- a/mk2rbc/version_defaults.go
+++ b/mk2rbc/version_defaults.go
@@ -15,7 +15,6 @@
package mk2rbc
import (
- mkparser "android/soong/androidmk/parser"
"bytes"
"fmt"
"io/ioutil"
@@ -23,6 +22,8 @@
"sort"
"strconv"
"strings"
+
+ mkparser "android/soong/androidmk/parser"
)
const codenamePrefix = "PLATFORM_VERSION_CODENAME."
@@ -97,7 +98,10 @@
strings.ToLower(name), genericValue(value)))
}
}
+
sort.Strings(lines)
+ sort.Strings(codenames)
+
sink.WriteString("version_defaults = struct(\n")
for _, l := range lines {
sink.WriteString(l)
diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go
index 47ca3a7..b113573 100644
--- a/rust/config/allowed_list.go
+++ b/rust/config/allowed_list.go
@@ -32,6 +32,7 @@
"system/security",
"system/tools/aidl",
"tools/security/fuzzing/example_rust_fuzzer",
+ "tools/security/fuzzing/orphans",
"vendor/",
}
diff --git a/scripts/build-mainline-modules.sh b/scripts/build-mainline-modules.sh
index b05861b..281cb82 100755
--- a/scripts/build-mainline-modules.sh
+++ b/scripts/build-mainline-modules.sh
@@ -17,6 +17,7 @@
MODULES_SDK_AND_EXPORTS=(
art-module-sdk
art-module-test-exports
+ compos-module-sdk
conscrypt-module-host-exports
conscrypt-module-sdk
conscrypt-module-test-exports
diff --git a/scripts/gen_ndk_backedby_apex.sh b/scripts/gen_ndk_backedby_apex.sh
index 4abaaba..212362e 100755
--- a/scripts/gen_ndk_backedby_apex.sh
+++ b/scripts/gen_ndk_backedby_apex.sh
@@ -21,52 +21,29 @@
# After the parse function below "dlopen" would be write to the output file.
printHelp() {
echo "**************************** Usage Instructions ****************************"
- echo "This script is used to generate the Mainline modules backed-by NDK symbols."
+ echo "This script is used to generate the native libraries backed by Mainline modules."
echo ""
- echo "To run this script use: ./gen_ndk_backed_by_apex.sh \$OUTPUT_FILE_PATH \$NDK_LIB_NAME_LIST \$MODULE_LIB1 \$MODULE_LIB2..."
+ echo "To run this script use: ./gen_ndk_backed_by_apex.sh \$OUTPUT_FILE_PATH \$MODULE_LIB1 \$MODULE_LIB2..."
echo "For example: If output write to /backedby.txt then the command would be:"
- echo "./gen_ndk_backed_by_apex.sh /backedby.txt /ndkLibList.txt lib1.so lib2.so"
+ echo "./gen_ndk_backed_by_apex.sh /backedby.txt lib1.so lib2.so"
echo "If the module1 is backing lib1 then the backedby.txt would contains: "
- echo "lib1"
+ echo "lib1.so lib2.so"
}
-contains() {
- val="$1"
- shift
- for x in "$@"; do
- if [ "$x" = "$val" ]; then
- return 0
- fi
- done
- return 1
-}
-
-
-genBackedByList() {
+genAllBackedByList() {
out="$1"
shift
- ndk_list="$1"
- shift
rm -f "$out"
touch "$out"
- while IFS= read -r line
- do
- soFileName=$(echo "$line" | sed 's/\(.*so\).*/\1/')
- if [[ ! -z "$soFileName" && "$soFileName" != *"#"* ]]
- then
- if contains "$soFileName" "$@"; then
- echo "$soFileName" >> "$out"
- fi
- fi
- done < "$ndk_list"
+ echo "$@" >> "$out"
}
if [[ "$1" == "help" ]]
then
printHelp
-elif [[ "$#" -lt 2 ]]
+elif [[ "$#" -lt 1 ]]
then
- echo "Wrong argument length. Expecting at least 2 argument representing output path, path to ndk library list, followed by a list of libraries in the Mainline module."
+ echo "Wrong argument length. Expecting at least 1 argument representing output path, followed by a list of libraries in the Mainline module."
else
- genBackedByList "$@"
+ genAllBackedByList "$@"
fi