Clean up some bp2build technical debt

Previously we ran mutators in bp2build mode to add dependencies, now we
look up modules by name directly. Remove workarounds to allow bp2build
mode to not fail when adding/handling dependencies.

Test: m bp2build
Change-Id: Ibf6fd905150cac306e5c395902ef28f609f4df2a
This commit is contained in:
Liz Kammer
2022-04-26 09:38:20 -04:00
parent d2ee3a6afa
commit 3bf97bd1c0
10 changed files with 9 additions and 50 deletions

View File

@@ -2446,7 +2446,7 @@ type baseModuleContext struct {
bazelConversionMode bool
}
func (b *baseModuleContext) BazelConversionMode() bool {
func (b *baseModuleContext) isBazelConversionMode() bool {
return b.bazelConversionMode
}
func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
@@ -2835,7 +2835,7 @@ func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, bluepri
}
func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) {
if !b.BazelConversionMode() {
if !b.isBazelConversionMode() {
panic("cannot call ModuleFromName if not in bazel conversion mode")
}
if moduleName, _ := SrcIsModuleWithTag(name); moduleName != "" {

View File

@@ -232,9 +232,6 @@ type BaseMutatorContext interface {
// Rename all variants of a module. The new name is not visible to calls to ModuleName,
// AddDependency or OtherModuleName until after this mutator pass is complete.
Rename(name string)
// BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion.
BazelConversionMode() bool
}
type TopDownMutator func(TopDownMutatorContext)
@@ -626,28 +623,11 @@ func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string
func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
names ...string) []blueprint.Module {
if b.bazelConversionMode {
_, noSelfDeps := RemoveFromList(b.ModuleName(), names)
if len(noSelfDeps) == 0 {
return []blueprint.Module(nil)
}
// In Bazel conversion mode, mutators should not have created any variants. So, when adding a
// dependency, the variations would not exist and the dependency could not be added, by
// specifying no variations, we will allow adding the dependency to succeed.
return b.bp.AddFarVariationDependencies(nil, tag, noSelfDeps...)
}
return b.bp.AddVariationDependencies(variations, tag, names...)
}
func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
tag blueprint.DependencyTag, names ...string) []blueprint.Module {
if b.bazelConversionMode {
// In Bazel conversion mode, mutators should not have created any variants. So, when adding a
// dependency, the variations would not exist and the dependency could not be added, by
// specifying no variations, we will allow adding the dependency to succeed.
return b.bp.AddFarVariationDependencies(nil, tag, names...)
}
return b.bp.AddFarVariationDependencies(variations, tag, names...)
}

View File

@@ -182,7 +182,7 @@ func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
}
}
if !binary.static() && inList("libc", deps.StaticLibs) && !ctx.BazelConversionMode() {
if !binary.static() && inList("libc", deps.StaticLibs) {
ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" +
"from static libs or set static_executable: true")
}

View File

@@ -2031,12 +2031,6 @@ func (c *Module) deps(ctx DepsContext) Deps {
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)

View File

@@ -36,19 +36,10 @@ type toolchainContext interface {
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)
}
panic(err)
}
return t
}

View File

@@ -389,9 +389,7 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
}
deps.SystemSharedLibs = linker.Properties.System_shared_libs
// 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() {
if deps.SystemSharedLibs == nil {
// 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.

View File

@@ -1245,10 +1245,10 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
if ctx.Arch().ArchType == android.Common || ctx.BazelConversionMode() {
if ctx.Arch().ArchType == android.Common {
j.deps(ctx)
}
if ctx.Arch().ArchType != android.Common || ctx.BazelConversionMode() {
if ctx.Arch().ArchType != android.Common {
// These dependencies ensure the host installation rules will install the jar file and
// the jni libraries when the wrapper is installed.
ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...)

View File

@@ -91,7 +91,7 @@ func protoDeps(ctx android.BottomUpMutatorContext, p *android.ProtoProperties) {
case "lite", unspecifiedProtobufPluginType:
ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-lite")
case "full":
if ctx.Host() || ctx.BazelConversionMode() {
if ctx.Host() {
ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-full")
} else {
ctx.PropertyErrorf("proto.type", "full java protos only supported on the host")

View File

@@ -246,10 +246,6 @@ func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) aut
return rlibAutoDep
} else if library.dylib() || library.shared() {
return dylibAutoDep
} else if ctx.BazelConversionMode() {
// In Bazel conversion mode, we are currently ignoring the deptag, so we just need to supply a
// compatible tag in order to add the dependency.
return rlibAutoDep
} else {
panic(fmt.Errorf("autoDep called on library %q that has no enabled variants.", ctx.ModuleName()))
}

View File

@@ -323,7 +323,7 @@ func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) {
ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...)
ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...),
shTestDataLibsTag, s.testProperties.Data_libs...)
if (ctx.Target().Os.Class == android.Host || ctx.BazelConversionMode()) && len(ctx.Config().Targets[android.Android]) > 0 {
if ctx.Target().Os.Class == android.Host && len(ctx.Config().Targets[android.Android]) > 0 {
deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...)
ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...),