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 15package android 16 17// ArchModuleContext can be embedded in other contexts to provide information about the module set by 18// the archMutator. 19type 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 35type archModuleContext struct { 36 // TODO: these should eventually go through a (possibly cached) provider like any other configuration instead 37 // of being special cased. 38 ready bool 39 os OsType 40 target Target 41 targetPrimary bool 42 multiTargets []Target 43 primaryArch bool 44} 45 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. 49func (a *archModuleContext) ArchReady() bool { 50 return a.ready 51} 52 53func (a *archModuleContext) Target() Target { 54 return a.target 55} 56 57func (a *archModuleContext) TargetPrimary() bool { 58 return a.targetPrimary 59} 60 61func (a *archModuleContext) MultiTargets() []Target { 62 return a.multiTargets 63} 64 65func (a *archModuleContext) Arch() Arch { 66 return a.target.Arch 67} 68 69func (a *archModuleContext) Os() OsType { 70 return a.os 71} 72 73func (a *archModuleContext) Host() bool { 74 return a.os.Class == Host 75} 76 77func (a *archModuleContext) Device() bool { 78 return a.os.Class == Device 79} 80 81func (a *archModuleContext) Darwin() bool { 82 return a.os == Darwin 83} 84 85func (a *archModuleContext) Windows() bool { 86 return a.os == Windows 87} 88 89func (b *archModuleContext) PrimaryArch() bool { 90 return b.primaryArch 91} 92