| Colin Cross | 1d3d9f1 | 2024-01-18 14:30:22 -0800 | [diff] [blame] | 1 | // Copyright 2024 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 |  | 
 | 15 | package android | 
 | 16 |  | 
 | 17 | // ArchModuleContext can be embedded in other contexts to provide information about the module set by | 
 | 18 | // the archMutator. | 
 | 19 | type ArchModuleContext interface { | 
 | 20 | 	Target() Target | 
 | 21 | 	TargetPrimary() bool | 
 | 22 |  | 
 | 23 | 	// The additional arch specific targets (e.g. 32/64 bit) that this module variant is | 
 | 24 | 	// responsible for creating. | 
 | 25 | 	MultiTargets() []Target | 
 | 26 | 	Arch() Arch | 
 | 27 | 	Os() OsType | 
 | 28 | 	Host() bool | 
 | 29 | 	Device() bool | 
 | 30 | 	Darwin() bool | 
 | 31 | 	Windows() bool | 
 | 32 | 	PrimaryArch() bool | 
 | 33 | } | 
 | 34 |  | 
 | 35 | type archModuleContext struct { | 
 | 36 | 	// TODO: these should eventually go through a (possibly cached) provider like any other configuration instead | 
 | 37 | 	//  of being special cased. | 
| Cole Faust | 0aa21cc | 2024-03-20 12:28:03 -0700 | [diff] [blame] | 38 | 	ready         bool | 
| Colin Cross | 1d3d9f1 | 2024-01-18 14:30:22 -0800 | [diff] [blame] | 39 | 	os            OsType | 
 | 40 | 	target        Target | 
 | 41 | 	targetPrimary bool | 
 | 42 | 	multiTargets  []Target | 
 | 43 | 	primaryArch   bool | 
 | 44 | } | 
 | 45 |  | 
| Cole Faust | 0aa21cc | 2024-03-20 12:28:03 -0700 | [diff] [blame] | 46 | // ArchReady returns true if the arch mutator has run on the module. Before this returns | 
 | 47 | // true, the module essentially doesn't have an arch and cannot make decisions based on | 
 | 48 | // architecture. | 
 | 49 | func (a *archModuleContext) ArchReady() bool { | 
 | 50 | 	return a.ready | 
 | 51 | } | 
 | 52 |  | 
| Colin Cross | 1d3d9f1 | 2024-01-18 14:30:22 -0800 | [diff] [blame] | 53 | func (a *archModuleContext) Target() Target { | 
 | 54 | 	return a.target | 
 | 55 | } | 
 | 56 |  | 
 | 57 | func (a *archModuleContext) TargetPrimary() bool { | 
 | 58 | 	return a.targetPrimary | 
 | 59 | } | 
 | 60 |  | 
 | 61 | func (a *archModuleContext) MultiTargets() []Target { | 
 | 62 | 	return a.multiTargets | 
 | 63 | } | 
 | 64 |  | 
 | 65 | func (a *archModuleContext) Arch() Arch { | 
 | 66 | 	return a.target.Arch | 
 | 67 | } | 
 | 68 |  | 
 | 69 | func (a *archModuleContext) Os() OsType { | 
 | 70 | 	return a.os | 
 | 71 | } | 
 | 72 |  | 
 | 73 | func (a *archModuleContext) Host() bool { | 
 | 74 | 	return a.os.Class == Host | 
 | 75 | } | 
 | 76 |  | 
 | 77 | func (a *archModuleContext) Device() bool { | 
 | 78 | 	return a.os.Class == Device | 
 | 79 | } | 
 | 80 |  | 
 | 81 | func (a *archModuleContext) Darwin() bool { | 
 | 82 | 	return a.os == Darwin | 
 | 83 | } | 
 | 84 |  | 
 | 85 | func (a *archModuleContext) Windows() bool { | 
 | 86 | 	return a.os == Windows | 
 | 87 | } | 
 | 88 |  | 
 | 89 | func (b *archModuleContext) PrimaryArch() bool { | 
 | 90 | 	return b.primaryArch | 
 | 91 | } |