blob: 3cf4b411545bd595f86a20532c740bd5571f6694 [file] [log] [blame]
Colin Cross1d3d9f12024-01-18 14:30:22 -08001// 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 os OsType
39 target Target
40 targetPrimary bool
41 multiTargets []Target
42 primaryArch bool
43}
44
45func (a *archModuleContext) Target() Target {
46 return a.target
47}
48
49func (a *archModuleContext) TargetPrimary() bool {
50 return a.targetPrimary
51}
52
53func (a *archModuleContext) MultiTargets() []Target {
54 return a.multiTargets
55}
56
57func (a *archModuleContext) Arch() Arch {
58 return a.target.Arch
59}
60
61func (a *archModuleContext) Os() OsType {
62 return a.os
63}
64
65func (a *archModuleContext) Host() bool {
66 return a.os.Class == Host
67}
68
69func (a *archModuleContext) Device() bool {
70 return a.os.Class == Device
71}
72
73func (a *archModuleContext) Darwin() bool {
74 return a.os == Darwin
75}
76
77func (a *archModuleContext) Windows() bool {
78 return a.os == Windows
79}
80
81func (b *archModuleContext) PrimaryArch() bool {
82 return b.primaryArch
83}