summaryrefslogtreecommitdiff
path: root/android/arch_module_context.go
blob: a3a03af026b0c4f8cd4aec83a6a21fcc961a2eb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package android

// ArchModuleContext can be embedded in other contexts to provide information about the module set by
// the archMutator.
type ArchModuleContext interface {
	Target() Target
	TargetPrimary() bool

	// The additional arch specific targets (e.g. 32/64 bit) that this module variant is
	// responsible for creating.
	MultiTargets() []Target
	Arch() Arch
	Os() OsType
	Host() bool
	Device() bool
	Darwin() bool
	Windows() bool
	PrimaryArch() bool
}

type archModuleContext struct {
	// TODO: these should eventually go through a (possibly cached) provider like any other configuration instead
	//  of being special cased.
	ready         bool
	os            OsType
	target        Target
	targetPrimary bool
	multiTargets  []Target
	primaryArch   bool
}

// ArchReady returns true if the arch mutator has run on the module. Before this returns
// true, the module essentially doesn't have an arch and cannot make decisions based on
// architecture.
func (a *archModuleContext) ArchReady() bool {
	return a.ready
}

func (a *archModuleContext) Target() Target {
	return a.target
}

func (a *archModuleContext) TargetPrimary() bool {
	return a.targetPrimary
}

func (a *archModuleContext) MultiTargets() []Target {
	return a.multiTargets
}

func (a *archModuleContext) Arch() Arch {
	return a.target.Arch
}

func (a *archModuleContext) Os() OsType {
	return a.os
}

func (a *archModuleContext) Host() bool {
	return a.os.Class == Host
}

func (a *archModuleContext) Device() bool {
	return a.os.Class == Device
}

func (a *archModuleContext) Darwin() bool {
	return a.os == Darwin
}

func (a *archModuleContext) Windows() bool {
	return a.os == Windows
}

func (b *archModuleContext) PrimaryArch() bool {
	return b.primaryArch
}