From 3bf97bd1c066cddd49e1ae1936bdeda0fbca805c Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Tue, 26 Apr 2022 09:38:20 -0400 Subject: [PATCH] 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 --- android/module.go | 4 ++-- android/mutator.go | 20 -------------------- cc/binary.go | 2 +- cc/cc.go | 6 ------ cc/config/toolchain.go | 11 +---------- cc/linker.go | 4 +--- java/java.go | 4 ++-- java/proto.go | 2 +- rust/library.go | 4 ---- sh/sh_binary.go | 2 +- 10 files changed, 9 insertions(+), 50 deletions(-) diff --git a/android/module.go b/android/module.go index ab68e24f1..57cfcc754 100644 --- a/android/module.go +++ b/android/module.go @@ -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 != "" { diff --git a/android/mutator.go b/android/mutator.go index 02a614353..f06ecdab0 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -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...) } diff --git a/cc/binary.go b/cc/binary.go index c5017c1dd..3e52fbc8d 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -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") } diff --git a/cc/cc.go b/cc/cc.go index 86069208c..f1a198385 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -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) diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index 7175fdc1a..253bb06d2 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -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 } diff --git a/cc/linker.go b/cc/linker.go index f34658485..4e9404c0f 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -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. diff --git a/java/java.go b/java/java.go index 079d4b9e7..9ecd362fc 100644 --- a/java/java.go +++ b/java/java.go @@ -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...) diff --git a/java/proto.go b/java/proto.go index 5ba486fd6..5280077f1 100644 --- a/java/proto.go +++ b/java/proto.go @@ -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") diff --git a/rust/library.go b/rust/library.go index 1286549c6..c2ce9de6b 100644 --- a/rust/library.go +++ b/rust/library.go @@ -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())) } diff --git a/sh/sh_binary.go b/sh/sh_binary.go index d1beaba41..4de01443d 100644 --- a/sh/sh_binary.go +++ b/sh/sh_binary.go @@ -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...),