diff --git a/context.go b/context.go index 2b83adf..cee434c 100644 --- a/context.go +++ b/context.go @@ -125,9 +125,9 @@ type moduleInfo struct { Deps []string } - variantName string - variants variantMap - dependencyVariants variantMap + variantName string + variant variationMap + dependencyVariant variationMap logicModule Module group *moduleGroup @@ -150,15 +150,22 @@ type moduleInfo struct { actionDefs localBuildActions } -type Variant struct { +// A Variation is a way that a variant of a module differs from other variants of the same module. +// For example, two variants of the same module might have Variation{"arch","arm"} and +// Variation{"arch","arm64"} +type Variation struct { + // Mutator is the axis on which this variation applies, i.e. "arch" or "link" Mutator string - Variant string + // Variation is the name of the variation on the axis, i.e. "arm" or "arm64" for arch, or + // "shared" or "static" for link. + Variation string } -type variantMap map[string]string +// A variationMap stores a map of Mutator to Variation to specify a variant of a module. +type variationMap map[string]string -func (vm variantMap) clone() variantMap { - newVm := make(variantMap) +func (vm variationMap) clone() variationMap { + newVm := make(variationMap) for k, v := range vm { newVm[k] = v } @@ -166,7 +173,7 @@ func (vm variantMap) clone() variantMap { return newVm } -func (vm variantMap) equal(other variantMap) bool { +func (vm variationMap) equal(other variationMap) bool { return reflect.DeepEqual(vm, other) } @@ -373,8 +380,7 @@ func (c *Context) RegisterBottomUpMutator(name string, mutator BottomUpMutator) // order is unpredictable. // // In order for dependencies to be satisifed in a later pass, all dependencies -// of a module either must have an identical variant or must have a single -// variant. +// of a module either must have an identical variant or must have no variations. // // The mutator type names given here must be unique to all bottom up or early // mutators in the Context. @@ -709,14 +715,14 @@ func (c *Context) processSubdirs( return nil, nil } -func (c *Context) createVariants(origModule *moduleInfo, mutatorName string, - variantNames []string) ([]*moduleInfo, []error) { +func (c *Context) createVariations(origModule *moduleInfo, mutatorName string, + variationNames []string) ([]*moduleInfo, []error) { newModules := []*moduleInfo{} var errs []error - for i, variantName := range variantNames { + for i, variationName := range variationNames { typeName := origModule.typeName factory, ok := c.moduleFactories[typeName] if !ok { @@ -750,27 +756,27 @@ func (c *Context) createVariants(origModule *moduleInfo, mutatorName string, } } - newVariants := origModule.variants.clone() - newVariants[mutatorName] = variantName + newVariant := origModule.variant.clone() + newVariant[mutatorName] = variationName m := *origModule newModule := &m newModule.directDeps = append([]*moduleInfo(nil), origModule.directDeps...) newModule.logicModule = newLogicModule - newModule.variants = newVariants - newModule.dependencyVariants = origModule.dependencyVariants.clone() + newModule.variant = newVariant + newModule.dependencyVariant = origModule.dependencyVariant.clone() newModule.moduleProperties = newProperties if newModule.variantName == "" { - newModule.variantName = variantName + newModule.variantName = variationName } else { - newModule.variantName += "_" + variantName + newModule.variantName += "_" + variationName } newModules = append(newModules, newModule) c.moduleInfo[newModule.logicModule] = newModule - newErrs := c.convertDepsToVariant(newModule, mutatorName, variantName) + newErrs := c.convertDepsToVariation(newModule, mutatorName, variationName) if len(newErrs) > 0 { errs = append(errs, newErrs...) } @@ -784,22 +790,22 @@ func (c *Context) createVariants(origModule *moduleInfo, mutatorName string, return newModules, errs } -func (c *Context) convertDepsToVariant(module *moduleInfo, - mutatorName, variantName string) (errs []error) { +func (c *Context) convertDepsToVariation(module *moduleInfo, + mutatorName, variationName string) (errs []error) { for i, dep := range module.directDeps { if dep.logicModule == nil { var newDep *moduleInfo for _, m := range dep.splitModules { - if m.variants[mutatorName] == variantName { + if m.variant[mutatorName] == variationName { newDep = m break } } if newDep == nil { errs = append(errs, &Error{ - Err: fmt.Errorf("failed to find variant %q for module %q needed by %q", - variantName, dep.properties.Name, module.properties.Name), + Err: fmt.Errorf("failed to find variation %q for module %q needed by %q", + variationName, dep.properties.Name, module.properties.Name), Pos: module.pos, }) continue @@ -811,7 +817,7 @@ func (c *Context) convertDepsToVariant(module *moduleInfo, return errs } -func (c *Context) prettyPrintVariant(variant variantMap) string { +func (c *Context) prettyPrintVariant(variant variationMap) string { names := make([]string, 0, len(variant)) for _, m := range c.variantMutatorNames { if v, ok := variant[m]; ok { @@ -936,7 +942,7 @@ func (c *Context) ResolveDependencies(config interface{}) []error { // DynamicDependerModule interface then this set consists of the union of those // module names listed in its "deps" property, those returned by its // DynamicDependencies method, and those added by calling AddDependencies or -// AddVariantDependencies on DynamicDependencyModuleContext. Otherwise it +// AddVariationDependencies on DynamicDependencyModuleContext. Otherwise it // is simply those names listed in its "deps" property. func (c *Context) moduleDeps(module *moduleInfo, config interface{}) (errs []error) { @@ -1032,7 +1038,7 @@ func (c *Context) addDependency(module *moduleInfo, depName string) []error { return nil } else { for _, m := range depInfo.modules { - if m.variants.equal(module.dependencyVariants) { + if m.variant.equal(module.dependencyVariant) { module.directDeps = append(module.directDeps, m) return nil } @@ -1042,12 +1048,12 @@ func (c *Context) addDependency(module *moduleInfo, depName string) []error { return []error{&Error{ Err: fmt.Errorf("dependency %q of %q missing variant %q", depInfo.modules[0].properties.Name, module.properties.Name, - c.prettyPrintVariant(module.dependencyVariants)), + c.prettyPrintVariant(module.dependencyVariant)), Pos: depsPos, }} } -func (c *Context) addVariantDependency(module *moduleInfo, variant []Variant, +func (c *Context) addVariationDependency(module *moduleInfo, variations []Variation, depName string) []error { depsPos := module.propertyPos["deps"] @@ -1064,16 +1070,16 @@ func (c *Context) addVariantDependency(module *moduleInfo, variant []Variant, // We can't just append variant.Variant to module.dependencyVariants.variantName and // compare the strings because the result won't be in mutator registration order. // Create a new map instead, and then deep compare the maps. - newVariants := module.dependencyVariants.clone() - for _, v := range variant { - newVariants[v.Mutator] = v.Variant + newVariant := module.dependencyVariant.clone() + for _, v := range variations { + newVariant[v.Mutator] = v.Variation } for _, m := range depInfo.modules { - if newVariants.equal(m.variants) { - // AddVariantDependency allows adding a dependency on itself, but only if + if newVariant.equal(m.variant) { + // AddVariationDependency allows adding a dependency on itself, but only if // that module is earlier in the module list than this one, since we always - // run the generator in order for the variants of a module + // run GenerateBuildActions in order for the variants of a module if depInfo == module.group && beforeInModuleList(module, m, module.group.modules) { return []error{&Error{ Err: fmt.Errorf("%q depends on later version of itself", depName), @@ -1088,7 +1094,7 @@ func (c *Context) addVariantDependency(module *moduleInfo, variant []Variant, return []error{&Error{ Err: fmt.Errorf("dependency %q of %q missing variant %q", depInfo.modules[0].properties.Name, module.properties.Name, - c.prettyPrintVariant(newVariants)), + c.prettyPrintVariant(newVariant)), Pos: depsPos, }} } diff --git a/module_ctx.go b/module_ctx.go index 1ba3dc8..9182c2d 100644 --- a/module_ctx.go +++ b/module_ctx.go @@ -119,7 +119,7 @@ type BaseModuleContext interface { type DynamicDependerModuleContext interface { BaseModuleContext - AddVariantDependencies([]Variant, ...string) + AddVariationDependencies([]Variation, ...string) } type ModuleContext interface { @@ -319,9 +319,15 @@ type dynamicDependerModuleContext struct { module *moduleInfo } -func (mctx *dynamicDependerModuleContext) AddVariantDependencies(variant []Variant, deps ...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 +// argument. +func (mctx *dynamicDependerModuleContext) AddVariationDependencies(variations []Variation, + deps ...string) { + for _, dep := range deps { - errs := mctx.context.addVariantDependency(mctx.module, variant, dep) + errs := mctx.context.addVariationDependency(mctx.module, variations, dep) if len(errs) > 0 { mctx.errs = append(mctx.errs, errs...) } @@ -347,8 +353,8 @@ type baseMutatorContext interface { type EarlyMutatorContext interface { baseMutatorContext - CreateVariants(...string) []Module - CreateLocalVariants(...string) []Module + CreateVariations(...string) []Module + CreateLocalVariations(...string) []Module } type TopDownMutatorContext interface { @@ -364,12 +370,12 @@ type BottomUpMutatorContext interface { baseMutatorContext AddDependency(module Module, name string) - CreateVariants(...string) []Module - SetDependencyVariant(string) + CreateVariations(...string) []Module + SetDependencyVariation(string) } // A Mutator function is called for each Module, and can use -// MutatorContext.CreateSubVariants to split a Module into multiple Modules, +// MutatorContext.CreateVariations to split a Module into multiple Modules, // modifying properties on the new modules to differentiate them. It is called // after parsing all Blueprint files, but before generating any build rules, // and is always called on dependencies before being called on the depending module. @@ -381,35 +387,35 @@ type TopDownMutator func(mctx TopDownMutatorContext) type BottomUpMutator func(mctx BottomUpMutatorContext) type EarlyMutator func(mctx EarlyMutatorContext) -// Split a module into mulitple variants, one for each name in the variantNames -// parameter. It returns a list of new modules in the same order as the variantNames +// Split a module into mulitple variants, one for each name in the variationNames +// parameter. It returns a list of new modules in the same order as the variationNames // list. // // If any of the dependencies of the module being operated on were already split -// by calling CreateVariants with the same name, the dependency will automatically +// by calling CreateVariations with the same name, the dependency will automatically // be updated to point the matching variant. // // If a module is split, and then a module depending on the first module is not split // when the Mutator is later called on it, the dependency of the depending module will // automatically be updated to point to the first variant. -func (mctx *mutatorContext) CreateVariants(variantNames ...string) []Module { - return mctx.createVariants(variantNames, false) +func (mctx *mutatorContext) CreateVariations(variationNames ...string) []Module { + return mctx.createVariations(variationNames, false) } // Split a module into mulitple variants, one for each name in the variantNames // parameter. It returns a list of new modules in the same order as the variantNames // list. // -// Local variants do not affect automatic dependency resolution - dependencies added +// Local variations do not affect automatic dependency resolution - dependencies added // to the split module via deps or DynamicDependerModule must exactly match a variant -// that contains all the non-local variants. -func (mctx *mutatorContext) CreateLocalVariants(variantNames ...string) []Module { - return mctx.createVariants(variantNames, true) +// that contains all the non-local variations. +func (mctx *mutatorContext) CreateLocalVariations(variationNames ...string) []Module { + return mctx.createVariations(variationNames, true) } -func (mctx *mutatorContext) createVariants(variantNames []string, local bool) []Module { +func (mctx *mutatorContext) createVariations(variationNames []string, local bool) []Module { ret := []Module{} - modules, errs := mctx.context.createVariants(mctx.module, mctx.name, variantNames) + modules, errs := mctx.context.createVariations(mctx.module, mctx.name, variationNames) if len(errs) > 0 { mctx.errs = append(mctx.errs, errs...) } @@ -417,21 +423,21 @@ func (mctx *mutatorContext) createVariants(variantNames []string, local bool) [] for i, module := range modules { ret = append(ret, module.logicModule) if !local { - module.dependencyVariants[mctx.name] = variantNames[i] + module.dependencyVariant[mctx.name] = variationNames[i] } } - if len(ret) != len(variantNames) { + if len(ret) != len(variationNames) { panic("oops!") } return ret } -// Set all dangling dependencies on the current module to point to the variant +// Set all dangling dependencies on the current module to point to the variation // with given name. -func (mctx *mutatorContext) SetDependencyVariant(variantName string) { - mctx.context.convertDepsToVariant(mctx.module, mctx.name, variantName) +func (mctx *mutatorContext) SetDependencyVariation(variationName string) { + mctx.context.convertDepsToVariation(mctx.module, mctx.name, variationName) } func (mctx *mutatorContext) Module() Module { @@ -439,7 +445,7 @@ func (mctx *mutatorContext) Module() Module { } // Add a dependency to the given module. The depender can be a specific variant -// of a module, but the dependee must be a module that only has a single variant. +// of a module, but the dependee must be a module that has no variations. // Does not affect the ordering of the current mutator pass, but will be ordered // correctly for all future mutator passes. func (mctx *mutatorContext) AddDependency(module Module, depName string) {