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