Add SetDefaultDependencyVariation

SetDefaultDependencyVariation sets the variation name that will be used
when a dangling dependency is found while a module is being split. A
dangling dependency can occur if a module is split to a variant that one
of its dependencies is not split into. When the default variation is not
set, such dangling dependency is a hard error. But with the new
function, the default variation can be set and subsequent calls to
CreateVariations and its variations on the same context uses the default
variation when necessary.

(If even the default variation does not exist for the dependent module,
it is an hard error)

Note that this is different from calling SetDependencyVariation("foo")
followed by CreateVariations("foo", "bar"). In that case, regardless of
whether a dependency of the current module has the variant 'bar' or not,
only the 'foo' variant is chosen.

With SetDefaultDependencyVariation("foo") followed by
CreateVariations("foo", "bar"), 'foo' variant is used only when the
'bar' variant of the current module depends on a module that does not
have 'bar' variant.

Bug: 138103882
Test: m
Change-Id: I4520ca87487994de024fdbacda3bef6636225f0d
This commit is contained in:
Jiyong Park 2019-07-29 19:59:15 +09:00 committed by Colin Cross
parent 876099e5e7
commit 1e2e56dc62
2 changed files with 30 additions and 12 deletions

View file

@ -1153,7 +1153,7 @@ func (c *Context) cloneLogicModule(origModule *moduleInfo) (Module, []interface{
}
func (c *Context) createVariations(origModule *moduleInfo, mutatorName string,
variationNames []string) ([]*moduleInfo, []error) {
defaultVariationName *string, variationNames []string) ([]*moduleInfo, []error) {
if len(variationNames) == 0 {
panic(fmt.Errorf("mutator %q passed zero-length variation list for module %q",
@ -1198,7 +1198,7 @@ func (c *Context) createVariations(origModule *moduleInfo, mutatorName string,
newModules = append(newModules, newModule)
newErrs := c.convertDepsToVariation(newModule, mutatorName, variationName)
newErrs := c.convertDepsToVariation(newModule, mutatorName, variationName, defaultVariationName)
if len(newErrs) > 0 {
errs = append(errs, newErrs...)
}
@ -1215,7 +1215,7 @@ func (c *Context) createVariations(origModule *moduleInfo, mutatorName string,
}
func (c *Context) convertDepsToVariation(module *moduleInfo,
mutatorName, variationName string) (errs []error) {
mutatorName, variationName string, defaultVariationName *string) (errs []error) {
for i, dep := range module.directDeps {
if dep.module.logicModule == nil {
@ -1226,6 +1226,15 @@ func (c *Context) convertDepsToVariation(module *moduleInfo,
break
}
}
if newDep == nil && defaultVariationName != nil {
// give it a second chance; match with defaultVariationName
for _, m := range dep.module.splitModules {
if m.variant[mutatorName] == *defaultVariationName {
newDep = m
break
}
}
}
if newDep == nil {
errs = append(errs, &BlueprintError{
Err: fmt.Errorf("failed to find variation %q for module %q needed by %q",

View file

@ -661,12 +661,13 @@ func (m *moduleContext) GetMissingDependencies() []string {
type mutatorContext struct {
baseModuleContext
name string
reverseDeps []reverseDep
rename []rename
replace []replace
newVariations []*moduleInfo // new variants of existing modules
newModules []*moduleInfo // brand new modules
name string
reverseDeps []reverseDep
rename []rename
replace []replace
newVariations []*moduleInfo // new variants of existing modules
newModules []*moduleInfo // brand new modules
defaultVariation *string
}
type BaseMutatorContext interface {
@ -752,9 +753,13 @@ type BottomUpMutatorContext interface {
CreateLocalVariations(...string) []Module
// SetDependencyVariation sets all dangling dependencies on the current module to point to the variation
// with given name.
// with given name. This function ignores the default variation set by SetDefaultDependencyVariation.
SetDependencyVariation(string)
// SetDefaultDependencyVariation sets the default variation when a dangling reference is detected
// during the subsequent calls on Create*Variations* functions. To reset, set it to nil.
SetDefaultDependencyVariation(*string)
// AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
// argument to select which variant of the dependency to use. A variant of the dependency must
// exist that matches the all of the non-local variations of the current module, plus the variations
@ -825,7 +830,7 @@ func (mctx *mutatorContext) CreateLocalVariations(variationNames ...string) []Mo
func (mctx *mutatorContext) createVariations(variationNames []string, local bool) []Module {
ret := []Module{}
modules, errs := mctx.context.createVariations(mctx.module, mctx.name, variationNames)
modules, errs := mctx.context.createVariations(mctx.module, mctx.name, mctx.defaultVariation, variationNames)
if len(errs) > 0 {
mctx.errs = append(mctx.errs, errs...)
}
@ -850,7 +855,11 @@ func (mctx *mutatorContext) createVariations(variationNames []string, local bool
}
func (mctx *mutatorContext) SetDependencyVariation(variationName string) {
mctx.context.convertDepsToVariation(mctx.module, mctx.name, variationName)
mctx.context.convertDepsToVariation(mctx.module, mctx.name, variationName, nil)
}
func (mctx *mutatorContext) SetDefaultDependencyVariation(variationName *string) {
mctx.defaultVariation = variationName
}
func (mctx *mutatorContext) Module() Module {