Add getter for EventHandler so its easier to mock

Test: m nothing
Change-Id: Ied338a25f12404ddc88c3b3cb7d7f2ff9ade3aab
This commit is contained in:
Liz Kammer 2023-02-13 17:55:50 -05:00
parent 58a29728ea
commit 073f69d723

View file

@ -50,15 +50,15 @@ const MockModuleListFile = "bplist"
// through a series of four phases. Each phase corresponds with a some methods // through a series of four phases. Each phase corresponds with a some methods
// on the Context object // on the Context object
// //
// Phase Methods // Phase Methods
// ------------ ------------------------------------------- // ------------ -------------------------------------------
// 1. Registration RegisterModuleType, RegisterSingletonType // 1. Registration RegisterModuleType, RegisterSingletonType
// //
// 2. Parse ParseBlueprintsFiles, Parse // 2. Parse ParseBlueprintsFiles, Parse
// //
// 3. Generate ResolveDependencies, PrepareBuildActions // 3. Generate ResolveDependencies, PrepareBuildActions
// //
// 4. Write WriteBuildFile // 4. Write WriteBuildFile
// //
// The registration phase prepares the context to process Blueprints files // The registration phase prepares the context to process Blueprints files
// containing various types of modules. The parse phase reads in one or more // containing various types of modules. The parse phase reads in one or more
@ -424,7 +424,7 @@ func newContext() *Context {
globs: make(map[globKey]pathtools.GlobResult), globs: make(map[globKey]pathtools.GlobResult),
fs: pathtools.OsFs, fs: pathtools.OsFs,
finishedMutators: make(map[*mutatorInfo]bool), finishedMutators: make(map[*mutatorInfo]bool),
includeTags: &IncludeTags{}, includeTags: &IncludeTags{},
outDir: nil, outDir: nil,
requiredNinjaMajor: 1, requiredNinjaMajor: 1,
requiredNinjaMinor: 7, requiredNinjaMinor: 7,
@ -481,32 +481,32 @@ type ModuleFactory func() (m Module, propertyStructs []interface{})
// //
// As an example, the follow code: // As an example, the follow code:
// //
// type myModule struct { // type myModule struct {
// properties struct { // properties struct {
// Foo string // Foo string
// Bar []string // Bar []string
// } // }
// } // }
// //
// func NewMyModule() (blueprint.Module, []interface{}) { // func NewMyModule() (blueprint.Module, []interface{}) {
// module := new(myModule) // module := new(myModule)
// properties := &module.properties // properties := &module.properties
// return module, []interface{}{properties} // return module, []interface{}{properties}
// } // }
// //
// func main() { // func main() {
// ctx := blueprint.NewContext() // ctx := blueprint.NewContext()
// ctx.RegisterModuleType("my_module", NewMyModule) // ctx.RegisterModuleType("my_module", NewMyModule)
// // ... // // ...
// } // }
// //
// would support parsing a module defined in a Blueprints file as follows: // would support parsing a module defined in a Blueprints file as follows:
// //
// my_module { // my_module {
// name: "myName", // name: "myName",
// foo: "my foo string", // foo: "my foo string",
// bar: ["my", "bar", "strings"], // bar: ["my", "bar", "strings"],
// } // }
// //
// The factory function may be called from multiple goroutines. Any accesses // The factory function may be called from multiple goroutines. Any accesses
// to global variables must be synchronized. // to global variables must be synchronized.
@ -992,7 +992,6 @@ func shouldVisitFile(c *Context, file *parser.File) (bool, []error) {
return true, []error{} return true, []error{}
} }
func (c *Context) ParseFileList(rootDir string, filePaths []string, func (c *Context) ParseFileList(rootDir string, filePaths []string,
config interface{}) (deps []string, errs []error) { config interface{}) (deps []string, errs []error) {
@ -4455,6 +4454,10 @@ func (c *Context) writeAllSingletonActions(nw *ninjaWriter) error {
return nil return nil
} }
func (c *Context) GetEventHandler() *metrics.EventHandler {
return c.EventHandler
}
func (c *Context) BeginEvent(name string) { func (c *Context) BeginEvent(name string) {
c.EventHandler.Begin(name) c.EventHandler.Begin(name)
} }