Convert rust_libraries and rust_stdlinkage mutators to TransitionMutators
Replace rust.LibraryMutator and rust.LibstdMutator with TransitionMutators. Bug: 319288033 Flag: EXEMPT refactor Test: all soong tests pass Test: no change to build.ninja Change-Id: Ia24a582119d39889279d7b93bac9259685153619
This commit is contained in:
@@ -86,20 +86,19 @@ endif`,
|
||||
},
|
||||
{
|
||||
name: "Blank line in rule's command",
|
||||
in: `all:
|
||||
in: `all:
|
||||
echo first line
|
||||
|
||||
echo second line`,
|
||||
out: []Node{
|
||||
&Rule{
|
||||
Target: SimpleMakeString("all", NoPos),
|
||||
RecipePos: NoPos,
|
||||
Recipe: "echo first line\necho second line",
|
||||
Target: SimpleMakeString("all", NoPos),
|
||||
RecipePos: NoPos,
|
||||
Recipe: "echo first line\necho second line",
|
||||
Prerequisites: SimpleMakeString("", NoPos),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
|
@@ -703,7 +703,6 @@ func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeM
|
||||
rustLibVariations := append(
|
||||
target.Variations(), []blueprint.Variation{
|
||||
{Mutator: "rust_libraries", Variation: "dylib"},
|
||||
{Mutator: "link", Variation: ""},
|
||||
}...,
|
||||
)
|
||||
|
||||
|
@@ -532,7 +532,7 @@ func OdexOnSystemOtherByName(name string, dexLocation string, global *GlobalConf
|
||||
}
|
||||
|
||||
for _, f := range global.PatternsOnSystemOther {
|
||||
if makefileMatch("/" + f, dexLocation) || makefileMatch(filepath.Join(SystemPartition, f), dexLocation) {
|
||||
if makefileMatch("/"+f, dexLocation) || makefileMatch(filepath.Join(SystemPartition, f), dexLocation) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
|
||||
|
||||
// no_std modules are missing libprofiler_builtins which provides coverage, so we need to add it as a dependency.
|
||||
if rustModule, ok := ctx.Module().(*Module); ok && rustModule.compiler.noStdlibs() {
|
||||
ctx.AddVariationDependencies([]blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}, {Mutator: "link", Variation: ""}}, rlibDepTag, ProfilerBuiltins)
|
||||
ctx.AddVariationDependencies([]blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}, rlibDepTag, ProfilerBuiltins)
|
||||
}
|
||||
}
|
||||
|
||||
|
203
rust/library.go
203
rust/library.go
@@ -20,6 +20,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
@@ -692,31 +694,28 @@ func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name stri
|
||||
}
|
||||
}
|
||||
|
||||
// LibraryMutator mutates the libraries into variants according to the
|
||||
// build{Rlib,Dylib} attributes.
|
||||
func LibraryMutator(mctx android.BottomUpMutatorContext) {
|
||||
// Only mutate on Rust libraries.
|
||||
m, ok := mctx.Module().(*Module)
|
||||
type libraryTransitionMutator struct{}
|
||||
|
||||
func (libraryTransitionMutator) Split(ctx android.BaseModuleContext) []string {
|
||||
m, ok := ctx.Module().(*Module)
|
||||
if !ok || m.compiler == nil {
|
||||
return
|
||||
return []string{""}
|
||||
}
|
||||
library, ok := m.compiler.(libraryInterface)
|
||||
if !ok {
|
||||
return
|
||||
return []string{""}
|
||||
}
|
||||
|
||||
// Don't produce rlib/dylib/source variants for shared or static variants
|
||||
if library.shared() || library.static() {
|
||||
return
|
||||
return []string{""}
|
||||
}
|
||||
|
||||
var variants []string
|
||||
// The source variant is used for SourceProvider modules. The other variants (i.e. rlib and dylib)
|
||||
// depend on this variant. It must be the first variant to be declared.
|
||||
sourceVariant := false
|
||||
if m.sourceProvider != nil {
|
||||
variants = append(variants, "source")
|
||||
sourceVariant = true
|
||||
variants = append(variants, sourceVariation)
|
||||
}
|
||||
if library.buildRlib() {
|
||||
variants = append(variants, rlibVariation)
|
||||
@@ -726,92 +725,134 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
if len(variants) == 0 {
|
||||
return
|
||||
return []string{""}
|
||||
}
|
||||
modules := mctx.CreateLocalVariations(variants...)
|
||||
|
||||
// The order of the variations (modules) matches the variant names provided. Iterate
|
||||
// through the new variation modules and set their mutated properties.
|
||||
var emptyVariant = false
|
||||
var rlibVariant = false
|
||||
for i, v := range modules {
|
||||
switch variants[i] {
|
||||
case rlibVariation:
|
||||
v.(*Module).compiler.(libraryInterface).setRlib()
|
||||
rlibVariant = true
|
||||
case dylibVariation:
|
||||
v.(*Module).compiler.(libraryInterface).setDylib()
|
||||
if v.(*Module).ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
|
||||
// TODO(b/165791368)
|
||||
// Disable dylib Vendor Ramdisk variations until we support these.
|
||||
v.(*Module).Disable()
|
||||
}
|
||||
return variants
|
||||
}
|
||||
|
||||
case "source":
|
||||
v.(*Module).compiler.(libraryInterface).setSource()
|
||||
// The source variant does not produce any library.
|
||||
// Disable the compilation steps.
|
||||
v.(*Module).compiler.SetDisabled()
|
||||
case "":
|
||||
emptyVariant = true
|
||||
func (libraryTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (libraryTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
|
||||
m, ok := ctx.Module().(*Module)
|
||||
if !ok || m.compiler == nil {
|
||||
return ""
|
||||
}
|
||||
library, ok := m.compiler.(libraryInterface)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
if incomingVariation == "" {
|
||||
if m.sourceProvider != nil {
|
||||
return sourceVariation
|
||||
}
|
||||
if library.shared() {
|
||||
return ""
|
||||
}
|
||||
if library.buildRlib() {
|
||||
return rlibVariation
|
||||
}
|
||||
if library.buildDylib() {
|
||||
return dylibVariation
|
||||
}
|
||||
}
|
||||
return incomingVariation
|
||||
}
|
||||
|
||||
if rlibVariant && library.isFFILibrary() {
|
||||
// If an rlib variant is set and this is an FFI library, make it the
|
||||
// default variant so CC can link against it appropriately.
|
||||
mctx.AliasVariation(rlibVariation)
|
||||
} else if emptyVariant {
|
||||
// If there's an empty variant, alias it so it is the default variant
|
||||
mctx.AliasVariation("")
|
||||
func (libraryTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
|
||||
m, ok := ctx.Module().(*Module)
|
||||
if !ok || m.compiler == nil {
|
||||
return
|
||||
}
|
||||
library, ok := m.compiler.(libraryInterface)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
switch variation {
|
||||
case rlibVariation:
|
||||
library.setRlib()
|
||||
case dylibVariation:
|
||||
library.setDylib()
|
||||
if m.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
|
||||
// TODO(b/165791368)
|
||||
// Disable dylib Vendor Ramdisk variations until we support these.
|
||||
m.Disable()
|
||||
}
|
||||
|
||||
case sourceVariation:
|
||||
library.setSource()
|
||||
// The source variant does not produce any library.
|
||||
// Disable the compilation steps.
|
||||
m.compiler.SetDisabled()
|
||||
}
|
||||
|
||||
// If a source variant is created, add an inter-variant dependency
|
||||
// between the other variants and the source variant.
|
||||
if sourceVariant {
|
||||
sv := modules[0]
|
||||
for _, v := range modules[1:] {
|
||||
if !v.Enabled(mctx) {
|
||||
continue
|
||||
}
|
||||
mctx.AddInterVariantDependency(sourceDepTag, v, sv)
|
||||
}
|
||||
// Alias the source variation so it can be named directly in "srcs" properties.
|
||||
mctx.AliasVariation("source")
|
||||
if m.sourceProvider != nil && variation != sourceVariation {
|
||||
ctx.AddVariationDependencies(
|
||||
[]blueprint.Variation{
|
||||
{"rust_libraries", sourceVariation},
|
||||
},
|
||||
sourceDepTag, ctx.ModuleName())
|
||||
}
|
||||
}
|
||||
|
||||
func LibstdMutator(mctx android.BottomUpMutatorContext) {
|
||||
if m, ok := mctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() {
|
||||
switch library := m.compiler.(type) {
|
||||
case libraryInterface:
|
||||
// Only create a variant if a library is actually being built.
|
||||
if library.rlib() && !library.sysroot() {
|
||||
// If this is a rust_ffi variant it only needs rlib-std
|
||||
if library.isFFILibrary() {
|
||||
variants := []string{"rlib-std"}
|
||||
modules := mctx.CreateLocalVariations(variants...)
|
||||
rlib := modules[0].(*Module)
|
||||
rlib.compiler.(libraryInterface).setRlibStd()
|
||||
rlib.Properties.RustSubName += RlibStdlibSuffix
|
||||
mctx.AliasVariation("rlib-std")
|
||||
} else {
|
||||
variants := []string{"rlib-std", "dylib-std"}
|
||||
modules := mctx.CreateLocalVariations(variants...)
|
||||
type libstdTransitionMutator struct{}
|
||||
|
||||
rlib := modules[0].(*Module)
|
||||
dylib := modules[1].(*Module)
|
||||
rlib.compiler.(libraryInterface).setRlibStd()
|
||||
dylib.compiler.(libraryInterface).setDylibStd()
|
||||
if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
|
||||
// TODO(b/165791368)
|
||||
// Disable rlibs that link against dylib-std on vendor ramdisk variations until those dylib
|
||||
// variants are properly supported.
|
||||
dylib.Disable()
|
||||
}
|
||||
rlib.Properties.RustSubName += RlibStdlibSuffix
|
||||
func (libstdTransitionMutator) Split(ctx android.BaseModuleContext) []string {
|
||||
if m, ok := ctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() {
|
||||
// Only create a variant if a library is actually being built.
|
||||
if library, ok := m.compiler.(libraryInterface); ok {
|
||||
if library.rlib() && !library.sysroot() {
|
||||
if library.isFFILibrary() {
|
||||
return []string{"rlib-std"}
|
||||
} else {
|
||||
return []string{"rlib-std", "dylib-std"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return []string{""}
|
||||
}
|
||||
|
||||
func (libstdTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (libstdTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
|
||||
if m, ok := ctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() {
|
||||
if library, ok := m.compiler.(libraryInterface); ok {
|
||||
if library.shared() {
|
||||
return ""
|
||||
}
|
||||
if library.rlib() && !library.sysroot() {
|
||||
if incomingVariation != "" {
|
||||
return incomingVariation
|
||||
}
|
||||
return "rlib-std"
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (libstdTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
|
||||
if variation == "rlib-std" {
|
||||
rlib := ctx.Module().(*Module)
|
||||
rlib.compiler.(libraryInterface).setRlibStd()
|
||||
rlib.Properties.RustSubName += RlibStdlibSuffix
|
||||
} else if variation == "dylib-std" {
|
||||
dylib := ctx.Module().(*Module)
|
||||
dylib.compiler.(libraryInterface).setDylibStd()
|
||||
if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
|
||||
// TODO(b/165791368)
|
||||
// Disable rlibs that link against dylib-std on vendor ramdisk variations until those dylib
|
||||
// variants are properly supported.
|
||||
dylib.Disable()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
rust/rust.go
37
rust/rust.go
@@ -37,20 +37,24 @@ var pctx = android.NewPackageContext("android/soong/rust")
|
||||
|
||||
func init() {
|
||||
android.RegisterModuleType("rust_defaults", defaultsFactory)
|
||||
android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
||||
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
|
||||
ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
|
||||
ctx.BottomUp("rust_begin", BeginMutator).Parallel()
|
||||
})
|
||||
android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
||||
ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
|
||||
})
|
||||
android.PreDepsMutators(registerPreDepsMutators)
|
||||
android.PostDepsMutators(registerPostDepsMutators)
|
||||
pctx.Import("android/soong/android")
|
||||
pctx.Import("android/soong/rust/config")
|
||||
pctx.ImportAs("cc_config", "android/soong/cc/config")
|
||||
android.InitRegistrationContext.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
|
||||
}
|
||||
|
||||
func registerPreDepsMutators(ctx android.RegisterMutatorsContext) {
|
||||
ctx.Transition("rust_libraries", &libraryTransitionMutator{})
|
||||
ctx.Transition("rust_stdlinkage", &libstdTransitionMutator{})
|
||||
ctx.BottomUp("rust_begin", BeginMutator).Parallel()
|
||||
}
|
||||
|
||||
func registerPostDepsMutators(ctx android.RegisterMutatorsContext) {
|
||||
ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
|
||||
}
|
||||
|
||||
type Flags struct {
|
||||
GlobalRustFlags []string // Flags that apply globally to rust
|
||||
GlobalLinkFlags []string // Flags that apply globally to linker
|
||||
@@ -1128,10 +1132,11 @@ type autoDep struct {
|
||||
}
|
||||
|
||||
var (
|
||||
rlibVariation = "rlib"
|
||||
dylibVariation = "dylib"
|
||||
rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
|
||||
dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
|
||||
sourceVariation = "source"
|
||||
rlibVariation = "rlib"
|
||||
dylibVariation = "dylib"
|
||||
rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
|
||||
dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
|
||||
)
|
||||
|
||||
type autoDeppable interface {
|
||||
@@ -1613,7 +1618,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
rlibDepVariations := commonDepVariations
|
||||
rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "link", Variation: ""})
|
||||
|
||||
if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
|
||||
rlibDepVariations = append(rlibDepVariations,
|
||||
@@ -1629,7 +1633,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
|
||||
// dylibs
|
||||
dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation})
|
||||
dylibDepVariations = append(dylibDepVariations, blueprint.Variation{Mutator: "link", Variation: ""})
|
||||
|
||||
for _, lib := range deps.Dylibs {
|
||||
actx.AddVariationDependencies(dylibDepVariations, dylibDepTag, lib)
|
||||
@@ -1650,7 +1653,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
// otherwise select the rlib variant.
|
||||
autoDepVariations := append(commonDepVariations,
|
||||
blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
|
||||
autoDepVariations = append(autoDepVariations, blueprint.Variation{Mutator: "link", Variation: ""})
|
||||
if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
|
||||
actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
|
||||
|
||||
@@ -1664,8 +1666,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
} else if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
|
||||
for _, lib := range deps.Rustlibs {
|
||||
srcProviderVariations := append(commonDepVariations,
|
||||
blueprint.Variation{Mutator: "rust_libraries", Variation: "source"})
|
||||
srcProviderVariations = append(srcProviderVariations, blueprint.Variation{Mutator: "link", Variation: ""})
|
||||
blueprint.Variation{Mutator: "rust_libraries", Variation: sourceVariation})
|
||||
|
||||
// Only add rustlib dependencies if they're source providers themselves.
|
||||
// This is used to track which crate names need to be added to the source generated
|
||||
@@ -1681,7 +1682,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
if deps.Stdlibs != nil {
|
||||
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
|
||||
for _, lib := range deps.Stdlibs {
|
||||
actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}, {Mutator: "link", Variation: ""}}...),
|
||||
actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
|
||||
rlibDepTag, lib)
|
||||
}
|
||||
} else {
|
||||
|
@@ -60,6 +60,7 @@ var rustMockedFiles = android.MockFS{
|
||||
// testRust returns a TestContext in which a basic environment has been setup.
|
||||
// This environment contains a few mocked files. See rustMockedFiles for the list of these files.
|
||||
func testRust(t *testing.T, bp string) *android.TestContext {
|
||||
t.Helper()
|
||||
skipTestIfOsNotSupported(t)
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForRustTest,
|
||||
|
@@ -200,15 +200,8 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
||||
ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
||||
ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
||||
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
||||
// rust mutators
|
||||
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
|
||||
ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
|
||||
ctx.BottomUp("rust_begin", BeginMutator).Parallel()
|
||||
})
|
||||
ctx.PreDepsMutators(registerPreDepsMutators)
|
||||
ctx.RegisterParallelSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
|
||||
ctx.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
|
||||
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
||||
ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
|
||||
})
|
||||
ctx.PostDepsMutators(registerPostDepsMutators)
|
||||
}
|
||||
|
@@ -86,28 +86,28 @@ func GetConfig(name string) PathConfig {
|
||||
// This list specifies whether a particular binary from $PATH is allowed to be
|
||||
// run during the build. For more documentation, see path_interposer.go .
|
||||
var Configuration = map[string]PathConfig{
|
||||
"bash": Allowed,
|
||||
"diff": Allowed,
|
||||
"dlv": Allowed,
|
||||
"expr": Allowed,
|
||||
"fuser": Allowed,
|
||||
"gcert": Allowed,
|
||||
"gcertstatus": Allowed,
|
||||
"gcloud": Allowed,
|
||||
"git": Allowed,
|
||||
"hexdump": Allowed,
|
||||
"jar": Allowed,
|
||||
"java": Allowed,
|
||||
"javap": Allowed,
|
||||
"lsof": Allowed,
|
||||
"openssl": Allowed,
|
||||
"pstree": Allowed,
|
||||
"rsync": Allowed,
|
||||
"sh": Allowed,
|
||||
"stubby": Allowed,
|
||||
"tr": Allowed,
|
||||
"unzip": Allowed,
|
||||
"zip": Allowed,
|
||||
"bash": Allowed,
|
||||
"diff": Allowed,
|
||||
"dlv": Allowed,
|
||||
"expr": Allowed,
|
||||
"fuser": Allowed,
|
||||
"gcert": Allowed,
|
||||
"gcertstatus": Allowed,
|
||||
"gcloud": Allowed,
|
||||
"git": Allowed,
|
||||
"hexdump": Allowed,
|
||||
"jar": Allowed,
|
||||
"java": Allowed,
|
||||
"javap": Allowed,
|
||||
"lsof": Allowed,
|
||||
"openssl": Allowed,
|
||||
"pstree": Allowed,
|
||||
"rsync": Allowed,
|
||||
"sh": Allowed,
|
||||
"stubby": Allowed,
|
||||
"tr": Allowed,
|
||||
"unzip": Allowed,
|
||||
"zip": Allowed,
|
||||
|
||||
// Host toolchain is removed. In-tree toolchain should be used instead.
|
||||
// GCC also can't find cc1 with this implementation.
|
||||
|
Reference in New Issue
Block a user