blob: f1c29869135316ad259a289d65c08ed860d0b75b [file] [log] [blame]
Colin Cross463a90e2015-06-17 14:20:06 -07001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross798bfce2016-10-12 14:28:16 -070015package android
Colin Cross463a90e2015-06-17 14:20:06 -070016
Colin Cross4498afc2016-10-13 14:18:27 -070017import (
Chris Parsons5011e612023-09-13 23:33:20 +000018 "bufio"
Paul Duffin0a286832019-12-19 12:23:01 +000019 "fmt"
Chris Parsons5011e612023-09-13 23:33:20 +000020 "path/filepath"
Colin Cross9aed5bc2020-12-28 15:15:34 -080021 "reflect"
Chris Parsons5011e612023-09-13 23:33:20 +000022 "regexp"
Paul Duffin0a286832019-12-19 12:23:01 +000023
Chris Parsons5011e612023-09-13 23:33:20 +000024 "android/soong/shared"
Colin Cross4498afc2016-10-13 14:18:27 -070025 "github.com/google/blueprint"
26)
Colin Cross463a90e2015-06-17 14:20:06 -070027
Paul Duffin1d2d42f2021-03-06 20:08:12 +000028// A sortable component is one whose registration order affects the order in which it is executed
29// and so affects the behavior of the build system. As a result it is important for the order in
30// which they are registered during tests to match the order used at runtime and so the test
31// infrastructure will sort them to match.
32//
33// The sortable components are mutators, singletons and pre-singletons. Module types are not
34// sortable because their order of registration does not affect the runtime behavior.
35type sortableComponent interface {
36 // componentName returns the name of the component.
37 //
Usta Shresthac725f472022-01-11 02:44:21 -050038 // Uniquely identifies the components within the set of components used at runtime and during
Paul Duffin1d2d42f2021-03-06 20:08:12 +000039 // tests.
40 componentName() string
41
Sasha Smundak1845f422022-12-13 14:18:58 -080042 // registers this component in the supplied context.
Paul Duffin1d2d42f2021-03-06 20:08:12 +000043 register(ctx *Context)
44}
45
46type sortableComponents []sortableComponent
47
48// registerAll registers all components in this slice with the supplied context.
49func (r sortableComponents) registerAll(ctx *Context) {
50 for _, c := range r {
51 c.register(ctx)
52 }
53}
54
Colin Cross463a90e2015-06-17 14:20:06 -070055type moduleType struct {
56 name string
Colin Cross7089c272019-01-25 22:43:35 -080057 factory ModuleFactory
Colin Cross463a90e2015-06-17 14:20:06 -070058}
59
Paul Duffin1d2d42f2021-03-06 20:08:12 +000060func (t moduleType) register(ctx *Context) {
61 ctx.RegisterModuleType(t.name, ModuleFactoryAdaptor(t.factory))
62}
63
Colin Cross463a90e2015-06-17 14:20:06 -070064var moduleTypes []moduleType
Colin Cross9aed5bc2020-12-28 15:15:34 -080065var moduleTypesForDocs = map[string]reflect.Value{}
Sam Delmerico286bf262022-03-09 20:46:37 +000066var moduleTypeByFactory = map[reflect.Value]string{}
Colin Cross463a90e2015-06-17 14:20:06 -070067
68type singleton struct {
Paul Duffin1d2d42f2021-03-06 20:08:12 +000069 // True if this should be registered as a pre-singleton, false otherwise.
70 pre bool
71
LaMont Jonese59c0db2023-05-15 21:50:29 +000072 // True if this should be registered as a parallel singleton.
73 parallel bool
74
Colin Cross463a90e2015-06-17 14:20:06 -070075 name string
Colin Cross06fa5882020-10-29 18:21:38 -070076 factory SingletonFactory
Colin Cross463a90e2015-06-17 14:20:06 -070077}
78
LaMont Jonese59c0db2023-05-15 21:50:29 +000079func newSingleton(name string, factory SingletonFactory, parallel bool) singleton {
80 return singleton{pre: false, parallel: parallel, name: name, factory: factory}
Paul Duffin1d2d42f2021-03-06 20:08:12 +000081}
82
83func newPreSingleton(name string, factory SingletonFactory) singleton {
LaMont Jonese59c0db2023-05-15 21:50:29 +000084 return singleton{pre: true, parallel: false, name: name, factory: factory}
Paul Duffin1d2d42f2021-03-06 20:08:12 +000085}
86
87func (s singleton) componentName() string {
88 return s.name
89}
90
91func (s singleton) register(ctx *Context) {
92 adaptor := SingletonFactoryAdaptor(ctx, s.factory)
93 if s.pre {
94 ctx.RegisterPreSingletonType(s.name, adaptor)
95 } else {
LaMont Jonese59c0db2023-05-15 21:50:29 +000096 ctx.RegisterSingletonType(s.name, adaptor, s.parallel)
Paul Duffin1d2d42f2021-03-06 20:08:12 +000097 }
98}
99
100var _ sortableComponent = singleton{}
101
102var singletons sortableComponents
103var preSingletons sortableComponents
Colin Cross463a90e2015-06-17 14:20:06 -0700104
Colin Cross6362e272015-10-29 15:25:03 -0700105type mutator struct {
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200106 name string
107 bottomUpMutator blueprint.BottomUpMutator
108 topDownMutator blueprint.TopDownMutator
109 transitionMutator blueprint.TransitionMutator
110 parallel bool
Colin Cross463a90e2015-06-17 14:20:06 -0700111}
112
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000113var _ sortableComponent = &mutator{}
114
Colin Cross36242852017-06-23 15:06:31 -0700115type ModuleFactory func() Module
116
Colin Cross0875c522017-11-28 17:34:01 -0800117// ModuleFactoryAdaptor wraps a ModuleFactory into a blueprint.ModuleFactory by converting a Module
Colin Cross36242852017-06-23 15:06:31 -0700118// into a blueprint.Module and a list of property structs
119func ModuleFactoryAdaptor(factory ModuleFactory) blueprint.ModuleFactory {
120 return func() (blueprint.Module, []interface{}) {
121 module := factory()
122 return module, module.GetProperties()
123 }
124}
125
Colin Cross0875c522017-11-28 17:34:01 -0800126type SingletonFactory func() Singleton
127
128// SingletonFactoryAdaptor wraps a SingletonFactory into a blueprint.SingletonFactory by converting
129// a Singleton into a blueprint.Singleton
Colin Cross06fa5882020-10-29 18:21:38 -0700130func SingletonFactoryAdaptor(ctx *Context, factory SingletonFactory) blueprint.SingletonFactory {
Colin Cross0875c522017-11-28 17:34:01 -0800131 return func() blueprint.Singleton {
132 singleton := factory()
Colin Crossed023ec2019-02-19 12:38:45 -0800133 if makevars, ok := singleton.(SingletonMakeVarsProvider); ok {
Sasha Smundak1845f422022-12-13 14:18:58 -0800134 ctx.registerSingletonMakeVarsProvider(makevars)
Colin Crossed023ec2019-02-19 12:38:45 -0800135 }
Colin Cross4c83e5c2019-02-25 14:54:28 -0800136 return &singletonAdaptor{Singleton: singleton}
Colin Cross0875c522017-11-28 17:34:01 -0800137 }
138}
139
Colin Cross36242852017-06-23 15:06:31 -0700140func RegisterModuleType(name string, factory ModuleFactory) {
Colin Cross7089c272019-01-25 22:43:35 -0800141 moduleTypes = append(moduleTypes, moduleType{name, factory})
Colin Cross9aed5bc2020-12-28 15:15:34 -0800142 RegisterModuleTypeForDocs(name, reflect.ValueOf(factory))
143}
144
145// RegisterModuleTypeForDocs associates a module type name with a reflect.Value of the factory
146// function that has documentation for the module type. It is normally called automatically
147// by RegisterModuleType, but can be called manually after RegisterModuleType in order to
148// override the factory method used for documentation, for example if the method passed to
149// RegisterModuleType was a lambda.
150func RegisterModuleTypeForDocs(name string, factory reflect.Value) {
151 moduleTypesForDocs[name] = factory
Sam Delmerico286bf262022-03-09 20:46:37 +0000152 moduleTypeByFactory[factory] = name
Colin Cross463a90e2015-06-17 14:20:06 -0700153}
154
LaMont Jonese59c0db2023-05-15 21:50:29 +0000155func registerSingletonType(name string, factory SingletonFactory, parallel bool) {
156 singletons = append(singletons, newSingleton(name, factory, parallel))
157}
158
Colin Cross0875c522017-11-28 17:34:01 -0800159func RegisterSingletonType(name string, factory SingletonFactory) {
LaMont Jonese59c0db2023-05-15 21:50:29 +0000160 registerSingletonType(name, factory, false)
161}
162
163func RegisterParallelSingletonType(name string, factory SingletonFactory) {
164 registerSingletonType(name, factory, true)
Colin Cross463a90e2015-06-17 14:20:06 -0700165}
166
Colin Cross0875c522017-11-28 17:34:01 -0800167func RegisterPreSingletonType(name string, factory SingletonFactory) {
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000168 preSingletons = append(preSingletons, newPreSingleton(name, factory))
Colin Cross5a79c832017-11-07 13:35:38 -0800169}
170
Colin Crosscec81712017-07-13 14:43:27 -0700171type Context struct {
172 *blueprint.Context
Colin Crossae8600b2020-10-29 17:09:13 -0700173 config Config
Colin Crosscec81712017-07-13 14:43:27 -0700174}
Colin Cross463a90e2015-06-17 14:20:06 -0700175
Colin Crossae8600b2020-10-29 17:09:13 -0700176func NewContext(config Config) *Context {
177 ctx := &Context{blueprint.NewContext(), config}
Colin Cross988414c2020-01-11 01:11:46 +0000178 ctx.SetSrcDir(absSrcDir)
Spandan Dasc5763832022-11-08 18:42:16 +0000179 ctx.AddIncludeTags(config.IncludeTags()...)
Sam Delmerico98a73292023-02-21 11:50:29 -0500180 ctx.AddSourceRootDirs(config.SourceRootDirs()...)
Colin Cross988414c2020-01-11 01:11:46 +0000181 return ctx
Colin Crosscec81712017-07-13 14:43:27 -0700182}
183
Spandan Das75e139b2022-11-28 20:12:03 +0000184// Helper function to register the module types used in bp2build and
185// api_bp2build.
186func registerModuleTypes(ctx *Context) {
Jingwen Chen4133ce62020-12-02 04:34:15 -0500187 for _, t := range moduleTypes {
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000188 t.register(ctx)
Jingwen Chen4133ce62020-12-02 04:34:15 -0500189 }
Jingwen Chendaa54bc2020-12-14 02:58:54 -0500190 // Required for SingletonModule types, even though we are not using them.
191 for _, t := range singletons {
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000192 t.register(ctx)
Liz Kammer2dd9ca42020-11-25 16:06:39 -0800193 }
Spandan Das75e139b2022-11-28 20:12:03 +0000194}
Jingwen Chen4133ce62020-12-02 04:34:15 -0500195
Spandan Das75e139b2022-11-28 20:12:03 +0000196// RegisterForBazelConversion registers an alternate shadow pipeline of
197// singletons, module types and mutators to register for converting Blueprint
198// files to semantically equivalent BUILD files.
199func (ctx *Context) RegisterForBazelConversion() {
200 registerModuleTypes(ctx)
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400201 RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators)
Jingwen Chen4133ce62020-12-02 04:34:15 -0500202}
203
Chris Parsons5011e612023-09-13 23:33:20 +0000204// RegisterExistingBazelTargets reads Bazel BUILD.bazel and BUILD files under
205// the workspace, and returns a map containing names of Bazel targets defined in
206// these BUILD files.
207// For example, maps "//foo/bar" to ["baz", "qux"] if `//foo/bar:{baz,qux}` exist.
208func (c *Context) RegisterExistingBazelTargets(topDir string, existingBazelFiles []string) error {
209 result := map[string][]string{}
210
211 // Search for instances of `name = "$NAME"` (with arbitrary spacing).
212 targetNameRegex := regexp.MustCompile(`(?m)^\s*name\s*=\s*\"([^\"]+)\"`)
213
214 parseBuildFile := func(path string) error {
215 fullPath := shared.JoinPath(topDir, path)
216 sourceDir := filepath.Dir(path)
217
218 fileInfo, err := c.Config().fs.Stat(fullPath)
219 if err != nil {
220 return fmt.Errorf("Error accessing Bazel file '%s': %s", path, err)
221 }
222 if !fileInfo.IsDir() &&
223 (fileInfo.Name() == "BUILD" || fileInfo.Name() == "BUILD.bazel") {
224 f, err := c.Config().fs.Open(fullPath)
225 if err != nil {
226 return fmt.Errorf("Error reading Bazel file '%s': %s", path, err)
227 }
228 defer f.Close()
229 scanner := bufio.NewScanner(f)
230 for scanner.Scan() {
231 line := scanner.Text()
232 matches := targetNameRegex.FindAllStringSubmatch(line, -1)
233 for _, match := range matches {
234 result[sourceDir] = append(result[sourceDir], match[1])
235 }
236 }
237 }
238 return nil
239 }
240
241 for _, path := range existingBazelFiles {
242 if !c.Config().Bp2buildPackageConfig.ShouldKeepExistingBuildFileForDir(filepath.Dir(path)) {
243 continue
244 }
245 err := parseBuildFile(path)
246 if err != nil {
247 return err
248 }
249 }
250 c.Config().SetBazelBuildFileTargets(result)
251 return nil
252}
253
Jingwen Chendaa54bc2020-12-14 02:58:54 -0500254// Register the pipeline of singletons, module types, and mutators for
255// generating build.ninja and other files for Kati, from Android.bp files.
Colin Crosscec81712017-07-13 14:43:27 -0700256func (ctx *Context) Register() {
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000257 preSingletons.registerAll(ctx)
Colin Cross5a79c832017-11-07 13:35:38 -0800258
Colin Cross463a90e2015-06-17 14:20:06 -0700259 for _, t := range moduleTypes {
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000260 t.register(ctx)
Colin Cross463a90e2015-06-17 14:20:06 -0700261 }
262
Paul Duffinc05b0342021-03-06 13:28:13 +0000263 mutators := collateGloballyRegisteredMutators()
264 mutators.registerAll(ctx)
Colin Cross1e676be2016-10-12 14:38:15 -0700265
Paul Duffin42d0b932021-03-06 20:24:50 +0000266 singletons := collateGloballyRegisteredSingletons()
267 singletons.registerAll(ctx)
268}
Chris Parsonsa798d962020-10-12 23:44:08 -0400269
Sasha Smundak1845f422022-12-13 14:18:58 -0800270func (ctx *Context) Config() Config {
271 return ctx.config
272}
273
274func (ctx *Context) registerSingletonMakeVarsProvider(makevars SingletonMakeVarsProvider) {
275 registerSingletonMakeVarsProvider(ctx.config, makevars)
276}
277
Paul Duffin42d0b932021-03-06 20:24:50 +0000278func collateGloballyRegisteredSingletons() sortableComponents {
279 allSingletons := append(sortableComponents(nil), singletons...)
280 allSingletons = append(allSingletons,
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000281 singleton{pre: false, parallel: true, name: "bazeldeps", factory: BazelSingleton},
Colin Crossc3d87d32020-06-04 13:25:17 -0700282
Paul Duffin42d0b932021-03-06 20:24:50 +0000283 // Register phony just before makevars so it can write out its phony rules as Make rules
LaMont Jonese59c0db2023-05-15 21:50:29 +0000284 singleton{pre: false, parallel: false, name: "phony", factory: phonySingletonFactory},
Colin Cross580d2ce2019-02-09 22:59:32 -0800285
Paul Duffin42d0b932021-03-06 20:24:50 +0000286 // Register makevars after other singletons so they can export values through makevars
LaMont Jonese59c0db2023-05-15 21:50:29 +0000287 singleton{pre: false, parallel: false, name: "makevars", factory: makeVarsSingletonFunc},
Paul Duffin42d0b932021-03-06 20:24:50 +0000288
289 // Register env and ninjadeps last so that they can track all used environment variables and
290 // Ninja file dependencies stored in the config.
LaMont Jonese59c0db2023-05-15 21:50:29 +0000291 singleton{pre: false, parallel: false, name: "ninjadeps", factory: ninjaDepsSingletonFactory},
Paul Duffin42d0b932021-03-06 20:24:50 +0000292 )
293
294 return allSingletons
Colin Cross463a90e2015-06-17 14:20:06 -0700295}
Colin Cross7089c272019-01-25 22:43:35 -0800296
297func ModuleTypeFactories() map[string]ModuleFactory {
298 ret := make(map[string]ModuleFactory)
299 for _, t := range moduleTypes {
300 ret[t.name] = t.factory
301 }
302 return ret
303}
Paul Duffinf9b1da02019-12-18 19:51:55 +0000304
Colin Cross9aed5bc2020-12-28 15:15:34 -0800305func ModuleTypeFactoriesForDocs() map[string]reflect.Value {
306 return moduleTypesForDocs
307}
308
Sam Delmerico286bf262022-03-09 20:46:37 +0000309func ModuleTypeByFactory() map[reflect.Value]string {
310 return moduleTypeByFactory
311}
312
Paul Duffinf9b1da02019-12-18 19:51:55 +0000313// Interface for registering build components.
314//
315// Provided to allow registration of build components to be shared between the runtime
316// and test environments.
317type RegistrationContext interface {
318 RegisterModuleType(name string, factory ModuleFactory)
Colin Cross9aed5bc2020-12-28 15:15:34 -0800319 RegisterSingletonModuleType(name string, factory SingletonModuleFactory)
LaMont Jonese59c0db2023-05-15 21:50:29 +0000320 RegisterParallelSingletonModuleType(name string, factory SingletonModuleFactory)
Paul Duffineafc16b2021-02-24 01:43:18 +0000321 RegisterPreSingletonType(name string, factory SingletonFactory)
LaMont Jonese59c0db2023-05-15 21:50:29 +0000322 RegisterParallelSingletonType(name string, factory SingletonFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000323 RegisterSingletonType(name string, factory SingletonFactory)
Paul Duffina48f7582019-12-19 11:25:19 +0000324 PreArchMutators(f RegisterMutatorFunc)
Paul Duffina80ef842020-01-14 12:09:36 +0000325
326 // Register pre arch mutators that are hard coded into mutator.go.
327 //
328 // Only registers mutators for testing, is a noop on the InitRegistrationContext.
329 HardCodedPreArchMutators(f RegisterMutatorFunc)
330
Paul Duffin2ccaffd2019-12-19 15:12:58 +0000331 PreDepsMutators(f RegisterMutatorFunc)
332 PostDepsMutators(f RegisterMutatorFunc)
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000333 FinalDepsMutators(f RegisterMutatorFunc)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000334}
335
336// Used to register build components from an init() method, e.g.
337//
Colin Crossd079e0b2022-08-16 10:27:33 -0700338// init() {
339// RegisterBuildComponents(android.InitRegistrationContext)
340// }
Paul Duffinf9b1da02019-12-18 19:51:55 +0000341//
Colin Crossd079e0b2022-08-16 10:27:33 -0700342// func RegisterBuildComponents(ctx android.RegistrationContext) {
343// ctx.RegisterModuleType(...)
344// ...
345// }
Paul Duffinf9b1da02019-12-18 19:51:55 +0000346//
347// Extracting the actual registration into a separate RegisterBuildComponents(ctx) function
348// allows it to be used to initialize test context, e.g.
349//
Colin Crossd079e0b2022-08-16 10:27:33 -0700350// ctx := android.NewTestContext(config)
351// RegisterBuildComponents(ctx)
Paul Duffin0a286832019-12-19 12:23:01 +0000352var InitRegistrationContext RegistrationContext = &initRegistrationContext{
Paul Duffin42da69d2021-03-22 13:41:36 +0000353 moduleTypes: make(map[string]ModuleFactory),
354 singletonTypes: make(map[string]SingletonFactory),
355 preSingletonTypes: make(map[string]SingletonFactory),
Paul Duffin0a286832019-12-19 12:23:01 +0000356}
Paul Duffinf9b1da02019-12-18 19:51:55 +0000357
358// Make sure the TestContext implements RegistrationContext.
359var _ RegistrationContext = (*TestContext)(nil)
360
Paul Duffin0a286832019-12-19 12:23:01 +0000361type initRegistrationContext struct {
Colin Cross9aed5bc2020-12-28 15:15:34 -0800362 moduleTypes map[string]ModuleFactory
363 singletonTypes map[string]SingletonFactory
Paul Duffineafc16b2021-02-24 01:43:18 +0000364 preSingletonTypes map[string]SingletonFactory
Colin Cross9aed5bc2020-12-28 15:15:34 -0800365 moduleTypesForDocs map[string]reflect.Value
Paul Duffin0a286832019-12-19 12:23:01 +0000366}
Paul Duffinf9b1da02019-12-18 19:51:55 +0000367
Paul Duffin0a286832019-12-19 12:23:01 +0000368func (ctx *initRegistrationContext) RegisterModuleType(name string, factory ModuleFactory) {
369 if _, present := ctx.moduleTypes[name]; present {
370 panic(fmt.Sprintf("module type %q is already registered", name))
371 }
372 ctx.moduleTypes[name] = factory
Paul Duffinf9b1da02019-12-18 19:51:55 +0000373 RegisterModuleType(name, factory)
Colin Cross9aed5bc2020-12-28 15:15:34 -0800374 RegisterModuleTypeForDocs(name, reflect.ValueOf(factory))
375}
376
377func (ctx *initRegistrationContext) RegisterSingletonModuleType(name string, factory SingletonModuleFactory) {
LaMont Jonese59c0db2023-05-15 21:50:29 +0000378 ctx.registerSingletonModuleType(name, factory, false)
379}
380func (ctx *initRegistrationContext) RegisterParallelSingletonModuleType(name string, factory SingletonModuleFactory) {
381 ctx.registerSingletonModuleType(name, factory, true)
382}
383
384func (ctx *initRegistrationContext) registerSingletonModuleType(name string, factory SingletonModuleFactory, parallel bool) {
Colin Cross9aed5bc2020-12-28 15:15:34 -0800385 s, m := SingletonModuleFactoryAdaptor(name, factory)
LaMont Jonese59c0db2023-05-15 21:50:29 +0000386 ctx.registerSingletonType(name, s, parallel)
Colin Cross9aed5bc2020-12-28 15:15:34 -0800387 ctx.RegisterModuleType(name, m)
388 // Overwrite moduleTypesForDocs with the original factory instead of the lambda returned by
389 // SingletonModuleFactoryAdaptor so that docs can find the module type documentation on the
390 // factory method.
391 RegisterModuleTypeForDocs(name, reflect.ValueOf(factory))
Paul Duffinf9b1da02019-12-18 19:51:55 +0000392}
393
LaMont Jonese59c0db2023-05-15 21:50:29 +0000394func (ctx *initRegistrationContext) registerSingletonType(name string, factory SingletonFactory, parallel bool) {
Paul Duffin0a286832019-12-19 12:23:01 +0000395 if _, present := ctx.singletonTypes[name]; present {
396 panic(fmt.Sprintf("singleton type %q is already registered", name))
397 }
398 ctx.singletonTypes[name] = factory
LaMont Jonese59c0db2023-05-15 21:50:29 +0000399 registerSingletonType(name, factory, parallel)
400}
401
402func (ctx *initRegistrationContext) RegisterSingletonType(name string, factory SingletonFactory) {
403 ctx.registerSingletonType(name, factory, false)
404}
405
406func (ctx *initRegistrationContext) RegisterParallelSingletonType(name string, factory SingletonFactory) {
407 ctx.registerSingletonType(name, factory, true)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000408}
Paul Duffina48f7582019-12-19 11:25:19 +0000409
Paul Duffineafc16b2021-02-24 01:43:18 +0000410func (ctx *initRegistrationContext) RegisterPreSingletonType(name string, factory SingletonFactory) {
411 if _, present := ctx.preSingletonTypes[name]; present {
412 panic(fmt.Sprintf("pre singleton type %q is already registered", name))
413 }
414 ctx.preSingletonTypes[name] = factory
415 RegisterPreSingletonType(name, factory)
416}
417
Paul Duffin0a286832019-12-19 12:23:01 +0000418func (ctx *initRegistrationContext) PreArchMutators(f RegisterMutatorFunc) {
Paul Duffina48f7582019-12-19 11:25:19 +0000419 PreArchMutators(f)
420}
Paul Duffin2ccaffd2019-12-19 15:12:58 +0000421
Sasha Smundak1845f422022-12-13 14:18:58 -0800422func (ctx *initRegistrationContext) HardCodedPreArchMutators(_ RegisterMutatorFunc) {
Paul Duffina80ef842020-01-14 12:09:36 +0000423 // Nothing to do as the mutators are hard code in preArch in mutator.go
424}
425
Paul Duffin2ccaffd2019-12-19 15:12:58 +0000426func (ctx *initRegistrationContext) PreDepsMutators(f RegisterMutatorFunc) {
427 PreDepsMutators(f)
428}
429
430func (ctx *initRegistrationContext) PostDepsMutators(f RegisterMutatorFunc) {
431 PostDepsMutators(f)
432}
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000433
434func (ctx *initRegistrationContext) FinalDepsMutators(f RegisterMutatorFunc) {
435 FinalDepsMutators(f)
436}