xref: /aosp_15_r20/build/soong/android/singleton.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright 2017 Google Inc. All rights reserved.
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage android
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerimport (
18*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint"
19*333d2b36SAndroid Build Coastguard Worker)
20*333d2b36SAndroid Build Coastguard Worker
21*333d2b36SAndroid Build Coastguard Worker// SingletonContext
22*333d2b36SAndroid Build Coastguard Workertype SingletonContext interface {
23*333d2b36SAndroid Build Coastguard Worker	blueprintSingletonContext() blueprint.SingletonContext
24*333d2b36SAndroid Build Coastguard Worker
25*333d2b36SAndroid Build Coastguard Worker	Config() Config
26*333d2b36SAndroid Build Coastguard Worker	DeviceConfig() DeviceConfig
27*333d2b36SAndroid Build Coastguard Worker
28*333d2b36SAndroid Build Coastguard Worker	ModuleName(module blueprint.Module) string
29*333d2b36SAndroid Build Coastguard Worker	ModuleDir(module blueprint.Module) string
30*333d2b36SAndroid Build Coastguard Worker	ModuleSubDir(module blueprint.Module) string
31*333d2b36SAndroid Build Coastguard Worker	ModuleType(module blueprint.Module) string
32*333d2b36SAndroid Build Coastguard Worker	BlueprintFile(module blueprint.Module) string
33*333d2b36SAndroid Build Coastguard Worker
34*333d2b36SAndroid Build Coastguard Worker	// ModuleVariantsFromName returns the list of module variants named `name` in the same namespace as `referer` enforcing visibility rules.
35*333d2b36SAndroid Build Coastguard Worker	// Allows generating build actions for `referer` based on the metadata for `name` deferred until the singleton context.
36*333d2b36SAndroid Build Coastguard Worker	ModuleVariantsFromName(referer Module, name string) []Module
37*333d2b36SAndroid Build Coastguard Worker
38*333d2b36SAndroid Build Coastguard Worker	otherModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool)
39*333d2b36SAndroid Build Coastguard Worker
40*333d2b36SAndroid Build Coastguard Worker	ModuleErrorf(module blueprint.Module, format string, args ...interface{})
41*333d2b36SAndroid Build Coastguard Worker	Errorf(format string, args ...interface{})
42*333d2b36SAndroid Build Coastguard Worker	Failed() bool
43*333d2b36SAndroid Build Coastguard Worker
44*333d2b36SAndroid Build Coastguard Worker	Variable(pctx PackageContext, name, value string)
45*333d2b36SAndroid Build Coastguard Worker	Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
46*333d2b36SAndroid Build Coastguard Worker	Build(pctx PackageContext, params BuildParams)
47*333d2b36SAndroid Build Coastguard Worker
48*333d2b36SAndroid Build Coastguard Worker	// Phony creates a Make-style phony rule, a rule with no commands that can depend on other
49*333d2b36SAndroid Build Coastguard Worker	// phony rules or real files.  Phony can be called on the same name multiple times to add
50*333d2b36SAndroid Build Coastguard Worker	// additional dependencies.
51*333d2b36SAndroid Build Coastguard Worker	Phony(name string, deps ...Path)
52*333d2b36SAndroid Build Coastguard Worker
53*333d2b36SAndroid Build Coastguard Worker	RequireNinjaVersion(major, minor, micro int)
54*333d2b36SAndroid Build Coastguard Worker
55*333d2b36SAndroid Build Coastguard Worker	// SetOutDir sets the value of the top-level "builddir" Ninja variable
56*333d2b36SAndroid Build Coastguard Worker	// that controls where Ninja stores its build log files.  This value can be
57*333d2b36SAndroid Build Coastguard Worker	// set at most one time for a single build, later calls are ignored.
58*333d2b36SAndroid Build Coastguard Worker	SetOutDir(pctx PackageContext, value string)
59*333d2b36SAndroid Build Coastguard Worker
60*333d2b36SAndroid Build Coastguard Worker	// Eval takes a string with embedded ninja variables, and returns a string
61*333d2b36SAndroid Build Coastguard Worker	// with all of the variables recursively expanded. Any variables references
62*333d2b36SAndroid Build Coastguard Worker	// are expanded in the scope of the PackageContext.
63*333d2b36SAndroid Build Coastguard Worker	Eval(pctx PackageContext, ninjaStr string) (string, error)
64*333d2b36SAndroid Build Coastguard Worker
65*333d2b36SAndroid Build Coastguard Worker	VisitAllModulesBlueprint(visit func(blueprint.Module))
66*333d2b36SAndroid Build Coastguard Worker	VisitAllModules(visit func(Module))
67*333d2b36SAndroid Build Coastguard Worker	VisitAllModuleProxies(visit func(proxy ModuleProxy))
68*333d2b36SAndroid Build Coastguard Worker	VisitAllModulesIf(pred func(Module) bool, visit func(Module))
69*333d2b36SAndroid Build Coastguard Worker
70*333d2b36SAndroid Build Coastguard Worker	VisitDirectDeps(module Module, visit func(Module))
71*333d2b36SAndroid Build Coastguard Worker	VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module))
72*333d2b36SAndroid Build Coastguard Worker
73*333d2b36SAndroid Build Coastguard Worker	// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
74*333d2b36SAndroid Build Coastguard Worker	VisitDepsDepthFirst(module Module, visit func(Module))
75*333d2b36SAndroid Build Coastguard Worker	// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
76*333d2b36SAndroid Build Coastguard Worker	VisitDepsDepthFirstIf(module Module, pred func(Module) bool,
77*333d2b36SAndroid Build Coastguard Worker		visit func(Module))
78*333d2b36SAndroid Build Coastguard Worker
79*333d2b36SAndroid Build Coastguard Worker	VisitAllModuleVariants(module Module, visit func(Module))
80*333d2b36SAndroid Build Coastguard Worker
81*333d2b36SAndroid Build Coastguard Worker	VisitAllModuleVariantProxies(module Module, visit func(proxy ModuleProxy))
82*333d2b36SAndroid Build Coastguard Worker
83*333d2b36SAndroid Build Coastguard Worker	PrimaryModule(module Module) Module
84*333d2b36SAndroid Build Coastguard Worker	IsFinalModule(module Module) bool
85*333d2b36SAndroid Build Coastguard Worker
86*333d2b36SAndroid Build Coastguard Worker	AddNinjaFileDeps(deps ...string)
87*333d2b36SAndroid Build Coastguard Worker
88*333d2b36SAndroid Build Coastguard Worker	// GlobWithDeps returns a list of files that match the specified pattern but do not match any
89*333d2b36SAndroid Build Coastguard Worker	// of the patterns in excludes.  It also adds efficient dependencies to rerun the primary
90*333d2b36SAndroid Build Coastguard Worker	// builder whenever a file matching the pattern as added or removed, without rerunning if a
91*333d2b36SAndroid Build Coastguard Worker	// file that does not match the pattern is added to a searched directory.
92*333d2b36SAndroid Build Coastguard Worker	GlobWithDeps(pattern string, excludes []string) ([]string, error)
93*333d2b36SAndroid Build Coastguard Worker
94*333d2b36SAndroid Build Coastguard Worker	// OtherModulePropertyErrorf reports an error on the line number of the given property of the given module
95*333d2b36SAndroid Build Coastguard Worker	OtherModulePropertyErrorf(module Module, property string, format string, args ...interface{})
96*333d2b36SAndroid Build Coastguard Worker
97*333d2b36SAndroid Build Coastguard Worker	// HasMutatorFinished returns true if the given mutator has finished running.
98*333d2b36SAndroid Build Coastguard Worker	// It will panic if given an invalid mutator name.
99*333d2b36SAndroid Build Coastguard Worker	HasMutatorFinished(mutatorName string) bool
100*333d2b36SAndroid Build Coastguard Worker}
101*333d2b36SAndroid Build Coastguard Worker
102*333d2b36SAndroid Build Coastguard Workertype singletonAdaptor struct {
103*333d2b36SAndroid Build Coastguard Worker	Singleton
104*333d2b36SAndroid Build Coastguard Worker
105*333d2b36SAndroid Build Coastguard Worker	buildParams []BuildParams
106*333d2b36SAndroid Build Coastguard Worker	ruleParams  map[blueprint.Rule]blueprint.RuleParams
107*333d2b36SAndroid Build Coastguard Worker}
108*333d2b36SAndroid Build Coastguard Worker
109*333d2b36SAndroid Build Coastguard Workervar _ testBuildProvider = (*singletonAdaptor)(nil)
110*333d2b36SAndroid Build Coastguard Worker
111*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonAdaptor) GenerateBuildActions(ctx blueprint.SingletonContext) {
112*333d2b36SAndroid Build Coastguard Worker	sctx := &singletonContextAdaptor{SingletonContext: ctx}
113*333d2b36SAndroid Build Coastguard Worker	if sctx.Config().captureBuild {
114*333d2b36SAndroid Build Coastguard Worker		sctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
115*333d2b36SAndroid Build Coastguard Worker	}
116*333d2b36SAndroid Build Coastguard Worker
117*333d2b36SAndroid Build Coastguard Worker	s.Singleton.GenerateBuildActions(sctx)
118*333d2b36SAndroid Build Coastguard Worker
119*333d2b36SAndroid Build Coastguard Worker	s.buildParams = sctx.buildParams
120*333d2b36SAndroid Build Coastguard Worker	s.ruleParams = sctx.ruleParams
121*333d2b36SAndroid Build Coastguard Worker}
122*333d2b36SAndroid Build Coastguard Worker
123*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonAdaptor) BuildParamsForTests() []BuildParams {
124*333d2b36SAndroid Build Coastguard Worker	return s.buildParams
125*333d2b36SAndroid Build Coastguard Worker}
126*333d2b36SAndroid Build Coastguard Worker
127*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonAdaptor) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
128*333d2b36SAndroid Build Coastguard Worker	return s.ruleParams
129*333d2b36SAndroid Build Coastguard Worker}
130*333d2b36SAndroid Build Coastguard Worker
131*333d2b36SAndroid Build Coastguard Workertype Singleton interface {
132*333d2b36SAndroid Build Coastguard Worker	GenerateBuildActions(SingletonContext)
133*333d2b36SAndroid Build Coastguard Worker}
134*333d2b36SAndroid Build Coastguard Worker
135*333d2b36SAndroid Build Coastguard Workertype singletonContextAdaptor struct {
136*333d2b36SAndroid Build Coastguard Worker	blueprint.SingletonContext
137*333d2b36SAndroid Build Coastguard Worker
138*333d2b36SAndroid Build Coastguard Worker	buildParams []BuildParams
139*333d2b36SAndroid Build Coastguard Worker	ruleParams  map[blueprint.Rule]blueprint.RuleParams
140*333d2b36SAndroid Build Coastguard Worker}
141*333d2b36SAndroid Build Coastguard Worker
142*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) blueprintSingletonContext() blueprint.SingletonContext {
143*333d2b36SAndroid Build Coastguard Worker	return s.SingletonContext
144*333d2b36SAndroid Build Coastguard Worker}
145*333d2b36SAndroid Build Coastguard Worker
146*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) Config() Config {
147*333d2b36SAndroid Build Coastguard Worker	return s.SingletonContext.Config().(Config)
148*333d2b36SAndroid Build Coastguard Worker}
149*333d2b36SAndroid Build Coastguard Worker
150*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) DeviceConfig() DeviceConfig {
151*333d2b36SAndroid Build Coastguard Worker	return DeviceConfig{s.Config().deviceConfig}
152*333d2b36SAndroid Build Coastguard Worker}
153*333d2b36SAndroid Build Coastguard Worker
154*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) Variable(pctx PackageContext, name, value string) {
155*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.Variable(pctx.PackageContext, name, value)
156*333d2b36SAndroid Build Coastguard Worker}
157*333d2b36SAndroid Build Coastguard Worker
158*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule {
159*333d2b36SAndroid Build Coastguard Worker	if s.Config().UseRemoteBuild() {
160*333d2b36SAndroid Build Coastguard Worker		if params.Pool == nil {
161*333d2b36SAndroid Build Coastguard Worker			// When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
162*333d2b36SAndroid Build Coastguard Worker			// jobs to the local parallelism value
163*333d2b36SAndroid Build Coastguard Worker			params.Pool = localPool
164*333d2b36SAndroid Build Coastguard Worker		} else if params.Pool == remotePool {
165*333d2b36SAndroid Build Coastguard Worker			// remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
166*333d2b36SAndroid Build Coastguard Worker			// pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
167*333d2b36SAndroid Build Coastguard Worker			// parallelism.
168*333d2b36SAndroid Build Coastguard Worker			params.Pool = nil
169*333d2b36SAndroid Build Coastguard Worker		}
170*333d2b36SAndroid Build Coastguard Worker	}
171*333d2b36SAndroid Build Coastguard Worker	rule := s.SingletonContext.Rule(pctx.PackageContext, name, params, argNames...)
172*333d2b36SAndroid Build Coastguard Worker	if s.Config().captureBuild {
173*333d2b36SAndroid Build Coastguard Worker		s.ruleParams[rule] = params
174*333d2b36SAndroid Build Coastguard Worker	}
175*333d2b36SAndroid Build Coastguard Worker	return rule
176*333d2b36SAndroid Build Coastguard Worker}
177*333d2b36SAndroid Build Coastguard Worker
178*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) Build(pctx PackageContext, params BuildParams) {
179*333d2b36SAndroid Build Coastguard Worker	if s.Config().captureBuild {
180*333d2b36SAndroid Build Coastguard Worker		s.buildParams = append(s.buildParams, params)
181*333d2b36SAndroid Build Coastguard Worker	}
182*333d2b36SAndroid Build Coastguard Worker	bparams := convertBuildParams(params)
183*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.Build(pctx.PackageContext, bparams)
184*333d2b36SAndroid Build Coastguard Worker}
185*333d2b36SAndroid Build Coastguard Worker
186*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) Phony(name string, deps ...Path) {
187*333d2b36SAndroid Build Coastguard Worker	addSingletonPhony(s.Config(), name, deps...)
188*333d2b36SAndroid Build Coastguard Worker}
189*333d2b36SAndroid Build Coastguard Worker
190*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) SetOutDir(pctx PackageContext, value string) {
191*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.SetOutDir(pctx.PackageContext, value)
192*333d2b36SAndroid Build Coastguard Worker}
193*333d2b36SAndroid Build Coastguard Worker
194*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) Eval(pctx PackageContext, ninjaStr string) (string, error) {
195*333d2b36SAndroid Build Coastguard Worker	return s.SingletonContext.Eval(pctx.PackageContext, ninjaStr)
196*333d2b36SAndroid Build Coastguard Worker}
197*333d2b36SAndroid Build Coastguard Worker
198*333d2b36SAndroid Build Coastguard Worker// visitAdaptor wraps a visit function that takes an android.Module parameter into
199*333d2b36SAndroid Build Coastguard Worker// a function that takes a blueprint.Module parameter and only calls the visit function if the
200*333d2b36SAndroid Build Coastguard Worker// blueprint.Module is an android.Module.
201*333d2b36SAndroid Build Coastguard Workerfunc visitAdaptor(visit func(Module)) func(blueprint.Module) {
202*333d2b36SAndroid Build Coastguard Worker	return func(module blueprint.Module) {
203*333d2b36SAndroid Build Coastguard Worker		if aModule, ok := module.(Module); ok {
204*333d2b36SAndroid Build Coastguard Worker			visit(aModule)
205*333d2b36SAndroid Build Coastguard Worker		}
206*333d2b36SAndroid Build Coastguard Worker	}
207*333d2b36SAndroid Build Coastguard Worker}
208*333d2b36SAndroid Build Coastguard Worker
209*333d2b36SAndroid Build Coastguard Worker// visitProxyAdaptor wraps a visit function that takes an android.ModuleProxy parameter into
210*333d2b36SAndroid Build Coastguard Worker// a function that takes a blueprint.ModuleProxy parameter.
211*333d2b36SAndroid Build Coastguard Workerfunc visitProxyAdaptor(visit func(proxy ModuleProxy)) func(proxy blueprint.ModuleProxy) {
212*333d2b36SAndroid Build Coastguard Worker	return func(module blueprint.ModuleProxy) {
213*333d2b36SAndroid Build Coastguard Worker		visit(ModuleProxy{
214*333d2b36SAndroid Build Coastguard Worker			module: module,
215*333d2b36SAndroid Build Coastguard Worker		})
216*333d2b36SAndroid Build Coastguard Worker	}
217*333d2b36SAndroid Build Coastguard Worker}
218*333d2b36SAndroid Build Coastguard Worker
219*333d2b36SAndroid Build Coastguard Worker// predAdaptor wraps a pred function that takes an android.Module parameter
220*333d2b36SAndroid Build Coastguard Worker// into a function that takes an blueprint.Module parameter and only calls the visit function if the
221*333d2b36SAndroid Build Coastguard Worker// blueprint.Module is an android.Module, otherwise returns false.
222*333d2b36SAndroid Build Coastguard Workerfunc predAdaptor(pred func(Module) bool) func(blueprint.Module) bool {
223*333d2b36SAndroid Build Coastguard Worker	return func(module blueprint.Module) bool {
224*333d2b36SAndroid Build Coastguard Worker		if aModule, ok := module.(Module); ok {
225*333d2b36SAndroid Build Coastguard Worker			return pred(aModule)
226*333d2b36SAndroid Build Coastguard Worker		} else {
227*333d2b36SAndroid Build Coastguard Worker			return false
228*333d2b36SAndroid Build Coastguard Worker		}
229*333d2b36SAndroid Build Coastguard Worker	}
230*333d2b36SAndroid Build Coastguard Worker}
231*333d2b36SAndroid Build Coastguard Worker
232*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitAllModulesBlueprint(visit func(blueprint.Module)) {
233*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitAllModules(visit)
234*333d2b36SAndroid Build Coastguard Worker}
235*333d2b36SAndroid Build Coastguard Worker
236*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitAllModules(visit func(Module)) {
237*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitAllModules(visitAdaptor(visit))
238*333d2b36SAndroid Build Coastguard Worker}
239*333d2b36SAndroid Build Coastguard Worker
240*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitAllModuleProxies(visit func(proxy ModuleProxy)) {
241*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitAllModuleProxies(visitProxyAdaptor(visit))
242*333d2b36SAndroid Build Coastguard Worker}
243*333d2b36SAndroid Build Coastguard Worker
244*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitAllModulesIf(pred func(Module) bool, visit func(Module)) {
245*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitAllModulesIf(predAdaptor(pred), visitAdaptor(visit))
246*333d2b36SAndroid Build Coastguard Worker}
247*333d2b36SAndroid Build Coastguard Worker
248*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitDirectDeps(module Module, visit func(Module)) {
249*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitDirectDeps(module, visitAdaptor(visit))
250*333d2b36SAndroid Build Coastguard Worker}
251*333d2b36SAndroid Build Coastguard Worker
252*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module)) {
253*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitDirectDepsIf(module, predAdaptor(pred), visitAdaptor(visit))
254*333d2b36SAndroid Build Coastguard Worker}
255*333d2b36SAndroid Build Coastguard Worker
256*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitDepsDepthFirst(module Module, visit func(Module)) {
257*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitDepsDepthFirst(module, visitAdaptor(visit))
258*333d2b36SAndroid Build Coastguard Worker}
259*333d2b36SAndroid Build Coastguard Worker
260*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitDepsDepthFirstIf(module Module, pred func(Module) bool, visit func(Module)) {
261*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitDepsDepthFirstIf(module, predAdaptor(pred), visitAdaptor(visit))
262*333d2b36SAndroid Build Coastguard Worker}
263*333d2b36SAndroid Build Coastguard Worker
264*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitAllModuleVariants(module Module, visit func(Module)) {
265*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitAllModuleVariants(module, visitAdaptor(visit))
266*333d2b36SAndroid Build Coastguard Worker}
267*333d2b36SAndroid Build Coastguard Worker
268*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) VisitAllModuleVariantProxies(module Module, visit func(proxy ModuleProxy)) {
269*333d2b36SAndroid Build Coastguard Worker	s.SingletonContext.VisitAllModuleVariantProxies(module, visitProxyAdaptor(visit))
270*333d2b36SAndroid Build Coastguard Worker}
271*333d2b36SAndroid Build Coastguard Worker
272*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) PrimaryModule(module Module) Module {
273*333d2b36SAndroid Build Coastguard Worker	return s.SingletonContext.PrimaryModule(module).(Module)
274*333d2b36SAndroid Build Coastguard Worker}
275*333d2b36SAndroid Build Coastguard Worker
276*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) IsFinalModule(module Module) bool {
277*333d2b36SAndroid Build Coastguard Worker	return s.SingletonContext.IsFinalModule(module)
278*333d2b36SAndroid Build Coastguard Worker}
279*333d2b36SAndroid Build Coastguard Worker
280*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) ModuleVariantsFromName(referer Module, name string) []Module {
281*333d2b36SAndroid Build Coastguard Worker	// get module reference for visibility enforcement
282*333d2b36SAndroid Build Coastguard Worker	qualified := createVisibilityModuleReference(s.ModuleName(referer), s.ModuleDir(referer), referer)
283*333d2b36SAndroid Build Coastguard Worker
284*333d2b36SAndroid Build Coastguard Worker	modules := s.SingletonContext.ModuleVariantsFromName(referer, name)
285*333d2b36SAndroid Build Coastguard Worker	result := make([]Module, 0, len(modules))
286*333d2b36SAndroid Build Coastguard Worker	for _, m := range modules {
287*333d2b36SAndroid Build Coastguard Worker		if module, ok := m.(Module); ok {
288*333d2b36SAndroid Build Coastguard Worker			// enforce visibility
289*333d2b36SAndroid Build Coastguard Worker			depName := s.ModuleName(module)
290*333d2b36SAndroid Build Coastguard Worker			depDir := s.ModuleDir(module)
291*333d2b36SAndroid Build Coastguard Worker			depQualified := qualifiedModuleName{depDir, depName}
292*333d2b36SAndroid Build Coastguard Worker			// Targets are always visible to other targets in their own package.
293*333d2b36SAndroid Build Coastguard Worker			if depQualified.pkg != qualified.name.pkg {
294*333d2b36SAndroid Build Coastguard Worker				rule := effectiveVisibilityRules(s.Config(), depQualified)
295*333d2b36SAndroid Build Coastguard Worker				if !rule.matches(qualified) {
296*333d2b36SAndroid Build Coastguard Worker					s.ModuleErrorf(referer, "module %q references %q which is not visible to this module\nYou may need to add %q to its visibility",
297*333d2b36SAndroid Build Coastguard Worker						referer.Name(), depQualified, "//"+s.ModuleDir(referer))
298*333d2b36SAndroid Build Coastguard Worker					continue
299*333d2b36SAndroid Build Coastguard Worker				}
300*333d2b36SAndroid Build Coastguard Worker			}
301*333d2b36SAndroid Build Coastguard Worker			result = append(result, module)
302*333d2b36SAndroid Build Coastguard Worker		}
303*333d2b36SAndroid Build Coastguard Worker	}
304*333d2b36SAndroid Build Coastguard Worker	return result
305*333d2b36SAndroid Build Coastguard Worker}
306*333d2b36SAndroid Build Coastguard Worker
307*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) otherModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) {
308*333d2b36SAndroid Build Coastguard Worker	return s.SingletonContext.ModuleProvider(module, provider)
309*333d2b36SAndroid Build Coastguard Worker}
310*333d2b36SAndroid Build Coastguard Worker
311*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) OtherModulePropertyErrorf(module Module, property string, format string, args ...interface{}) {
312*333d2b36SAndroid Build Coastguard Worker	s.blueprintSingletonContext().OtherModulePropertyErrorf(module, property, format, args...)
313*333d2b36SAndroid Build Coastguard Worker}
314*333d2b36SAndroid Build Coastguard Worker
315*333d2b36SAndroid Build Coastguard Workerfunc (s *singletonContextAdaptor) HasMutatorFinished(mutatorName string) bool {
316*333d2b36SAndroid Build Coastguard Worker	return s.blueprintSingletonContext().HasMutatorFinished(mutatorName)
317*333d2b36SAndroid Build Coastguard Worker}
318