Merge "Write Soong tests to confirm Sysprop directories"
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 5c79fa2..8bef725 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -46,19 +46,16 @@
"bionic": Bp2BuildDefaultTrueRecursively,
"bootable/recovery/tools/recovery_l10n": Bp2BuildDefaultTrue,
- "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
- "build/bazel/examples/soong_config_variables": Bp2BuildDefaultTrueRecursively,
- "build/bazel/examples/python": Bp2BuildDefaultTrueRecursively,
- "build/bazel/examples/gensrcs": Bp2BuildDefaultTrueRecursively,
- "build/make/target/product/security": Bp2BuildDefaultTrue,
- "build/make/tools/signapk": Bp2BuildDefaultTrue,
- "build/make/tools/zipalign": Bp2BuildDefaultTrueRecursively,
- "build/soong": Bp2BuildDefaultTrue,
- "build/soong/cc/libbuildversion": Bp2BuildDefaultTrue, // Skip tests subdir
- "build/soong/cc/ndkstubgen": Bp2BuildDefaultTrue,
- "build/soong/cc/symbolfile": Bp2BuildDefaultTrue,
- "build/soong/linkerconfig": Bp2BuildDefaultTrueRecursively,
- "build/soong/scripts": Bp2BuildDefaultTrueRecursively,
+ "build/bazel": Bp2BuildDefaultTrueRecursively,
+ "build/make/target/product/security": Bp2BuildDefaultTrue,
+ "build/make/tools/signapk": Bp2BuildDefaultTrue,
+ "build/make/tools/zipalign": Bp2BuildDefaultTrueRecursively,
+ "build/soong": Bp2BuildDefaultTrue,
+ "build/soong/cc/libbuildversion": Bp2BuildDefaultTrue, // Skip tests subdir
+ "build/soong/cc/ndkstubgen": Bp2BuildDefaultTrue,
+ "build/soong/cc/symbolfile": Bp2BuildDefaultTrue,
+ "build/soong/linkerconfig": Bp2BuildDefaultTrueRecursively,
+ "build/soong/scripts": Bp2BuildDefaultTrueRecursively,
"cts/common/device-side/nativetesthelper/jni": Bp2BuildDefaultTrueRecursively,
"development/apps/DevelopmentSettings": Bp2BuildDefaultTrue,
@@ -137,6 +134,7 @@
"external/libjpeg-turbo": Bp2BuildDefaultTrueRecursively,
"external/libmpeg2": Bp2BuildDefaultTrueRecursively,
"external/libpng": Bp2BuildDefaultTrueRecursively,
+ "external/libyuv": Bp2BuildDefaultTrueRecursively,
"external/lz4/lib": Bp2BuildDefaultTrue,
"external/lzma/C": Bp2BuildDefaultTrueRecursively,
"external/mdnsresponder": Bp2BuildDefaultTrueRecursively,
@@ -148,6 +146,7 @@
"external/scudo": Bp2BuildDefaultTrueRecursively,
"external/selinux/libselinux": Bp2BuildDefaultTrueRecursively,
"external/selinux/libsepol": Bp2BuildDefaultTrueRecursively,
+ "external/speex": Bp2BuildDefaultTrueRecursively,
"external/toybox": Bp2BuildDefaultTrueRecursively,
"external/zlib": Bp2BuildDefaultTrueRecursively,
"external/zopfli": Bp2BuildDefaultTrueRecursively,
@@ -157,11 +156,15 @@
"frameworks/av/media/liberror": Bp2BuildDefaultTrueRecursively,
"frameworks/av/services/minijail": Bp2BuildDefaultTrueRecursively,
"frameworks/base/media/tests/MediaDump": Bp2BuildDefaultTrue,
+ "frameworks/base/services/tests/servicestests/aidl": Bp2BuildDefaultTrue,
"frameworks/base/startop/apps/test": Bp2BuildDefaultTrue,
"frameworks/base/tests/appwidgets/AppWidgetHostTest": Bp2BuildDefaultTrueRecursively,
"frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively,
"frameworks/native/libs/arect": Bp2BuildDefaultTrueRecursively,
"frameworks/native/libs/math": Bp2BuildDefaultTrueRecursively,
+ "hardware/interfaces/common/aidl": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/common/aidl": Bp2BuildDefaultTrue,
+ "hardware/interfaces/neuralnetworks/aidl": Bp2BuildDefaultTrue,
"frameworks/native/libs/nativebase": Bp2BuildDefaultTrueRecursively,
"frameworks/native/opengl/tests/gl2_cameraeye": Bp2BuildDefaultTrue,
"frameworks/native/opengl/tests/gl2_java": Bp2BuildDefaultTrue,
@@ -170,7 +173,35 @@
"frameworks/native/opengl/tests/testViewport": Bp2BuildDefaultTrue,
"frameworks/proto_logging/stats/stats_log_api_gen": Bp2BuildDefaultTrueRecursively,
- "libnativehelper": Bp2BuildDefaultTrueRecursively,
+ "hardware/interfaces": Bp2BuildDefaultTrue,
+ "hardware/interfaces/configstore/1.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/configstore/1.1": Bp2BuildDefaultTrue,
+ "hardware/interfaces/configstore/utils": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/allocator/2.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/allocator/3.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/allocator/4.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/bufferqueue/1.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/bufferqueue/2.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/common/1.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/common/1.1": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/common/1.2": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/mapper/2.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/mapper/2.1": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/mapper/3.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/graphics/mapper/4.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/media/1.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/media/bufferpool/2.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/media/c2/1.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/media/c2/1.1": Bp2BuildDefaultTrue,
+ "hardware/interfaces/media/c2/1.2": Bp2BuildDefaultTrue,
+ "hardware/interfaces/media/omx/1.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/neuralnetworks/1.0": Bp2BuildDefaultTrue,
+ "hardware/interfaces/neuralnetworks/1.1": Bp2BuildDefaultTrue,
+ "hardware/interfaces/neuralnetworks/1.2": Bp2BuildDefaultTrue,
+ "hardware/interfaces/neuralnetworks/1.3": Bp2BuildDefaultTrue,
+
+ "libnativehelper": Bp2BuildDefaultTrueRecursively,
+
"packages/apps/DevCamera": Bp2BuildDefaultTrue,
"packages/apps/HTMLViewer": Bp2BuildDefaultTrue,
"packages/apps/Protips": Bp2BuildDefaultTrue,
@@ -216,15 +247,24 @@
"system/libartpalette": Bp2BuildDefaultTrueRecursively,
"system/libbase": Bp2BuildDefaultTrueRecursively,
"system/libfmq": Bp2BuildDefaultTrue,
+ "system/libhidl/libhidlmemory": Bp2BuildDefaultTrue,
+ "system/libhidl/transport": Bp2BuildDefaultTrue,
+ "system/libhidl/transport/allocator/1.0": Bp2BuildDefaultTrue,
"system/libhidl/transport/base/1.0": Bp2BuildDefaultTrue,
"system/libhidl/transport/manager/1.0": Bp2BuildDefaultTrue,
"system/libhidl/transport/manager/1.1": Bp2BuildDefaultTrue,
"system/libhidl/transport/manager/1.2": Bp2BuildDefaultTrue,
+ "system/libhidl/transport/memory/1.0": Bp2BuildDefaultTrue,
+ "system/libhidl/transport/memory/token/1.0": Bp2BuildDefaultTrue,
+ "system/libhidl/transport/safe_union/1.0": Bp2BuildDefaultTrue,
+ "system/libhidl/transport/token/1.0": Bp2BuildDefaultTrue,
+ "system/libhidl/transport/token/1.0/utils": Bp2BuildDefaultTrue,
"system/libhwbinder": Bp2BuildDefaultTrueRecursively,
"system/libprocinfo": Bp2BuildDefaultTrue,
"system/libziparchive": Bp2BuildDefaultTrueRecursively,
"system/logging/liblog": Bp2BuildDefaultTrueRecursively,
"system/media/audio": Bp2BuildDefaultTrueRecursively,
+ "system/media/audio_utils": Bp2BuildDefaultTrueRecursively,
"system/memory/libion": Bp2BuildDefaultTrueRecursively,
"system/memory/libmemunreachable": Bp2BuildDefaultTrueRecursively,
"system/sepolicy/apex": Bp2BuildDefaultTrueRecursively,
@@ -242,23 +282,7 @@
// This is actually build/bazel/build.BAZEL symlinked to ./BUILD
".":/*recursive = */ false,
- // build/bazel/examples/apex/... BUILD files should be generated, so
- // build/bazel is not recursive. Instead list each subdirectory under
- // build/bazel explicitly.
- "build/bazel":/* recursive = */ false,
- "build/bazel/ci/dist":/* recursive = */ false,
- "build/bazel/examples/android_app":/* recursive = */ true,
- "build/bazel/examples/java":/* recursive = */ true,
- "build/bazel/examples/partitions":/* recursive = */ true,
- "build/bazel/bazel_skylib":/* recursive = */ true,
- "build/bazel/rules":/* recursive = */ true,
- "build/bazel/rules_cc":/* recursive = */ true,
- "build/bazel/scripts":/* recursive = */ true,
- "build/bazel/tests":/* recursive = */ true,
- "build/bazel/platforms":/* recursive = */ true,
- "build/bazel/product_config":/* recursive = */ true,
- "build/bazel/product_variables":/* recursive = */ true,
- "build/bazel/vendor/google":/* recursive = */ true,
+ "build/bazel":/* recursive = */ true,
"build/bazel_common_rules":/* recursive = */ true,
// build/make/tools/signapk BUILD file is generated, so build/make/tools is not recursive.
"build/make/tools":/* recursive = */ false,
@@ -306,7 +330,8 @@
"libandroid_runtime_lazy",
"libandroid_runtime_vm_headers",
"libaudioclient_aidl_conversion_util",
- "libaudioutils_fixedfft",
+ "libbinder",
+ "libbinder_device_interface_sources",
"libbinder_aidl",
"libbinder_headers",
"libbinder_headers_platform_shared",
@@ -402,12 +427,16 @@
//frameworks/native/libs/input
"inputconstants_aidl",
+
+ // needed for aidl_interface's ndk backend
+ "libbinder_ndk",
}
Bp2buildModuleTypeAlwaysConvertList = []string{
"linker_config",
"java_import",
"java_import_host",
+ "aidl_interface_headers",
}
Bp2buildModuleDoNotConvertList = []string{
@@ -419,7 +448,6 @@
"linker", // TODO(b/228316882): cc_binary uses link_crt
"libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs
"versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library
- "libspeexresampler", // TODO(b/231995978): Filter out unknown cflags
"libvpx", // TODO(b/240756936): Arm neon variant not supported
"art_libartbase_headers", // TODO(b/236268577): Header libraries do not support export_shared_libs_headers
"apexer_test", // Requires aapt2
@@ -504,7 +532,7 @@
"libnativehelper_lazy_mts_jni", "libnativehelper_mts_jni", // depends on unconverted modules: libnativetesthelper_jni, libgmock_ndk
"libnativetesthelper_jni", // depends on unconverted modules: libgtest_ndk_c++
"libprotobuf-java-nano", // b/220869005, depends on non-public_current SDK
- "libstatslog", // depends on unconverted modules: libstatspull, statsd-aidl-ndk, libbinder_ndk
+ "libstatslog", // depends on unconverted modules: libstatspull, statsd-aidl-ndk
"libstatslog_art", // depends on unconverted modules: statslog_art.cpp, statslog_art.h
"linker_reloc_bench_main", // depends on unconverted modules: liblinker_reloc_bench_*
"pbtombstone", "crash_dump", // depends on libdebuggerd, libunwindstack
@@ -524,6 +552,24 @@
// '//bionic/libc:libc_bp2build_cc_library_static' is duplicated in the 'deps' attribute of rule
"toybox-static",
+
+ // Do not convert the following modules because of duplicate labels checking in Bazel.
+ // See b/241283350. They should be removed from this list once the bug is fixed.
+ "libartpalette",
+ "libartbase",
+ "libdexfile",
+ "libartbased",
+ "libdexfile_static",
+ "libartbase-testing",
+ "libartbased-testing",
+ "libdexfile_support",
+ "libunwindstack",
+ "libunwindstack_local",
+ "libfdtrack",
+ "libc_malloc_debug",
+ "libutilscallstack",
+ "libunwindstack_utils",
+ "unwind_for_offline",
}
Bp2buildCcLibraryStaticOnlyList = []string{}
@@ -595,4 +641,9 @@
"prebuilt_platform-robolectric-4.5.1-prebuilt",
"prebuilt_currysrc_org.eclipse",
}
+
+ ProdMixedBuildsEnabledList = []string{
+ // This list left intentionally empty for now. Add specific module names
+ // to have them built by Bazel in Prod Mixed Builds mode.
+ }
)
diff --git a/android/bazel.go b/android/bazel.go
index 71eb036..15729c1 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -211,7 +211,7 @@
return "" // no label for unconverted module
}
-type bp2BuildConversionAllowlist struct {
+type Bp2BuildConversionAllowlist struct {
// Configure modules in these directories to enable bp2build_available: true or false by default.
defaultConfig allowlists.Bp2BuildConfig
@@ -219,16 +219,16 @@
// in the synthetic Bazel workspace.
keepExistingBuildFile map[string]bool
- // Per-module allowlist to always opt modules in of both bp2build and mixed builds.
- // These modules are usually in directories with many other modules that are not ready for
- // conversion.
+ // Per-module allowlist to always opt modules into both bp2build and Bazel Dev Mode mixed
+ // builds. These modules are usually in directories with many other modules that are not ready
+ // for conversion.
//
// A module can either be in this list or its directory allowlisted entirely
// in bp2buildDefaultConfig, but not both at the same time.
moduleAlwaysConvert map[string]bool
- // Per-module-type allowlist to always opt modules in to both bp2build and mixed builds
- // when they have the same type as one listed.
+ // Per-module-type allowlist to always opt modules in to both bp2build and
+ // Bazel Dev Mode mixed builds when they have the same type as one listed.
moduleTypeAlwaysConvert map[string]bool
// Per-module denylist to always opt modules out of bp2build conversion.
@@ -241,14 +241,14 @@
// GenerateCcLibraryStaticOnly returns whether a cc_library module should only
// generate a static version of itself based on the current global configuration.
-func (a bp2BuildConversionAllowlist) GenerateCcLibraryStaticOnly(moduleName string) bool {
+func (a Bp2BuildConversionAllowlist) GenerateCcLibraryStaticOnly(moduleName string) bool {
return a.ccLibraryStaticOnly[moduleName]
}
-// NewBp2BuildAllowlist creates a new, empty bp2BuildConversionAllowlist
+// NewBp2BuildAllowlist creates a new, empty Bp2BuildConversionAllowlist
// which can be populated using builder pattern Set* methods
-func NewBp2BuildAllowlist() bp2BuildConversionAllowlist {
- return bp2BuildConversionAllowlist{
+func NewBp2BuildAllowlist() Bp2BuildConversionAllowlist {
+ return Bp2BuildConversionAllowlist{
allowlists.Bp2BuildConfig{},
map[string]bool{},
map[string]bool{},
@@ -259,7 +259,7 @@
}
// SetDefaultConfig copies the entries from defaultConfig into the allowlist
-func (a bp2BuildConversionAllowlist) SetDefaultConfig(defaultConfig allowlists.Bp2BuildConfig) bp2BuildConversionAllowlist {
+func (a Bp2BuildConversionAllowlist) SetDefaultConfig(defaultConfig allowlists.Bp2BuildConfig) Bp2BuildConversionAllowlist {
if a.defaultConfig == nil {
a.defaultConfig = allowlists.Bp2BuildConfig{}
}
@@ -271,7 +271,7 @@
}
// SetKeepExistingBuildFile copies the entries from keepExistingBuildFile into the allowlist
-func (a bp2BuildConversionAllowlist) SetKeepExistingBuildFile(keepExistingBuildFile map[string]bool) bp2BuildConversionAllowlist {
+func (a Bp2BuildConversionAllowlist) SetKeepExistingBuildFile(keepExistingBuildFile map[string]bool) Bp2BuildConversionAllowlist {
if a.keepExistingBuildFile == nil {
a.keepExistingBuildFile = map[string]bool{}
}
@@ -283,7 +283,7 @@
}
// SetModuleAlwaysConvertList copies the entries from moduleAlwaysConvert into the allowlist
-func (a bp2BuildConversionAllowlist) SetModuleAlwaysConvertList(moduleAlwaysConvert []string) bp2BuildConversionAllowlist {
+func (a Bp2BuildConversionAllowlist) SetModuleAlwaysConvertList(moduleAlwaysConvert []string) Bp2BuildConversionAllowlist {
if a.moduleAlwaysConvert == nil {
a.moduleAlwaysConvert = map[string]bool{}
}
@@ -295,7 +295,7 @@
}
// SetModuleTypeAlwaysConvertList copies the entries from moduleTypeAlwaysConvert into the allowlist
-func (a bp2BuildConversionAllowlist) SetModuleTypeAlwaysConvertList(moduleTypeAlwaysConvert []string) bp2BuildConversionAllowlist {
+func (a Bp2BuildConversionAllowlist) SetModuleTypeAlwaysConvertList(moduleTypeAlwaysConvert []string) Bp2BuildConversionAllowlist {
if a.moduleTypeAlwaysConvert == nil {
a.moduleTypeAlwaysConvert = map[string]bool{}
}
@@ -307,7 +307,7 @@
}
// SetModuleDoNotConvertList copies the entries from moduleDoNotConvert into the allowlist
-func (a bp2BuildConversionAllowlist) SetModuleDoNotConvertList(moduleDoNotConvert []string) bp2BuildConversionAllowlist {
+func (a Bp2BuildConversionAllowlist) SetModuleDoNotConvertList(moduleDoNotConvert []string) Bp2BuildConversionAllowlist {
if a.moduleDoNotConvert == nil {
a.moduleDoNotConvert = map[string]bool{}
}
@@ -319,7 +319,7 @@
}
// SetCcLibraryStaticOnlyList copies the entries from ccLibraryStaticOnly into the allowlist
-func (a bp2BuildConversionAllowlist) SetCcLibraryStaticOnlyList(ccLibraryStaticOnly []string) bp2BuildConversionAllowlist {
+func (a Bp2BuildConversionAllowlist) SetCcLibraryStaticOnlyList(ccLibraryStaticOnly []string) Bp2BuildConversionAllowlist {
if a.ccLibraryStaticOnly == nil {
a.ccLibraryStaticOnly = map[string]bool{}
}
@@ -330,33 +330,15 @@
return a
}
-var bp2BuildAllowListKey = NewOnceKey("Bp2BuildAllowlist")
-var bp2buildAllowlist OncePer
-
-func GetBp2BuildAllowList() bp2BuildConversionAllowlist {
- return bp2buildAllowlist.Once(bp2BuildAllowListKey, func() interface{} {
- return NewBp2BuildAllowlist().SetDefaultConfig(allowlists.Bp2buildDefaultConfig).
- SetKeepExistingBuildFile(allowlists.Bp2buildKeepExistingBuildFile).
- SetModuleAlwaysConvertList(allowlists.Bp2buildModuleAlwaysConvertList).
- SetModuleTypeAlwaysConvertList(allowlists.Bp2buildModuleTypeAlwaysConvertList).
- SetModuleDoNotConvertList(allowlists.Bp2buildModuleDoNotConvertList).
- SetCcLibraryStaticOnlyList(allowlists.Bp2buildCcLibraryStaticOnlyList)
- }).(bp2BuildConversionAllowlist)
-}
-
// ShouldKeepExistingBuildFileForDir returns whether an existing BUILD file should be
// added to the build symlink forest based on the current global configuration.
-func ShouldKeepExistingBuildFileForDir(dir string) bool {
- return shouldKeepExistingBuildFileForDir(GetBp2BuildAllowList(), dir)
-}
-
-func shouldKeepExistingBuildFileForDir(allowlist bp2BuildConversionAllowlist, dir string) bool {
- if _, ok := allowlist.keepExistingBuildFile[dir]; ok {
+func (a Bp2BuildConversionAllowlist) ShouldKeepExistingBuildFileForDir(dir string) bool {
+ if _, ok := a.keepExistingBuildFile[dir]; ok {
// Exact dir match
return true
}
// Check if subtree match
- for prefix, recursive := range allowlist.keepExistingBuildFile {
+ for prefix, recursive := range a.keepExistingBuildFile {
if recursive {
if strings.HasPrefix(dir, prefix+"/") {
return true
@@ -367,6 +349,20 @@
return false
}
+var bp2BuildAllowListKey = NewOnceKey("Bp2BuildAllowlist")
+var bp2buildAllowlist OncePer
+
+func GetBp2BuildAllowList() Bp2BuildConversionAllowlist {
+ return bp2buildAllowlist.Once(bp2BuildAllowListKey, func() interface{} {
+ return NewBp2BuildAllowlist().SetDefaultConfig(allowlists.Bp2buildDefaultConfig).
+ SetKeepExistingBuildFile(allowlists.Bp2buildKeepExistingBuildFile).
+ SetModuleAlwaysConvertList(allowlists.Bp2buildModuleAlwaysConvertList).
+ SetModuleTypeAlwaysConvertList(allowlists.Bp2buildModuleTypeAlwaysConvertList).
+ SetModuleDoNotConvertList(allowlists.Bp2buildModuleDoNotConvertList).
+ SetCcLibraryStaticOnlyList(allowlists.Bp2buildCcLibraryStaticOnlyList)
+ }).(Bp2BuildConversionAllowlist)
+}
+
// MixedBuildsEnabled returns true if a module is ready to be replaced by a
// converted or handcrafted Bazel target. As a side effect, calling this
// method will also log whether this module is mixed build enabled for
@@ -431,7 +427,7 @@
}
moduleName := module.Name()
- allowlist := ctx.Config().bp2buildPackageConfig
+ allowlist := ctx.Config().Bp2buildPackageConfig
moduleNameAllowed := allowlist.moduleAlwaysConvert[moduleName]
moduleTypeAllowed := allowlist.moduleTypeAlwaysConvert[ctx.OtherModuleType(module)]
allowlistConvert := moduleNameAllowed || moduleTypeAllowed
@@ -447,14 +443,6 @@
return false
}
- if allowlistConvert && shouldKeepExistingBuildFileForDir(allowlist, packagePath) {
- if moduleNameAllowed {
- ctx.ModuleErrorf("A module cannot be in a directory listed in keepExistingBuildFile"+
- " and also be in moduleAlwaysConvert. Directory: '%s'", packagePath)
- return false
- }
- }
-
// This is a tristate value: true, false, or unset.
if ok, directoryPath := bp2buildDefaultTrueRecursively(packagePath, allowlist.defaultConfig); ok {
if moduleNameAllowed {
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index d87f988..93b6779 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -343,7 +343,30 @@
}
func NewBazelContext(c *config) (BazelContext, error) {
- if !c.IsMixedBuildsEnabled() {
+ var modulesDefaultToBazel bool
+ disabledModules := map[string]bool{}
+ enabledModules := map[string]bool{}
+
+ switch c.BuildMode {
+ case BazelProdMode:
+ modulesDefaultToBazel = false
+
+ for _, enabledProdModule := range allowlists.ProdMixedBuildsEnabledList {
+ enabledModules[enabledProdModule] = true
+ }
+ case BazelDevMode:
+ modulesDefaultToBazel = true
+
+ // Don't use partially-converted cc_library targets in mixed builds,
+ // since mixed builds would generally rely on both static and shared
+ // variants of a cc_library.
+ for staticOnlyModule, _ := range GetBp2BuildAllowList().ccLibraryStaticOnly {
+ disabledModules[staticOnlyModule] = true
+ }
+ for _, disabledDevModule := range allowlists.MixedBuildsDisabledList {
+ disabledModules[disabledDevModule] = true
+ }
+ default:
return noopBazelContext{}, nil
}
@@ -352,24 +375,12 @@
return nil, err
}
- // TODO(cparsons): Use a different allowlist depending on prod vs. dev
- // bazel mode.
- disabledModules := map[string]bool{}
- // Don't use partially-converted cc_library targets in mixed builds,
- // since mixed builds would generally rely on both static and shared
- // variants of a cc_library.
- for staticOnlyModule, _ := range GetBp2BuildAllowList().ccLibraryStaticOnly {
- disabledModules[staticOnlyModule] = true
- }
- for _, disabledDevModule := range allowlists.MixedBuildsDisabledList {
- disabledModules[disabledDevModule] = true
- }
-
return &bazelContext{
bazelRunner: &builtinBazelRunner{},
paths: p,
requests: make(map[cqueryKey]bool),
- modulesDefaultToBazel: true,
+ modulesDefaultToBazel: modulesDefaultToBazel,
+ bazelEnabledModules: enabledModules,
bazelDisabledModules: disabledModules,
}, nil
}
diff --git a/android/bazel_test.go b/android/bazel_test.go
index 98f0a46..b578cca 100644
--- a/android/bazel_test.go
+++ b/android/bazel_test.go
@@ -158,7 +158,7 @@
type TestBazelConversionContext struct {
omc bazel.OtherModuleTestContext
- allowlist bp2BuildConversionAllowlist
+ allowlist Bp2BuildConversionAllowlist
errors []string
}
@@ -183,7 +183,7 @@
func (bcc *TestBazelConversionContext) Config() Config {
return Config{
&config{
- bp2buildPackageConfig: bcc.allowlist,
+ Bp2buildPackageConfig: bcc.allowlist,
},
}
}
@@ -202,7 +202,7 @@
shouldConvert bool
expectedErrors []string
module TestBazelModule
- allowlist bp2BuildConversionAllowlist
+ allowlist Bp2BuildConversionAllowlist
}{
{
description: "allowlist enables module",
@@ -215,7 +215,7 @@
},
BazelModuleBase: bazelableBazelModuleBase,
},
- allowlist: bp2BuildConversionAllowlist{
+ allowlist: Bp2BuildConversionAllowlist{
moduleAlwaysConvert: map[string]bool{
"foo": true,
},
@@ -233,7 +233,7 @@
},
BazelModuleBase: bazelableBazelModuleBase,
},
- allowlist: bp2BuildConversionAllowlist{
+ allowlist: Bp2BuildConversionAllowlist{
moduleAlwaysConvert: map[string]bool{
"foo": true,
},
@@ -254,7 +254,7 @@
},
BazelModuleBase: bazelableBazelModuleBase,
},
- allowlist: bp2BuildConversionAllowlist{
+ allowlist: Bp2BuildConversionAllowlist{
moduleAlwaysConvert: map[string]bool{
"foo": true,
},
@@ -264,27 +264,6 @@
},
},
{
- description: "module in allowlist and existing BUILD file",
- shouldConvert: false,
- expectedErrors: []string{"A module cannot be in a directory listed in keepExistingBuildFile and also be in moduleAlwaysConvert. Directory: 'existing/build/dir'"},
- module: TestBazelModule{
- TestModuleInfo: bazel.TestModuleInfo{
- ModuleName: "foo",
- Typ: "rule1",
- Dir: "existing/build/dir",
- },
- BazelModuleBase: bazelableBazelModuleBase,
- },
- allowlist: bp2BuildConversionAllowlist{
- moduleAlwaysConvert: map[string]bool{
- "foo": true,
- },
- keepExistingBuildFile: map[string]bool{
- "existing/build/dir": true,
- },
- },
- },
- {
description: "module allowlist and enabled directory",
shouldConvert: false,
expectedErrors: []string{"A module cannot be in a directory marked Bp2BuildDefaultTrue or Bp2BuildDefaultTrueRecursively and also be in moduleAlwaysConvert. Directory: 'existing/build/dir'"},
@@ -296,7 +275,7 @@
},
BazelModuleBase: bazelableBazelModuleBase,
},
- allowlist: bp2BuildConversionAllowlist{
+ allowlist: Bp2BuildConversionAllowlist{
moduleAlwaysConvert: map[string]bool{
"foo": true,
},
@@ -317,7 +296,7 @@
},
BazelModuleBase: bazelableBazelModuleBase,
},
- allowlist: bp2BuildConversionAllowlist{
+ allowlist: Bp2BuildConversionAllowlist{
moduleAlwaysConvert: map[string]bool{
"foo": true,
},
@@ -344,7 +323,7 @@
},
},
},
- allowlist: bp2BuildConversionAllowlist{
+ allowlist: Bp2BuildConversionAllowlist{
moduleAlwaysConvert: map[string]bool{
"foo": true,
},
diff --git a/android/config.go b/android/config.go
index 5ca9420..745410f 100644
--- a/android/config.go
+++ b/android/config.go
@@ -96,7 +96,6 @@
// Use bazel during analysis of build modules from an allowlist carefully
// curated by the build team to be proven stable.
- // TODO(cparsons): Implement this mode.
BazelProdMode
)
@@ -190,7 +189,7 @@
mockBpList string
BuildMode SoongBuildMode
- bp2buildPackageConfig bp2BuildConversionAllowlist
+ Bp2buildPackageConfig Bp2BuildConversionAllowlist
Bp2buildSoongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions
// If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
@@ -481,17 +480,9 @@
config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
}
- // Checking USE_BAZEL_ANALYSIS must be done here instead of in the caller, so
- // that we can invoke IsEnvTrue (which also registers the env var as a
- // dependency of the build).
- // TODO(cparsons): Remove this hack once USE_BAZEL_ANALYSIS is removed.
- if buildMode == AnalysisNoBazel && config.IsEnvTrue("USE_BAZEL_ANALYSIS") {
- buildMode = BazelDevMode
- }
-
config.BuildMode = buildMode
config.BazelContext, err = NewBazelContext(config)
- config.bp2buildPackageConfig = GetBp2BuildAllowList()
+ config.Bp2buildPackageConfig = GetBp2BuildAllowList()
return Config{config}, err
}
@@ -678,9 +669,7 @@
// DeviceProduct returns the current product target. There could be multiple of
// these per device type.
//
-// NOTE: Do not base conditional logic on this value. It may break product
-//
-// inheritance.
+// NOTE: Do not base conditional logic on this value. It may break product inheritance.
func (c *config) DeviceProduct() string {
return *c.productVariables.DeviceProduct
}
@@ -1630,6 +1619,10 @@
return uncheckedFinalApiLevel(apiLevel)
}
+func (c *deviceConfig) BuildBrokenClangProperty() bool {
+ return c.config.productVariables.BuildBrokenClangProperty
+}
+
func (c *deviceConfig) BuildBrokenEnforceSyspropOwner() bool {
return c.config.productVariables.BuildBrokenEnforceSyspropOwner
}
diff --git a/android/filegroup.go b/android/filegroup.go
index 7d39238..e609f63 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -16,6 +16,7 @@
import (
"path/filepath"
+ "regexp"
"strings"
"android/soong/bazel"
@@ -37,6 +38,34 @@
return ctx.OtherModuleType(m) == "filegroup"
}
+var (
+ // ignoring case, checks for proto or protos as an independent word in the name, whether at the
+ // beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
+ filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")
+ filegroupLikelyAidlPattern = regexp.MustCompile("(?i)(^|[^a-z])aidl([^a-z]|$)")
+
+ ProtoSrcLabelPartition = bazel.LabelPartition{
+ Extensions: []string{".proto"},
+ LabelMapper: isFilegroupWithPattern(filegroupLikelyProtoPattern),
+ }
+ AidlSrcLabelPartition = bazel.LabelPartition{
+ Extensions: []string{".aidl"},
+ LabelMapper: isFilegroupWithPattern(filegroupLikelyAidlPattern),
+ }
+)
+
+func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper {
+ return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
+ m, exists := ctx.ModuleFromName(label.OriginalModuleName)
+ labelStr := label.Label
+ if !exists || !IsFilegroup(ctx, m) {
+ return labelStr, false
+ }
+ likelyMatched := pattern.MatchString(label.OriginalModuleName)
+ return labelStr, likelyMatched
+ }
+}
+
// https://docs.bazel.build/versions/master/be/general.html#filegroup
type bazelFilegroupAttributes struct {
Srcs bazel.LabelListAttribute
@@ -232,3 +261,16 @@
return fg.GetBazelLabel(ctx, fg)
}
}
+
+// Given a name in srcs prop, check to see if the name references a filegroup
+// and the filegroup is converted to aidl_library
+func IsConvertedToAidlLibrary(ctx BazelConversionPathContext, name string) bool {
+ if module, ok := ctx.ModuleFromName(name); ok {
+ if IsFilegroup(ctx, module) {
+ if fg, ok := module.(Bp2buildAidlLibrary); ok {
+ return fg.ShouldConvertToAidlLibrary(ctx)
+ }
+ }
+ }
+ return false
+}
diff --git a/android/fixture.go b/android/fixture.go
index f718935..f33e718 100644
--- a/android/fixture.go
+++ b/android/fixture.go
@@ -642,6 +642,20 @@
NinjaDeps []string
}
+type TestPathContext struct {
+ *TestResult
+}
+
+var _ PathContext = &TestPathContext{}
+
+func (t *TestPathContext) Config() Config {
+ return t.TestResult.Config
+}
+
+func (t *TestPathContext) AddNinjaFileDeps(deps ...string) {
+ panic("unimplemented")
+}
+
func createFixture(t *testing.T, buildDir string, preparers []*simpleFixturePreparer) Fixture {
config := TestConfig(buildDir, nil, "", nil)
ctx := NewTestContext(config)
diff --git a/android/paths.go b/android/paths.go
index 74d9f13..1f69125 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -1978,6 +1978,18 @@
return testPath{basePath{path: p, rel: p}}
}
+func PathForTestingWithRel(path, rel string) Path {
+ p, err := validateSafePath(path, rel)
+ if err != nil {
+ panic(err)
+ }
+ r, err := validatePath(rel)
+ if err != nil {
+ panic(err)
+ }
+ return testPath{basePath{path: p, rel: r}}
+}
+
// PathsForTesting returns a Path constructed from each element in strs. It should only be used from within tests.
func PathsForTesting(strs ...string) Paths {
p := make(Paths, len(strs))
diff --git a/android/proto.go b/android/proto.go
index c3759f8..8ad16a6 100644
--- a/android/proto.go
+++ b/android/proto.go
@@ -16,7 +16,6 @@
import (
"android/soong/bazel"
- "regexp"
"strings"
"github.com/google/blueprint"
@@ -27,14 +26,6 @@
canonicalPathFromRootDefault = true
)
-var (
- // ignoring case, checks for proto or protos as an independent word in the name, whether at the
- // beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
- filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")
-
- ProtoSrcLabelPartition = bazel.LabelPartition{Extensions: []string{".proto"}, LabelMapper: isProtoFilegroup}
-)
-
// TODO(ccross): protos are often used to communicate between multiple modules. If the only
// way to convert a proto to source is to reference it as a source file, and external modules cannot
// reference source files in other modules, then every module that owns a proto file will need to
@@ -213,13 +204,3 @@
return info, true
}
-
-func isProtoFilegroup(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
- m, exists := ctx.ModuleFromName(label.OriginalModuleName)
- labelStr := label.Label
- if !exists || !IsFilegroup(ctx, m) {
- return labelStr, false
- }
- likelyProtos := filegroupLikelyProtoPattern.MatchString(label.OriginalModuleName)
- return labelStr, likelyProtos
-}
diff --git a/android/testing.go b/android/testing.go
index ef5e5a9..3708501 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -213,8 +213,8 @@
ctx.finalDeps = append(ctx.finalDeps, f)
}
-func (ctx *TestContext) RegisterBp2BuildConfig(config bp2BuildConversionAllowlist) {
- ctx.config.bp2buildPackageConfig = config
+func (ctx *TestContext) RegisterBp2BuildConfig(config Bp2BuildConversionAllowlist) {
+ ctx.config.Bp2buildPackageConfig = config
}
// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
diff --git a/android/variable.go b/android/variable.go
index 2d7b0bf..7a080fe 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -430,6 +430,7 @@
ShippingApiLevel *string `json:",omitempty"`
+ BuildBrokenClangProperty bool `json:",omitempty"`
BuildBrokenDepfile *bool `json:",omitempty"`
BuildBrokenEnforceSyspropOwner bool `json:",omitempty"`
BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"`
diff --git a/bazel/configurability.go b/bazel/configurability.go
index 0ab49eb..d9b0a12 100644
--- a/bazel/configurability.go
+++ b/bazel/configurability.go
@@ -27,7 +27,7 @@
archX86_64 = "x86_64"
// OsType names in arch.go
- osAndroid = "android"
+ OsAndroid = "android"
osDarwin = "darwin"
osLinux = "linux_glibc"
osLinuxMusl = "linux_musl"
@@ -64,6 +64,9 @@
ConditionsDefaultSelectKey = "//conditions:default"
productVariableBazelPackage = "//build/bazel/product_variables"
+
+ AndroidAndInApex = "android-in_apex"
+ AndroidAndNonApex = "android-non_apex"
)
var (
@@ -85,7 +88,7 @@
// A map of target operating systems to the Bazel label of the
// constraint_value for the @platforms//os:os constraint_setting
platformOsMap = map[string]string{
- osAndroid: "//build/bazel/platforms/os:android",
+ OsAndroid: "//build/bazel/platforms/os:android",
osDarwin: "//build/bazel/platforms/os:darwin",
osLinux: "//build/bazel/platforms/os:linux",
osLinuxMusl: "//build/bazel/platforms/os:linux_musl",
@@ -120,7 +123,7 @@
// TODO(cparsons): Source from arch.go; this task is nontrivial, as it currently results
// in a cyclic dependency.
osToArchMap = map[string][]string{
- osAndroid: {archArm, archArm64, archX86, archX86_64},
+ OsAndroid: {archArm, archArm64, archX86, archX86_64},
osLinux: {archX86, archX86_64},
osLinuxMusl: {archX86, archX86_64},
osDarwin: {archArm64, archX86_64},
@@ -128,6 +131,12 @@
// TODO(cparsons): According to arch.go, this should contain archArm, archArm64, as well.
osWindows: {archX86, archX86_64},
}
+
+ osAndInApexMap = map[string]string{
+ AndroidAndInApex: "//build/bazel/rules/apex:android-in_apex",
+ AndroidAndNonApex: "//build/bazel/rules/apex:android-non_apex",
+ ConditionsDefaultConfigKey: ConditionsDefaultSelectKey,
+ }
)
// basic configuration types
@@ -139,6 +148,7 @@
os
osArch
productVariables
+ osAndInApex
)
func osArchString(os string, arch string) string {
@@ -152,6 +162,7 @@
os: "os",
osArch: "arch_os",
productVariables: "product_variables",
+ osAndInApex: "os_in_apex",
}[ct]
}
@@ -175,6 +186,10 @@
}
case productVariables:
// do nothing
+ case osAndInApex:
+ if _, ok := osAndInApexMap[config]; !ok {
+ panic(fmt.Errorf("Unknown os+in_apex config: %s", config))
+ }
default:
panic(fmt.Errorf("Unrecognized ConfigurationType %d", ct))
}
@@ -198,6 +213,8 @@
return ConditionsDefaultSelectKey
}
return fmt.Sprintf("%s:%s", productVariableBazelPackage, config)
+ case osAndInApex:
+ return osAndInApexMap[config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationType %d", ca.configurationType))
}
@@ -212,6 +229,8 @@
OsConfigurationAxis = ConfigurationAxis{configurationType: os}
// An axis for arch+os-specific configurations
OsArchConfigurationAxis = ConfigurationAxis{configurationType: osArch}
+ // An axis for os+in_apex-specific configurations
+ OsAndInApexAxis = ConfigurationAxis{configurationType: osAndInApex}
)
// ProductVariableConfigurationAxis returns an axis for the given product variable
diff --git a/bazel/properties.go b/bazel/properties.go
index 963e27b..13e36b5 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -119,7 +119,7 @@
return dirs
}
-// Add inserts the label Label at the end of the LabelList.
+// Add inserts the label Label at the end of the LabelList.Includes.
func (ll *LabelList) Add(label *Label) {
if label == nil {
return
@@ -127,6 +127,14 @@
ll.Includes = append(ll.Includes, *label)
}
+// AddExclude inserts the label Label at the end of the LabelList.Excludes.
+func (ll *LabelList) AddExclude(label *Label) {
+ if label == nil {
+ return
+ }
+ ll.Excludes = append(ll.Excludes, *label)
+}
+
// Append appends the fields of other labelList to the corresponding fields of ll.
func (ll *LabelList) Append(other LabelList) {
if len(ll.Includes) > 0 || len(other.Includes) > 0 {
@@ -137,6 +145,30 @@
}
}
+// Partition splits a LabelList into two LabelLists depending on the return value
+// of the predicate.
+// This function preserves the Includes and Excludes, but it does not provide
+// that information to the partition function.
+func (ll *LabelList) Partition(predicate func(label Label) bool) (LabelList, LabelList) {
+ predicated := LabelList{}
+ unpredicated := LabelList{}
+ for _, include := range ll.Includes {
+ if predicate(include) {
+ predicated.Add(&include)
+ } else {
+ unpredicated.Add(&include)
+ }
+ }
+ for _, exclude := range ll.Excludes {
+ if predicate(exclude) {
+ predicated.AddExclude(&exclude)
+ } else {
+ unpredicated.AddExclude(&exclude)
+ }
+ }
+ return predicated, unpredicated
+}
+
// UniqueSortedBazelLabels takes a []Label and deduplicates the labels, and returns
// the slice in a sorted order.
func UniqueSortedBazelLabels(originalLabels []Label) []Label {
@@ -332,7 +364,7 @@
switch axis.configurationType {
case noConfig:
la.Value = &value
- case arch, os, osArch, productVariables:
+ case arch, os, osArch, productVariables, osAndInApex:
if la.ConfigurableValues == nil {
la.ConfigurableValues = make(configurableLabels)
}
@@ -348,7 +380,7 @@
switch axis.configurationType {
case noConfig:
return la.Value
- case arch, os, osArch, productVariables:
+ case arch, os, osArch, productVariables, osAndInApex:
return la.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
@@ -424,7 +456,7 @@
switch axis.configurationType {
case noConfig:
ba.Value = value
- case arch, os, osArch, productVariables:
+ case arch, os, osArch, productVariables, osAndInApex:
if ba.ConfigurableValues == nil {
ba.ConfigurableValues = make(configurableBools)
}
@@ -540,7 +572,7 @@
switch axis.configurationType {
case noConfig:
return ba.Value
- case arch, os, osArch, productVariables:
+ case arch, os, osArch, productVariables, osAndInApex:
if v, ok := ba.ConfigurableValues[axis][config]; ok {
return &v
} else {
@@ -676,7 +708,7 @@
switch axis.configurationType {
case noConfig:
lla.Value = list
- case arch, os, osArch, productVariables:
+ case arch, os, osArch, productVariables, osAndInApex:
if lla.ConfigurableValues == nil {
lla.ConfigurableValues = make(configurableLabelLists)
}
@@ -692,8 +724,8 @@
switch axis.configurationType {
case noConfig:
return lla.Value
- case arch, os, osArch, productVariables:
- return lla.ConfigurableValues[axis][config]
+ case arch, os, osArch, productVariables, osAndInApex:
+ return (lla.ConfigurableValues[axis][config])
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
}
@@ -822,6 +854,29 @@
}
}
+// Partition splits a LabelListAttribute into two LabelListAttributes depending
+// on the return value of the predicate.
+// This function preserves the Includes and Excludes, but it does not provide
+// that information to the partition function.
+func (lla LabelListAttribute) Partition(predicate func(label Label) bool) (LabelListAttribute, LabelListAttribute) {
+ predicated := LabelListAttribute{}
+ unpredicated := LabelListAttribute{}
+
+ valuePartitionTrue, valuePartitionFalse := lla.Value.Partition(predicate)
+ predicated.SetValue(valuePartitionTrue)
+ unpredicated.SetValue(valuePartitionFalse)
+
+ for axis, selectValueLabelLists := range lla.ConfigurableValues {
+ for config, labelList := range selectValueLabelLists {
+ configPredicated, configUnpredicated := labelList.Partition(predicate)
+ predicated.SetSelectValue(axis, config, configPredicated)
+ unpredicated.SetSelectValue(axis, config, configUnpredicated)
+ }
+ }
+
+ return predicated, unpredicated
+}
+
// OtherModuleContext is a limited context that has methods with information about other modules.
type OtherModuleContext interface {
ModuleFromName(name string) (blueprint.Module, bool)
@@ -1189,7 +1244,7 @@
switch axis.configurationType {
case noConfig:
sla.Value = list
- case arch, os, osArch, productVariables:
+ case arch, os, osArch, productVariables, osAndInApex:
if sla.ConfigurableValues == nil {
sla.ConfigurableValues = make(configurableStringLists)
}
@@ -1205,7 +1260,7 @@
switch axis.configurationType {
case noConfig:
return sla.Value
- case arch, os, osArch, productVariables:
+ case arch, os, osArch, productVariables, osAndInApex:
return sla.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
diff --git a/bazel/properties_test.go b/bazel/properties_test.go
index 7b76b74..dc4d5b0 100644
--- a/bazel/properties_test.go
+++ b/bazel/properties_test.go
@@ -310,6 +310,134 @@
}
}
+func TestLabelListAttributePartition(t *testing.T) {
+ testCases := []struct {
+ name string
+ input LabelListAttribute
+ predicated LabelListAttribute
+ unpredicated LabelListAttribute
+ predicate func(label Label) bool
+ }{
+ {
+ name: "move all to predicated partition",
+ input: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ )),
+ predicated: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ )),
+ unpredicated: LabelListAttribute{},
+ predicate: func(label Label) bool {
+ return true
+ },
+ },
+ {
+ name: "move all to unpredicated partition",
+ input: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ )),
+ predicated: LabelListAttribute{},
+ unpredicated: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ )),
+ predicate: func(label Label) bool {
+ return false
+ },
+ },
+ {
+ name: "partition includes and excludes",
+ input: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ )),
+ predicated: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "keep2"},
+ []string{"keep1", "keep2"},
+ )),
+ unpredicated: MakeLabelListAttribute(makeLabelList(
+ []string{"throw1", "throw2"},
+ []string{"throw1", "throw2"},
+ )),
+ predicate: func(label Label) bool {
+ return strings.HasPrefix(label.Label, "keep")
+ },
+ },
+ {
+ name: "partition excludes only",
+ input: MakeLabelListAttribute(makeLabelList(
+ []string{},
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ )),
+ predicated: MakeLabelListAttribute(makeLabelList(
+ []string{},
+ []string{"keep1", "keep2"},
+ )),
+ unpredicated: MakeLabelListAttribute(makeLabelList(
+ []string{},
+ []string{"throw1", "throw2"},
+ )),
+ predicate: func(label Label) bool {
+ return strings.HasPrefix(label.Label, "keep")
+ },
+ },
+ {
+ name: "partition includes only",
+ input: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "throw1", "keep2", "throw2"},
+ []string{},
+ )),
+ predicated: MakeLabelListAttribute(makeLabelList(
+ []string{"keep1", "keep2"},
+ []string{},
+ )),
+ unpredicated: MakeLabelListAttribute(makeLabelList(
+ []string{"throw1", "throw2"},
+ []string{},
+ )),
+ predicate: func(label Label) bool {
+ return strings.HasPrefix(label.Label, "keep")
+ },
+ },
+ {
+ name: "empty partition",
+ input: MakeLabelListAttribute(makeLabelList([]string{}, []string{})),
+ predicated: LabelListAttribute{},
+ unpredicated: LabelListAttribute{},
+ predicate: func(label Label) bool {
+ return true
+ },
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ predicated, unpredicated := tc.input.Partition(tc.predicate)
+ if !predicated.Value.Equals(tc.predicated.Value) {
+ t.Errorf("expected predicated labels to be %v; got %v", tc.predicated, predicated)
+ }
+ for axis, configs := range predicated.ConfigurableValues {
+ tcConfigs, ok := tc.predicated.ConfigurableValues[axis]
+ if !ok || !reflect.DeepEqual(configs, tcConfigs) {
+ t.Errorf("expected predicated labels to be %v; got %v", tc.predicated, predicated)
+ }
+ }
+ if !unpredicated.Value.Equals(tc.unpredicated.Value) {
+ t.Errorf("expected unpredicated labels to be %v; got %v", tc.unpredicated, unpredicated)
+ }
+ for axis, configs := range unpredicated.ConfigurableValues {
+ tcConfigs, ok := tc.unpredicated.ConfigurableValues[axis]
+ if !ok || !reflect.DeepEqual(configs, tcConfigs) {
+ t.Errorf("expected unpredicated labels to be %v; got %v", tc.unpredicated, unpredicated)
+ }
+ }
+ })
+ }
+}
+
// labelAddSuffixForTypeMapper returns a LabelMapper that adds suffix to label name for modules of
// typ
func labelAddSuffixForTypeMapper(suffix, typ string) LabelMapper {
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index 242ea1e..8de6d18 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -373,6 +373,15 @@
if generateFilegroups {
// Add a filegroup target that exposes all sources in the subtree of this package
// NOTE: This also means we generate a BUILD file for every Android.bp file (as long as it has at least one module)
+ //
+ // This works because: https://bazel.build/reference/be/functions#exports_files
+ // "As a legacy behaviour, also files mentioned as input to a rule are exported with the
+ // default visibility until the flag --incompatible_no_implicit_file_export is flipped. However, this behavior
+ // should not be relied upon and actively migrated away from."
+ //
+ // TODO(b/198619163): We should change this to export_files(glob(["**/*"])) instead, but doing that causes these errors:
+ // "Error in exports_files: generated label '//external/avb:avbtool' conflicts with existing py_binary rule"
+ // So we need to solve all the "target ... is both a rule and a file" warnings first.
for dir, _ := range dirs {
buildFileToTargets[dir] = append(buildFileToTargets[dir], BazelTarget{
name: "bp2build_all_srcs",
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 1f69b5a..9e449eb 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -581,3 +581,32 @@
},
})
}
+
+func TestCcBinaryWithInstructionSet(t *testing.T) {
+ runCcBinaryTests(t, ccBinaryBp2buildTestCase{
+ description: "instruction set",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ }
+ }
+}
+`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "features": `select({
+ "//build/bazel/platforms/arch:arm": [
+ "arm_isa_arm",
+ "-arm_isa_thumb",
+ ],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ },
+ },
+ },
+ })
+}
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index f6d5067..024d4e0 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -1301,10 +1301,10 @@
"additional_linker_inputs": true,
"linkopts": true,
"strip": true,
- "stubs_symbol_file": true,
- "stubs_versions": true,
"inject_bssl_hash": true,
+ "has_stubs": true,
}
+
sharedAttrs := AttrNameToString{}
staticAttrs := AttrNameToString{}
for key, val := range attrs {
@@ -1321,6 +1321,26 @@
return []string{staticTarget, sharedTarget}
}
+func makeCcStubSuiteTargets(name string, attrs AttrNameToString) string {
+ if _, hasStubs := attrs["stubs_symbol_file"]; !hasStubs {
+ return ""
+ }
+ STUB_SUITE_ATTRS := map[string]string{
+ "stubs_symbol_file": "symbol_file",
+ "stubs_versions": "versions",
+ "soname": "soname",
+ "source_library": "source_library",
+ }
+
+ stubSuiteAttrs := AttrNameToString{}
+ for key, _ := range attrs {
+ if _, stubSuiteAttr := STUB_SUITE_ATTRS[key]; stubSuiteAttr {
+ stubSuiteAttrs[STUB_SUITE_ATTRS[key]] = attrs[key]
+ }
+ }
+ return makeBazelTarget("cc_stub_suite", name+"_stub_libs", stubSuiteAttrs)
+}
+
func TestCCLibraryNoLibCrtFalse(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library",
@@ -2424,6 +2444,19 @@
}
func TestCcLibraryStubs(t *testing.T) {
+ expectedBazelTargets := makeCcLibraryTargets("a", AttrNameToString{
+ "has_stubs": `True`,
+ })
+ expectedBazelTargets = append(expectedBazelTargets, makeCcStubSuiteTargets("a", AttrNameToString{
+ "soname": `"a.so"`,
+ "source_library": `":a"`,
+ "stubs_symbol_file": `"a.map.txt"`,
+ "stubs_versions": `[
+ "28",
+ "29",
+ "current",
+ ]`,
+ }))
runCcLibraryTestCase(t, Bp2buildTestCase{
Description: "cc_library stubs",
ModuleTypeUnderTest: "cc_library",
@@ -2439,15 +2472,8 @@
}
`,
},
- Blueprint: soongCcLibraryPreamble,
- ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
- "stubs_symbol_file": `"a.map.txt"`,
- "stubs_versions": `[
- "28",
- "29",
- "current",
- ]`,
- }),
+ Blueprint: soongCcLibraryPreamble,
+ ExpectedBazelTargets: expectedBazelTargets,
},
)
}
@@ -2540,3 +2566,109 @@
},
})
}
+
+func TestCcLibraryWithInstructionSet(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `cc_library {
+ name: "foo",
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ }
+ }
+}
+`,
+ ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{
+ "features": `select({
+ "//build/bazel/platforms/arch:arm": [
+ "arm_isa_arm",
+ "-arm_isa_thumb",
+ ],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ }),
+ })
+}
+
+func TestCcLibraryWithAidlSrcs(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library with aidl srcs",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `
+filegroup {
+ name: "A_aidl",
+ srcs: ["aidl/A.aidl"],
+ path: "aidl",
+}
+cc_library {
+ name: "foo",
+ srcs: [
+ ":A_aidl",
+ "B.aidl",
+ ],
+}`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{
+ "srcs": `["aidl/A.aidl"]`,
+ "strip_import_prefix": `"aidl"`,
+ }),
+ makeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{
+ "srcs": `["B.aidl"]`,
+ }),
+ makeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
+ "deps": `[
+ ":A_aidl",
+ ":foo_aidl_library",
+ ]`,
+ }),
+ makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "whole_archive_deps": `[":foo_cc_aidl_library"]`,
+ "local_includes": `["."]`,
+ }),
+ makeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "whole_archive_deps": `[":foo_cc_aidl_library"]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
+
+func TestCcLibraryWithNonAdjacentAidlFilegroup(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library with non aidl filegroup",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
+ "path/to/A/Android.bp": `
+filegroup {
+ name: "A_aidl",
+ srcs: ["aidl/A.aidl"],
+ path: "aidl",
+}`,
+ },
+ Blueprint: `
+cc_library {
+ name: "foo",
+ srcs: [
+ ":A_aidl",
+ ],
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
+ "deps": `["//path/to/A:A_aidl"]`,
+ }),
+ makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "whole_archive_deps": `[":foo_cc_aidl_library"]`,
+ "local_includes": `["."]`,
+ }),
+ makeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "whole_archive_deps": `[":foo_cc_aidl_library"]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index de57e5a..7a44f69 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -485,12 +485,7 @@
},
Blueprint: soongCcLibraryPreamble,
ExpectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "a", AttrNameToString{
- "stubs_symbol_file": `"a.map.txt"`,
- "stubs_versions": `[
- "28",
- "29",
- "current",
- ]`,
+ "has_stubs": `True`,
}),
},
},
diff --git a/bp2build/conversion.go b/bp2build/conversion.go
index 8cf9bea..d98b6a3 100644
--- a/bp2build/conversion.go
+++ b/bp2build/conversion.go
@@ -2,7 +2,6 @@
import (
"encoding/json"
- "fmt"
"reflect"
"strings"
@@ -80,21 +79,14 @@
files = append(files, newFile(bazelRulesSubDir, "soong_module.bzl", generateSoongModuleBzl(ruleShims)))
}
- files = append(files, createBuildFiles(cfg, buildToTargets, mode)...)
+ files = append(files, createBuildFiles(buildToTargets, mode)...)
return files
}
-func createBuildFiles(cfg android.Config, buildToTargets map[string]BazelTargets, mode CodegenMode) []BazelFile {
+func createBuildFiles(buildToTargets map[string]BazelTargets, mode CodegenMode) []BazelFile {
files := make([]BazelFile, 0, len(buildToTargets))
- warnNotWriting := cfg.IsEnvTrue("BP2BUILD_VERBOSE")
for _, dir := range android.SortedStringKeys(buildToTargets) {
- if mode == Bp2Build && android.ShouldKeepExistingBuildFileForDir(dir) {
- if warnNotWriting {
- fmt.Printf("[bp2build] Not writing generated BUILD file for dir: '%s'\n", dir)
- }
- continue
- }
targets := buildToTargets[dir]
targets.sort()
diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go
index 7fa19d9..b57cf35 100644
--- a/bp2build/java_library_conversion_test.go
+++ b/bp2build/java_library_conversion_test.go
@@ -372,3 +372,165 @@
ExpectedBazelTargets: []string{},
})
}
+
+func TestJavaLibraryAidl(t *testing.T) {
+ runJavaLibraryTestCase(t, Bp2buildTestCase{
+ Description: "Java library - aidl creates separate dependency",
+ ModuleTypeUnderTest: "java_library",
+ ModuleTypeUnderTestFactory: java.LibraryFactory,
+ Blueprint: `java_library {
+ name: "example_lib",
+ srcs: [
+ "a.java",
+ "b.java",
+ "a.aidl",
+ "b.aidl",
+ ],
+ bazel_module: { bp2build_available: true },
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("aidl_library", "example_lib_aidl_library", AttrNameToString{
+ "srcs": `[
+ "a.aidl",
+ "b.aidl",
+ ]`,
+ }),
+ makeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{
+ "deps": `[":example_lib_aidl_library"]`,
+ }),
+ makeBazelTarget("java_library", "example_lib", AttrNameToString{
+ "deps": `[":example_lib_java_aidl_library"]`,
+ "exports": `[":example_lib_java_aidl_library"]`,
+ "srcs": `[
+ "a.java",
+ "b.java",
+ ]`,
+ }),
+ }})
+}
+
+func TestJavaLibraryAidlSrcsNoFileGroup(t *testing.T) {
+ runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
+ Description: "Java library - aidl filegroup is parsed",
+ ModuleTypeUnderTest: "java_library",
+ ModuleTypeUnderTestFactory: java.LibraryFactory,
+ Blueprint: `
+java_library {
+ name: "example_lib",
+ srcs: [
+ "a.java",
+ "b.aidl",
+ ],
+ bazel_module: { bp2build_available: true },
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("aidl_library", "example_lib_aidl_library", AttrNameToString{
+ "srcs": `["b.aidl"]`,
+ }),
+ makeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{
+ "deps": `[":example_lib_aidl_library"]`,
+ }),
+ makeBazelTarget("java_library", "example_lib", AttrNameToString{
+ "deps": `[":example_lib_java_aidl_library"]`,
+ "exports": `[":example_lib_java_aidl_library"]`,
+ "srcs": `["a.java"]`,
+ }),
+ },
+ }, func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ })
+}
+
+func TestJavaLibraryAidlFilegroup(t *testing.T) {
+ runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
+ Description: "Java library - aidl filegroup is parsed",
+ ModuleTypeUnderTest: "java_library",
+ ModuleTypeUnderTestFactory: java.LibraryFactory,
+ Blueprint: `
+filegroup {
+ name: "random_other_files",
+ srcs: [
+ "a.java",
+ "b.java",
+ ],
+}
+filegroup {
+ name: "aidl_files",
+ srcs: [
+ "a.aidl",
+ "b.aidl",
+ ],
+}
+java_library {
+ name: "example_lib",
+ srcs: [
+ "a.java",
+ "b.java",
+ ":aidl_files",
+ ":random_other_files",
+ ],
+ bazel_module: { bp2build_available: true },
+}`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTargetNoRestrictions("aidl_library", "aidl_files", AttrNameToString{
+ "srcs": `[
+ "a.aidl",
+ "b.aidl",
+ ]`,
+ }),
+ makeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{
+ "deps": `[":aidl_files"]`,
+ }),
+ makeBazelTarget("java_library", "example_lib", AttrNameToString{
+ "deps": `[":example_lib_java_aidl_library"]`,
+ "exports": `[":example_lib_java_aidl_library"]`,
+ "srcs": `[
+ "a.java",
+ "b.java",
+ ":random_other_files",
+ ]`,
+ }),
+ MakeBazelTargetNoRestrictions("filegroup", "random_other_files", AttrNameToString{
+ "srcs": `[
+ "a.java",
+ "b.java",
+ ]`,
+ }),
+ },
+ }, func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ })
+}
+
+func TestJavaLibraryAidlNonAdjacentAidlFilegroup(t *testing.T) {
+ runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
+ Description: "java_library with non adjacent aidl filegroup",
+ ModuleTypeUnderTest: "java_library",
+ ModuleTypeUnderTestFactory: java.LibraryFactory,
+ Filesystem: map[string]string{
+ "path/to/A/Android.bp": `
+filegroup {
+ name: "A_aidl",
+ srcs: ["aidl/A.aidl"],
+ path: "aidl",
+}`,
+ },
+ Blueprint: `
+java_library {
+ name: "foo",
+ srcs: [
+ ":A_aidl",
+ ],
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("java_aidl_library", "foo_java_aidl_library", AttrNameToString{
+ "deps": `["//path/to/A:A_aidl"]`,
+ }),
+ makeBazelTarget("java_library", "foo", AttrNameToString{
+ "exports": `[":foo_java_aidl_library"]`,
+ }),
+ },
+ }, func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ })
+}
diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go
index 78e7b0e..023ec96 100644
--- a/bp2build/symlink_forest.go
+++ b/bp2build/symlink_forest.go
@@ -1,12 +1,27 @@
+// Copyright 2022 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"
"fmt"
"io/ioutil"
"os"
"path/filepath"
+ "regexp"
+ "android/soong/android"
"android/soong/shared"
)
@@ -58,6 +73,57 @@
return result
}
+func mergeBuildFiles(output string, srcBuildFile string, generatedBuildFile string, verbose bool) error {
+
+ srcBuildFileContent, err := os.ReadFile(srcBuildFile)
+ if err != nil {
+ return err
+ }
+
+ generatedBuildFileContent, err := os.ReadFile(generatedBuildFile)
+ if err != nil {
+ return err
+ }
+
+ // There can't be a package() call in both the source and generated BUILD files.
+ // bp2build will generate a package() call for licensing information, but if
+ // there's no licensing information, it will still generate a package() call
+ // that just sets default_visibility=public. If the handcrafted build file
+ // also has a package() call, we'll allow it to override the bp2build
+ // generated one if it doesn't have any licensing information. If the bp2build
+ // one has licensing information and the handcrafted one exists, we'll leave
+ // them both in for bazel to throw an error.
+ packageRegex := regexp.MustCompile(`(?m)^package\s*\(`)
+ packageDefaultVisibilityRegex := regexp.MustCompile(`(?m)^package\s*\(\s*default_visibility\s*=\s*\[\s*"//visibility:public",?\s*]\s*\)`)
+ if packageRegex.Find(srcBuildFileContent) != nil {
+ if verbose && packageDefaultVisibilityRegex.Find(generatedBuildFileContent) != nil {
+ fmt.Fprintf(os.Stderr, "Both '%s' and '%s' have a package() target, removing the first one\n",
+ generatedBuildFile, srcBuildFile)
+ }
+ generatedBuildFileContent = packageDefaultVisibilityRegex.ReplaceAll(generatedBuildFileContent, []byte{})
+ }
+
+ outFile, err := os.Create(output)
+ if err != nil {
+ return err
+ }
+
+ _, err = outFile.Write(generatedBuildFileContent)
+ if err != nil {
+ return err
+ }
+
+ if generatedBuildFileContent[len(generatedBuildFileContent)-1] != '\n' {
+ _, err = outFile.WriteString("\n")
+ if err != nil {
+ return err
+ }
+ }
+
+ _, err = outFile.Write(srcBuildFileContent)
+ return err
+}
+
// Calls readdir() and returns it as a map from the basename of the files in dir
// to os.FileInfo.
func readdirToMap(dir string) map[string]os.FileInfo {
@@ -125,6 +191,17 @@
srcDirMap := readdirToMap(shared.JoinPath(topdir, srcDir))
buildFilesMap := readdirToMap(shared.JoinPath(topdir, buildFilesDir))
+ renamingBuildFile := false
+ if _, ok := srcDirMap["BUILD"]; ok {
+ if _, ok := srcDirMap["BUILD.bazel"]; !ok {
+ if _, ok := buildFilesMap["BUILD.bazel"]; ok {
+ renamingBuildFile = true
+ srcDirMap["BUILD.bazel"] = srcDirMap["BUILD"]
+ delete(srcDirMap, "BUILD")
+ }
+ }
+ }
+
allEntries := make(map[string]bool)
for n := range srcDirMap {
allEntries[n] = true
@@ -148,21 +225,28 @@
// The full paths of children in the input trees and in the output tree
forestChild := shared.JoinPath(forestDir, f)
srcChild := shared.JoinPath(srcDir, f)
+ if f == "BUILD.bazel" && renamingBuildFile {
+ srcChild = shared.JoinPath(srcDir, "BUILD")
+ }
buildFilesChild := shared.JoinPath(buildFilesDir, f)
// Descend in the exclusion tree, if there are any excludes left
- var excludeChild *node
- if exclude == nil {
- excludeChild = nil
- } else {
- excludeChild = exclude.children[f]
+ var excludeChild *node = nil
+ if exclude != nil {
+ if f == "BUILD.bazel" && renamingBuildFile {
+ excludeChild = exclude.children["BUILD"]
+ } else {
+ excludeChild = exclude.children[f]
+ }
}
srcChildEntry, sExists := srcDirMap[f]
buildFilesChildEntry, bExists := buildFilesMap[f]
- excluded := excludeChild != nil && excludeChild.excluded
- if excluded {
+ if excludeChild != nil && excludeChild.excluded {
+ if bExists {
+ symlinkIntoForest(topdir, forestChild, buildFilesChild)
+ }
continue
}
@@ -198,13 +282,15 @@
// Both are directories. Descend.
plantSymlinkForestRecursive(cfg, topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
} else if !sDir && !bDir {
- // Neither is a directory. Prioritize BUILD files generated by bp2build
- // over any BUILD file imported into external/.
- if cfg.IsEnvTrue("BP2BUILD_VERBOSE") {
- fmt.Fprintf(os.Stderr, "Both '%s' and '%s' exist, symlinking the former to '%s'\n",
- buildFilesChild, srcChild, forestChild)
+ // Neither is a directory. Merge them.
+ srcBuildFile := shared.JoinPath(topdir, srcChild)
+ generatedBuildFile := shared.JoinPath(topdir, buildFilesChild)
+ err = mergeBuildFiles(shared.JoinPath(topdir, forestChild), srcBuildFile, generatedBuildFile, cfg.IsEnvTrue("BP2BUILD_VERBOSE"))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error merging %s and %s: %s",
+ srcBuildFile, generatedBuildFile, err)
+ *okay = false
}
- symlinkIntoForest(topdir, forestChild, buildFilesChild)
} else {
// Both exist and one is a file. This is an error.
fmt.Fprintf(os.Stderr,
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 5954098..625e7ce 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -35,16 +35,18 @@
llSrcPartition = "ll"
cppSrcPartition = "cpp"
protoSrcPartition = "proto"
+ aidlSrcPartition = "aidl"
)
// 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 {
- Srcs bazel.LabelListAttribute
- Srcs_c bazel.LabelListAttribute
- Srcs_as bazel.LabelListAttribute
- Hdrs bazel.LabelListAttribute
- Copts bazel.StringListAttribute
+ Srcs bazel.LabelListAttribute
+ Srcs_c bazel.LabelListAttribute
+ Srcs_as bazel.LabelListAttribute
+ Srcs_aidl bazel.LabelListAttribute
+ Hdrs bazel.LabelListAttribute
+ Copts bazel.StringListAttribute
Deps bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute
@@ -68,10 +70,17 @@
// Convert filegroup dependencies into extension-specific filegroups filtered in the filegroup.bzl
// macro.
addSuffixForFilegroup := func(suffix string) bazel.LabelMapper {
- return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
- m, exists := ctx.ModuleFromName(label.OriginalModuleName)
+ return func(otherModuleCtx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
+
+ m, exists := otherModuleCtx.ModuleFromName(label.OriginalModuleName)
labelStr := label.Label
- if !exists || !android.IsFilegroup(ctx, m) {
+ if !exists || !android.IsFilegroup(otherModuleCtx, m) {
+ return labelStr, false
+ }
+ // If the filegroup is already converted to aidl_library, skip creating
+ // _c_srcs, _as_srcs, _cpp_srcs filegroups
+ fg, _ := m.(android.Bp2buildAidlLibrary)
+ if fg.ShouldConvertToAidlLibrary(ctx) {
return labelStr, false
}
return labelStr + suffix, true
@@ -84,6 +93,7 @@
cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
asmSrcPartition: bazel.LabelPartition{Extensions: []string{".asm"}},
+ aidlSrcPartition: android.AidlSrcLabelPartition,
// TODO(http://b/231968910): If there is ever a filegroup target that
// contains .l or .ll files we will need to find a way to add a
// LabelMapper for these that identifies these filegroups and
@@ -282,7 +292,10 @@
compilerAttributes
linkerAttributes
+ // A combination of compilerAttributes.features and linkerAttributes.features
+ features bazel.StringListAttribute
protoDependency *bazel.LabelAttribute
+ aidlDependency *bazel.LabelAttribute
}
// Convenience struct to hold all attributes parsed from compiler properties.
@@ -320,9 +333,12 @@
includes BazelIncludes
protoSrcs bazel.LabelListAttribute
+ aidlSrcs bazel.LabelListAttribute
stubsSymbolFile *string
stubsVersions bazel.StringListAttribute
+
+ features bazel.StringListAttribute
}
type filterOutFn func(string) bool
@@ -386,6 +402,13 @@
ca.absoluteIncludes.SetSelectValue(axis, config, props.Include_dirs)
ca.localIncludes.SetSelectValue(axis, config, localIncludeDirs)
+ instructionSet := proptools.StringDefault(props.Instruction_set, "")
+ if instructionSet == "arm" {
+ ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm", "-arm_isa_thumb"})
+ } else if instructionSet != "" && instructionSet != "thumb" {
+ ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet)
+ }
+
// In Soong, cflags occur on the command line before -std=<val> flag, resulting in the value being
// overridden. In Bazel we always allow overriding, via flags; however, this can cause
// incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other
@@ -438,6 +461,7 @@
partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs)
ca.protoSrcs = partitionedSrcs[protoSrcPartition]
+ ca.aidlSrcs = partitionedSrcs[aidlSrcPartition]
for p, lla := range partitionedSrcs {
// if there are no sources, there is no need for headers
@@ -470,12 +494,27 @@
}
allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs)
+
if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
anySrcs = true
}
+
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
}
+// Given a name in srcs prop, check to see if the name references a filegroup
+// and the filegroup is converted to aidl_library
+func isConvertedToAidlLibrary(ctx android.BazelConversionPathContext, name string) bool {
+ if module, ok := ctx.ModuleFromName(name); ok {
+ if android.IsFilegroup(ctx, module) {
+ if fg, ok := module.(android.Bp2buildAidlLibrary); ok {
+ return fg.ShouldConvertToAidlLibrary(ctx)
+ }
+ }
+ }
+ return false
+}
+
func bp2buildStdVal(std *string, prefix string, useGnu bool) *string {
defaultVal := prefix + "_std_default"
// If c{,pp}std properties are not specified, don't generate them in the BUILD file.
@@ -642,9 +681,12 @@
includes, absoluteIncludes := includesFromLabelList(headers.implementation)
currAbsoluteIncludes := compilerAttrs.absoluteIncludes.SelectValue(axis, config)
currAbsoluteIncludes = android.FirstUniqueStrings(append(currAbsoluteIncludes, absoluteIncludes...))
+
compilerAttrs.absoluteIncludes.SetSelectValue(axis, config, currAbsoluteIncludes)
+
currIncludes := compilerAttrs.localIncludes.SelectValue(axis, config)
currIncludes = android.FirstUniqueStrings(append(currIncludes, includes...))
+
compilerAttrs.localIncludes.SetSelectValue(axis, config, currIncludes)
if libraryProps, ok := archVariantLibraryProperties[axis][config].(*LibraryProperties); ok {
@@ -655,6 +697,7 @@
}
}
}
+
compilerAttrs.convertStlProps(ctx, module)
(&linkerAttrs).convertStripProps(ctx, module)
@@ -675,24 +718,106 @@
(&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs))
protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs)
+ aidlDep := bp2buildCcAidlLibrary(ctx, module, compilerAttrs.aidlSrcs)
// bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know
// which. This will add the newly generated proto library to the appropriate attribute and nothing
// to the other
(&linkerAttrs).wholeArchiveDeps.Add(protoDep.wholeStaticLib)
(&linkerAttrs).implementationWholeArchiveDeps.Add(protoDep.implementationWholeStaticLib)
+ // TODO(b/243023967) Add aidlDep to implementationWholeArchiveDeps if aidl.export_aidl_headers is true
+ (&linkerAttrs).wholeArchiveDeps.Add(aidlDep)
convertedLSrcs := bp2BuildLex(ctx, module.Name(), compilerAttrs)
(&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
(&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
+ features := compilerAttrs.features.Clone().Append(linkerAttrs.features)
+ features.DeduplicateAxesFromBase()
+
return baseAttributes{
compilerAttrs,
linkerAttrs,
+ *features,
protoDep.protoDep,
+ aidlDep,
}
}
+func bp2buildAidlLibraries(
+ ctx android.Bp2buildMutatorContext,
+ m *Module,
+ aidlSrcs bazel.LabelListAttribute,
+) bazel.LabelList {
+ var aidlLibraries bazel.LabelList
+ var directAidlSrcs bazel.LabelList
+
+ // Make a list of labels that correspond to filegroups that are already converted to aidl_library
+ for _, aidlSrc := range aidlSrcs.Value.Includes {
+ src := aidlSrc.OriginalModuleName
+ if isConvertedToAidlLibrary(ctx, src) {
+ module, _ := ctx.ModuleFromName(src)
+ fg, _ := module.(android.Bp2buildAidlLibrary)
+ aidlLibraries.Add(&bazel.Label{
+ Label: fg.GetAidlLibraryLabel(ctx),
+ })
+ } else {
+ directAidlSrcs.Add(&aidlSrc)
+ }
+ }
+
+ if len(directAidlSrcs.Includes) > 0 {
+ aidlLibraryLabel := m.Name() + "_aidl_library"
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "aidl_library",
+ Bzl_load_location: "//build/bazel/rules/aidl:library.bzl",
+ },
+ android.CommonAttributes{Name: aidlLibraryLabel},
+ &aidlLibraryAttributes{
+ Srcs: bazel.MakeLabelListAttribute(directAidlSrcs),
+ },
+ )
+ aidlLibraries.Add(&bazel.Label{
+ Label: ":" + aidlLibraryLabel,
+ })
+ }
+ return aidlLibraries
+}
+
+func bp2buildCcAidlLibrary(
+ ctx android.Bp2buildMutatorContext,
+ m *Module,
+ aidlSrcs bazel.LabelListAttribute,
+) *bazel.LabelAttribute {
+ suffix := "_cc_aidl_library"
+ ccAidlLibrarylabel := m.Name() + suffix
+
+ aidlLibraries := bp2buildAidlLibraries(ctx, m, aidlSrcs)
+
+ if aidlLibraries.IsEmpty() {
+ return nil
+ }
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_aidl_library",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl",
+ },
+ android.CommonAttributes{Name: ccAidlLibrarylabel},
+ &ccAidlLibraryAttributes{
+ Deps: bazel.MakeLabelListAttribute(aidlLibraries),
+ },
+ )
+
+ label := &bazel.LabelAttribute{
+ Value: &bazel.Label{
+ Label: ":" + ccAidlLibrarylabel,
+ },
+ }
+ return label
+}
+
func bp2BuildParseSdkAttributes(module *Module) sdkAttributes {
return sdkAttributes{
Sdk_version: module.Properties.Sdk_version,
@@ -779,6 +904,45 @@
sharedDeps := maybePartitionExportedAndImplementationsDepsExcludes(ctx, !isBinary, sharedLibs, props.Exclude_shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDepsExcludes)
la.dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
la.implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
+ if axis == bazel.NoConfigAxis || (axis == bazel.OsConfigurationAxis && config == bazel.OsAndroid) {
+ // If a dependency in la.implementationDynamicDeps has stubs, its stub variant should be
+ // used when the dependency is linked in a APEX. The dependencies in NoConfigAxis and
+ // OsConfigurationAxis/OsAndroid are grouped by having stubs or not, so Bazel select()
+ // statement can be used to choose source/stub variants of them.
+ depsWithStubs := []bazel.Label{}
+ for _, l := range sharedDeps.implementation.Includes {
+ dep, _ := ctx.ModuleFromName(l.OriginalModuleName)
+ if m, ok := dep.(*Module); ok && m.HasStubsVariants() {
+ depsWithStubs = append(depsWithStubs, l)
+ }
+ }
+ if len(depsWithStubs) > 0 {
+ implDynamicDeps := bazel.SubtractBazelLabelList(sharedDeps.implementation, bazel.MakeLabelList(depsWithStubs))
+ la.implementationDynamicDeps.SetSelectValue(axis, config, implDynamicDeps)
+
+ stubLibLabels := []bazel.Label{}
+ for _, l := range depsWithStubs {
+ l.Label = l.Label + "_stub_libs_current"
+ stubLibLabels = append(stubLibLabels, l)
+ }
+ inApexSelectValue := la.implementationDynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex)
+ nonApexSelectValue := la.implementationDynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex)
+ defaultSelectValue := la.implementationDynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey)
+ if axis == bazel.NoConfigAxis {
+ (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
+ (&nonApexSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
+ (&defaultSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
+ la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, inApexSelectValue)
+ la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, nonApexSelectValue)
+ la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, defaultSelectValue)
+ } else if config == bazel.OsAndroid {
+ (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
+ (&nonApexSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
+ la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, inApexSelectValue)
+ la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, nonApexSelectValue)
+ }
+ }
+ }
if !BoolDefault(props.Pack_relocations, packRelocationsDefault) {
axisFeatures = append(axisFeatures, "disable_pack_relocations")
diff --git a/cc/builder.go b/cc/builder.go
index f3faca8..35ae69b 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -282,7 +282,7 @@
sAbiDiff = pctx.RuleFunc("sAbiDiff",
func(ctx android.PackageRuleContext) blueprint.RuleParams {
commandStr := "($sAbiDiffer ${extraFlags} -lib ${libName} -arch ${arch} -o ${out} -new ${in} -old ${referenceDump})"
- commandStr += "|| (echo 'error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py ${createReferenceDumpFlags} -l ${libName}'"
+ commandStr += "|| (echo '${errorMessage}'"
commandStr += " && (mkdir -p $$DIST_DIR/abidiffs && cp ${out} $$DIST_DIR/abidiffs/)"
commandStr += " && exit 1)"
return blueprint.RuleParams{
@@ -290,7 +290,7 @@
CommandDeps: []string{"$sAbiDiffer"},
}
},
- "extraFlags", "referenceDump", "libName", "arch", "createReferenceDumpFlags")
+ "extraFlags", "referenceDump", "libName", "arch", "errorMessage")
// Rule to unzip a reference abi dump.
unzipRefSAbiDump = pctx.AndroidStaticRule("unzipRefSAbiDump",
@@ -940,9 +940,21 @@
"-allow-unreferenced-elf-symbol-changes")
}
- // TODO(b/241496591): Remove -advice-only after b/239792343 and b/239790286 are reolved.
+ var errorMessage string
+ // When error occurs in previous version ABI diff, Developers can't just update ABI
+ // reference but need to follow instructions to ensure ABI backward compatibility.
if previousVersionDiff {
+ // TODO(b/241496591): Remove -advice-only after b/239792343 and b/239790286 are reolved.
extraFlags = append(extraFlags, "-advice-only")
+ errorMessage = "error: Please follow development/vndk/tools/header-checker/README.md to ensure the ABI compatibility between your source code and version " + prevVersion + "."
+ // The prevVersion is expected as a string of int, skip it if not.
+ if prevVersionInt, err := strconv.Atoi(prevVersion); err == nil {
+ sourceVersion := strconv.Itoa(prevVersionInt + 1)
+ extraFlags = append(extraFlags, "-target-version", sourceVersion)
+ }
+ } else {
+ errorMessage = "error: Please update ABI references with: $ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName
+ extraFlags = append(extraFlags, "-target-version", "current")
}
if isLlndk || isNdk {
@@ -961,11 +973,11 @@
Input: inputDump,
Implicit: referenceDump,
Args: map[string]string{
- "referenceDump": referenceDump.String(),
- "libName": libName,
- "arch": ctx.Arch().ArchType.Name,
- "extraFlags": strings.Join(extraFlags, " "),
- "createReferenceDumpFlags": "",
+ "referenceDump": referenceDump.String(),
+ "libName": libName,
+ "arch": ctx.Arch().ArchType.Name,
+ "extraFlags": strings.Join(extraFlags, " "),
+ "errorMessage": errorMessage,
},
})
return android.OptionalPathForPath(outputFile)
diff --git a/cc/cc.go b/cc/cc.go
index 336771a..f1e9bf6 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1900,6 +1900,8 @@
if c.Properties.Clang != nil && *c.Properties.Clang == false {
ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
+ } else if c.Properties.Clang != nil && !ctx.DeviceConfig().BuildBrokenClangProperty() {
+ ctx.PropertyErrorf("clang", "property is deprecated, see Changes.md file")
}
flags := Flags{
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 75a9f19..5d569cc 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -4336,3 +4336,53 @@
}
}
+
+func TestCcBuildBrokenClangProperty(t *testing.T) {
+ tests := []struct {
+ name string
+ clang bool
+ BuildBrokenClangProperty bool
+ err string
+ }{
+ {
+ name: "error when clang is set to false",
+ clang: false,
+ err: "is no longer supported",
+ },
+ {
+ name: "error when clang is set to true",
+ clang: true,
+ err: "property is deprecated, see Changes.md",
+ },
+ {
+ name: "no error when BuildBrokenClangProperty is explicitly set to true",
+ clang: true,
+ BuildBrokenClangProperty: true,
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ bp := fmt.Sprintf(`
+ cc_library {
+ name: "foo",
+ clang: %t,
+ }`, test.clang)
+
+ if test.err == "" {
+ android.GroupFixturePreparers(
+ prepareForCcTest,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ if test.BuildBrokenClangProperty {
+ variables.BuildBrokenClangProperty = test.BuildBrokenClangProperty
+ }
+ }),
+ ).RunTestWithBp(t, bp)
+ } else {
+ prepareForCcTest.
+ ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)).
+ RunTestWithBp(t, bp)
+ }
+ })
+ }
+}
diff --git a/cc/library.go b/cc/library.go
index 41dca01..fc03fa2 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -270,6 +270,15 @@
Features bazel.StringListAttribute
}
+type aidlLibraryAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Include_dir *string
+}
+
+type ccAidlLibraryAttributes struct {
+ Deps bazel.LabelListAttribute
+}
+
type stripAttributes struct {
Keep_symbols bazel.BoolAttribute
Keep_symbols_and_debug_frame bazel.BoolAttribute
@@ -359,7 +368,7 @@
C_std: compilerAttrs.cStd,
Use_version_lib: linkerAttrs.useVersionLib,
- Features: linkerAttrs.features,
+ Features: baseAttributes.features,
}
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
@@ -391,10 +400,12 @@
All: linkerAttrs.stripAll,
None: linkerAttrs.stripNone,
},
- Features: linkerAttrs.features,
+ Features: baseAttributes.features,
+ }
- Stubs_symbol_file: compilerAttrs.stubsSymbolFile,
- Stubs_versions: compilerAttrs.stubsVersions,
+ if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
+ hasStubs := true
+ sharedTargetAttrs.Has_stubs.SetValue(&hasStubs)
}
for axis, configToProps := range m.GetArchVariantProperties(ctx, &LibraryProperties{}) {
@@ -427,6 +438,25 @@
ctx.CreateBazelTargetModuleWithRestrictions(sharedProps,
android.CommonAttributes{Name: m.Name()},
sharedTargetAttrs, sharedAttrs.Enabled)
+
+ if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
+ stubSuitesProps := bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_stub_suite",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_stub_library.bzl",
+ }
+ soname := m.Name() + ".so"
+ stubSuitesAttrs := &bazelCcStubSuiteAttributes{
+ Symbol_file: compilerAttrs.stubsSymbolFile,
+ Versions: compilerAttrs.stubsVersions,
+ Export_includes: exportedIncludes.Includes,
+ Soname: &soname,
+ Source_library: *bazel.MakeLabelAttribute(":" + m.Name()),
+ Deps: baseAttributes.deps,
+ }
+ ctx.CreateBazelTargetModule(stubSuitesProps,
+ android.CommonAttributes{Name: m.Name() + "_stub_libs"},
+ stubSuitesAttrs)
+ }
}
// cc_library creates both static and/or shared libraries for a device and/or
@@ -2579,12 +2609,12 @@
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
- Features: linkerAttrs.features,
+ Features: baseAttributes.features,
}
} else {
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
- attrs = &bazelCcLibrarySharedAttributes{
+ sharedLibAttrs := &bazelCcLibrarySharedAttributes{
staticOrSharedAttributes: commonAttrs,
Cppflags: compilerAttrs.cppFlags,
@@ -2616,11 +2646,13 @@
None: linkerAttrs.stripNone,
},
- Features: linkerAttrs.features,
-
- Stubs_symbol_file: compilerAttrs.stubsSymbolFile,
- Stubs_versions: compilerAttrs.stubsVersions,
+ Features: baseAttributes.features,
}
+ if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
+ hasStubs := true
+ sharedLibAttrs.Has_stubs.SetValue(&hasStubs)
+ }
+ attrs = sharedLibAttrs
}
var modType string
@@ -2694,7 +2726,16 @@
Features bazel.StringListAttribute
- Stubs_symbol_file *string
- Stubs_versions bazel.StringListAttribute
- Inject_bssl_hash bazel.BoolAttribute
+ Has_stubs bazel.BoolAttribute
+
+ Inject_bssl_hash bazel.BoolAttribute
+}
+
+type bazelCcStubSuiteAttributes struct {
+ Symbol_file *string
+ Versions bazel.StringListAttribute
+ Export_includes bazel.StringListAttribute
+ Source_library bazel.LabelAttribute
+ Soname *string
+ Deps bazel.LabelListAttribute
}
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 6930943..0b8cc88 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -84,6 +84,8 @@
flag.StringVar(&bp2buildMarker, "bp2build_marker", "", "If set, run bp2build, touch the specified marker file then exit")
flag.StringVar(&cmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output")
flag.BoolVar(&cmdlineArgs.EmptyNinjaFile, "empty-ninja-file", false, "write out a 0-byte ninja file")
+ flag.BoolVar(&cmdlineArgs.BazelMode, "bazel-mode", false, "use bazel for analysis of certain modules")
+ flag.BoolVar(&cmdlineArgs.BazelModeDev, "bazel-mode-dev", false, "use bazel for analysis of a large number of modules (less stable)")
// Flags that probably shouldn't be flags of soong_build but we haven't found
// the time to remove them yet
@@ -131,6 +133,10 @@
buildMode = android.GenerateModuleGraph
} else if docFile != "" {
buildMode = android.GenerateDocFile
+ } else if cmdlineArgs.BazelModeDev {
+ buildMode = android.BazelDevMode
+ } else if cmdlineArgs.BazelMode {
+ buildMode = android.BazelProdMode
} else {
buildMode = android.AnalysisNoBazel
}
@@ -234,7 +240,7 @@
// doChosenActivity runs Soong for a specific activity, like bp2build, queryview
// or the actual Soong build for the build.ninja file. Returns the top level
// output file of the specific activity.
-func doChosenActivity(ctx *android.Context, configuration android.Config, extraNinjaDeps []string, logDir string) string {
+func doChosenActivity(ctx *android.Context, configuration android.Config, extraNinjaDeps []string) string {
if configuration.BuildMode == android.Bp2build {
// Run the alternate pipeline of bp2build mutators and singleton to convert
// Blueprint to BUILD files before everything else.
@@ -347,7 +353,7 @@
ctx := newContext(configuration)
ctx.EventHandler.Begin("soong_build")
- finalOutputFile := doChosenActivity(ctx, configuration, extraNinjaDeps, logDir)
+ finalOutputFile := doChosenActivity(ctx, configuration, extraNinjaDeps)
ctx.EventHandler.End("soong_build")
writeMetrics(configuration, *ctx.EventHandler, logDir)
@@ -400,14 +406,10 @@
}
}
-// Find BUILD files in the srcDir which...
-//
-// - are not on the allow list (android/bazel.go#ShouldKeepExistingBuildFileForDir())
-//
-// - won't be overwritten by corresponding bp2build generated files
-//
-// And return their paths so they can be left out of the Bazel workspace dir (i.e. ignored)
-func getPathsToIgnoredBuildFiles(topDir string, generatedRoot string, srcDirBazelFiles []string, verbose bool) []string {
+// Find BUILD files in the srcDir which are not in the allowlist
+// (android.Bp2BuildConversionAllowlist#ShouldKeepExistingBuildFileForDir)
+// and return their paths so they can be left out of the Bazel workspace dir (i.e. ignored)
+func getPathsToIgnoredBuildFiles(config android.Bp2BuildConversionAllowlist, topDir string, srcDirBazelFiles []string, verbose bool) []string {
paths := make([]string, 0)
for _, srcDirBazelFileRelativePath := range srcDirBazelFiles {
@@ -422,21 +424,14 @@
// Don't ignore entire directories
continue
}
- if !(fileInfo.Name() == "BUILD" || fileInfo.Name() == "BUILD.bazel") {
+ if fileInfo.Name() != "BUILD" && fileInfo.Name() != "BUILD.bazel" {
// Don't ignore this file - it is not a build file
continue
}
- srcDirBazelFileDir := filepath.Dir(srcDirBazelFileRelativePath)
- if android.ShouldKeepExistingBuildFileForDir(srcDirBazelFileDir) {
+ if config.ShouldKeepExistingBuildFileForDir(filepath.Dir(srcDirBazelFileRelativePath)) {
// Don't ignore this existing build file
continue
}
- correspondingBp2BuildFile := shared.JoinPath(topDir, generatedRoot, srcDirBazelFileRelativePath)
- if _, err := os.Stat(correspondingBp2BuildFile); err == nil {
- // If bp2build generated an alternate BUILD file, don't exclude this workspace path
- // BUILD file clash resolution happens later in the symlink forest creation
- continue
- }
if verbose {
fmt.Fprintf(os.Stderr, "Ignoring existing BUILD file: %s\n", srcDirBazelFileRelativePath)
}
@@ -547,7 +542,7 @@
os.Exit(1)
}
- pathsToIgnoredBuildFiles := getPathsToIgnoredBuildFiles(topDir, generatedRoot, existingBazelRelatedFiles, configuration.IsEnvTrue("BP2BUILD_VERBOSE"))
+ pathsToIgnoredBuildFiles := getPathsToIgnoredBuildFiles(configuration.Bp2buildPackageConfig, topDir, existingBazelRelatedFiles, configuration.IsEnvTrue("BP2BUILD_VERBOSE"))
excludes = append(excludes, pathsToIgnoredBuildFiles...)
excludes = append(excludes, getTemporaryExcludes()...)
diff --git a/java/base.go b/java/base.go
index 2da7cbd..cf3b3d5 100644
--- a/java/base.go
+++ b/java/base.go
@@ -820,7 +820,7 @@
}
func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
- aidlIncludeDirs android.Paths) (string, android.Paths) {
+ aidlIncludeDirs android.Paths, aidlSrcs android.Paths) (string, android.Paths) {
aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
aidlIncludes = append(aidlIncludes,
@@ -830,6 +830,7 @@
var flags []string
var deps android.Paths
+ var includeDirs android.Paths
flags = append(flags, j.deviceProperties.Aidl.Flags...)
@@ -837,21 +838,24 @@
flags = append(flags, "-p"+aidlPreprocess.String())
deps = append(deps, aidlPreprocess.Path())
} else if len(aidlIncludeDirs) > 0 {
- flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
+ includeDirs = append(includeDirs, aidlIncludeDirs...)
}
if len(j.exportAidlIncludeDirs) > 0 {
- flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
+ includeDirs = append(includeDirs, j.exportAidlIncludeDirs...)
}
if len(aidlIncludes) > 0 {
- flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
+ includeDirs = append(includeDirs, aidlIncludes...)
}
- flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
+ includeDirs = append(includeDirs, android.PathForModuleSrc(ctx))
if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
- flags = append(flags, "-I"+src.String())
+ includeDirs = append(includeDirs, src.Path())
}
+ flags = append(flags, android.JoinWithPrefix(includeDirs.Strings(), "-I"))
+ // add flags for dirs containing AIDL srcs that haven't been specified yet
+ flags = append(flags, genAidlIncludeFlags(ctx, aidlSrcs, includeDirs))
if Bool(j.deviceProperties.Aidl.Generate_traces) {
flags = append(flags, "-t")
@@ -935,9 +939,6 @@
// systemModules
flags.systemModules = deps.systemModules
- // aidl flags.
- flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
-
return flags
}
@@ -1046,6 +1047,9 @@
ctx.PropertyErrorf("common_srcs", "common_srcs must be .kt files")
}
+ aidlSrcs := srcFiles.FilterByExt(".aidl")
+ flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs, aidlSrcs)
+
nonGeneratedSrcJars := srcFiles.FilterByExt(".srcjar")
srcFiles = j.genSources(ctx, srcFiles, flags)
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 901419c..9b1f43b 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -314,7 +314,7 @@
outSrcFiles := make(android.Paths, 0, len(srcFiles))
var aidlSrcs android.Paths
- aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
+ aidlIncludeFlags := genAidlIncludeFlags(ctx, srcFiles, android.Paths{})
for _, srcFile := range srcFiles {
switch srcFile.Ext() {
diff --git a/java/gen.go b/java/gen.go
index 1572bf0..638da25 100644
--- a/java/gen.go
+++ b/java/gen.go
@@ -15,6 +15,7 @@
package java
import (
+ "path/filepath"
"strconv"
"strings"
@@ -116,12 +117,31 @@
return javaFile
}
-func genAidlIncludeFlags(srcFiles android.Paths) string {
+// genAidlIncludeFlags returns additional include flags based on the relative path
+// of each .aidl file passed in srcFiles. excludeDirs is a list of paths relative to
+// the Android checkout root that should not be included in the returned flags.
+func genAidlIncludeFlags(ctx android.PathContext, srcFiles android.Paths, excludeDirs android.Paths) string {
var baseDirs []string
+ excludeDirsStrings := excludeDirs.Strings()
for _, srcFile := range srcFiles {
if srcFile.Ext() == ".aidl" {
baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
- if baseDir != "" && !android.InList(baseDir, baseDirs) {
+ baseDir = filepath.Clean(baseDir)
+ baseDirSeen := android.InList(baseDir, baseDirs) || android.InList(baseDir, excludeDirsStrings)
+
+ // For go/bp2build mixed builds, a file may be listed under a
+ // directory in the Bazel output tree that is symlinked to a
+ // directory under the android source tree. We should only
+ // include one copy of this directory so that the AIDL tool
+ // doesn't find multiple definitions of the same AIDL class.
+ // This code comes into effect when filegroups are used in mixed builds.
+ bazelPathPrefix := android.PathForBazelOut(ctx, "").String()
+ bazelBaseDir, err := filepath.Rel(bazelPathPrefix, baseDir)
+ bazelBaseDirSeen := err == nil &&
+ android.InList(bazelBaseDir, baseDirs) ||
+ android.InList(bazelBaseDir, excludeDirsStrings)
+
+ if baseDir != "" && !baseDirSeen && !bazelBaseDirSeen {
baseDirs = append(baseDirs, baseDir)
}
}
@@ -136,8 +156,6 @@
var protoSrcs android.Paths
var aidlSrcs android.Paths
- aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
-
for _, srcFile := range srcFiles {
switch srcFile.Ext() {
case ".aidl":
@@ -168,7 +186,7 @@
individualFlags[aidlSrc.String()] = flags
}
}
- srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, individualFlags, flags.aidlDeps)
+ srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags, individualFlags, flags.aidlDeps)
outSrcFiles = append(outSrcFiles, srcJarFiles...)
}
diff --git a/java/java.go b/java/java.go
index 210b883..0251b57 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2259,16 +2259,27 @@
StaticDeps bazel.LabelListAttribute
}
-// convertLibraryAttrsBp2Build converts a few shared attributes from java_* modules
-// and also separates dependencies into dynamic dependencies and static dependencies.
-// Each corresponding Bazel target type, can have a different method for handling
-// dynamic vs. static dependencies, and so these are returned to the calling function.
type eventLogTagsAttributes struct {
Srcs bazel.LabelListAttribute
}
+type aidlLibraryAttributes struct {
+ Srcs bazel.LabelListAttribute
+}
+
+type javaAidlLibraryAttributes struct {
+ Deps bazel.LabelListAttribute
+}
+
+// convertLibraryAttrsBp2Build converts a few shared attributes from java_* modules
+// and also separates dependencies into dynamic dependencies and static dependencies.
+// Each corresponding Bazel target type, can have a different method for handling
+// dynamic vs. static dependencies, and so these are returned to the calling function.
func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) (*javaCommonAttributes, *javaDependencyLabels) {
var srcs bazel.LabelListAttribute
+ var deps bazel.LabelList
+ var staticDeps bazel.LabelList
+
archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
for axis, configToProps := range archVariantProps {
for config, _props := range configToProps {
@@ -2282,18 +2293,18 @@
javaSrcPartition := "java"
protoSrcPartition := "proto"
logtagSrcPartition := "logtag"
+ aidlSrcPartition := "aidl"
srcPartitions := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
javaSrcPartition: bazel.LabelPartition{Extensions: []string{".java"}, Keep_remainder: true},
logtagSrcPartition: bazel.LabelPartition{Extensions: []string{".logtags", ".logtag"}},
protoSrcPartition: android.ProtoSrcLabelPartition,
+ aidlSrcPartition: android.AidlSrcLabelPartition,
})
javaSrcs := srcPartitions[javaSrcPartition]
- var logtagsSrcs bazel.LabelList
if !srcPartitions[logtagSrcPartition].IsEmpty() {
logtagsLibName := m.Name() + "_logtags"
- logtagsSrcs = bazel.MakeLabelList([]bazel.Label{{Label: ":" + logtagsLibName}})
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "event_log_tags",
@@ -2304,8 +2315,45 @@
Srcs: srcPartitions[logtagSrcPartition],
},
)
+
+ logtagsSrcs := bazel.MakeLabelList([]bazel.Label{{Label: ":" + logtagsLibName}})
+ javaSrcs.Append(bazel.MakeLabelListAttribute(logtagsSrcs))
}
- javaSrcs.Append(bazel.MakeLabelListAttribute(logtagsSrcs))
+
+ if !srcPartitions[aidlSrcPartition].IsEmpty() {
+ aidlLibs, aidlSrcs := srcPartitions[aidlSrcPartition].Partition(func(src bazel.Label) bool {
+ return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName)
+ })
+
+ if !aidlSrcs.IsEmpty() {
+ aidlLibName := m.Name() + "_aidl_library"
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "aidl_library",
+ Bzl_load_location: "//build/bazel/rules/aidl:library.bzl",
+ },
+ android.CommonAttributes{Name: aidlLibName},
+ &aidlLibraryAttributes{
+ Srcs: aidlSrcs,
+ },
+ )
+ aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
+ }
+
+ javaAidlLibName := m.Name() + "_java_aidl_library"
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "java_aidl_library",
+ Bzl_load_location: "//build/bazel/rules/java:aidl_library.bzl",
+ },
+ android.CommonAttributes{Name: javaAidlLibName},
+ &javaAidlLibraryAttributes{
+ Deps: aidlLibs,
+ },
+ )
+
+ staticDeps.Add(&bazel.Label{Label: ":" + javaAidlLibName})
+ }
var javacopts []string
if m.properties.Javacflags != nil {
@@ -2331,14 +2379,10 @@
Javacopts: bazel.MakeStringListAttribute(javacopts),
}
- depLabels := &javaDependencyLabels{}
-
- var deps bazel.LabelList
if m.properties.Libs != nil {
deps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Libs))))
}
- var staticDeps bazel.LabelList
if m.properties.Static_libs != nil {
staticDeps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Static_libs))))
}
@@ -2352,6 +2396,7 @@
// and so this should be a static dependency.
staticDeps.Add(protoDepLabel)
+ depLabels := &javaDependencyLabels{}
depLabels.Deps = bazel.MakeLabelListAttribute(deps)
depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
@@ -2376,7 +2421,7 @@
// TODO(b/220869005) remove forced dependency on current public android.jar
deps.Add(bazel.MakeLabelAttribute("//prebuilts/sdk:public_current_android_sdk_java_import"))
}
- } else if !depLabels.Deps.IsEmpty() {
+ } else if !deps.IsEmpty() {
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
}
diff --git a/java/java_test.go b/java/java_test.go
index bfd97eb..7f0cea7 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1747,3 +1747,37 @@
android.AssertDeepEquals(t, "Implementation/Resources JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationAndResourcesJars))
android.AssertDeepEquals(t, "Implementation JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationJars))
}
+
+func TestGenAidlIncludeFlagsForMixedBuilds(t *testing.T) {
+ bazelOutputBaseDir := filepath.Join("out", "bazel")
+ result := android.GroupFixturePreparers(
+ PrepareForIntegrationTestWithJava,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.BazelContext = android.MockBazelContext{
+ OutputBaseDir: bazelOutputBaseDir,
+ }
+ }),
+ ).RunTest(t)
+
+ ctx := &android.TestPathContext{TestResult: result}
+
+ srcDirectory := filepath.Join("frameworks", "base")
+ srcDirectoryAlreadyIncluded := filepath.Join("frameworks", "base", "core", "java")
+ bazelSrcDirectory := android.PathForBazelOut(ctx, srcDirectory)
+ bazelSrcDirectoryAlreadyIncluded := android.PathForBazelOut(ctx, srcDirectoryAlreadyIncluded)
+ srcs := android.Paths{
+ android.PathForTestingWithRel(bazelSrcDirectory.String(), "bazelAidl.aidl"),
+ android.PathForTestingWithRel(bazelSrcDirectory.String(), "bazelAidl2.aidl"),
+ android.PathForTestingWithRel(bazelSrcDirectoryAlreadyIncluded.String(), "bazelAidlExclude.aidl"),
+ android.PathForTestingWithRel(bazelSrcDirectoryAlreadyIncluded.String(), "bazelAidl2Exclude.aidl"),
+ }
+ dirsAlreadyIncluded := android.Paths{
+ android.PathForTesting(srcDirectoryAlreadyIncluded),
+ }
+
+ expectedFlags := " -Iout/bazel/execroot/__main__/frameworks/base"
+ flags := genAidlIncludeFlags(ctx, srcs, dirsAlreadyIncluded)
+ if flags != expectedFlags {
+ t.Errorf("expected flags to be %q; was %q", expectedFlags, flags)
+ }
+}
diff --git a/tests/apex_comparison_tests.sh b/tests/apex_comparison_tests.sh
index 4b2f795..ac3c177 100755
--- a/tests/apex_comparison_tests.sh
+++ b/tests/apex_comparison_tests.sh
@@ -33,6 +33,10 @@
SOONG_OUTPUT_DIR="$OUTPUT_DIR/soong"
BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel"
+function call_bazel() {
+ tools/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
+}
+
function cleanup {
# call bazel clean because some bazel outputs don't have w bits.
call_bazel clean
@@ -54,9 +58,6 @@
######################
build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build
-function call_bazel() {
- tools/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
-}
BAZEL_OUT="$(call_bazel info output_path)"
call_bazel build --config=bp2build --config=ci --config=android_arm \
diff --git a/ui/build/build.go b/ui/build/build.go
index f7a2d7b..c61baa1 100644
--- a/ui/build/build.go
+++ b/ui/build/build.go
@@ -110,6 +110,24 @@
RunAllWithBazel = RunProductConfig | RunSoong | RunKati | RunKatiNinja | RunBazel
)
+// checkBazelMode fails the build if there are conflicting arguments for which bazel
+// build mode to use.
+func checkBazelMode(ctx Context, config Config) {
+ // TODO(cparsons): Remove USE_BAZEL_ANALYSIS handling.
+ if config.Environment().IsEnvTrue("USE_BAZEL_ANALYSIS") {
+ if config.bazelProdMode || config.bazelDevMode {
+ ctx.Fatalf("USE_BAZEL_ANALYSIS is deprecated.\n" +
+ "Unset USE_BAZEL_ANALYSIS when using --bazel-mode or --bazel-mode-dev.")
+ } else {
+ config.bazelDevMode = true
+ }
+ }
+ if config.bazelProdMode && config.bazelDevMode {
+ ctx.Fatalf("Conflicting bazel mode.\n" +
+ "Do not specify both --bazel-mode and --bazel-mode-dev")
+ }
+}
+
// checkProblematicFiles fails the build if existing Android.mk or CleanSpec.mk files are found at the root of the tree.
func checkProblematicFiles(ctx Context) {
files := []string{"Android.mk", "CleanSpec.mk"}
@@ -221,6 +239,8 @@
defer waitForDist(ctx)
+ checkBazelMode(ctx, config)
+
// checkProblematicFiles aborts the build if Android.mk or CleanSpec.mk are found at the root of the tree.
checkProblematicFiles(ctx)
diff --git a/ui/build/config.go b/ui/build/config.go
index e140867..590aeb9 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -99,7 +99,10 @@
pathReplaced bool
- useBazel bool
+ // TODO(b/243077098): Remove useBazel.
+ useBazel bool
+ bazelProdMode bool
+ bazelDevMode bool
// During Bazel execution, Bazel cannot write outside OUT_DIR.
// So if DIST_DIR is set to an external dir (outside of OUT_DIR), we need to rig it temporarily and then migrate files at the end of the build.
@@ -130,18 +133,6 @@
BUILD_MODULES
)
-type bazelBuildMode int
-
-// Bazel-related build modes.
-const (
- // Don't use bazel at all.
- noBazel bazelBuildMode = iota
-
- // Generate synthetic build files and incorporate these files into a build which
- // partially uses Bazel. Build metadata may come from Android.bp or BUILD files.
- mixedBuild
-)
-
// checkTopDir validates that the current directory is at the root directory of the source tree.
func checkTopDir(ctx Context) {
if _, err := os.Stat(srcDirFileCheck); err != nil {
@@ -496,7 +487,7 @@
UseGoma: proto.Bool(config.UseGoma()),
UseRbe: proto.Bool(config.UseRBE()),
BazelAsNinja: proto.Bool(config.UseBazel()),
- BazelMixedBuild: proto.Bool(config.bazelBuildMode() == mixedBuild),
+ BazelMixedBuild: proto.Bool(config.BazelBuildEnabled()),
}
c.Targets = append(c.Targets, config.arguments...)
@@ -747,6 +738,10 @@
c.skipSoongTests = true
} else if arg == "--mk-metrics" {
c.reportMkMetrics = true
+ } else if arg == "--bazel-mode" {
+ c.bazelProdMode = true
+ } else if arg == "--bazel-mode-dev" {
+ c.bazelDevMode = true
} else if len(arg) > 0 && arg[0] == '-' {
parseArgNum := func(def int) int {
if len(arg) > 2 {
@@ -1134,16 +1129,13 @@
return false
}
+// TODO(b/243077098): Remove UseBazel.
func (c *configImpl) UseBazel() bool {
return c.useBazel
}
-func (c *configImpl) bazelBuildMode() bazelBuildMode {
- if c.Environment().IsEnvTrue("USE_BAZEL_ANALYSIS") {
- return mixedBuild
- } else {
- return noBazel
- }
+func (c *configImpl) BazelBuildEnabled() bool {
+ return c.bazelProdMode || c.bazelDevMode
}
func (c *configImpl) StartRBE() bool {
diff --git a/ui/build/config_test.go b/ui/build/config_test.go
index e293275..63716b0 100644
--- a/ui/build/config_test.go
+++ b/ui/build/config_test.go
@@ -28,6 +28,7 @@
"android/soong/ui/logger"
smpb "android/soong/ui/metrics/metrics_proto"
"android/soong/ui/status"
+ "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
)
@@ -1005,6 +1006,8 @@
environ Environment
arguments []string
useBazel bool
+ bazelDevMode bool
+ bazelProdMode bool
expectedBuildConfig *smpb.BuildConfig
}{
{
@@ -1064,7 +1067,7 @@
},
},
{
- name: "bazel mixed build",
+ name: "bazel mixed build from env",
environ: Environment{"USE_BAZEL_ANALYSIS=1"},
expectedBuildConfig: &smpb.BuildConfig{
ForceUseGoma: proto.Bool(false),
@@ -1075,6 +1078,30 @@
},
},
{
+ name: "bazel mixed build from dev mode",
+ environ: Environment{},
+ bazelDevMode: true,
+ expectedBuildConfig: &smpb.BuildConfig{
+ ForceUseGoma: proto.Bool(false),
+ UseGoma: proto.Bool(false),
+ UseRbe: proto.Bool(false),
+ BazelAsNinja: proto.Bool(false),
+ BazelMixedBuild: proto.Bool(true),
+ },
+ },
+ {
+ name: "bazel mixed build from prod mode",
+ environ: Environment{},
+ bazelProdMode: true,
+ expectedBuildConfig: &smpb.BuildConfig{
+ ForceUseGoma: proto.Bool(false),
+ UseGoma: proto.Bool(false),
+ UseRbe: proto.Bool(false),
+ BazelAsNinja: proto.Bool(false),
+ BazelMixedBuild: proto.Bool(true),
+ },
+ },
+ {
name: "specified targets",
environ: Environment{},
useBazel: true,
@@ -1094,9 +1121,9 @@
"FORCE_USE_GOMA=1",
"USE_GOMA=1",
"USE_RBE=1",
- "USE_BAZEL_ANALYSIS=1",
},
- useBazel: true,
+ useBazel: true,
+ bazelDevMode: true,
expectedBuildConfig: &smpb.BuildConfig{
ForceUseGoma: proto.Bool(true),
UseGoma: proto.Bool(true),
@@ -1107,17 +1134,23 @@
},
}
+ ctx := testContext()
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
c := &configImpl{
- environ: &tc.environ,
- useBazel: tc.useBazel,
- arguments: tc.arguments,
+ environ: &tc.environ,
+ useBazel: tc.useBazel,
+ bazelDevMode: tc.bazelDevMode,
+ bazelProdMode: tc.bazelProdMode,
+ arguments: tc.arguments,
}
config := Config{c}
+ checkBazelMode(ctx, config)
actualBuildConfig := buildConfig(config)
if expected := tc.expectedBuildConfig; !proto.Equal(expected, actualBuildConfig) {
- t.Errorf("Expected build config != actual build config: %#v != %#v", *expected, *actualBuildConfig)
+ t.Errorf("Build config mismatch.\n"+
+ "Expected build config: %#v\n"+
+ "Actual build config: %#v", prototext.Format(expected), prototext.Format(actualBuildConfig))
}
})
}
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 3920ddd..ff6d68f 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -170,9 +170,8 @@
commonArgs = append(commonArgs, "-l", filepath.Join(config.FileListDir(), "Android.bp.list"))
invocationEnv := make(map[string]string)
- debugMode := os.Getenv("SOONG_DELVE") != ""
-
- if debugMode {
+ if os.Getenv("SOONG_DELVE") != "" {
+ //debug mode
commonArgs = append(commonArgs, "--delve_listen", os.Getenv("SOONG_DELVE"))
commonArgs = append(commonArgs, "--delve_path", shared.ResolveDelveBinary())
// GODEBUG=asyncpreemptoff=1 disables the preemption of goroutines. This
@@ -187,7 +186,7 @@
invocationEnv["GODEBUG"] = "asyncpreemptoff=1"
}
- allArgs := make([]string, 0, 0)
+ var allArgs []string
allArgs = append(allArgs, specificArgs...)
allArgs = append(allArgs,
"--globListDir", name,
@@ -254,6 +253,12 @@
if config.EmptyNinjaFile() {
mainSoongBuildExtraArgs = append(mainSoongBuildExtraArgs, "--empty-ninja-file")
}
+ if config.bazelProdMode {
+ mainSoongBuildExtraArgs = append(mainSoongBuildExtraArgs, "--bazel-mode")
+ }
+ if config.bazelDevMode {
+ mainSoongBuildExtraArgs = append(mainSoongBuildExtraArgs, "--bazel-mode-dev")
+ }
mainSoongBuildInvocation := primaryBuilderInvocation(
config,
@@ -263,7 +268,7 @@
fmt.Sprintf("analyzing Android.bp files and generating ninja file at %s", config.SoongNinjaFile()),
)
- if config.bazelBuildMode() == mixedBuild {
+ if config.BazelBuildEnabled() {
// Mixed builds call Bazel from soong_build and they therefore need the
// Bazel workspace to be available. Make that so by adding a dependency on
// the bp2build marker file to the action that invokes soong_build .
@@ -373,9 +378,6 @@
// unused variables were changed?
envFile := filepath.Join(config.SoongOutDir(), availableEnvFile)
- buildMode := config.bazelBuildMode()
- integratedBp2Build := buildMode == mixedBuild
-
// This is done unconditionally, but does not take a measurable amount of time
bootstrapBlueprint(ctx, config)
@@ -405,7 +407,7 @@
checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(soongBuildTag))
- if integratedBp2Build || config.Bp2Build() {
+ if config.BazelBuildEnabled() || config.Bp2Build() {
checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(bp2buildTag))
}
diff --git a/ui/status/ninja.go b/ui/status/ninja.go
index 4d99621..fc0e21a 100644
--- a/ui/status/ninja.go
+++ b/ui/status/ninja.go
@@ -35,8 +35,7 @@
func NewNinjaReader(ctx logger.Logger, status ToolStatus, fifo string) *NinjaReader {
os.Remove(fifo)
- err := syscall.Mkfifo(fifo, 0666)
- if err != nil {
+ if err := syscall.Mkfifo(fifo, 0666); err != nil {
ctx.Fatalf("Failed to mkfifo(%q): %v", fifo, err)
}