bp2build: convert paths/module refs to Bazel label
This currently expands all globs, still need to support converting glob
syntax.
Test: go build_conversion_test
Test: GENERATE_BAZEL_FILES=true m nothing
Test: m nothing
Bug: 165114590
Change-Id: If7b26e8e663d17566fad9614ca87a8da1f095284
diff --git a/cc/binary.go b/cc/binary.go
index 71c865b..999b82c 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -182,7 +182,7 @@
}
}
- if !binary.static() && inList("libc", deps.StaticLibs) {
+ if !binary.static() && inList("libc", deps.StaticLibs) && !ctx.BazelConversionMode() {
ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" +
"from static libs or set static_executable: true")
}
diff --git a/cc/cc.go b/cc/cc.go
index d282b6e..55661c8 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1741,7 +1741,7 @@
func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
if c.cachedToolchain == nil {
- c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
+ c.cachedToolchain = config.FindToolchainWithContext(ctx)
}
return c.cachedToolchain
}
@@ -1833,6 +1833,12 @@
deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
+ // In Bazel conversion mode, we dependency and build validations will occur in Bazel, so there is
+ // no need to do so in Soong.
+ if ctx.BazelConversionMode() {
+ return deps
+ }
+
for _, lib := range deps.ReexportSharedLibHeaders {
if !inList(lib, deps.SharedLibs) {
ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go
index db9092d..59c0422 100644
--- a/cc/config/toolchain.go
+++ b/cc/config/toolchain.go
@@ -32,12 +32,42 @@
toolchainFactories[os][arch] = factory
}
+type toolchainContext interface {
+ Os() android.OsType
+ Arch() android.Arch
+}
+
+type conversionContext interface {
+ BazelConversionMode() bool
+}
+
+func FindToolchainWithContext(ctx toolchainContext) Toolchain {
+ t, err := findToolchain(ctx.Os(), ctx.Arch())
+ if err != nil {
+ if c, ok := ctx.(conversionContext); ok && c.BazelConversionMode() {
+ // TODO(b/179123288): determine conversion for toolchain
+ return &toolchainX86_64{}
+ } else {
+ panic(err)
+ }
+ }
+ return t
+}
+
func FindToolchain(os android.OsType, arch android.Arch) Toolchain {
+ t, err := findToolchain(os, arch)
+ if err != nil {
+ panic(err)
+ }
+ return t
+}
+
+func findToolchain(os android.OsType, arch android.Arch) (Toolchain, error) {
factory := toolchainFactories[os][arch.ArchType]
if factory == nil {
- panic(fmt.Errorf("Toolchain not found for %s arch %q", os.String(), arch.String()))
+ return nil, fmt.Errorf("Toolchain not found for %s arch %q", os.String(), arch.String())
}
- return factory(arch)
+ return factory(arch), nil
}
type Toolchain interface {
diff --git a/cc/linker.go b/cc/linker.go
index ff07224..6d0d416 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -328,7 +328,9 @@
}
deps.SystemSharedLibs = linker.Properties.System_shared_libs
- if deps.SystemSharedLibs == nil {
+ // In Bazel conversion mode, variations have not been specified, so SystemSharedLibs may
+ // inaccuarately appear unset, which can cause issues with circular dependencies.
+ if deps.SystemSharedLibs == nil && !ctx.BazelConversionMode() {
// Provide a default system_shared_libs if it is unspecified. Note: If an
// empty list [] is specified, it implies that the module declines the
// default system_shared_libs.