2015-01-23 23:15:10 +01:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
package blueprint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2020-05-13 10:06:17 +02:00
|
|
|
"strings"
|
2019-12-31 03:40:09 +01:00
|
|
|
"sync"
|
2014-07-03 01:40:31 +02:00
|
|
|
"text/scanner"
|
2017-02-01 22:21:35 +01:00
|
|
|
|
2020-05-13 10:06:17 +02:00
|
|
|
"github.com/google/blueprint/parser"
|
2017-02-01 22:21:35 +01:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2017-07-28 23:32:36 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2014-05-28 01:34:41 +02:00
|
|
|
)
|
|
|
|
|
2014-09-25 05:28:11 +02:00
|
|
|
// A Module handles generating all of the Ninja build actions needed to build a
|
2014-12-19 01:28:54 +01:00
|
|
|
// single module based on properties defined in a Blueprints file. Module
|
|
|
|
// objects are initially created during the parse phase of a Context using one
|
|
|
|
// of the registered module types (and the associated ModuleFactory function).
|
|
|
|
// The Module's properties struct is automatically filled in with the property
|
|
|
|
// values specified in the Blueprints file (see Context.RegisterModuleType for more
|
2014-09-25 05:28:11 +02:00
|
|
|
// information on this).
|
|
|
|
//
|
2014-12-19 01:28:54 +01:00
|
|
|
// A Module can be split into multiple Modules by a Mutator. All existing
|
|
|
|
// properties set on the module will be duplicated to the new Module, and then
|
|
|
|
// modified as necessary by the Mutator.
|
|
|
|
//
|
2014-09-25 05:28:11 +02:00
|
|
|
// The Module implementation can access the build configuration as well as any
|
|
|
|
// modules on which on which it depends (as defined by the "deps" property
|
2015-10-29 23:32:56 +01:00
|
|
|
// specified in the Blueprints file, dynamically added by implementing the
|
|
|
|
// (deprecated) DynamicDependerModule interface, or dynamically added by a
|
|
|
|
// BottomUpMutator) using the ModuleContext passed to GenerateBuildActions.
|
|
|
|
// This ModuleContext is also used to create Ninja build actions and to report
|
|
|
|
// errors to the user.
|
2014-09-25 05:28:11 +02:00
|
|
|
//
|
|
|
|
// In addition to implementing the GenerateBuildActions method, a Module should
|
|
|
|
// implement methods that provide dependant modules and singletons information
|
|
|
|
// they need to generate their build actions. These methods will only be called
|
|
|
|
// after GenerateBuildActions is called because the Context calls
|
|
|
|
// GenerateBuildActions in dependency-order (and singletons are invoked after
|
|
|
|
// all the Modules). The set of methods a Module supports will determine how
|
|
|
|
// dependant Modules interact with it.
|
|
|
|
//
|
|
|
|
// For example, consider a Module that is responsible for generating a library
|
|
|
|
// that other modules can link against. The library Module might implement the
|
|
|
|
// following interface:
|
|
|
|
//
|
|
|
|
// type LibraryProducer interface {
|
|
|
|
// LibraryFileName() string
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func IsLibraryProducer(module blueprint.Module) {
|
|
|
|
// _, ok := module.(LibraryProducer)
|
|
|
|
// return ok
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// A binary-producing Module that depends on the library Module could then do:
|
|
|
|
//
|
|
|
|
// func (m *myBinaryModule) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
|
|
|
// ...
|
|
|
|
// var libraryFiles []string
|
|
|
|
// ctx.VisitDepsDepthFirstIf(IsLibraryProducer,
|
|
|
|
// func(module blueprint.Module) {
|
|
|
|
// libProducer := module.(LibraryProducer)
|
|
|
|
// libraryFiles = append(libraryFiles, libProducer.LibraryFileName())
|
|
|
|
// })
|
|
|
|
// ...
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// to build the list of library file names that should be included in its link
|
|
|
|
// command.
|
2015-01-08 03:08:56 +01:00
|
|
|
//
|
|
|
|
// GenerateBuildActions may be called from multiple threads. It is guaranteed to
|
|
|
|
// be called after it has finished being called on all dependencies and on all
|
|
|
|
// variants of that appear earlier in the ModuleContext.VisitAllModuleVariants list.
|
|
|
|
// Any accesses to global variables or to Module objects that are not dependencies
|
|
|
|
// or variants of the current Module must be synchronized by the implementation of
|
|
|
|
// GenerateBuildActions.
|
2014-05-28 01:34:41 +02:00
|
|
|
type Module interface {
|
2016-05-17 23:58:05 +02:00
|
|
|
// Name returns a string used to uniquely identify each module. The return
|
|
|
|
// value must be unique across all modules. It is only called once, during
|
|
|
|
// initial blueprint parsing. To change the name later a mutator must call
|
|
|
|
// MutatorContext.Rename
|
|
|
|
//
|
|
|
|
// In most cases, Name should return the contents of a "name:" property from
|
|
|
|
// the blueprint file. An embeddable SimpleName object can be used for this
|
|
|
|
// case.
|
|
|
|
Name() string
|
|
|
|
|
2014-09-25 05:28:11 +02:00
|
|
|
// GenerateBuildActions is called by the Context that created the Module
|
|
|
|
// during its generate phase. This call should generate all Ninja build
|
|
|
|
// actions (rules, pools, and build statements) needed to build the module.
|
2014-05-28 01:34:41 +02:00
|
|
|
GenerateBuildActions(ModuleContext)
|
|
|
|
}
|
|
|
|
|
2014-09-25 05:28:11 +02:00
|
|
|
// A DynamicDependerModule is a Module that may add dependencies that do not
|
|
|
|
// appear in its "deps" property. Any Module that implements this interface
|
|
|
|
// will have its DynamicDependencies method called by the Context that created
|
|
|
|
// it during generate phase.
|
2015-10-29 23:32:56 +01:00
|
|
|
//
|
|
|
|
// Deprecated, use a BottomUpMutator instead
|
2014-09-25 05:28:11 +02:00
|
|
|
type DynamicDependerModule interface {
|
|
|
|
Module
|
|
|
|
|
|
|
|
// DynamicDependencies is called by the Context that created the
|
|
|
|
// DynamicDependerModule during its generate phase. This call should return
|
|
|
|
// the list of module names that the DynamicDependerModule depends on
|
|
|
|
// dynamically. Module names that already appear in the "deps" property may
|
|
|
|
// but do not need to be included in the returned list.
|
|
|
|
DynamicDependencies(DynamicDependerModuleContext) []string
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:40:09 +01:00
|
|
|
type EarlyModuleContext interface {
|
2019-05-20 23:51:55 +02:00
|
|
|
// Module returns the current module as a Module. It should rarely be necessary, as the module already has a
|
|
|
|
// reference to itself.
|
2019-03-30 00:35:02 +01:00
|
|
|
Module() Module
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
|
|
|
|
// the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
|
2014-05-28 01:34:41 +02:00
|
|
|
ModuleName() string
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// ModuleDir returns the path to the directory that contains the defintion of the module.
|
2014-05-28 01:34:41 +02:00
|
|
|
ModuleDir() string
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// ModuleType returns the name of the module type that was used to create the module, as specified in
|
|
|
|
// RegisterModuleType.
|
2019-03-01 22:43:09 +01:00
|
|
|
ModuleType() string
|
2019-05-20 23:51:55 +02:00
|
|
|
|
2020-01-14 21:59:10 +01:00
|
|
|
// BlueprintFile returns the name of the blueprint file that contains the definition of this
|
|
|
|
// module.
|
|
|
|
BlueprintsFile() string
|
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// Config returns the config object that was passed to Context.PrepareBuildActions.
|
2014-06-12 03:31:16 +02:00
|
|
|
Config() interface{}
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// ContainsProperty returns true if the specified property name was set in the module definition.
|
2014-10-29 22:51:13 +01:00
|
|
|
ContainsProperty(name string) bool
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// Errorf reports an error at the specified position of the module definition file.
|
2014-07-03 01:40:31 +02:00
|
|
|
Errorf(pos scanner.Position, fmt string, args ...interface{})
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// ModuleErrorf reports an error at the line number of the module type in the module definition.
|
2014-05-28 01:34:41 +02:00
|
|
|
ModuleErrorf(fmt string, args ...interface{})
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// PropertyErrorf reports an error at the line number of a property in the module definition.
|
2014-05-28 01:34:41 +02:00
|
|
|
PropertyErrorf(property, fmt string, args ...interface{})
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// Failed returns true if any errors have been reported. In most cases the module can continue with generating
|
|
|
|
// build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
|
|
|
|
// has prevented the module from creating necessary data it can return early when Failed returns true.
|
2014-07-03 01:40:31 +02:00
|
|
|
Failed() bool
|
2015-03-11 04:08:19 +01:00
|
|
|
|
2018-02-23 23:49:45 +01:00
|
|
|
// GlobWithDeps returns a list of files and directories that match the
|
|
|
|
// specified pattern but do not match any of the patterns in excludes.
|
|
|
|
// Any directories will have a '/' suffix. It also adds efficient
|
|
|
|
// dependencies to rerun the primary builder whenever a file matching
|
|
|
|
// the pattern as added or removed, without rerunning if a file that
|
|
|
|
// does not match the pattern is added to a searched directory.
|
2016-11-01 19:10:51 +01:00
|
|
|
GlobWithDeps(pattern string, excludes []string) ([]string, error)
|
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// Fs returns a pathtools.Filesystem that can be used to interact with files. Using the Filesystem interface allows
|
|
|
|
// the module to be used in build system tests that run against a mock filesystem.
|
2017-02-01 22:21:35 +01:00
|
|
|
Fs() pathtools.FileSystem
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
|
|
|
|
// primary builder will be rerun whenever the specified files are modified.
|
2017-08-01 02:26:06 +02:00
|
|
|
AddNinjaFileDeps(deps ...string)
|
2017-02-01 22:21:35 +01:00
|
|
|
|
2015-10-29 23:32:56 +01:00
|
|
|
moduleInfo() *moduleInfo
|
2016-01-07 22:43:09 +01:00
|
|
|
error(err error)
|
2017-11-11 00:12:08 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
|
|
|
|
// default SimpleNameInterface if Context.SetNameInterface was not called.
|
2017-11-11 00:12:08 +01:00
|
|
|
Namespace() Namespace
|
2019-12-31 03:38:20 +01:00
|
|
|
|
|
|
|
// ModuleFactories returns a map of all of the global ModuleFactories by name.
|
|
|
|
ModuleFactories() map[string]ModuleFactory
|
2019-12-31 03:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type BaseModuleContext interface {
|
|
|
|
EarlyModuleContext
|
2014-12-18 20:05:45 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
|
|
|
|
// none exists. It panics if the dependency does not have the specified tag.
|
2019-03-30 00:35:02 +01:00
|
|
|
GetDirectDepWithTag(name string, tag DependencyTag) Module
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
|
|
|
|
// name, or nil if none exists. If there are multiple dependencies on the same module it returns
|
|
|
|
// the first DependencyTag.
|
2019-03-30 00:35:02 +01:00
|
|
|
GetDirectDep(name string) (Module, DependencyTag)
|
2015-10-29 23:32:56 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// VisitDirectDeps calls visit for each direct dependency. If there are multiple direct dependencies on the same
|
|
|
|
// module visit will be called multiple times on that module and OtherModuleDependencyTag will return a different
|
|
|
|
// tag for each.
|
|
|
|
//
|
|
|
|
// The Module passed to the visit function should not be retained outside of the visit function, it may be
|
|
|
|
// invalidated by future mutators.
|
2019-03-30 00:35:02 +01:00
|
|
|
VisitDirectDeps(visit func(Module))
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
|
|
|
|
// multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
|
|
|
|
// OtherModuleDependencyTag will return a different tag for each.
|
|
|
|
//
|
|
|
|
// The Module passed to the visit function should not be retained outside of the visit function, it may be
|
|
|
|
// invalidated by future mutators.
|
2019-03-30 00:35:02 +01:00
|
|
|
VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// VisitDepsDepthFirst calls visit for each transitive dependency, traversing the dependency tree in depth first
|
|
|
|
// order. visit will only be called once for any given module, even if there are multiple paths through the
|
|
|
|
// dependency tree to the module or multiple direct dependencies with different tags. OtherModuleDependencyTag will
|
|
|
|
// return the tag for the first path found to the module.
|
|
|
|
//
|
|
|
|
// The Module passed to the visit function should not be retained outside of the visit function, it may be
|
|
|
|
// invalidated by future mutators.
|
2019-03-30 00:35:02 +01:00
|
|
|
VisitDepsDepthFirst(visit func(Module))
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// VisitDepsDepthFirst calls pred for each transitive dependency, and if pred returns true calls visit, traversing
|
|
|
|
// the dependency tree in depth first order. visit will only be called once for any given module, even if there are
|
|
|
|
// multiple paths through the dependency tree to the module or multiple direct dependencies with different tags.
|
|
|
|
// OtherModuleDependencyTag will return the tag for the first path found to the module. The return value of pred
|
|
|
|
// does not affect which branches of the tree are traversed.
|
|
|
|
//
|
|
|
|
// The Module passed to the visit function should not be retained outside of the visit function, it may be
|
|
|
|
// invalidated by future mutators.
|
2019-03-30 00:35:02 +01:00
|
|
|
VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
|
|
|
|
// be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
|
|
|
|
// child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
|
|
|
|
// (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child.
|
|
|
|
//
|
|
|
|
// The Modules passed to the visit function should not be retained outside of the visit function, they may be
|
|
|
|
// invalidated by future mutators.
|
2019-03-30 00:35:02 +01:00
|
|
|
WalkDeps(visit func(Module, Module) bool)
|
2014-09-25 05:28:11 +02:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
|
|
|
|
// It is intended for use inside the visit functions of Visit* and WalkDeps.
|
2014-09-25 05:28:11 +02:00
|
|
|
OtherModuleName(m Module) string
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
|
|
|
|
// It is intended for use inside the visit functions of Visit* and WalkDeps.
|
2019-03-01 22:43:09 +01:00
|
|
|
OtherModuleDir(m Module) string
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// OtherModuleSubDir returns the unique subdirectory name of another Module. See ModuleContext.ModuleSubDir for
|
|
|
|
// more information.
|
|
|
|
// It is intended for use inside the visit functions of Visit* and WalkDeps.
|
2019-03-01 22:43:09 +01:00
|
|
|
OtherModuleSubDir(m Module) string
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
|
|
|
|
// It is intended for use inside the visit functions of Visit* and WalkDeps.
|
2019-03-01 22:43:09 +01:00
|
|
|
OtherModuleType(m Module) string
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
|
|
|
|
// It is intended for use inside the visit functions of Visit* and WalkDeps.
|
2014-09-25 05:28:11 +02:00
|
|
|
OtherModuleErrorf(m Module, fmt string, args ...interface{})
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
|
|
|
|
// on the module. When called inside a Visit* method with current module being visited, and there are multiple
|
|
|
|
// dependencies on the module being visited, it returns the dependency tag used for the current dependency.
|
2016-04-12 00:47:28 +02:00
|
|
|
OtherModuleDependencyTag(m Module) DependencyTag
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
|
|
|
|
// passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
|
2019-03-30 00:35:02 +01:00
|
|
|
OtherModuleExists(name string) bool
|
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2019-03-30 00:35:02 +01:00
|
|
|
type DynamicDependerModuleContext BottomUpMutatorContext
|
2016-12-14 01:45:06 +01:00
|
|
|
|
2019-03-30 00:35:02 +01:00
|
|
|
type ModuleContext interface {
|
|
|
|
BaseModuleContext
|
2014-11-11 23:18:53 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// ModuleSubDir returns a unique name for the current variant of a module that can be used as part of the path
|
|
|
|
// to ensure that each variant of a module gets its own intermediates directory to write to.
|
2014-12-19 01:28:54 +01:00
|
|
|
ModuleSubDir() string
|
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// Variable creates a new ninja variable scoped to the module. It can be referenced by calls to Rule and Build
|
|
|
|
// in the same module.
|
2015-11-26 00:29:32 +01:00
|
|
|
Variable(pctx PackageContext, name, value string)
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// Rule creates a new ninja rule scoped to the module. It can be referenced by calls to Build in the same module.
|
2015-11-26 00:29:32 +01:00
|
|
|
Rule(pctx PackageContext, name string, params RuleParams, argNames ...string) Rule
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// Build creates a new ninja build statement.
|
2015-11-26 00:29:32 +01:00
|
|
|
Build(pctx PackageContext, params BuildParams)
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
|
|
|
|
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
|
|
|
|
// Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
|
|
|
|
// only done once for all variants of a module.
|
2014-12-19 01:28:54 +01:00
|
|
|
PrimaryModule() Module
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// FinalModule returns the last variant of the current module. Variants of a module are always visited in
|
|
|
|
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
|
|
|
|
// variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
|
|
|
|
// singleton actions that are only done once for all variants of a module.
|
2015-01-07 01:19:59 +01:00
|
|
|
FinalModule() Module
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
|
|
|
|
// visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
|
|
|
|
// from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
|
|
|
|
// data modified by the current mutator.
|
2015-01-07 01:19:59 +01:00
|
|
|
VisitAllModuleVariants(visit func(Module))
|
2015-12-18 00:49:30 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
|
|
|
|
// but do not exist. It can be used with Context.SetAllowMissingDependencies to allow the primary builder to
|
|
|
|
// handle missing dependencies on its own instead of having Blueprint treat them as an error.
|
2015-12-18 00:49:30 +01:00
|
|
|
GetMissingDependencies() []string
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
var _ BaseModuleContext = (*baseModuleContext)(nil)
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
type baseModuleContext struct {
|
2016-08-07 07:52:01 +02:00
|
|
|
context *Context
|
|
|
|
config interface{}
|
|
|
|
module *moduleInfo
|
|
|
|
errs []error
|
|
|
|
visitingParent *moduleInfo
|
|
|
|
visitingDep depInfo
|
2017-08-01 02:26:06 +02:00
|
|
|
ninjaFileDeps []string
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:32:56 +01:00
|
|
|
func (d *baseModuleContext) moduleInfo() *moduleInfo {
|
|
|
|
return d.module
|
|
|
|
}
|
|
|
|
|
2019-03-30 00:35:02 +01:00
|
|
|
func (d *baseModuleContext) Module() Module {
|
|
|
|
return d.module.logicModule
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) ModuleName() string {
|
2016-05-17 23:58:05 +02:00
|
|
|
return d.module.Name()
|
2014-06-23 02:02:55 +02:00
|
|
|
}
|
|
|
|
|
2019-03-01 22:43:09 +01:00
|
|
|
func (d *baseModuleContext) ModuleType() string {
|
|
|
|
return d.module.typeName
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) ContainsProperty(name string) bool {
|
2015-03-11 08:57:25 +01:00
|
|
|
_, ok := d.module.propertyPos[name]
|
2014-10-29 22:51:13 +01:00
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) ModuleDir() string {
|
2015-03-11 08:57:25 +01:00
|
|
|
return filepath.Dir(d.module.relBlueprintsFile)
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2020-01-14 21:59:10 +01:00
|
|
|
func (d *baseModuleContext) BlueprintsFile() string {
|
|
|
|
return d.module.relBlueprintsFile
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) Config() interface{} {
|
2014-09-25 05:28:11 +02:00
|
|
|
return d.config
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2016-01-07 22:43:09 +01:00
|
|
|
func (d *baseModuleContext) error(err error) {
|
|
|
|
if err != nil {
|
|
|
|
d.errs = append(d.errs, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) Errorf(pos scanner.Position,
|
2014-09-25 05:28:11 +02:00
|
|
|
format string, args ...interface{}) {
|
2014-07-03 01:40:31 +02:00
|
|
|
|
2016-10-08 02:13:10 +02:00
|
|
|
d.error(&BlueprintError{
|
2014-07-03 01:40:31 +02:00
|
|
|
Err: fmt.Errorf(format, args...),
|
|
|
|
Pos: pos,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) ModuleErrorf(format string,
|
2014-09-25 05:28:11 +02:00
|
|
|
args ...interface{}) {
|
|
|
|
|
2016-10-08 02:13:10 +02:00
|
|
|
d.error(&ModuleError{
|
|
|
|
BlueprintError: BlueprintError{
|
|
|
|
Err: fmt.Errorf(format, args...),
|
|
|
|
Pos: d.module.pos,
|
|
|
|
},
|
|
|
|
module: d.module,
|
2014-05-28 01:34:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) PropertyErrorf(property, format string,
|
2014-05-28 01:34:41 +02:00
|
|
|
args ...interface{}) {
|
|
|
|
|
2015-11-03 01:10:23 +01:00
|
|
|
pos := d.module.propertyPos[property]
|
|
|
|
|
|
|
|
if !pos.IsValid() {
|
|
|
|
pos = d.module.pos
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2016-10-08 02:13:10 +02:00
|
|
|
d.error(&PropertyError{
|
|
|
|
ModuleError: ModuleError{
|
|
|
|
BlueprintError: BlueprintError{
|
|
|
|
Err: fmt.Errorf(format, args...),
|
|
|
|
Pos: pos,
|
|
|
|
},
|
|
|
|
module: d.module,
|
|
|
|
},
|
|
|
|
property: property,
|
2014-05-28 01:34:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-18 20:05:45 +01:00
|
|
|
func (d *baseModuleContext) Failed() bool {
|
2014-09-25 05:28:11 +02:00
|
|
|
return len(d.errs) > 0
|
|
|
|
}
|
|
|
|
|
2016-11-01 19:10:51 +01:00
|
|
|
func (d *baseModuleContext) GlobWithDeps(pattern string,
|
|
|
|
excludes []string) ([]string, error) {
|
|
|
|
return d.context.glob(pattern, excludes)
|
|
|
|
}
|
|
|
|
|
2017-02-01 22:21:35 +01:00
|
|
|
func (d *baseModuleContext) Fs() pathtools.FileSystem {
|
|
|
|
return d.context.fs
|
|
|
|
}
|
|
|
|
|
2017-11-11 00:12:08 +01:00
|
|
|
func (d *baseModuleContext) Namespace() Namespace {
|
2017-12-02 02:10:52 +01:00
|
|
|
return d.context.nameInterface.GetNamespace(newNamespaceContext(d.module))
|
2017-11-11 00:12:08 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 22:23:56 +01:00
|
|
|
var _ ModuleContext = (*moduleContext)(nil)
|
2014-09-25 05:28:11 +02:00
|
|
|
|
2014-12-17 22:23:56 +01:00
|
|
|
type moduleContext struct {
|
2014-12-18 20:05:45 +01:00
|
|
|
baseModuleContext
|
2015-12-18 00:49:30 +01:00
|
|
|
scope *localScope
|
|
|
|
actionDefs localBuildActions
|
|
|
|
handledMissingDeps bool
|
2014-09-25 05:28:11 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (m *baseModuleContext) OtherModuleName(logicModule Module) string {
|
2015-03-11 08:57:25 +01:00
|
|
|
module := m.context.moduleInfo[logicModule]
|
2016-05-17 23:58:05 +02:00
|
|
|
return module.Name()
|
2014-09-25 05:28:11 +02:00
|
|
|
}
|
|
|
|
|
2019-03-01 22:43:09 +01:00
|
|
|
func (m *baseModuleContext) OtherModuleDir(logicModule Module) string {
|
|
|
|
module := m.context.moduleInfo[logicModule]
|
|
|
|
return filepath.Dir(module.relBlueprintsFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *baseModuleContext) OtherModuleSubDir(logicModule Module) string {
|
|
|
|
module := m.context.moduleInfo[logicModule]
|
|
|
|
return module.variantName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *baseModuleContext) OtherModuleType(logicModule Module) string {
|
|
|
|
module := m.context.moduleInfo[logicModule]
|
|
|
|
return module.typeName
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (m *baseModuleContext) OtherModuleErrorf(logicModule Module, format string,
|
2014-06-23 02:02:55 +02:00
|
|
|
args ...interface{}) {
|
|
|
|
|
2015-03-11 08:57:25 +01:00
|
|
|
module := m.context.moduleInfo[logicModule]
|
2016-10-08 02:13:10 +02:00
|
|
|
m.errs = append(m.errs, &ModuleError{
|
|
|
|
BlueprintError: BlueprintError{
|
|
|
|
Err: fmt.Errorf(format, args...),
|
|
|
|
Pos: module.pos,
|
|
|
|
},
|
|
|
|
module: module,
|
2014-06-23 02:02:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (m *baseModuleContext) OtherModuleDependencyTag(logicModule Module) DependencyTag {
|
|
|
|
// fast path for calling OtherModuleDependencyTag from inside VisitDirectDeps
|
2016-08-07 07:52:01 +02:00
|
|
|
if logicModule == m.visitingDep.module.logicModule {
|
|
|
|
return m.visitingDep.tag
|
2016-04-12 00:47:28 +02:00
|
|
|
}
|
|
|
|
|
2016-08-07 07:52:01 +02:00
|
|
|
for _, dep := range m.visitingParent.directDeps {
|
2016-04-12 00:47:28 +02:00
|
|
|
if dep.module.logicModule == logicModule {
|
|
|
|
return dep.tag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2015-02-10 20:24:52 +01:00
|
|
|
}
|
|
|
|
|
2019-03-30 00:35:02 +01:00
|
|
|
func (m *baseModuleContext) OtherModuleExists(name string) bool {
|
|
|
|
_, exists := m.context.nameInterface.ModuleFromName(name, m.module.namespace())
|
|
|
|
return exists
|
|
|
|
}
|
|
|
|
|
2016-12-14 01:45:06 +01:00
|
|
|
func (m *baseModuleContext) GetDirectDep(name string) (Module, DependencyTag) {
|
|
|
|
for _, dep := range m.module.directDeps {
|
|
|
|
if dep.module.Name() == name {
|
|
|
|
return dep.module.logicModule, dep.tag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *baseModuleContext) GetDirectDepWithTag(name string, tag DependencyTag) Module {
|
2019-02-28 00:31:52 +01:00
|
|
|
var deps []depInfo
|
2016-12-14 01:45:06 +01:00
|
|
|
for _, dep := range m.module.directDeps {
|
|
|
|
if dep.module.Name() == name {
|
2019-02-28 00:31:52 +01:00
|
|
|
if dep.tag == tag {
|
|
|
|
return dep.module.logicModule
|
2016-12-14 01:45:06 +01:00
|
|
|
}
|
2019-02-28 00:31:52 +01:00
|
|
|
deps = append(deps, dep)
|
2016-12-14 01:45:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-28 00:31:52 +01:00
|
|
|
if len(deps) != 0 {
|
|
|
|
panic(fmt.Errorf("Unable to find dependency %q with requested tag %#v. Found: %#v", deps[0].module, tag, deps))
|
|
|
|
}
|
|
|
|
|
2016-12-14 01:45:06 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (m *baseModuleContext) VisitDirectDeps(visit func(Module)) {
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
panic(newPanicErrorf(r, "VisitDirectDeps(%s, %s) for dependency %s",
|
2016-08-07 07:52:01 +02:00
|
|
|
m.module, funcName(visit), m.visitingDep.module))
|
2016-04-12 00:47:28 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-08-07 07:52:01 +02:00
|
|
|
m.visitingParent = m.module
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
for _, dep := range m.module.directDeps {
|
2016-08-07 07:52:01 +02:00
|
|
|
m.visitingDep = dep
|
2016-04-12 00:47:28 +02:00
|
|
|
visit(dep.module.logicModule)
|
|
|
|
}
|
2016-08-07 07:52:01 +02:00
|
|
|
|
|
|
|
m.visitingParent = nil
|
|
|
|
m.visitingDep = depInfo{}
|
2016-04-12 00:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
panic(newPanicErrorf(r, "VisitDirectDepsIf(%s, %s, %s) for dependency %s",
|
2016-08-07 07:52:01 +02:00
|
|
|
m.module, funcName(pred), funcName(visit), m.visitingDep.module))
|
2016-04-12 00:47:28 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-08-07 07:52:01 +02:00
|
|
|
m.visitingParent = m.module
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
for _, dep := range m.module.directDeps {
|
2016-08-07 07:52:01 +02:00
|
|
|
m.visitingDep = dep
|
2016-04-12 00:47:28 +02:00
|
|
|
if pred(dep.module.logicModule) {
|
|
|
|
visit(dep.module.logicModule)
|
|
|
|
}
|
|
|
|
}
|
2016-08-07 07:52:01 +02:00
|
|
|
|
|
|
|
m.visitingParent = nil
|
|
|
|
m.visitingDep = depInfo{}
|
2015-02-10 20:24:52 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (m *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
|
2016-08-07 07:52:01 +02:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
panic(newPanicErrorf(r, "VisitDepsDepthFirst(%s, %s) for dependency %s",
|
|
|
|
m.module, funcName(visit), m.visitingDep.module))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-06-20 20:16:37 +02:00
|
|
|
m.context.walkDeps(m.module, false, nil, func(dep depInfo, parent *moduleInfo) {
|
2016-08-07 07:52:01 +02:00
|
|
|
m.visitingParent = parent
|
|
|
|
m.visitingDep = dep
|
|
|
|
visit(dep.module.logicModule)
|
|
|
|
})
|
|
|
|
|
|
|
|
m.visitingParent = nil
|
|
|
|
m.visitingDep = depInfo{}
|
2014-11-11 23:18:53 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (m *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool,
|
2014-11-11 23:18:53 +01:00
|
|
|
visit func(Module)) {
|
|
|
|
|
2016-08-07 07:52:01 +02:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
panic(newPanicErrorf(r, "VisitDepsDepthFirstIf(%s, %s, %s) for dependency %s",
|
|
|
|
m.module, funcName(pred), funcName(visit), m.visitingDep.module))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-06-20 20:16:37 +02:00
|
|
|
m.context.walkDeps(m.module, false, nil, func(dep depInfo, parent *moduleInfo) {
|
2016-08-07 07:52:01 +02:00
|
|
|
if pred(dep.module.logicModule) {
|
|
|
|
m.visitingParent = parent
|
|
|
|
m.visitingDep = dep
|
|
|
|
visit(dep.module.logicModule)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
m.visitingParent = nil
|
|
|
|
m.visitingDep = depInfo{}
|
2014-11-11 23:18:53 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 22:31:53 +02:00
|
|
|
func (m *baseModuleContext) WalkDeps(visit func(child, parent Module) bool) {
|
2018-06-20 20:16:37 +02:00
|
|
|
m.context.walkDeps(m.module, true, func(dep depInfo, parent *moduleInfo) bool {
|
2016-08-07 07:52:01 +02:00
|
|
|
m.visitingParent = parent
|
|
|
|
m.visitingDep = dep
|
|
|
|
return visit(dep.module.logicModule, parent.logicModule)
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
m.visitingParent = nil
|
|
|
|
m.visitingDep = depInfo{}
|
2015-10-06 23:03:27 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 02:26:06 +02:00
|
|
|
func (m *baseModuleContext) AddNinjaFileDeps(deps ...string) {
|
|
|
|
m.ninjaFileDeps = append(m.ninjaFileDeps, deps...)
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:38:20 +01:00
|
|
|
func (m *baseModuleContext) ModuleFactories() map[string]ModuleFactory {
|
|
|
|
ret := make(map[string]ModuleFactory)
|
|
|
|
for k, v := range m.context.moduleFactories {
|
|
|
|
ret[k] = v
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2014-12-19 01:28:54 +01:00
|
|
|
func (m *moduleContext) ModuleSubDir() string {
|
2015-03-11 22:35:41 +01:00
|
|
|
return m.module.variantName
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
2015-11-26 00:29:32 +01:00
|
|
|
func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
|
2014-10-03 11:49:58 +02:00
|
|
|
m.scope.ReparentTo(pctx)
|
2014-07-01 03:07:17 +02:00
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
v, err := m.scope.AddLocalVariable(name, value)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.actionDefs.variables = append(m.actionDefs.variables, v)
|
|
|
|
}
|
|
|
|
|
2015-11-26 00:29:32 +01:00
|
|
|
func (m *moduleContext) Rule(pctx PackageContext, name string,
|
2014-10-03 11:49:58 +02:00
|
|
|
params RuleParams, argNames ...string) Rule {
|
2014-06-06 05:00:22 +02:00
|
|
|
|
2014-10-03 11:49:58 +02:00
|
|
|
m.scope.ReparentTo(pctx)
|
2014-07-01 03:07:17 +02:00
|
|
|
|
2014-06-06 05:00:22 +02:00
|
|
|
r, err := m.scope.AddLocalRule(name, ¶ms, argNames...)
|
2014-05-28 01:34:41 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.actionDefs.rules = append(m.actionDefs.rules, r)
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2015-11-26 00:29:32 +01:00
|
|
|
func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
|
2014-10-03 11:49:58 +02:00
|
|
|
m.scope.ReparentTo(pctx)
|
2014-07-01 03:07:17 +02:00
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
def, err := parseBuildParams(m.scope, ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.actionDefs.buildDefs = append(m.actionDefs.buildDefs, def)
|
|
|
|
}
|
|
|
|
|
2014-12-19 01:28:54 +01:00
|
|
|
func (m *moduleContext) PrimaryModule() Module {
|
2015-01-07 01:19:59 +01:00
|
|
|
return m.module.group.modules[0].logicModule
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleContext) FinalModule() Module {
|
|
|
|
return m.module.group.modules[len(m.module.group.modules)-1].logicModule
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
|
2016-01-07 22:43:09 +01:00
|
|
|
m.context.visitAllModuleVariants(m.module, visit)
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 00:49:30 +01:00
|
|
|
func (m *moduleContext) GetMissingDependencies() []string {
|
|
|
|
m.handledMissingDeps = true
|
|
|
|
return m.module.missingDeps
|
|
|
|
}
|
|
|
|
|
2014-12-19 01:28:54 +01:00
|
|
|
//
|
|
|
|
// MutatorContext
|
|
|
|
//
|
|
|
|
|
|
|
|
type mutatorContext struct {
|
|
|
|
baseModuleContext
|
2019-07-29 12:59:15 +02:00
|
|
|
name string
|
|
|
|
reverseDeps []reverseDep
|
|
|
|
rename []rename
|
|
|
|
replace []replace
|
|
|
|
newVariations []*moduleInfo // new variants of existing modules
|
|
|
|
newModules []*moduleInfo // brand new modules
|
|
|
|
defaultVariation *string
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
2019-03-30 00:35:02 +01:00
|
|
|
type BaseMutatorContext interface {
|
2014-12-19 01:28:54 +01:00
|
|
|
BaseModuleContext
|
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// 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.
|
2016-10-12 19:45:05 +02:00
|
|
|
Rename(name string)
|
2019-07-02 00:27:04 +02:00
|
|
|
|
|
|
|
// MutatorName returns the name that this mutator was registered with.
|
|
|
|
MutatorName() string
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
2015-03-11 04:08:19 +01:00
|
|
|
type EarlyMutatorContext interface {
|
2019-03-30 00:35:02 +01:00
|
|
|
BaseMutatorContext
|
2015-03-11 04:08:19 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// CreateVariations splits 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 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.
|
2015-03-14 00:02:36 +01:00
|
|
|
CreateVariations(...string) []Module
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// CreateLocationVariations splits 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 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 variations.
|
2015-03-14 00:02:36 +01:00
|
|
|
CreateLocalVariations(...string) []Module
|
2015-03-11 04:08:19 +01:00
|
|
|
}
|
|
|
|
|
2014-12-19 01:28:54 +01:00
|
|
|
type TopDownMutatorContext interface {
|
2019-03-30 00:35:02 +01:00
|
|
|
BaseMutatorContext
|
2015-11-03 01:11:32 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
|
|
|
|
// the specified property structs to it as if the properties were set in a blueprint file.
|
2019-09-25 20:24:19 +02:00
|
|
|
CreateModule(ModuleFactory, ...interface{}) Module
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type BottomUpMutatorContext interface {
|
2019-03-30 00:35:02 +01:00
|
|
|
BaseMutatorContext
|
2014-12-19 01:28:54 +01:00
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// AddDependency adds a dependency to the given module.
|
|
|
|
// Does not affect the ordering of the current mutator pass, but will be ordered
|
|
|
|
// correctly for all future mutator passes.
|
2016-04-12 00:47:28 +02:00
|
|
|
AddDependency(module Module, tag DependencyTag, name ...string)
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// AddReverseDependency adds a dependency from the destination to the given module.
|
|
|
|
// Does not affect the ordering of the current mutator pass, but will be ordered
|
|
|
|
// correctly for all future mutator passes. All reverse dependencies for a destination module are
|
|
|
|
// collected until the end of the mutator pass, sorted by name, and then appended to the destination
|
|
|
|
// module's dependency list.
|
2016-04-12 00:47:28 +02:00
|
|
|
AddReverseDependency(module Module, tag DependencyTag, name string)
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// CreateVariations splits 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 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.
|
2015-03-14 00:02:36 +01:00
|
|
|
CreateVariations(...string) []Module
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// CreateLocationVariations splits 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 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 variations.
|
2015-05-19 20:26:11 +02:00
|
|
|
CreateLocalVariations(...string) []Module
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// SetDependencyVariation sets all dangling dependencies on the current module to point to the variation
|
2019-07-29 12:59:15 +02:00
|
|
|
// with given name. This function ignores the default variation set by SetDefaultDependencyVariation.
|
2015-03-14 00:02:36 +01:00
|
|
|
SetDependencyVariation(string)
|
2019-05-20 23:51:55 +02:00
|
|
|
|
2019-07-29 12:59:15 +02:00
|
|
|
// 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)
|
|
|
|
|
2019-05-20 23:51:55 +02:00
|
|
|
// 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.
|
2016-04-12 00:47:28 +02:00
|
|
|
AddVariationDependencies([]Variation, DependencyTag, ...string)
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// AddFarVariationDependencies 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 variations argument, but may also have other variations.
|
|
|
|
// For any unspecified variation the first variant will be used.
|
|
|
|
//
|
|
|
|
// Unlike AddVariationDependencies, the variations of the current module are ignored - the
|
|
|
|
// dependency only needs to match the supplied variations.
|
2016-04-12 00:47:28 +02:00
|
|
|
AddFarVariationDependencies([]Variation, DependencyTag, ...string)
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// AddInterVariantDependency adds a dependency between two variants of the same module. Variants are always
|
|
|
|
// ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change
|
|
|
|
// that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps,
|
|
|
|
// WalkDeps, etc.
|
2016-04-12 02:33:13 +02:00
|
|
|
AddInterVariantDependency(tag DependencyTag, from, to Module)
|
2019-05-20 23:51:55 +02:00
|
|
|
|
|
|
|
// ReplaceDependencies replaces all dependencies on the identical variant of the module with the
|
|
|
|
// specified name with the current variant of this module. Replacements don't take effect until
|
|
|
|
// after the mutator pass is finished.
|
2016-10-11 18:58:53 +02:00
|
|
|
ReplaceDependencies(string)
|
2019-11-14 05:11:14 +01:00
|
|
|
|
|
|
|
// AliasVariation takes a variationName that was passed to CreateVariations for this module, and creates an
|
|
|
|
// alias from the current variant to the new variant. The alias will be valid until the next time a mutator
|
|
|
|
// calls CreateVariations or CreateLocalVariations on this module without also calling AliasVariation. The
|
|
|
|
// alias can be used to add dependencies on the newly created variant using the variant map from before
|
|
|
|
// CreateVariations was run.
|
|
|
|
AliasVariation(variationName string)
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// A Mutator function is called for each Module, and can use
|
2015-03-14 00:02:36 +01:00
|
|
|
// MutatorContext.CreateVariations to split a Module into multiple Modules,
|
2014-12-19 01:28:54 +01:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// The Mutator function should only modify members of properties structs, and not
|
|
|
|
// members of the module struct itself, to ensure the modified values are copied
|
|
|
|
// if a second Mutator chooses to split the module a second time.
|
|
|
|
type TopDownMutator func(mctx TopDownMutatorContext)
|
|
|
|
type BottomUpMutator func(mctx BottomUpMutatorContext)
|
2015-03-11 04:08:19 +01:00
|
|
|
type EarlyMutator func(mctx EarlyMutatorContext)
|
2014-12-19 01:28:54 +01:00
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
// DependencyTag is an interface to an arbitrary object that embeds BaseDependencyTag. It can be
|
|
|
|
// used to transfer information on a dependency between the mutator that called AddDependency
|
|
|
|
// and the GenerateBuildActions method. Variants created by CreateVariations have a copy of the
|
|
|
|
// interface (pointing to the same concrete object) from their original module.
|
|
|
|
type DependencyTag interface {
|
|
|
|
dependencyTag(DependencyTag)
|
|
|
|
}
|
|
|
|
|
|
|
|
type BaseDependencyTag struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (BaseDependencyTag) dependencyTag(DependencyTag) {
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ DependencyTag = BaseDependencyTag{}
|
|
|
|
|
2019-07-02 00:27:04 +02:00
|
|
|
func (mctx *mutatorContext) MutatorName() string {
|
|
|
|
return mctx.name
|
|
|
|
}
|
|
|
|
|
2015-03-14 00:02:36 +01:00
|
|
|
func (mctx *mutatorContext) CreateVariations(variationNames ...string) []Module {
|
|
|
|
return mctx.createVariations(variationNames, false)
|
2015-03-11 04:08:19 +01:00
|
|
|
}
|
|
|
|
|
2015-03-14 00:02:36 +01:00
|
|
|
func (mctx *mutatorContext) CreateLocalVariations(variationNames ...string) []Module {
|
|
|
|
return mctx.createVariations(variationNames, true)
|
2015-03-11 04:08:19 +01:00
|
|
|
}
|
|
|
|
|
2015-03-14 00:02:36 +01:00
|
|
|
func (mctx *mutatorContext) createVariations(variationNames []string, local bool) []Module {
|
2014-12-19 01:28:54 +01:00
|
|
|
ret := []Module{}
|
2019-07-29 12:59:15 +02:00
|
|
|
modules, errs := mctx.context.createVariations(mctx.module, mctx.name, mctx.defaultVariation, variationNames)
|
2015-03-04 02:37:03 +01:00
|
|
|
if len(errs) > 0 {
|
|
|
|
mctx.errs = append(mctx.errs, errs...)
|
|
|
|
}
|
2014-12-19 01:28:54 +01:00
|
|
|
|
2015-03-11 04:08:19 +01:00
|
|
|
for i, module := range modules {
|
2014-12-19 01:28:54 +01:00
|
|
|
ret = append(ret, module.logicModule)
|
2015-03-11 04:08:19 +01:00
|
|
|
if !local {
|
2019-11-14 05:11:04 +01:00
|
|
|
if module.dependencyVariant == nil {
|
|
|
|
module.dependencyVariant = make(variationMap)
|
|
|
|
}
|
2015-03-14 00:02:36 +01:00
|
|
|
module.dependencyVariant[mctx.name] = variationNames[i]
|
2015-03-11 04:08:19 +01:00
|
|
|
}
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
2017-07-29 00:22:46 +02:00
|
|
|
if mctx.newVariations != nil {
|
2016-08-06 07:30:44 +02:00
|
|
|
panic("module already has variations from this mutator")
|
|
|
|
}
|
2017-07-29 00:22:46 +02:00
|
|
|
mctx.newVariations = modules
|
2016-08-06 07:30:44 +02:00
|
|
|
|
2015-03-14 00:02:36 +01:00
|
|
|
if len(ret) != len(variationNames) {
|
2014-12-19 01:28:54 +01:00
|
|
|
panic("oops!")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2019-11-14 05:11:14 +01:00
|
|
|
func (mctx *mutatorContext) AliasVariation(variationName string) {
|
|
|
|
if mctx.module.aliasTarget != nil {
|
|
|
|
panic(fmt.Errorf("AliasVariation already called"))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, variant := range mctx.newVariations {
|
|
|
|
if variant.variant[mctx.name] == variationName {
|
|
|
|
mctx.module.aliasTarget = variant
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var foundVariations []string
|
|
|
|
for _, variant := range mctx.newVariations {
|
|
|
|
foundVariations = append(foundVariations, variant.variant[mctx.name])
|
|
|
|
}
|
|
|
|
panic(fmt.Errorf("no %q variation in module variations %q", variationName, foundVariations))
|
|
|
|
}
|
|
|
|
|
2015-03-14 00:02:36 +01:00
|
|
|
func (mctx *mutatorContext) SetDependencyVariation(variationName string) {
|
2019-07-29 12:59:15 +02:00
|
|
|
mctx.context.convertDepsToVariation(mctx.module, mctx.name, variationName, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mctx *mutatorContext) SetDefaultDependencyVariation(variationName *string) {
|
|
|
|
mctx.defaultVariation = variationName
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mctx *mutatorContext) Module() Module {
|
|
|
|
return mctx.module.logicModule
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (mctx *mutatorContext) AddDependency(module Module, tag DependencyTag, deps ...string) {
|
2015-10-29 23:32:56 +01:00
|
|
|
for _, dep := range deps {
|
2017-11-11 00:12:08 +01:00
|
|
|
modInfo := mctx.context.moduleInfo[module]
|
|
|
|
errs := mctx.context.addDependency(modInfo, tag, dep)
|
2015-10-29 23:32:56 +01:00
|
|
|
if len(errs) > 0 {
|
|
|
|
mctx.errs = append(mctx.errs, errs...)
|
|
|
|
}
|
2015-03-11 04:08:19 +01:00
|
|
|
}
|
2015-07-25 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (mctx *mutatorContext) AddReverseDependency(module Module, tag DependencyTag, destName string) {
|
2017-03-11 01:39:27 +01:00
|
|
|
if _, ok := tag.(BaseDependencyTag); ok {
|
|
|
|
panic("BaseDependencyTag is not allowed to be used directly!")
|
|
|
|
}
|
|
|
|
|
2015-11-04 01:41:29 +01:00
|
|
|
destModule, errs := mctx.context.findReverseDependency(mctx.context.moduleInfo[module], destName)
|
2015-07-25 01:53:27 +02:00
|
|
|
if len(errs) > 0 {
|
|
|
|
mctx.errs = append(mctx.errs, errs...)
|
2015-11-04 01:41:29 +01:00
|
|
|
return
|
2015-07-25 01:53:27 +02:00
|
|
|
}
|
2015-11-04 01:41:29 +01:00
|
|
|
|
2016-08-06 07:30:44 +02:00
|
|
|
mctx.reverseDeps = append(mctx.reverseDeps, reverseDep{
|
|
|
|
destModule,
|
|
|
|
depInfo{mctx.context.moduleInfo[module], tag},
|
|
|
|
})
|
2014-12-19 01:28:54 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (mctx *mutatorContext) AddVariationDependencies(variations []Variation, tag DependencyTag,
|
2015-10-29 23:32:56 +01:00
|
|
|
deps ...string) {
|
|
|
|
|
|
|
|
for _, dep := range deps {
|
2016-04-12 00:47:28 +02:00
|
|
|
errs := mctx.context.addVariationDependency(mctx.module, variations, tag, dep, false)
|
2015-10-29 23:32:56 +01:00
|
|
|
if len(errs) > 0 {
|
|
|
|
mctx.errs = append(mctx.errs, errs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:47:28 +02:00
|
|
|
func (mctx *mutatorContext) AddFarVariationDependencies(variations []Variation, tag DependencyTag,
|
2015-10-29 23:32:56 +01:00
|
|
|
deps ...string) {
|
|
|
|
|
|
|
|
for _, dep := range deps {
|
2016-04-12 00:47:28 +02:00
|
|
|
errs := mctx.context.addVariationDependency(mctx.module, variations, tag, dep, true)
|
2015-10-29 23:32:56 +01:00
|
|
|
if len(errs) > 0 {
|
|
|
|
mctx.errs = append(mctx.errs, errs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 02:33:13 +02:00
|
|
|
|
|
|
|
func (mctx *mutatorContext) AddInterVariantDependency(tag DependencyTag, from, to Module) {
|
|
|
|
mctx.context.addInterVariantDependency(mctx.module, tag, from, to)
|
|
|
|
}
|
2016-05-17 23:58:05 +02:00
|
|
|
|
2016-10-11 18:58:53 +02:00
|
|
|
func (mctx *mutatorContext) ReplaceDependencies(name string) {
|
2016-12-09 19:29:05 +01:00
|
|
|
target := mctx.context.moduleMatchingVariant(mctx.module, name)
|
|
|
|
|
|
|
|
if target == nil {
|
|
|
|
panic(fmt.Errorf("ReplaceDependencies could not find identical variant %q for module %q",
|
|
|
|
mctx.module.variantName, name))
|
|
|
|
}
|
|
|
|
|
|
|
|
mctx.replace = append(mctx.replace, replace{target, mctx.module})
|
2016-10-11 18:58:53 +02:00
|
|
|
}
|
|
|
|
|
2016-10-12 19:45:05 +02:00
|
|
|
func (mctx *mutatorContext) Rename(name string) {
|
2016-12-09 19:29:05 +01:00
|
|
|
mctx.rename = append(mctx.rename, rename{mctx.module.group, name})
|
2016-10-12 19:45:05 +02:00
|
|
|
}
|
|
|
|
|
2019-09-25 20:24:19 +02:00
|
|
|
func (mctx *mutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
|
2020-05-13 10:06:17 +02:00
|
|
|
module := newModule(factory)
|
2017-07-28 23:32:36 +02:00
|
|
|
|
2017-10-28 01:30:46 +02:00
|
|
|
module.relBlueprintsFile = mctx.module.relBlueprintsFile
|
|
|
|
module.pos = mctx.module.pos
|
2019-05-20 22:55:14 +02:00
|
|
|
module.propertyPos = mctx.module.propertyPos
|
|
|
|
module.createdBy = mctx.module
|
2017-10-28 01:30:46 +02:00
|
|
|
|
2017-07-28 23:32:36 +02:00
|
|
|
for _, p := range props {
|
|
|
|
err := proptools.AppendMatchingProperties(module.properties, p, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mctx.newModules = append(mctx.newModules, module)
|
2019-09-25 20:24:19 +02:00
|
|
|
|
|
|
|
return module.logicModule
|
2017-07-28 23:32:36 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 23:58:05 +02:00
|
|
|
// SimpleName is an embeddable object to implement the ModuleContext.Name method using a property
|
|
|
|
// called "name". Modules that embed it must also add SimpleName.Properties to their property
|
|
|
|
// structure list.
|
|
|
|
type SimpleName struct {
|
|
|
|
Properties struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SimpleName) Name() string {
|
|
|
|
return s.Properties.Name
|
|
|
|
}
|
2019-12-31 03:40:09 +01:00
|
|
|
|
|
|
|
// Load Hooks
|
|
|
|
|
|
|
|
type LoadHookContext interface {
|
|
|
|
EarlyModuleContext
|
|
|
|
|
|
|
|
// CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
|
|
|
|
// the specified property structs to it as if the properties were set in a blueprint file.
|
|
|
|
CreateModule(ModuleFactory, ...interface{}) Module
|
2019-12-31 03:38:20 +01:00
|
|
|
|
|
|
|
// RegisterScopedModuleType creates a new module type that is scoped to the current Blueprints
|
|
|
|
// file.
|
|
|
|
RegisterScopedModuleType(name string, factory ModuleFactory)
|
2019-12-31 03:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
|
2020-05-13 10:06:17 +02:00
|
|
|
module := newModule(factory)
|
2019-12-31 03:40:09 +01:00
|
|
|
|
|
|
|
module.relBlueprintsFile = l.module.relBlueprintsFile
|
|
|
|
module.pos = l.module.pos
|
|
|
|
module.propertyPos = l.module.propertyPos
|
|
|
|
module.createdBy = l.module
|
|
|
|
|
|
|
|
for _, p := range props {
|
|
|
|
err := proptools.AppendMatchingProperties(module.properties, p, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
l.newModules = append(l.newModules, module)
|
|
|
|
|
|
|
|
return module.logicModule
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:38:20 +01:00
|
|
|
func (l *loadHookContext) RegisterScopedModuleType(name string, factory ModuleFactory) {
|
|
|
|
if _, exists := l.context.moduleFactories[name]; exists {
|
|
|
|
panic(fmt.Errorf("A global module type named %q already exists", name))
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, exists := (*l.scopedModuleFactories)[name]; exists {
|
|
|
|
panic(fmt.Errorf("A module type named %q already exists in this scope", name))
|
|
|
|
}
|
|
|
|
|
|
|
|
if *l.scopedModuleFactories == nil {
|
|
|
|
(*l.scopedModuleFactories) = make(map[string]ModuleFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
(*l.scopedModuleFactories)[name] = factory
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:40:09 +01:00
|
|
|
type loadHookContext struct {
|
|
|
|
baseModuleContext
|
2019-12-31 03:38:20 +01:00
|
|
|
newModules []*moduleInfo
|
|
|
|
scopedModuleFactories *map[string]ModuleFactory
|
2019-12-31 03:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LoadHook func(ctx LoadHookContext)
|
|
|
|
|
|
|
|
// Load hooks need to be added by module factories, which don't have any parameter to get to the
|
|
|
|
// Context, and only produce a Module interface with no base implementation, so the load hooks
|
|
|
|
// must be stored in a global map. The key is a pointer allocated by the module factory, so there
|
|
|
|
// is no chance of collisions even if tests are running in parallel with multiple contexts. The
|
|
|
|
// contents should be short-lived, they are added during a module factory and removed immediately
|
|
|
|
// after the module factory returns.
|
|
|
|
var pendingHooks sync.Map
|
|
|
|
|
|
|
|
func AddLoadHook(module Module, hook LoadHook) {
|
|
|
|
// Only one goroutine can be processing a given module, so no additional locking is required
|
|
|
|
// for the slice stored in the sync.Map.
|
|
|
|
v, exists := pendingHooks.Load(module)
|
|
|
|
if !exists {
|
|
|
|
v, _ = pendingHooks.LoadOrStore(module, new([]LoadHook))
|
|
|
|
}
|
|
|
|
hooks := v.(*[]LoadHook)
|
|
|
|
*hooks = append(*hooks, hook)
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:38:20 +01:00
|
|
|
func runAndRemoveLoadHooks(ctx *Context, config interface{}, module *moduleInfo,
|
|
|
|
scopedModuleFactories *map[string]ModuleFactory) (newModules []*moduleInfo, errs []error) {
|
2019-12-31 03:40:09 +01:00
|
|
|
|
|
|
|
if v, exists := pendingHooks.Load(module.logicModule); exists {
|
|
|
|
hooks := v.(*[]LoadHook)
|
|
|
|
mctx := &loadHookContext{
|
|
|
|
baseModuleContext: baseModuleContext{
|
|
|
|
context: ctx,
|
|
|
|
config: config,
|
|
|
|
module: module,
|
|
|
|
},
|
2019-12-31 03:38:20 +01:00
|
|
|
scopedModuleFactories: scopedModuleFactories,
|
2019-12-31 03:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, hook := range *hooks {
|
|
|
|
hook(mctx)
|
|
|
|
newModules = append(newModules, mctx.newModules...)
|
|
|
|
errs = append(errs, mctx.errs...)
|
|
|
|
}
|
|
|
|
pendingHooks.Delete(module.logicModule)
|
|
|
|
|
|
|
|
return newModules, errs
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
2020-05-13 10:06:17 +02:00
|
|
|
|
|
|
|
// Check the syntax of a generated blueprint file.
|
|
|
|
//
|
|
|
|
// This is intended to perform a quick sanity check for generated blueprint
|
|
|
|
// code to ensure that it is syntactically correct, where syntactically correct
|
|
|
|
// means:
|
|
|
|
// * No variable definitions.
|
|
|
|
// * Valid module types.
|
|
|
|
// * Valid property names.
|
|
|
|
// * Valid values for the property type.
|
|
|
|
//
|
|
|
|
// It does not perform any semantic checking of properties, existence of referenced
|
|
|
|
// files, or dependencies.
|
|
|
|
//
|
|
|
|
// At a low level it:
|
|
|
|
// * Parses the contents.
|
|
|
|
// * Invokes relevant factory to create Module instances.
|
|
|
|
// * Unpacks the properties into the Module.
|
|
|
|
// * Does not invoke load hooks or any mutators.
|
|
|
|
//
|
|
|
|
// The filename is only used for reporting errors.
|
|
|
|
func CheckBlueprintSyntax(moduleFactories map[string]ModuleFactory, filename string, contents string) []error {
|
|
|
|
scope := parser.NewScope(nil)
|
|
|
|
file, errs := parser.Parse(filename, strings.NewReader(contents), scope)
|
|
|
|
if len(errs) != 0 {
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, def := range file.Defs {
|
|
|
|
switch def := def.(type) {
|
|
|
|
case *parser.Module:
|
|
|
|
_, moduleErrs := processModuleDef(def, filename, moduleFactories, nil, false)
|
|
|
|
errs = append(errs, moduleErrs...)
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unknown definition type: %T", def))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|