blob: 5c7bbbf2bad73061f68c0ff10d33238408522b38 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 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
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross69452e12023-11-15 11:20:53 -080018 "android/soong/bazel"
Inseob Kim81b00a82023-05-15 18:06:31 +090019 "crypto/md5"
20 "encoding/hex"
21 "encoding/json"
Colin Cross6ff51382015-12-17 16:39:19 -080022 "fmt"
Bob Badour4101c712022-02-09 11:54:35 -080023 "net/url"
Colin Cross3f40fa42015-01-30 17:27:36 -080024 "path/filepath"
Liz Kammer9525e712022-01-05 13:46:24 -050025 "reflect"
Colin Crossd6fd0132023-11-06 13:54:06 -080026 "slices"
Bob Badour4101c712022-02-09 11:54:35 -080027 "sort"
Colin Cross6ff51382015-12-17 16:39:19 -080028 "strings"
Tahsin Loqman77dc7d02022-12-19 16:27:25 +000029
Colin Crossf6566ed2015-03-24 11:13:38 -070030 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070031 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080032)
33
34var (
35 DeviceSharedLibrary = "shared_library"
36 DeviceStaticLibrary = "static_library"
Colin Cross3f40fa42015-01-30 17:27:36 -080037)
38
Colin Cross635c3b02016-05-18 15:37:25 -070039type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -080040 blueprint.Module
41
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070042 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
43 // but GenerateAndroidBuildActions also has access to Android-specific information.
44 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -070045 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070046
Paul Duffin44f1d842020-06-26 20:17:02 +010047 // Add dependencies to the components of a module, i.e. modules that are created
48 // by the module and which are considered to be part of the creating module.
49 //
50 // This is called before prebuilts are renamed so as to allow a dependency to be
51 // added directly to a prebuilt child module instead of depending on a source module
52 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
53 //
54 // A dependency on a prebuilt must include the "prebuilt_" prefix.
55 ComponentDepsMutator(ctx BottomUpMutatorContext)
56
Colin Cross1e676be2016-10-12 14:38:15 -070057 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -080058
Colin Cross635c3b02016-05-18 15:37:25 -070059 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +090060 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -080061 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -070062 Target() Target
Paul Duffinc04fb9e2021-03-01 12:25:10 +000063 MultiTargets() []Target
Paul Duffinb42fa672021-09-09 16:37:49 +010064
65 // ImageVariation returns the image variation of this module.
66 //
67 // The returned structure has its Mutator field set to "image" and its Variation field set to the
68 // image variation, e.g. recovery, ramdisk, etc.. The Variation field is "" for host modules and
69 // device modules that have no image variation.
70 ImageVariation() blueprint.Variation
71
Anton Hansson1ee62c02020-06-30 11:51:53 +010072 Owner() string
Dan Willemsen782a2d12015-12-21 14:55:28 -080073 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -070074 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -070075 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -080076 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -070077 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +090078 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +090079 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -070080 InstallInRoot() bool
Colin Crossea30d852023-11-29 16:00:16 -080081 InstallInOdm() bool
82 InstallInProduct() bool
Kiyoung Kimae11c232021-07-19 11:38:04 +090083 InstallInVendor() bool
Jiyong Park87788b52020-09-01 12:37:45 +090084 InstallForceOS() (*OsType, *ArchType)
Jiyong Parkce243632023-02-17 18:22:25 +090085 PartitionTag(DeviceConfig) string
Colin Crossa9c8c9f2020-12-16 10:20:23 -080086 HideFromMake()
87 IsHideFromMake() bool
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +000088 IsSkipInstall() bool
Iván Budnik295da162023-03-10 16:11:26 +000089 MakeUninstallable()
Liz Kammer5ca3a622020-08-05 15:40:41 -070090 ReplacedByPrebuilt()
91 IsReplacedByPrebuilt() bool
Jiyong Park374510b2018-03-19 18:23:01 +090092 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +090093 InitRc() Paths
94 VintfFragments() Paths
Justin Yun1871f902023-04-07 20:13:19 +090095 EffectiveLicenseKinds() []string
Justin Yun885a7de2021-06-29 20:34:53 +090096 EffectiveLicenseFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -070097
98 AddProperties(props ...interface{})
99 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700100
Colin Crossae887032017-10-23 17:16:14 -0700101 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800102 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800103 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100104
Colin Cross9a362232019-07-01 15:32:45 -0700105 // String returns a string that includes the module name and variants for printing during debugging.
106 String() string
107
Paul Duffine2453c72019-05-31 14:00:04 +0100108 // Get the qualified module id for this module.
109 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
110
111 // Get information about the properties that can contain visibility rules.
112 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100113
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900114 RequiredModuleNames() []string
115 HostRequiredModuleNames() []string
116 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800117
Jiyong Park4dc2a1a2020-09-28 17:46:22 +0900118 FilesToInstall() InstallPaths
Jiyong Park073ea552020-11-09 14:08:34 +0900119 PackagingSpecs() []PackagingSpec
Colin Crossffe6b9d2020-12-01 15:40:06 -0800120
121 // TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive
122 // dependencies with dependency tags for which IsInstallDepNeeded() returns true.
123 TransitivePackagingSpecs() []PackagingSpec
Paul Duffine2453c72019-05-31 14:00:04 +0100124}
125
126// Qualified id for a module
127type qualifiedModuleName struct {
128 // The package (i.e. directory) in which the module is defined, without trailing /
129 pkg string
130
131 // The name of the module, empty string if package.
132 name string
133}
134
135func (q qualifiedModuleName) String() string {
136 if q.name == "" {
137 return "//" + q.pkg
138 }
139 return "//" + q.pkg + ":" + q.name
140}
141
Paul Duffine484f472019-06-20 16:38:08 +0100142func (q qualifiedModuleName) isRootPackage() bool {
143 return q.pkg == "" && q.name == ""
144}
145
Paul Duffine2453c72019-05-31 14:00:04 +0100146// Get the id for the package containing this module.
147func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
148 pkg := q.pkg
149 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100150 if pkg == "" {
151 panic(fmt.Errorf("Cannot get containing package id of root package"))
152 }
153
154 index := strings.LastIndex(pkg, "/")
155 if index == -1 {
156 pkg = ""
157 } else {
158 pkg = pkg[:index]
159 }
Paul Duffine2453c72019-05-31 14:00:04 +0100160 }
161 return newPackageId(pkg)
162}
163
164func newPackageId(pkg string) qualifiedModuleName {
165 // A qualified id for a package module has no name.
166 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800167}
168
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000169type Dist struct {
170 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
171 // command line and any of these targets are also on the command line, or otherwise
172 // built
173 Targets []string `android:"arch_variant"`
174
175 // The name of the output artifact. This defaults to the basename of the output of
176 // the module.
177 Dest *string `android:"arch_variant"`
178
179 // The directory within the dist directory to store the artifact. Defaults to the
180 // top level directory ("").
181 Dir *string `android:"arch_variant"`
182
183 // A suffix to add to the artifact file name (before any extension).
184 Suffix *string `android:"arch_variant"`
185
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000186 // If true, then the artifact file will be appended with _<product name>. For
187 // example, if the product is coral and the module is an android_app module
188 // of name foo, then the artifact would be foo_coral.apk. If false, there is
189 // no change to the artifact file name.
190 Append_artifact_with_product *bool `android:"arch_variant"`
191
Paul Duffin74f05592020-11-25 16:37:46 +0000192 // A string tag to select the OutputFiles associated with the tag.
193 //
194 // If no tag is specified then it will select the default dist paths provided
195 // by the module type. If a tag of "" is specified then it will return the
196 // default output files provided by the modules, i.e. the result of calling
197 // OutputFiles("").
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000198 Tag *string `android:"arch_variant"`
199}
200
Bob Badour4101c712022-02-09 11:54:35 -0800201// NamedPath associates a path with a name. e.g. a license text path with a package name
202type NamedPath struct {
203 Path Path
204 Name string
205}
206
207// String returns an escaped string representing the `NamedPath`.
208func (p NamedPath) String() string {
209 if len(p.Name) > 0 {
210 return p.Path.String() + ":" + url.QueryEscape(p.Name)
211 }
212 return p.Path.String()
213}
214
215// NamedPaths describes a list of paths each associated with a name.
216type NamedPaths []NamedPath
217
218// Strings returns a list of escaped strings representing each `NamedPath` in the list.
219func (l NamedPaths) Strings() []string {
220 result := make([]string, 0, len(l))
221 for _, p := range l {
222 result = append(result, p.String())
223 }
224 return result
225}
226
227// SortedUniqueNamedPaths modifies `l` in place to return the sorted unique subset.
228func SortedUniqueNamedPaths(l NamedPaths) NamedPaths {
229 if len(l) == 0 {
230 return l
231 }
232 sort.Slice(l, func(i, j int) bool {
233 return l[i].String() < l[j].String()
234 })
235 k := 0
236 for i := 1; i < len(l); i++ {
237 if l[i].String() == l[k].String() {
238 continue
239 }
240 k++
241 if k < i {
242 l[k] = l[i]
243 }
244 }
245 return l[:k+1]
246}
247
Inseob Kim81b00a82023-05-15 18:06:31 +0900248// soongConfigTrace holds all references to VendorVars. Uses []string for blueprint:"mutated"
249type soongConfigTrace struct {
250 Bools []string `json:",omitempty"`
251 Strings []string `json:",omitempty"`
252 IsSets []string `json:",omitempty"`
253}
254
255func (c *soongConfigTrace) isEmpty() bool {
256 return len(c.Bools) == 0 && len(c.Strings) == 0 && len(c.IsSets) == 0
257}
258
259// Returns hash of serialized trace records (empty string if there's no trace recorded)
260func (c *soongConfigTrace) hash() string {
261 // Use MD5 for speed. We don't care collision or preimage attack
262 if c.isEmpty() {
263 return ""
264 }
265 j, err := json.Marshal(c)
266 if err != nil {
267 panic(fmt.Errorf("json marshal of %#v failed: %#v", *c, err))
268 }
269 hash := md5.Sum(j)
270 return hex.EncodeToString(hash[:])
271}
272
Colin Crossfc754582016-05-17 16:34:16 -0700273type nameProperties struct {
274 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800275 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700276}
277
Colin Cross08d6f8f2020-11-19 02:33:19 +0000278type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800279 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000280 //
281 // Disabling a module should only be done for those modules that cannot be built
282 // in the current environment. Modules that can build in the current environment
283 // but are not usually required (e.g. superceded by a prebuilt) should not be
284 // disabled as that will prevent them from being built by the checkbuild target
285 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800286 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800287
Paul Duffin2e61fa62019-03-28 14:10:57 +0000288 // Controls the visibility of this module to other modules. Allowable values are one or more of
289 // these formats:
290 //
291 // ["//visibility:public"]: Anyone can use this module.
292 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
293 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100294 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
295 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000296 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
297 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
298 // this module. Note that sub-packages do not have access to the rule; for example,
299 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
300 // is a special module and must be used verbatim. It represents all of the modules in the
301 // package.
302 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
303 // or other or in one of their sub-packages have access to this module. For example,
304 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
305 // to depend on this rule (but not //independent:evil)
306 // ["//project"]: This is shorthand for ["//project:__pkg__"]
307 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
308 // //project is the module's package. e.g. using [":__subpackages__"] in
309 // packages/apps/Settings/Android.bp is equivalent to
310 // //packages/apps/Settings:__subpackages__.
311 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
312 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100313 //
314 // If a module does not specify the `visibility` property then it uses the
315 // `default_visibility` property of the `package` module in the module's package.
316 //
317 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100318 // it will use the `default_visibility` of its closest ancestor package for which
319 // a `default_visibility` property is specified.
320 //
321 // If no `default_visibility` property can be found then the module uses the
322 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100323 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100324 // The `visibility` property has no effect on a defaults module although it does
325 // apply to any non-defaults module that uses it. To set the visibility of a
326 // defaults module, use the `defaults_visibility` property on the defaults module;
327 // not to be confused with the `default_visibility` property on the package module.
328 //
Elliott Hughes10363162024-01-09 22:02:03 +0000329 // See https://android.googlesource.com/platform/build/soong/+/main/README.md#visibility for
Paul Duffin2e61fa62019-03-28 14:10:57 +0000330 // more details.
331 Visibility []string
332
Bob Badour37af0462021-01-07 03:34:31 +0000333 // Describes the licenses applicable to this module. Must reference license modules.
334 Licenses []string
335
336 // Flattened from direct license dependencies. Equal to Licenses unless particular module adds more.
337 Effective_licenses []string `blueprint:"mutated"`
338 // Override of module name when reporting licenses
339 Effective_package_name *string `blueprint:"mutated"`
340 // Notice files
Bob Badour4101c712022-02-09 11:54:35 -0800341 Effective_license_text NamedPaths `blueprint:"mutated"`
Bob Badour37af0462021-01-07 03:34:31 +0000342 // License names
343 Effective_license_kinds []string `blueprint:"mutated"`
344 // License conditions
345 Effective_license_conditions []string `blueprint:"mutated"`
346
Colin Cross7d5136f2015-05-11 13:39:40 -0700347 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800348 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
349 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
Roland Levillain24bb2e62020-09-22 11:18:38 +0000350 // platform).
Colin Cross7d716ba2017-11-01 10:38:29 -0700351 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700352
353 Target struct {
354 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700355 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700356 }
357 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700358 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700359 }
360 }
361
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000362 // If set to true then the archMutator will create variants for each arch specific target
363 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
364 // create a variant for the architecture and will list the additional arch specific targets
365 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700366 UseTargetVariants bool `blueprint:"mutated"`
367 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800368
Dan Willemsen782a2d12015-12-21 14:55:28 -0800369 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700370 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800371
Colin Cross55708f32017-03-20 13:23:34 -0700372 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700373 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700374
Jiyong Park2db76922017-11-08 16:03:48 +0900375 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
376 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
377 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700378 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700379
Jiyong Park2db76922017-11-08 16:03:48 +0900380 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
381 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
382 Soc_specific *bool
383
384 // whether this module is specific to a device, not only for SoC, but also for off-chip
385 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
386 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
387 // This implies `soc_specific:true`.
388 Device_specific *bool
389
390 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900391 // network operator, etc). When set to true, it is installed into /product (or
392 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900393 Product_specific *bool
394
Justin Yund5f6c822019-06-25 16:47:17 +0900395 // whether this module extends system. When set to true, it is installed into /system_ext
396 // (or /system/system_ext if system_ext partition does not exist).
397 System_ext_specific *bool
398
Jiyong Parkf9332f12018-02-01 00:54:12 +0900399 // Whether this module is installed to recovery partition
400 Recovery *bool
401
Yifan Hong1b3348d2020-01-21 15:53:22 -0800402 // Whether this module is installed to ramdisk
403 Ramdisk *bool
404
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700405 // Whether this module is installed to vendor ramdisk
406 Vendor_ramdisk *bool
407
Inseob Kim08758f02021-04-08 21:13:22 +0900408 // Whether this module is installed to debug ramdisk
409 Debug_ramdisk *bool
410
Jaewoong Jung8e93aba2021-03-02 16:58:08 -0800411 // Whether this module is built for non-native architectures (also known as native bridge binary)
dimitry1f33e402019-03-26 12:39:31 +0100412 Native_bridge_supported *bool `android:"arch_variant"`
413
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700414 // init.rc files to be installed if this module is installed
Colin Cross0bab8772020-09-25 14:01:21 -0700415 Init_rc []string `android:"arch_variant,path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700416
Steven Moreland57a23d22018-04-04 15:42:19 -0700417 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800418 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700419
Chris Wolfe998306e2016-08-15 14:47:23 -0400420 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700421 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400422
Sasha Smundakb6d23052019-04-01 18:37:36 -0700423 // names of other modules to install on host if this module is installed
424 Host_required []string `android:"arch_variant"`
425
426 // names of other modules to install on target if this module is installed
427 Target_required []string `android:"arch_variant"`
428
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000429 // The OsType of artifacts that this module variant is responsible for creating.
430 //
431 // Set by osMutator
432 CompileOS OsType `blueprint:"mutated"`
433
434 // The Target of artifacts that this module variant is responsible for creating.
435 //
436 // Set by archMutator
437 CompileTarget Target `blueprint:"mutated"`
438
439 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
440 // responsible for creating.
441 //
442 // By default this is nil as, where necessary, separate variants are created for the
443 // different multilib types supported and that information is encapsulated in the
444 // CompileTarget so the module variant simply needs to create artifacts for that.
445 //
446 // However, if UseTargetVariants is set to false (e.g. by
447 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
448 // multilib targets. Instead a single variant is created for the architecture and
449 // this contains the multilib specific targets that this variant should create.
450 //
451 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700452 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000453
454 // True if the module variant's CompileTarget is the primary target
455 //
456 // Set by archMutator
457 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800458
459 // Set by InitAndroidModule
460 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700461 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700462
Paul Duffin1356d8c2020-02-25 19:26:33 +0000463 // If set to true then a CommonOS variant will be created which will have dependencies
464 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
465 // that covers all os and architecture variants.
466 //
467 // The OsType specific variants can be retrieved by calling
468 // GetOsSpecificVariantsOfCommonOSVariant
469 //
470 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
471 CreateCommonOSVariant bool `blueprint:"mutated"`
472
473 // If set to true then this variant is the CommonOS variant that has dependencies on its
474 // OsType specific variants.
475 //
476 // Set by osMutator.
477 CommonOSVariant bool `blueprint:"mutated"`
478
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800479 // When HideFromMake is set to true, no entry for this variant will be emitted in the
480 // generated Android.mk file.
481 HideFromMake bool `blueprint:"mutated"`
482
483 // When SkipInstall is set to true, calls to ctx.InstallFile, ctx.InstallExecutable,
484 // ctx.InstallSymlink and ctx.InstallAbsoluteSymlink act like calls to ctx.PackageFile
485 // and don't create a rule to install the file.
Colin Crossce75d2c2016-10-06 16:12:58 -0700486 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800487
Colin Crossbd3a16b2023-04-25 11:30:51 -0700488 // UninstallableApexPlatformVariant is set by MakeUninstallable called by the apex
489 // mutator. MakeUninstallable also sets HideFromMake. UninstallableApexPlatformVariant
490 // is used to avoid adding install or packaging dependencies into libraries provided
491 // by apexes.
492 UninstallableApexPlatformVariant bool `blueprint:"mutated"`
493
Liz Kammer5ca3a622020-08-05 15:40:41 -0700494 // Whether the module has been replaced by a prebuilt
495 ReplacedByPrebuilt bool `blueprint:"mutated"`
496
Justin Yun32f053b2020-07-31 23:07:17 +0900497 // Disabled by mutators. If set to true, it overrides Enabled property.
498 ForcedDisabled bool `blueprint:"mutated"`
499
Jeff Gaston088e29e2017-11-29 16:47:17 -0800500 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700501
Liz Kammerc13f7852023-05-17 13:01:48 -0400502 MissingDeps []string `blueprint:"mutated"`
503 CheckedMissingDeps bool `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700504
505 // Name and variant strings stored by mutators to enable Module.String()
506 DebugName string `blueprint:"mutated"`
507 DebugMutators []string `blueprint:"mutated"`
508 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800509
Colin Crossa6845402020-11-16 15:08:19 -0800510 // ImageVariation is set by ImageMutator to specify which image this variation is for,
511 // for example "" for core or "recovery" for recovery. It will often be set to one of the
512 // constants in image.go, but can also be set to a custom value by individual module types.
Colin Cross7228ecd2019-11-18 16:00:16 -0800513 ImageVariation string `blueprint:"mutated"`
Liz Kammer2ada09a2021-08-11 00:17:36 -0400514
Inseob Kim8ff69de2023-06-16 14:19:33 +0900515 // SoongConfigTrace records accesses to VendorVars (soong_config). The trace will be hashed
516 // and used as a subdir of PathForModuleOut. Note that we mainly focus on incremental
517 // builds among similar products (e.g. aosp_cf_x86_64_phone and aosp_cf_x86_64_foldable),
518 // and there are variables other than soong_config, which isn't captured by soong config
519 // trace, but influence modules among products.
Inseob Kim81b00a82023-05-15 18:06:31 +0900520 SoongConfigTrace soongConfigTrace `blueprint:"mutated"`
521 SoongConfigTraceHash string `blueprint:"mutated"`
Ronald Braunstein73b08ff2023-12-19 10:24:47 -0800522
523 // The team (defined by the owner/vendor) who owns the property.
524 Team *string `android:"path"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800525}
526
Paul Duffined875132020-09-02 13:08:57 +0100527type distProperties struct {
528 // configuration to distribute output files from this module to the distribution
529 // directory (default: $OUT/dist, configurable with $DIST_DIR)
530 Dist Dist `android:"arch_variant"`
531
532 // a list of configurations to distribute output files from this module to the
533 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
534 Dists []Dist `android:"arch_variant"`
535}
536
Ronald Braunstein73b08ff2023-12-19 10:24:47 -0800537type TeamDepTagType struct {
538 blueprint.BaseDependencyTag
539}
540
541var teamDepTag = TeamDepTagType{}
542
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800543// CommonTestOptions represents the common `test_options` properties in
544// Android.bp.
545type CommonTestOptions struct {
546 // If the test is a hostside (no device required) unittest that shall be run
547 // during presubmit check.
548 Unit_test *bool
Zhenhuang Wang409d2772022-08-22 16:00:05 +0800549
550 // Tags provide additional metadata to customize test execution by downstream
551 // test runners. The tags have no special meaning to Soong.
552 Tags []string
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800553}
554
555// SetAndroidMkEntries sets AndroidMkEntries according to the value of base
556// `test_options`.
557func (t *CommonTestOptions) SetAndroidMkEntries(entries *AndroidMkEntries) {
558 entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(t.Unit_test))
Zhenhuang Wang409d2772022-08-22 16:00:05 +0800559 if len(t.Tags) > 0 {
560 entries.AddStrings("LOCAL_TEST_OPTIONS_TAGS", t.Tags...)
561 }
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800562}
563
Paul Duffin74f05592020-11-25 16:37:46 +0000564// The key to use in TaggedDistFiles when a Dist structure does not specify a
565// tag property. This intentionally does not use "" as the default because that
566// would mean that an empty tag would have a different meaning when used in a dist
567// structure that when used to reference a specific set of output paths using the
568// :module{tag} syntax, which passes tag to the OutputFiles(tag) method.
569const DefaultDistTag = "<default-dist-tag>"
570
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000571// A map of OutputFile tag keys to Paths, for disting purposes.
572type TaggedDistFiles map[string]Paths
573
Paul Duffin74f05592020-11-25 16:37:46 +0000574// addPathsForTag adds a mapping from the tag to the paths. If the map is nil
575// then it will create a map, update it and then return it. If a mapping already
576// exists for the tag then the paths are appended to the end of the current list
577// of paths, ignoring any duplicates.
578func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles {
579 if t == nil {
580 t = make(TaggedDistFiles)
581 }
582
583 for _, distFile := range paths {
584 if distFile != nil && !t[tag].containsPath(distFile) {
585 t[tag] = append(t[tag], distFile)
586 }
587 }
588
589 return t
590}
591
592// merge merges the entries from the other TaggedDistFiles object into this one.
593// If the TaggedDistFiles is nil then it will create a new instance, merge the
594// other into it, and then return it.
595func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
596 for tag, paths := range other {
597 t = t.addPathsForTag(tag, paths...)
598 }
599
600 return t
601}
602
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000603func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
Sasha Smundake198eaf2022-08-04 13:07:02 -0700604 for _, p := range paths {
605 if p == nil {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000606 panic("The path to a dist file cannot be nil.")
607 }
608 }
609
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000610 // The default OutputFile tag is the empty "" string.
Paul Duffin74f05592020-11-25 16:37:46 +0000611 return TaggedDistFiles{DefaultDistTag: paths}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000612}
613
Colin Cross3f40fa42015-01-30 17:27:36 -0800614type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800615 // If set to true, build a variant of the module for the host. Defaults to false.
616 Host_supported *bool
617
618 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700619 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800620}
621
Colin Crossc472d572015-03-17 15:06:21 -0700622type Multilib string
623
624const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800625 MultilibBoth Multilib = "both"
626 MultilibFirst Multilib = "first"
627 MultilibCommon Multilib = "common"
628 MultilibCommonFirst Multilib = "common_first"
Colin Crossc472d572015-03-17 15:06:21 -0700629)
630
Colin Crossa1ad8d12016-06-01 17:09:44 -0700631type HostOrDeviceSupported int
632
633const (
Colin Cross34037c62020-11-17 13:19:17 -0800634 hostSupported = 1 << iota
635 hostCrossSupported
636 deviceSupported
637 hostDefault
638 deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700639
640 // Host and HostCross are built by default. Device is not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800641 HostSupported = hostSupported | hostCrossSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700642
643 // Host is built by default. HostCross and Device are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800644 HostSupportedNoCross = hostSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700645
646 // Device is built by default. Host and HostCross are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800647 DeviceSupported = deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700648
Liz Kammer8631cc72021-08-23 21:12:07 +0000649 // By default, _only_ device variant is built. Device variant can be disabled with `device_supported: false`
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -0700650 // Host and HostCross are disabled by default and can be enabled with `host_supported: true`
Colin Cross34037c62020-11-17 13:19:17 -0800651 HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700652
653 // Host, HostCross, and Device are built by default.
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -0700654 // Building Device can be disabled with `device_supported: false`
655 // Building Host and HostCross can be disabled with `host_supported: false`
Colin Cross34037c62020-11-17 13:19:17 -0800656 HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
657 deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700658
659 // Nothing is supported. This is not exposed to the user, but used to mark a
660 // host only module as unsupported when the module type is not supported on
661 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Colin Cross34037c62020-11-17 13:19:17 -0800662 NeitherHostNorDeviceSupported = 0
Colin Crossa1ad8d12016-06-01 17:09:44 -0700663)
664
Jiyong Park2db76922017-11-08 16:03:48 +0900665type moduleKind int
666
667const (
668 platformModule moduleKind = iota
669 deviceSpecificModule
670 socSpecificModule
671 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900672 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900673)
674
675func (k moduleKind) String() string {
676 switch k {
677 case platformModule:
678 return "platform"
679 case deviceSpecificModule:
680 return "device-specific"
681 case socSpecificModule:
682 return "soc-specific"
683 case productSpecificModule:
684 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900685 case systemExtSpecificModule:
686 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900687 default:
688 panic(fmt.Errorf("unknown module kind %d", k))
689 }
690}
691
Colin Cross9d34f352019-11-22 16:03:51 -0800692func initAndroidModuleBase(m Module) {
693 m.base().module = m
694}
695
Colin Crossa6845402020-11-16 15:08:19 -0800696// InitAndroidModule initializes the Module as an Android module that is not architecture-specific.
697// It adds the common properties, for example "name" and "enabled".
Colin Cross36242852017-06-23 15:06:31 -0700698func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800699 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800700 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700701
Colin Cross36242852017-06-23 15:06:31 -0700702 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700703 &base.nameProperties,
Paul Duffined875132020-09-02 13:08:57 +0100704 &base.commonProperties,
705 &base.distProperties)
Colin Cross18c46802019-09-24 22:19:02 -0700706
Colin Crosseabaedd2020-02-06 17:01:55 -0800707 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -0700708
Paul Duffin63c6e182019-07-24 14:24:38 +0100709 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +0100710 // its checking and parsing phases so make it the primary visibility property.
711 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Bob Badour37af0462021-01-07 03:34:31 +0000712
713 // The default_applicable_licenses property needs to be checked and parsed by the licenses module during
714 // its checking and parsing phases so make it the primary licenses property.
715 setPrimaryLicensesProperty(m, "licenses", &base.commonProperties.Licenses)
Colin Cross5049f022015-03-18 13:28:46 -0700716}
717
Colin Crossa6845402020-11-16 15:08:19 -0800718// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific.
719// It adds the common properties, for example "name" and "enabled", as well as runtime generated
720// property structs for architecture-specific versions of generic properties tagged with
721// `android:"arch_variant"`.
722//
Colin Crossd079e0b2022-08-16 10:27:33 -0700723// InitAndroidModule should not be called if InitAndroidArchModule was called.
Colin Cross36242852017-06-23 15:06:31 -0700724func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
725 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700726
727 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800728 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700729 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700730 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700731 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800732
Colin Cross34037c62020-11-17 13:19:17 -0800733 if hod&hostSupported != 0 && hod&deviceSupported != 0 {
Colin Cross36242852017-06-23 15:06:31 -0700734 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800735 }
736
Colin Crossa6845402020-11-16 15:08:19 -0800737 initArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800738}
739
Colin Crossa6845402020-11-16 15:08:19 -0800740// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is
741// architecture-specific, but will only have a single variant per OS that handles all the
742// architectures simultaneously. The list of Targets that it must handle will be available from
743// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as
744// well as runtime generated property structs for architecture-specific versions of generic
745// properties tagged with `android:"arch_variant"`.
746//
747// InitAndroidModule or InitAndroidArchModule should not be called if
748// InitAndroidMultiTargetsArchModule was called.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700749func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
750 InitAndroidArchModule(m, hod, defaultMultilib)
751 m.base().commonProperties.UseTargetVariants = false
752}
753
Colin Crossa6845402020-11-16 15:08:19 -0800754// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is
755// architecture-specific, but will only have a single variant per OS that handles all the
756// architectures simultaneously, and will also have an additional CommonOS variant that has
757// dependencies on all the OS-specific variants. The list of Targets that it must handle will be
758// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and
759// "enabled", as well as runtime generated property structs for architecture-specific versions of
760// generic properties tagged with `android:"arch_variant"`.
761//
762// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be
763// called if InitCommonOSAndroidMultiTargetsArchModule was called.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000764func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
765 InitAndroidArchModule(m, hod, defaultMultilib)
766 m.base().commonProperties.UseTargetVariants = false
767 m.base().commonProperties.CreateCommonOSVariant = true
768}
769
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800770// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800771// modules. It should be included as an anonymous field in every module
772// struct definition. InitAndroidModule should then be called from the module's
773// factory function, and the return values from InitAndroidModule should be
774// returned from the factory function.
775//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800776// The ModuleBase type is responsible for implementing the GenerateBuildActions
777// method to support the blueprint.Module interface. This method will then call
778// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700779// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
780// rather than the usual blueprint.ModuleContext.
781// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800782// system including details about the particular build variant that is to be
783// generated.
784//
785// For example:
786//
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800787// import (
788// "android/soong/android"
789// )
Colin Cross3f40fa42015-01-30 17:27:36 -0800790//
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800791// type myModule struct {
792// android.ModuleBase
793// properties struct {
794// MyProperty string
795// }
796// }
Colin Cross3f40fa42015-01-30 17:27:36 -0800797//
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800798// func NewMyModule() android.Module {
799// m := &myModule{}
800// m.AddProperties(&m.properties)
801// android.InitAndroidModule(m)
802// return m
803// }
Colin Cross3f40fa42015-01-30 17:27:36 -0800804//
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800805// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
806// // Get the CPU architecture for the current build variant.
807// variantArch := ctx.Arch()
Colin Cross3f40fa42015-01-30 17:27:36 -0800808//
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800809// // ...
810// }
Colin Cross635c3b02016-05-18 15:37:25 -0700811type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800812 // Putting the curiously recurring thing pointing to the thing that contains
813 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700814 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700815 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800816
Colin Crossfc754582016-05-17 16:34:16 -0700817 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800818 commonProperties commonProperties
Paul Duffined875132020-09-02 13:08:57 +0100819 distProperties distProperties
Colin Cross18c46802019-09-24 22:19:02 -0700820 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800821 hostAndDeviceProperties hostAndDeviceProperties
Jingwen Chen5d864492021-02-24 07:20:12 -0500822
Usta851a3272022-01-05 23:42:33 -0500823 // Arch specific versions of structs in GetProperties() prior to
824 // initialization in InitAndroidArchModule, lets call it `generalProperties`.
825 // The outer index has the same order as generalProperties and the inner index
826 // chooses the props specific to the architecture. The interface{} value is an
827 // archPropRoot that is filled with arch specific values by the arch mutator.
Jingwen Chen5d864492021-02-24 07:20:12 -0500828 archProperties [][]interface{}
829
Jingwen Chen73850672020-12-14 08:25:34 -0500830 // Properties specific to the Blueprint to BUILD migration.
831 bazelTargetModuleProperties bazel.BazelTargetModuleProperties
832
Paul Duffin63c6e182019-07-24 14:24:38 +0100833 // Information about all the properties on the module that contains visibility rules that need
834 // checking.
835 visibilityPropertyInfo []visibilityProperty
836
837 // The primary visibility property, may be nil, that controls access to the module.
838 primaryVisibilityProperty visibilityProperty
839
Bob Badour37af0462021-01-07 03:34:31 +0000840 // The primary licenses property, may be nil, records license metadata for the module.
841 primaryLicensesProperty applicableLicensesProperty
842
Colin Crossffe6b9d2020-12-01 15:40:06 -0800843 noAddressSanitizer bool
844 installFiles InstallPaths
Colin Crossc85750b2022-04-21 12:50:51 -0700845 installFilesDepSet *DepSet[InstallPath]
Colin Crossffe6b9d2020-12-01 15:40:06 -0800846 checkbuildFiles Paths
847 packagingSpecs []PackagingSpec
Colin Crossc85750b2022-04-21 12:50:51 -0700848 packagingSpecsDepSet *DepSet[PackagingSpec]
Colin Cross6301c3c2021-09-28 17:40:21 -0700849 // katiInstalls tracks the install rules that were created by Soong but are being exported
850 // to Make to convert to ninja rules so that Make can add additional dependencies.
851 katiInstalls katiInstalls
Colin Crossd9bbf4b2023-11-17 16:23:48 -0800852 // katiInitRcInstalls and katiVintfInstalls track the install rules created by Soong that are
853 // allowed to have duplicates across modules and variants.
854 katiInitRcInstalls katiInstalls
855 katiVintfInstalls katiInstalls
856 katiSymlinks katiInstalls
857 testData []DataPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700858
Paul Duffinaf970a22020-11-23 23:32:56 +0000859 // The files to copy to the dist as explicitly specified in the .bp file.
860 distFiles TaggedDistFiles
861
Colin Cross1f8c52b2015-06-16 16:38:17 -0700862 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
863 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800864 installTarget WritablePath
865 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700866 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700867
Colin Cross178a5092016-09-13 13:42:32 -0700868 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700869
870 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700871
872 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700873 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800874 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800875 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700876
Inseob Kim8471cda2019-11-15 09:59:12 +0900877 initRcPaths Paths
878 vintfFragmentsPaths Paths
Colin Cross4acaea92021-12-10 23:05:02 +0000879
Colin Crossd9bbf4b2023-11-17 16:23:48 -0800880 installedInitRcPaths InstallPaths
881 installedVintfFragmentsPaths InstallPaths
882
Colin Cross4acaea92021-12-10 23:05:02 +0000883 // set of dependency module:location mappings used to populate the license metadata for
884 // apex containers.
885 licenseInstallMap []string
Colin Crossaa1cab02022-01-28 14:49:24 -0800886
887 // The path to the generated license metadata file for the module.
888 licenseMetadataFile WritablePath
Colin Crossd6fd0132023-11-06 13:54:06 -0800889
890 // moduleInfoJSON can be filled out by GenerateAndroidBuildActions to write a JSON file that will
891 // be included in the final module-info.json produced by Make.
892 moduleInfoJSON *ModuleInfoJSON
Colin Cross36242852017-06-23 15:06:31 -0700893}
894
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +0200895func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
Liz Kammer9525e712022-01-05 13:46:24 -0500896 (*d)["Android"] = map[string]interface{}{
897 // Properties set in Blueprint or in blueprint of a defaults modules
898 "SetProperties": m.propertiesWithValues(),
899 }
900}
901
902type propInfo struct {
Liz Kammer898e0762022-03-22 11:27:26 -0400903 Name string
904 Type string
905 Value string
906 Values []string
Liz Kammer9525e712022-01-05 13:46:24 -0500907}
908
909func (m *ModuleBase) propertiesWithValues() []propInfo {
910 var info []propInfo
911 props := m.GetProperties()
912
913 var propsWithValues func(name string, v reflect.Value)
914 propsWithValues = func(name string, v reflect.Value) {
915 kind := v.Kind()
916 switch kind {
917 case reflect.Ptr, reflect.Interface:
918 if v.IsNil() {
919 return
920 }
921 propsWithValues(name, v.Elem())
922 case reflect.Struct:
923 if v.IsZero() {
924 return
925 }
926 for i := 0; i < v.NumField(); i++ {
927 namePrefix := name
928 sTyp := v.Type().Field(i)
929 if proptools.ShouldSkipProperty(sTyp) {
930 continue
931 }
932 if name != "" && !strings.HasSuffix(namePrefix, ".") {
933 namePrefix += "."
934 }
935 if !proptools.IsEmbedded(sTyp) {
936 namePrefix += sTyp.Name
937 }
938 sVal := v.Field(i)
939 propsWithValues(namePrefix, sVal)
940 }
941 case reflect.Array, reflect.Slice:
942 if v.IsNil() {
943 return
944 }
945 elKind := v.Type().Elem().Kind()
Liz Kammer898e0762022-03-22 11:27:26 -0400946 info = append(info, propInfo{Name: name, Type: elKind.String() + " " + kind.String(), Values: sliceReflectionValue(v)})
Liz Kammer9525e712022-01-05 13:46:24 -0500947 default:
Liz Kammer898e0762022-03-22 11:27:26 -0400948 info = append(info, propInfo{Name: name, Type: kind.String(), Value: reflectionValue(v)})
Liz Kammer9525e712022-01-05 13:46:24 -0500949 }
950 }
951
952 for _, p := range props {
953 propsWithValues("", reflect.ValueOf(p).Elem())
954 }
Liz Kammer898e0762022-03-22 11:27:26 -0400955 sort.Slice(info, func(i, j int) bool {
956 return info[i].Name < info[j].Name
957 })
Liz Kammer9525e712022-01-05 13:46:24 -0500958 return info
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +0200959}
960
Liz Kammer898e0762022-03-22 11:27:26 -0400961func reflectionValue(value reflect.Value) string {
962 switch value.Kind() {
963 case reflect.Bool:
964 return fmt.Sprintf("%t", value.Bool())
965 case reflect.Int64:
966 return fmt.Sprintf("%d", value.Int())
967 case reflect.String:
968 return fmt.Sprintf("%s", value.String())
969 case reflect.Struct:
970 if value.IsZero() {
971 return "{}"
972 }
973 length := value.NumField()
974 vals := make([]string, length, length)
975 for i := 0; i < length; i++ {
976 sTyp := value.Type().Field(i)
977 if proptools.ShouldSkipProperty(sTyp) {
978 continue
979 }
980 name := sTyp.Name
981 vals[i] = fmt.Sprintf("%s: %s", name, reflectionValue(value.Field(i)))
982 }
983 return fmt.Sprintf("%s{%s}", value.Type(), strings.Join(vals, ", "))
984 case reflect.Array, reflect.Slice:
985 vals := sliceReflectionValue(value)
986 return fmt.Sprintf("[%s]", strings.Join(vals, ", "))
987 }
988 return ""
989}
990
991func sliceReflectionValue(value reflect.Value) []string {
992 length := value.Len()
993 vals := make([]string, length, length)
994 for i := 0; i < length; i++ {
995 vals[i] = reflectionValue(value.Index(i))
996 }
997 return vals
998}
999
Paul Duffin44f1d842020-06-26 20:17:02 +01001000func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
1001
Colin Cross4157e882019-06-06 16:57:04 -07001002func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -08001003
Ronald Braunstein73b08ff2023-12-19 10:24:47 -08001004func (m *ModuleBase) baseDepsMutator(ctx BottomUpMutatorContext) {
1005 if m.Team() != "" {
1006 ctx.AddDependency(ctx.Module(), teamDepTag, m.Team())
1007 }
1008}
1009
Usta355a5872021-12-01 15:16:32 -05001010// AddProperties "registers" the provided props
1011// each value in props MUST be a pointer to a struct
Colin Cross4157e882019-06-06 16:57:04 -07001012func (m *ModuleBase) AddProperties(props ...interface{}) {
1013 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -07001014}
1015
Colin Cross4157e882019-06-06 16:57:04 -07001016func (m *ModuleBase) GetProperties() []interface{} {
1017 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -08001018}
1019
Colin Cross4157e882019-06-06 16:57:04 -07001020func (m *ModuleBase) BuildParamsForTests() []BuildParams {
Chih-Hung Hsiehb8082292021-09-09 23:20:39 -07001021 // Expand the references to module variables like $flags[0-9]*,
1022 // so we do not need to change many existing unit tests.
1023 // This looks like undoing the shareFlags optimization in cc's
1024 // transformSourceToObj, and should only affects unit tests.
1025 vars := m.VariablesForTests()
1026 buildParams := append([]BuildParams(nil), m.buildParams...)
Sasha Smundake198eaf2022-08-04 13:07:02 -07001027 for i := range buildParams {
Chih-Hung Hsiehb8082292021-09-09 23:20:39 -07001028 newArgs := make(map[string]string)
1029 for k, v := range buildParams[i].Args {
1030 newArgs[k] = v
1031 // Replaces both ${flags1} and $flags1 syntax.
1032 if strings.HasPrefix(v, "${") && strings.HasSuffix(v, "}") {
1033 if value, found := vars[v[2:len(v)-1]]; found {
1034 newArgs[k] = value
1035 }
1036 } else if strings.HasPrefix(v, "$") {
1037 if value, found := vars[v[1:]]; found {
1038 newArgs[k] = value
1039 }
1040 }
1041 }
1042 buildParams[i].Args = newArgs
1043 }
1044 return buildParams
Colin Crosscec81712017-07-13 14:43:27 -07001045}
1046
Colin Cross4157e882019-06-06 16:57:04 -07001047func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
1048 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001049}
1050
Colin Cross4157e882019-06-06 16:57:04 -07001051func (m *ModuleBase) VariablesForTests() map[string]string {
1052 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001053}
1054
Colin Crossce75d2c2016-10-06 16:12:58 -07001055// Name returns the name of the module. It may be overridden by individual module types, for
1056// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -07001057func (m *ModuleBase) Name() string {
1058 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -07001059}
1060
Colin Cross9a362232019-07-01 15:32:45 -07001061// String returns a string that includes the module name and variants for printing during debugging.
1062func (m *ModuleBase) String() string {
1063 sb := strings.Builder{}
1064 sb.WriteString(m.commonProperties.DebugName)
1065 sb.WriteString("{")
1066 for i := range m.commonProperties.DebugMutators {
1067 if i != 0 {
1068 sb.WriteString(",")
1069 }
1070 sb.WriteString(m.commonProperties.DebugMutators[i])
1071 sb.WriteString(":")
1072 sb.WriteString(m.commonProperties.DebugVariations[i])
1073 }
1074 sb.WriteString("}")
1075 return sb.String()
1076}
1077
Colin Crossce75d2c2016-10-06 16:12:58 -07001078// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -07001079func (m *ModuleBase) BaseModuleName() string {
1080 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -07001081}
1082
Colin Cross4157e882019-06-06 16:57:04 -07001083func (m *ModuleBase) base() *ModuleBase {
1084 return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001085}
1086
Paul Duffine2453c72019-05-31 14:00:04 +01001087func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
1088 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
1089}
1090
1091func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +01001092 return m.visibilityPropertyInfo
1093}
1094
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001095func (m *ModuleBase) Dists() []Dist {
Paul Duffined875132020-09-02 13:08:57 +01001096 if len(m.distProperties.Dist.Targets) > 0 {
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001097 // Make a copy of the underlying Dists slice to protect against
1098 // backing array modifications with repeated calls to this method.
Paul Duffined875132020-09-02 13:08:57 +01001099 distsCopy := append([]Dist(nil), m.distProperties.Dists...)
1100 return append(distsCopy, m.distProperties.Dist)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001101 } else {
Paul Duffined875132020-09-02 13:08:57 +01001102 return m.distProperties.Dists
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001103 }
1104}
1105
1106func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
Paul Duffin74f05592020-11-25 16:37:46 +00001107 var distFiles TaggedDistFiles
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001108 for _, dist := range m.Dists() {
Paul Duffin74f05592020-11-25 16:37:46 +00001109 // If no tag is specified then it means to use the default dist paths so use
1110 // the special tag name which represents that.
1111 tag := proptools.StringDefault(dist.Tag, DefaultDistTag)
1112
Paul Duffinaf970a22020-11-23 23:32:56 +00001113 if outputFileProducer, ok := m.module.(OutputFileProducer); ok {
1114 // Call the OutputFiles(tag) method to get the paths associated with the tag.
1115 distFilesForTag, err := outputFileProducer.OutputFiles(tag)
Paul Duffin74f05592020-11-25 16:37:46 +00001116
Paul Duffinaf970a22020-11-23 23:32:56 +00001117 // If the tag was not supported and is not DefaultDistTag then it is an error.
1118 // Failing to find paths for DefaultDistTag is not an error. It just means
1119 // that the module type requires the legacy behavior.
1120 if err != nil && tag != DefaultDistTag {
1121 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1122 }
1123
1124 distFiles = distFiles.addPathsForTag(tag, distFilesForTag...)
1125 } else if tag != DefaultDistTag {
1126 // If the tag was specified then it is an error if the module does not
1127 // implement OutputFileProducer because there is no other way of accessing
1128 // the paths for the specified tag.
1129 ctx.PropertyErrorf("dist.tag",
1130 "tag %s not supported because the module does not implement OutputFileProducer", tag)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001131 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001132 }
1133
1134 return distFiles
1135}
1136
Colin Cross4157e882019-06-06 16:57:04 -07001137func (m *ModuleBase) Target() Target {
1138 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -08001139}
1140
Colin Cross4157e882019-06-06 16:57:04 -07001141func (m *ModuleBase) TargetPrimary() bool {
1142 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001143}
1144
Colin Cross4157e882019-06-06 16:57:04 -07001145func (m *ModuleBase) MultiTargets() []Target {
1146 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001147}
1148
Colin Cross4157e882019-06-06 16:57:04 -07001149func (m *ModuleBase) Os() OsType {
1150 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001151}
1152
Colin Cross4157e882019-06-06 16:57:04 -07001153func (m *ModuleBase) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09001154 return m.Os().Class == Host
Dan Willemsen97750522016-02-09 17:43:51 -08001155}
1156
Yo Chiangbba545e2020-06-09 16:15:37 +08001157func (m *ModuleBase) Device() bool {
1158 return m.Os().Class == Device
1159}
1160
Colin Cross4157e882019-06-06 16:57:04 -07001161func (m *ModuleBase) Arch() Arch {
1162 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -08001163}
1164
Colin Cross4157e882019-06-06 16:57:04 -07001165func (m *ModuleBase) ArchSpecific() bool {
1166 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -07001167}
1168
Paul Duffin1356d8c2020-02-25 19:26:33 +00001169// True if the current variant is a CommonOS variant, false otherwise.
1170func (m *ModuleBase) IsCommonOSVariant() bool {
1171 return m.commonProperties.CommonOSVariant
1172}
1173
Colin Cross34037c62020-11-17 13:19:17 -08001174// supportsTarget returns true if the given Target is supported by the current module.
1175func (m *ModuleBase) supportsTarget(target Target) bool {
1176 switch target.Os.Class {
1177 case Host:
1178 if target.HostCross {
1179 return m.HostCrossSupported()
1180 } else {
1181 return m.HostSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001182 }
Colin Cross34037c62020-11-17 13:19:17 -08001183 case Device:
1184 return m.DeviceSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001185 default:
Jiyong Park1613e552020-09-14 19:43:17 +09001186 return false
Colin Crossa1ad8d12016-06-01 17:09:44 -07001187 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001188}
1189
Colin Cross34037c62020-11-17 13:19:17 -08001190// DeviceSupported returns true if the current module is supported and enabled for device targets,
1191// i.e. the factory method set the HostOrDeviceSupported value to include device support and
1192// the device support is enabled by default or enabled by the device_supported property.
Colin Cross4157e882019-06-06 16:57:04 -07001193func (m *ModuleBase) DeviceSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001194 hod := m.commonProperties.HostOrDeviceSupported
1195 // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
1196 // value has the deviceDefault bit set.
1197 deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
1198 return hod&deviceSupported != 0 && deviceEnabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001199}
1200
Colin Cross34037c62020-11-17 13:19:17 -08001201// HostSupported returns true if the current module is supported and enabled for host targets,
1202// i.e. the factory method set the HostOrDeviceSupported value to include host support and
1203// the host support is enabled by default or enabled by the host_supported property.
Paul Duffine44358f2019-11-26 18:04:12 +00001204func (m *ModuleBase) HostSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001205 hod := m.commonProperties.HostOrDeviceSupported
1206 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1207 // value has the hostDefault bit set.
1208 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1209 return hod&hostSupported != 0 && hostEnabled
1210}
1211
1212// HostCrossSupported returns true if the current module is supported and enabled for host cross
1213// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
1214// support and the host cross support is enabled by default or enabled by the
1215// host_supported property.
1216func (m *ModuleBase) HostCrossSupported() bool {
1217 hod := m.commonProperties.HostOrDeviceSupported
1218 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1219 // value has the hostDefault bit set.
1220 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1221 return hod&hostCrossSupported != 0 && hostEnabled
Paul Duffine44358f2019-11-26 18:04:12 +00001222}
1223
Colin Cross4157e882019-06-06 16:57:04 -07001224func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +09001225 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +09001226}
1227
Colin Cross4157e882019-06-06 16:57:04 -07001228func (m *ModuleBase) DeviceSpecific() bool {
1229 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001230}
1231
Colin Cross4157e882019-06-06 16:57:04 -07001232func (m *ModuleBase) SocSpecific() bool {
1233 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001234}
1235
Colin Cross4157e882019-06-06 16:57:04 -07001236func (m *ModuleBase) ProductSpecific() bool {
1237 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001238}
1239
Justin Yund5f6c822019-06-25 16:47:17 +09001240func (m *ModuleBase) SystemExtSpecific() bool {
1241 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +01001242}
1243
Colin Crossc2d24052020-05-13 11:05:02 -07001244// RequiresStableAPIs returns true if the module will be installed to a partition that may
1245// be updated separately from the system image.
1246func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
1247 return m.SocSpecific() || m.DeviceSpecific() ||
1248 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
1249}
1250
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001251func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
1252 partition := "system"
1253 if m.SocSpecific() {
1254 // A SoC-specific module could be on the vendor partition at
1255 // "vendor" or the system partition at "system/vendor".
1256 if config.VendorPath() == "vendor" {
1257 partition = "vendor"
1258 }
1259 } else if m.DeviceSpecific() {
1260 // A device-specific module could be on the odm partition at
1261 // "odm", the vendor partition at "vendor/odm", or the system
1262 // partition at "system/vendor/odm".
1263 if config.OdmPath() == "odm" {
1264 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001265 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001266 partition = "vendor"
1267 }
1268 } else if m.ProductSpecific() {
1269 // A product-specific module could be on the product partition
1270 // at "product" or the system partition at "system/product".
1271 if config.ProductPath() == "product" {
1272 partition = "product"
1273 }
1274 } else if m.SystemExtSpecific() {
1275 // A system_ext-specific module could be on the system_ext
1276 // partition at "system_ext" or the system partition at
1277 // "system/system_ext".
1278 if config.SystemExtPath() == "system_ext" {
1279 partition = "system_ext"
1280 }
1281 }
1282 return partition
1283}
1284
Colin Cross4157e882019-06-06 16:57:04 -07001285func (m *ModuleBase) Enabled() bool {
Justin Yun32f053b2020-07-31 23:07:17 +09001286 if m.commonProperties.ForcedDisabled {
1287 return false
1288 }
Colin Cross08d6f8f2020-11-19 02:33:19 +00001289 if m.commonProperties.Enabled == nil {
1290 return !m.Os().DefaultDisabled
1291 }
1292 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001293}
1294
Inseob Kimeec88e12020-01-22 11:11:29 +09001295func (m *ModuleBase) Disable() {
Justin Yun32f053b2020-07-31 23:07:17 +09001296 m.commonProperties.ForcedDisabled = true
Inseob Kimeec88e12020-01-22 11:11:29 +09001297}
1298
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001299// HideFromMake marks this variant so that it is not emitted in the generated Android.mk file.
1300func (m *ModuleBase) HideFromMake() {
1301 m.commonProperties.HideFromMake = true
1302}
1303
1304// IsHideFromMake returns true if HideFromMake was previously called.
1305func (m *ModuleBase) IsHideFromMake() bool {
1306 return m.commonProperties.HideFromMake == true
1307}
1308
1309// SkipInstall marks this variant to not create install rules when ctx.Install* are called.
Colin Cross4157e882019-06-06 16:57:04 -07001310func (m *ModuleBase) SkipInstall() {
1311 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001312}
1313
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +00001314// IsSkipInstall returns true if this variant is marked to not create install
1315// rules when ctx.Install* are called.
1316func (m *ModuleBase) IsSkipInstall() bool {
1317 return m.commonProperties.SkipInstall
1318}
1319
Iván Budnik295da162023-03-10 16:11:26 +00001320// Similar to HideFromMake, but if the AndroidMk entry would set
1321// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
1322// rather than leaving it out altogether. That happens in cases where it would
1323// have other side effects, in particular when it adds a NOTICE file target,
1324// which other install targets might depend on.
1325func (m *ModuleBase) MakeUninstallable() {
Colin Crossbd3a16b2023-04-25 11:30:51 -07001326 m.commonProperties.UninstallableApexPlatformVariant = true
Iván Budnik295da162023-03-10 16:11:26 +00001327 m.HideFromMake()
1328}
1329
Liz Kammer5ca3a622020-08-05 15:40:41 -07001330func (m *ModuleBase) ReplacedByPrebuilt() {
1331 m.commonProperties.ReplacedByPrebuilt = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001332 m.HideFromMake()
Liz Kammer5ca3a622020-08-05 15:40:41 -07001333}
1334
1335func (m *ModuleBase) IsReplacedByPrebuilt() bool {
1336 return m.commonProperties.ReplacedByPrebuilt
1337}
1338
Colin Cross4157e882019-06-06 16:57:04 -07001339func (m *ModuleBase) ExportedToMake() bool {
1340 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001341}
1342
Justin Yun1871f902023-04-07 20:13:19 +09001343func (m *ModuleBase) EffectiveLicenseKinds() []string {
1344 return m.commonProperties.Effective_license_kinds
1345}
1346
Justin Yun885a7de2021-06-29 20:34:53 +09001347func (m *ModuleBase) EffectiveLicenseFiles() Paths {
Bob Badour4101c712022-02-09 11:54:35 -08001348 result := make(Paths, 0, len(m.commonProperties.Effective_license_text))
1349 for _, p := range m.commonProperties.Effective_license_text {
1350 result = append(result, p.Path)
1351 }
1352 return result
Justin Yun885a7de2021-06-29 20:34:53 +09001353}
1354
Colin Crosse9fe2942020-11-10 18:12:15 -08001355// computeInstallDeps finds the installed paths of all dependencies that have a dependency
Colin Crossbd3a16b2023-04-25 11:30:51 -07001356// tag that is annotated as needing installation via the isInstallDepNeeded method.
Colin Crossc85750b2022-04-21 12:50:51 -07001357func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*DepSet[InstallPath], []*DepSet[PackagingSpec]) {
1358 var installDeps []*DepSet[InstallPath]
1359 var packagingSpecs []*DepSet[PackagingSpec]
Colin Cross5d583952020-11-24 16:21:24 -08001360 ctx.VisitDirectDeps(func(dep Module) {
Colin Crossbd3a16b2023-04-25 11:30:51 -07001361 if isInstallDepNeeded(dep, ctx.OtherModuleDependencyTag(dep)) {
1362 // Installation is still handled by Make, so anything hidden from Make is not
1363 // installable.
1364 if !dep.IsHideFromMake() && !dep.IsSkipInstall() {
1365 installDeps = append(installDeps, dep.base().installFilesDepSet)
1366 }
1367 // Add packaging deps even when the dependency is not installed so that uninstallable
1368 // modules can still be packaged. Often the package will be installed instead.
Colin Crossffe6b9d2020-12-01 15:40:06 -08001369 packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet)
Colin Cross897266e2020-02-13 13:22:08 -08001370 }
1371 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001372
Colin Crossffe6b9d2020-12-01 15:40:06 -08001373 return installDeps, packagingSpecs
Colin Cross3f40fa42015-01-30 17:27:36 -08001374}
1375
Colin Crossbd3a16b2023-04-25 11:30:51 -07001376// isInstallDepNeeded returns true if installing the output files of the current module
1377// should also install the output files of the given dependency and dependency tag.
1378func isInstallDepNeeded(dep Module, tag blueprint.DependencyTag) bool {
1379 // Don't add a dependency from the platform to a library provided by an apex.
1380 if dep.base().commonProperties.UninstallableApexPlatformVariant {
1381 return false
1382 }
1383 // Only install modules if the dependency tag is an InstallDepNeeded tag.
1384 return IsInstallDepNeededTag(tag)
1385}
1386
Jiyong Park4dc2a1a2020-09-28 17:46:22 +09001387func (m *ModuleBase) FilesToInstall() InstallPaths {
Colin Cross4157e882019-06-06 16:57:04 -07001388 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001389}
1390
Jiyong Park073ea552020-11-09 14:08:34 +09001391func (m *ModuleBase) PackagingSpecs() []PackagingSpec {
1392 return m.packagingSpecs
1393}
1394
Colin Crossffe6b9d2020-12-01 15:40:06 -08001395func (m *ModuleBase) TransitivePackagingSpecs() []PackagingSpec {
1396 return m.packagingSpecsDepSet.ToList()
1397}
1398
Colin Cross4157e882019-06-06 16:57:04 -07001399func (m *ModuleBase) NoAddressSanitizer() bool {
1400 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -08001401}
1402
Colin Cross4157e882019-06-06 16:57:04 -07001403func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -08001404 return false
1405}
1406
Jaewoong Jung0949f312019-09-11 10:25:18 -07001407func (m *ModuleBase) InstallInTestcases() bool {
1408 return false
1409}
1410
Colin Cross4157e882019-06-06 16:57:04 -07001411func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001412 return false
1413}
1414
Yifan Hong1b3348d2020-01-21 15:53:22 -08001415func (m *ModuleBase) InstallInRamdisk() bool {
1416 return Bool(m.commonProperties.Ramdisk)
1417}
1418
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001419func (m *ModuleBase) InstallInVendorRamdisk() bool {
1420 return Bool(m.commonProperties.Vendor_ramdisk)
1421}
1422
Inseob Kim08758f02021-04-08 21:13:22 +09001423func (m *ModuleBase) InstallInDebugRamdisk() bool {
1424 return Bool(m.commonProperties.Debug_ramdisk)
1425}
1426
Colin Cross4157e882019-06-06 16:57:04 -07001427func (m *ModuleBase) InstallInRecovery() bool {
1428 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +09001429}
1430
Colin Crossea30d852023-11-29 16:00:16 -08001431func (m *ModuleBase) InstallInOdm() bool {
1432 return false
1433}
1434
1435func (m *ModuleBase) InstallInProduct() bool {
1436 return false
1437}
1438
Kiyoung Kimae11c232021-07-19 11:38:04 +09001439func (m *ModuleBase) InstallInVendor() bool {
Kiyoung Kimf160f7f2022-11-29 10:58:08 +09001440 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Soc_specific) || Bool(m.commonProperties.Proprietary)
Kiyoung Kimae11c232021-07-19 11:38:04 +09001441}
1442
Colin Cross90ba5f42019-10-02 11:10:58 -07001443func (m *ModuleBase) InstallInRoot() bool {
1444 return false
1445}
1446
Jiyong Park87788b52020-09-01 12:37:45 +09001447func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) {
1448 return nil, nil
Colin Cross6e359402020-02-10 15:29:54 -08001449}
1450
Colin Cross4157e882019-06-06 16:57:04 -07001451func (m *ModuleBase) Owner() string {
1452 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +09001453}
1454
Ronald Braunstein73b08ff2023-12-19 10:24:47 -08001455func (m *ModuleBase) Team() string {
1456 return String(m.commonProperties.Team)
1457}
1458
Colin Cross7228ecd2019-11-18 16:00:16 -08001459func (m *ModuleBase) setImageVariation(variant string) {
1460 m.commonProperties.ImageVariation = variant
1461}
1462
1463func (m *ModuleBase) ImageVariation() blueprint.Variation {
1464 return blueprint.Variation{
1465 Mutator: "image",
1466 Variation: m.base().commonProperties.ImageVariation,
1467 }
1468}
1469
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001470func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
1471 for i, v := range m.commonProperties.DebugMutators {
1472 if v == mutator {
1473 return m.commonProperties.DebugVariations[i]
1474 }
1475 }
1476
1477 return ""
1478}
1479
Yifan Hong1b3348d2020-01-21 15:53:22 -08001480func (m *ModuleBase) InRamdisk() bool {
1481 return m.base().commonProperties.ImageVariation == RamdiskVariation
1482}
1483
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001484func (m *ModuleBase) InVendorRamdisk() bool {
1485 return m.base().commonProperties.ImageVariation == VendorRamdiskVariation
1486}
1487
Inseob Kim08758f02021-04-08 21:13:22 +09001488func (m *ModuleBase) InDebugRamdisk() bool {
1489 return m.base().commonProperties.ImageVariation == DebugRamdiskVariation
1490}
1491
Colin Cross7228ecd2019-11-18 16:00:16 -08001492func (m *ModuleBase) InRecovery() bool {
1493 return m.base().commonProperties.ImageVariation == RecoveryVariation
1494}
1495
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001496func (m *ModuleBase) RequiredModuleNames() []string {
1497 return m.base().commonProperties.Required
1498}
1499
1500func (m *ModuleBase) HostRequiredModuleNames() []string {
1501 return m.base().commonProperties.Host_required
1502}
1503
1504func (m *ModuleBase) TargetRequiredModuleNames() []string {
1505 return m.base().commonProperties.Target_required
1506}
1507
Inseob Kim8471cda2019-11-15 09:59:12 +09001508func (m *ModuleBase) InitRc() Paths {
1509 return append(Paths{}, m.initRcPaths...)
1510}
1511
1512func (m *ModuleBase) VintfFragments() Paths {
1513 return append(Paths{}, m.vintfFragmentsPaths...)
1514}
1515
Yu Liu4ae55d12022-01-05 17:17:23 -08001516func (m *ModuleBase) CompileMultilib() *string {
1517 return m.base().commonProperties.Compile_multilib
1518}
1519
Colin Cross4acaea92021-12-10 23:05:02 +00001520// SetLicenseInstallMap stores the set of dependency module:location mappings for files in an
1521// apex container for use when generation the license metadata file.
1522func (m *ModuleBase) SetLicenseInstallMap(installMap []string) {
1523 m.licenseInstallMap = append(m.licenseInstallMap, installMap...)
1524}
1525
Colin Cross4157e882019-06-06 16:57:04 -07001526func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Colin Cross897266e2020-02-13 13:22:08 -08001527 var allInstalledFiles InstallPaths
1528 var allCheckbuildFiles Paths
Colin Cross0875c522017-11-28 17:34:01 -08001529 ctx.VisitAllModuleVariants(func(module Module) {
1530 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001531 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
Chih-Hung Hsieh80783772021-10-11 16:46:56 -07001532 // A module's -checkbuild phony targets should
Chih-Hung Hsieha3d135b2021-10-14 20:32:53 -07001533 // not be created if the module is not exported to make.
1534 // Those could depend on the build target and fail to compile
1535 // for the current build target.
1536 if !ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(a) {
1537 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Chih-Hung Hsieha3d135b2021-10-14 20:32:53 -07001538 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001539 })
1540
Colin Cross0875c522017-11-28 17:34:01 -08001541 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001542
Colin Cross133ebef2020-08-14 17:38:45 -07001543 namespacePrefix := ctx.Namespace().id
Jeff Gaston088e29e2017-11-29 16:47:17 -08001544 if namespacePrefix != "" {
1545 namespacePrefix = namespacePrefix + "-"
1546 }
1547
Colin Cross3f40fa42015-01-30 17:27:36 -08001548 if len(allInstalledFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001549 name := namespacePrefix + ctx.ModuleName() + "-install"
1550 ctx.Phony(name, allInstalledFiles.Paths()...)
1551 m.installTarget = PathForPhony(ctx, name)
1552 deps = append(deps, m.installTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001553 }
1554
1555 if len(allCheckbuildFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001556 name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
1557 ctx.Phony(name, allCheckbuildFiles...)
1558 m.checkbuildTarget = PathForPhony(ctx, name)
1559 deps = append(deps, m.checkbuildTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001560 }
1561
1562 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001563 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05001564 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001565 suffix = "-soong"
1566 }
1567
Colin Crossc3d87d32020-06-04 13:25:17 -07001568 ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001569
Colin Cross4157e882019-06-06 16:57:04 -07001570 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001571 }
1572}
1573
Colin Crossc34d2322020-01-03 15:23:27 -08001574func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001575 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1576 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1577 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001578 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001579
Dario Frenifd05a742018-05-29 13:28:54 +01001580 msg := "conflicting value set here"
1581 if socSpecific && deviceSpecific {
1582 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001583 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001584 ctx.PropertyErrorf("vendor", msg)
1585 }
Colin Cross4157e882019-06-06 16:57:04 -07001586 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001587 ctx.PropertyErrorf("proprietary", msg)
1588 }
Colin Cross4157e882019-06-06 16:57:04 -07001589 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001590 ctx.PropertyErrorf("soc_specific", msg)
1591 }
1592 }
1593
Justin Yund5f6c822019-06-25 16:47:17 +09001594 if productSpecific && systemExtSpecific {
1595 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1596 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001597 }
1598
Justin Yund5f6c822019-06-25 16:47:17 +09001599 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001600 if productSpecific {
1601 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1602 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001603 ctx.PropertyErrorf("system_ext_specific", "a module cannot be specific to SoC or device and system_ext at the same time.")
Dario Frenifd05a742018-05-29 13:28:54 +01001604 }
1605 if deviceSpecific {
1606 ctx.PropertyErrorf("device_specific", msg)
1607 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001608 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001609 ctx.PropertyErrorf("vendor", msg)
1610 }
Colin Cross4157e882019-06-06 16:57:04 -07001611 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001612 ctx.PropertyErrorf("proprietary", msg)
1613 }
Colin Cross4157e882019-06-06 16:57:04 -07001614 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001615 ctx.PropertyErrorf("soc_specific", msg)
1616 }
1617 }
1618 }
1619
Jiyong Park2db76922017-11-08 16:03:48 +09001620 if productSpecific {
1621 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001622 } else if systemExtSpecific {
1623 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001624 } else if deviceSpecific {
1625 return deviceSpecificModule
1626 } else if socSpecific {
1627 return socSpecificModule
1628 } else {
1629 return platformModule
1630 }
1631}
1632
Colin Crossc34d2322020-01-03 15:23:27 -08001633func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001634 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001635 EarlyModuleContext: ctx,
1636 kind: determineModuleKind(m, ctx),
1637 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001638 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001639}
1640
Colin Cross1184b642019-12-30 18:43:07 -08001641func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1642 return baseModuleContext{
1643 bp: ctx,
Colin Cross1d3d9f12024-01-18 14:30:22 -08001644 archModuleContext: m.archModuleContextFactory(ctx),
Colin Cross1184b642019-12-30 18:43:07 -08001645 earlyModuleContext: m.earlyModuleContextFactory(ctx),
Colin Cross1184b642019-12-30 18:43:07 -08001646 }
1647}
1648
Colin Cross4aa3e0a2024-01-18 17:22:58 -08001649func (m *ModuleBase) archModuleContextFactory(ctx blueprint.IncomingTransitionContext) archModuleContext {
Colin Cross1d3d9f12024-01-18 14:30:22 -08001650 config := ctx.Config().(Config)
1651 target := m.Target()
1652 primaryArch := false
1653 if len(config.Targets[target.Os]) <= 1 {
1654 primaryArch = true
1655 } else {
1656 primaryArch = target.Arch.ArchType == config.Targets[target.Os][0].Arch.ArchType
1657 }
1658
1659 return archModuleContext{
1660 os: m.commonProperties.CompileOS,
1661 target: m.commonProperties.CompileTarget,
1662 targetPrimary: m.commonProperties.CompilePrimary,
1663 multiTargets: m.commonProperties.CompileMultiTargets,
1664 primaryArch: primaryArch,
1665 }
1666
1667}
1668
Colin Cross4157e882019-06-06 16:57:04 -07001669func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001670 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001671 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001672 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001673 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
Colin Cross0ea8ba82019-06-06 14:33:29 -07001674 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001675 }
1676
Colin Crossaa1cab02022-01-28 14:49:24 -08001677 m.licenseMetadataFile = PathForModuleOut(ctx, "meta_lic")
1678
Colin Crossffe6b9d2020-12-01 15:40:06 -08001679 dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx)
Colin Cross5d583952020-11-24 16:21:24 -08001680 // set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
1681 // of installed files of this module. It will be replaced by a depset including the installed
1682 // files of this module at the end for use by modules that depend on this one.
Colin Crossc85750b2022-04-21 12:50:51 -07001683 m.installFilesDepSet = NewDepSet[InstallPath](TOPOLOGICAL, nil, dependencyInstallFiles)
Colin Cross5d583952020-11-24 16:21:24 -08001684
Colin Cross6c4f21f2019-06-06 15:41:36 -07001685 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1686 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1687 // TODO: This will be removed once defaults modules handle missing dependency errors
1688 blueprintCtx.GetMissingDependencies()
1689
Colin Crossdc35e212019-06-06 16:13:11 -07001690 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffin1356d8c2020-02-25 19:26:33 +00001691 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1692 // (because the dependencies are added before the modules are disabled). The
1693 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1694 // ignored.
1695 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001696
Colin Cross4c83e5c2019-02-25 14:54:28 -08001697 if ctx.config.captureBuild {
1698 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1699 }
1700
Colin Cross67a5c132017-05-09 13:45:28 -07001701 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1702 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001703 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1704 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001705 }
Colin Cross0875c522017-11-28 17:34:01 -08001706 if !ctx.PrimaryArch() {
1707 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001708 }
Colin Crossff694a82023-12-13 15:54:49 -08001709 if apexInfo, _ := ModuleProvider(ctx, ApexInfoProvider); !apexInfo.IsForPlatform() {
Colin Cross56a83212020-09-15 18:30:11 -07001710 suffix = append(suffix, apexInfo.ApexVariationName)
Dan Willemsenb13a9482020-02-14 11:25:54 -08001711 }
Colin Cross67a5c132017-05-09 13:45:28 -07001712
1713 ctx.Variable(pctx, "moduleDesc", desc)
1714
1715 s := ""
1716 if len(suffix) > 0 {
1717 s = " [" + strings.Join(suffix, " ") + "]"
1718 }
1719 ctx.Variable(pctx, "moduleDescSuffix", s)
1720
Dan Willemsen569edc52018-11-19 09:33:29 -08001721 // Some common property checks for properties that will be used later in androidmk.go
Paul Duffin89968e32020-11-23 18:17:03 +00001722 checkDistProperties(ctx, "dist", &m.distProperties.Dist)
Sasha Smundake198eaf2022-08-04 13:07:02 -07001723 for i := range m.distProperties.Dists {
Paul Duffin89968e32020-11-23 18:17:03 +00001724 checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
Dan Willemsen569edc52018-11-19 09:33:29 -08001725 }
1726
Colin Cross4157e882019-06-06 16:57:04 -07001727 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001728 // ensure all direct android.Module deps are enabled
1729 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01001730 if m, ok := bm.(Module); ok {
LaMont Jones34314b72024-01-18 18:27:35 +00001731 ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps, false)
Jooyung Hand48f3c32019-08-23 11:18:57 +09001732 }
1733 })
1734
Colin Crossd9bbf4b2023-11-17 16:23:48 -08001735 if m.Device() {
1736 // Handle any init.rc and vintf fragment files requested by the module. All files installed by this
1737 // module will automatically have a dependency on the installed init.rc or vintf fragment file.
1738 // The same init.rc or vintf fragment file may be requested by multiple modules or variants,
1739 // so instead of installing them now just compute the install path and store it for later.
1740 // The full list of all init.rc and vintf fragment install rules will be deduplicated later
1741 // so only a single rule is created for each init.rc or vintf fragment file.
1742
1743 if !m.InVendorRamdisk() {
1744 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1745 rcDir := PathForModuleInstall(ctx, "etc", "init")
1746 for _, src := range m.initRcPaths {
1747 installedInitRc := rcDir.Join(ctx, src.Base())
1748 m.katiInitRcInstalls = append(m.katiInitRcInstalls, katiInstall{
1749 from: src,
1750 to: installedInitRc,
1751 })
1752 ctx.PackageFile(rcDir, src.Base(), src)
1753 m.installedInitRcPaths = append(m.installedInitRcPaths, installedInitRc)
1754 }
1755 }
1756
1757 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
1758 vintfDir := PathForModuleInstall(ctx, "etc", "vintf", "manifest")
1759 for _, src := range m.vintfFragmentsPaths {
1760 installedVintfFragment := vintfDir.Join(ctx, src.Base())
1761 m.katiVintfInstalls = append(m.katiVintfInstalls, katiInstall{
1762 from: src,
1763 to: installedVintfFragment,
1764 })
1765 ctx.PackageFile(vintfDir, src.Base(), src)
1766 m.installedVintfFragmentsPaths = append(m.installedVintfFragmentsPaths, installedVintfFragment)
1767 }
1768 }
1769
Bob Badour37af0462021-01-07 03:34:31 +00001770 licensesPropertyFlattener(ctx)
1771 if ctx.Failed() {
1772 return
1773 }
1774
Colin Crossb63d7b32023-12-07 16:54:51 -08001775 m.module.GenerateAndroidBuildActions(ctx)
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001776 if ctx.Failed() {
1777 return
1778 }
1779
LaMont Jonesb5099382024-01-10 23:42:36 +00001780 aconfigUpdateAndroidBuildActions(ctx)
1781 if ctx.Failed() {
1782 return
1783 }
1784
Paul Duffinaf970a22020-11-23 23:32:56 +00001785 // Create the set of tagged dist files after calling GenerateAndroidBuildActions
1786 // as GenerateTaggedDistFiles() calls OutputFiles(tag) and so relies on the
1787 // output paths being set which must be done before or during
1788 // GenerateAndroidBuildActions.
1789 m.distFiles = m.GenerateTaggedDistFiles(ctx)
1790 if ctx.Failed() {
1791 return
1792 }
1793
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001794 m.installFiles = append(m.installFiles, ctx.installFiles...)
1795 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jiyong Park073ea552020-11-09 14:08:34 +09001796 m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
Colin Cross6301c3c2021-09-28 17:40:21 -07001797 m.katiInstalls = append(m.katiInstalls, ctx.katiInstalls...)
1798 m.katiSymlinks = append(m.katiSymlinks, ctx.katiSymlinks...)
Colin Cross5c1d5fb2023-11-15 12:39:40 -08001799 m.testData = append(m.testData, ctx.testData...)
Colin Crossdc35e212019-06-06 16:13:11 -07001800 } else if ctx.Config().AllowMissingDependencies() {
1801 // If the module is not enabled it will not create any build rules, nothing will call
1802 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1803 // and report them as an error even when AllowMissingDependencies = true. Call
1804 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1805 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001806 }
1807
Colin Cross4157e882019-06-06 16:57:04 -07001808 if m == ctx.FinalModule().(Module).base() {
1809 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001810 if ctx.Failed() {
1811 return
1812 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001813 }
Colin Crosscec81712017-07-13 14:43:27 -07001814
Colin Crossc85750b2022-04-21 12:50:51 -07001815 m.installFilesDepSet = NewDepSet[InstallPath](TOPOLOGICAL, m.installFiles, dependencyInstallFiles)
1816 m.packagingSpecsDepSet = NewDepSet[PackagingSpec](TOPOLOGICAL, m.packagingSpecs, dependencyPackagingSpecs)
Colin Cross5d583952020-11-24 16:21:24 -08001817
Colin Crossaa1cab02022-01-28 14:49:24 -08001818 buildLicenseMetadata(ctx, m.licenseMetadataFile)
Colin Cross4acaea92021-12-10 23:05:02 +00001819
Colin Crossd6fd0132023-11-06 13:54:06 -08001820 if m.moduleInfoJSON != nil {
1821 var installed InstallPaths
1822 installed = append(installed, m.katiInstalls.InstallPaths()...)
1823 installed = append(installed, m.katiSymlinks.InstallPaths()...)
1824 installed = append(installed, m.katiInitRcInstalls.InstallPaths()...)
1825 installed = append(installed, m.katiVintfInstalls.InstallPaths()...)
1826 installedStrings := installed.Strings()
1827
1828 var targetRequired, hostRequired []string
1829 if ctx.Host() {
1830 targetRequired = m.commonProperties.Target_required
1831 } else {
1832 hostRequired = m.commonProperties.Host_required
1833 }
1834
1835 var data []string
1836 for _, d := range m.testData {
1837 data = append(data, d.ToRelativeInstallPath())
1838 }
1839
1840 if m.moduleInfoJSON.Uninstallable {
1841 installedStrings = nil
1842 if len(m.moduleInfoJSON.CompatibilitySuites) == 1 && m.moduleInfoJSON.CompatibilitySuites[0] == "null-suite" {
1843 m.moduleInfoJSON.CompatibilitySuites = nil
1844 m.moduleInfoJSON.TestConfig = nil
1845 m.moduleInfoJSON.AutoTestConfig = nil
1846 data = nil
1847 }
1848 }
1849
1850 m.moduleInfoJSON.core = CoreModuleInfoJSON{
1851 RegisterName: m.moduleInfoRegisterName(ctx, m.moduleInfoJSON.SubName),
1852 Path: []string{ctx.ModuleDir()},
1853 Installed: installedStrings,
1854 ModuleName: m.BaseModuleName() + m.moduleInfoJSON.SubName,
1855 SupportedVariants: []string{m.moduleInfoVariant(ctx)},
1856 TargetDependencies: targetRequired,
1857 HostDependencies: hostRequired,
1858 Data: data,
1859 }
1860 SetProvider(ctx, ModuleInfoJSONProvider, m.moduleInfoJSON)
1861 }
1862
Colin Cross4157e882019-06-06 16:57:04 -07001863 m.buildParams = ctx.buildParams
1864 m.ruleParams = ctx.ruleParams
1865 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001866}
1867
Colin Crossd6fd0132023-11-06 13:54:06 -08001868func (m *ModuleBase) moduleInfoRegisterName(ctx ModuleContext, subName string) string {
1869 name := m.BaseModuleName()
1870
1871 prefix := ""
1872 if ctx.Host() {
1873 if ctx.Os() != ctx.Config().BuildOS {
1874 prefix = "host_cross_"
1875 }
1876 }
1877 suffix := ""
1878 arches := slices.Clone(ctx.Config().Targets[ctx.Os()])
1879 arches = slices.DeleteFunc(arches, func(target Target) bool {
1880 return target.NativeBridge != ctx.Target().NativeBridge
1881 })
1882 if len(arches) > 0 && ctx.Arch().ArchType != arches[0].Arch.ArchType {
1883 if ctx.Arch().ArchType.Multilib == "lib32" {
1884 suffix = "_32"
1885 } else {
1886 suffix = "_64"
1887 }
1888 }
1889 return prefix + name + subName + suffix
1890}
1891
1892func (m *ModuleBase) moduleInfoVariant(ctx ModuleContext) string {
1893 variant := "DEVICE"
1894 if ctx.Host() {
1895 if ctx.Os() != ctx.Config().BuildOS {
1896 variant = "HOST_CROSS"
1897 } else {
1898 variant = "HOST"
1899 }
1900 }
1901 return variant
1902}
1903
Paul Duffin89968e32020-11-23 18:17:03 +00001904// Check the supplied dist structure to make sure that it is valid.
1905//
1906// property - the base property, e.g. dist or dists[1], which is combined with the
1907// name of the nested property to produce the full property, e.g. dist.dest or
1908// dists[1].dir.
1909func checkDistProperties(ctx *moduleContext, property string, dist *Dist) {
1910 if dist.Dest != nil {
1911 _, err := validateSafePath(*dist.Dest)
1912 if err != nil {
1913 ctx.PropertyErrorf(property+".dest", "%s", err.Error())
1914 }
1915 }
1916 if dist.Dir != nil {
1917 _, err := validateSafePath(*dist.Dir)
1918 if err != nil {
1919 ctx.PropertyErrorf(property+".dir", "%s", err.Error())
1920 }
1921 }
1922 if dist.Suffix != nil {
1923 if strings.Contains(*dist.Suffix, "/") {
1924 ctx.PropertyErrorf(property+".suffix", "Suffix may not contain a '/' character.")
1925 }
1926 }
1927
1928}
1929
Colin Cross6301c3c2021-09-28 17:40:21 -07001930// katiInstall stores a request from Soong to Make to create an install rule.
1931type katiInstall struct {
1932 from Path
1933 to InstallPath
1934 implicitDeps Paths
1935 orderOnlyDeps Paths
1936 executable bool
Colin Cross50ed1f92021-11-12 17:41:02 -08001937 extraFiles *extraFilesZip
Colin Cross6301c3c2021-09-28 17:40:21 -07001938
1939 absFrom string
1940}
1941
Colin Cross50ed1f92021-11-12 17:41:02 -08001942type extraFilesZip struct {
1943 zip Path
1944 dir InstallPath
1945}
1946
Colin Cross6301c3c2021-09-28 17:40:21 -07001947type katiInstalls []katiInstall
1948
1949// BuiltInstalled returns the katiInstalls in the form used by $(call copy-many-files) in Make, a
1950// space separated list of from:to tuples.
1951func (installs katiInstalls) BuiltInstalled() string {
1952 sb := strings.Builder{}
1953 for i, install := range installs {
1954 if i != 0 {
1955 sb.WriteRune(' ')
1956 }
1957 sb.WriteString(install.from.String())
1958 sb.WriteRune(':')
1959 sb.WriteString(install.to.String())
1960 }
1961 return sb.String()
1962}
1963
1964// InstallPaths returns the install path of each entry.
1965func (installs katiInstalls) InstallPaths() InstallPaths {
1966 paths := make(InstallPaths, 0, len(installs))
1967 for _, install := range installs {
1968 paths = append(paths, install.to)
1969 }
1970 return paths
1971}
1972
Jiyong Park5baac542018-08-28 09:55:37 +09001973// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001974// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001975func (m *ModuleBase) MakeAsPlatform() {
1976 m.commonProperties.Vendor = boolPtr(false)
1977 m.commonProperties.Proprietary = boolPtr(false)
1978 m.commonProperties.Soc_specific = boolPtr(false)
1979 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001980 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001981}
1982
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001983func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001984 m.commonProperties.Vendor = boolPtr(false)
1985 m.commonProperties.Proprietary = boolPtr(false)
1986 m.commonProperties.Soc_specific = boolPtr(false)
1987 m.commonProperties.Product_specific = boolPtr(false)
1988 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001989}
1990
Jooyung Han344d5432019-08-23 11:17:39 +09001991// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1992func (m *ModuleBase) IsNativeBridgeSupported() bool {
1993 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1994}
1995
Colin Crossb63d7b32023-12-07 16:54:51 -08001996// ModuleNameWithPossibleOverride returns the name of the OverrideModule that overrides the current
1997// variant of this OverridableModule, or ctx.ModuleName() if this module is not an OverridableModule
1998// or if this variant is not overridden.
1999func ModuleNameWithPossibleOverride(ctx BaseModuleContext) string {
2000 if overridable, ok := ctx.Module().(OverridableModule); ok {
2001 if o := overridable.GetOverriddenBy(); o != "" {
2002 return o
2003 }
2004 }
2005 return ctx.ModuleName()
2006}
2007
Paul Duffine6ba0722021-07-12 20:12:12 +01002008// SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name"
2009// into the module name, or empty string if the input was not a module reference.
Colin Cross41955e82019-05-29 14:40:35 -07002010func SrcIsModule(s string) (module string) {
Paul Duffine6ba0722021-07-12 20:12:12 +01002011 if len(s) > 1 {
2012 if s[0] == ':' {
2013 module = s[1:]
2014 if !isUnqualifiedModuleName(module) {
2015 // The module name should be unqualified but is not so do not treat it as a module.
2016 module = ""
2017 }
2018 } else if s[0] == '/' && s[1] == '/' {
2019 module = s
2020 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002021 }
Paul Duffine6ba0722021-07-12 20:12:12 +01002022 return module
Colin Cross068e0fe2016-12-13 15:23:47 -08002023}
2024
Yi-Yo Chiangba9ea322021-07-15 17:18:21 +08002025// SrcIsModuleWithTag decodes module references in the format ":unqualified-name{.tag}" or
2026// "//namespace:name{.tag}" into the module name and tag, ":unqualified-name" or "//namespace:name"
2027// into the module name and an empty string for the tag, or empty strings if the input was not a
2028// module reference.
Colin Cross41955e82019-05-29 14:40:35 -07002029func SrcIsModuleWithTag(s string) (module, tag string) {
Paul Duffine6ba0722021-07-12 20:12:12 +01002030 if len(s) > 1 {
2031 if s[0] == ':' {
2032 module = s[1:]
2033 } else if s[0] == '/' && s[1] == '/' {
2034 module = s
2035 }
2036
2037 if module != "" {
2038 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
2039 if module[len(module)-1] == '}' {
2040 tag = module[tagStart+1 : len(module)-1]
2041 module = module[:tagStart]
2042 }
2043 }
2044
2045 if s[0] == ':' && !isUnqualifiedModuleName(module) {
2046 // The module name should be unqualified but is not so do not treat it as a module.
2047 module = ""
2048 tag = ""
Colin Cross41955e82019-05-29 14:40:35 -07002049 }
2050 }
Colin Cross41955e82019-05-29 14:40:35 -07002051 }
Paul Duffine6ba0722021-07-12 20:12:12 +01002052
2053 return module, tag
2054}
2055
2056// isUnqualifiedModuleName makes sure that the supplied module is an unqualified module name, i.e.
2057// does not contain any /.
2058func isUnqualifiedModuleName(module string) bool {
2059 return strings.IndexByte(module, '/') == -1
Colin Cross068e0fe2016-12-13 15:23:47 -08002060}
2061
Paul Duffin40131a32021-07-09 17:10:35 +01002062// sourceOrOutputDependencyTag is the dependency tag added automatically by pathDepsMutator for any
2063// module reference in a property annotated with `android:"path"` or passed to ExtractSourceDeps
2064// or ExtractSourcesDeps.
2065//
2066// If uniquely identifies the dependency that was added as it contains both the module name used to
2067// add the dependency as well as the tag. That makes it very simple to find the matching dependency
2068// in GetModuleFromPathDep as all it needs to do is find the dependency whose tag matches the tag
2069// used to add it. It does not need to check that the module name as returned by one of
2070// Module.Name(), BaseModuleContext.OtherModuleName() or ModuleBase.BaseModuleName() matches the
2071// name supplied in the tag. That means it does not need to handle differences in module names
2072// caused by prebuilt_ prefix, or fully qualified module names.
Colin Cross41955e82019-05-29 14:40:35 -07002073type sourceOrOutputDependencyTag struct {
2074 blueprint.BaseDependencyTag
Paul Duffin40131a32021-07-09 17:10:35 +01002075
2076 // The name of the module.
2077 moduleName string
2078
2079 // The tag that will be passed to the module's OutputFileProducer.OutputFiles(tag) method.
Colin Cross41955e82019-05-29 14:40:35 -07002080 tag string
2081}
2082
Paul Duffin40131a32021-07-09 17:10:35 +01002083func sourceOrOutputDepTag(moduleName, tag string) blueprint.DependencyTag {
2084 return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag}
Colin Cross41955e82019-05-29 14:40:35 -07002085}
2086
Paul Duffind5cf92e2021-07-09 17:38:55 +01002087// IsSourceDepTagWithOutputTag returns true if the supplied blueprint.DependencyTag is one that was
2088// used to add dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for
2089// properties tagged with `android:"path"` AND it was added using a module reference of
2090// :moduleName{outputTag}.
2091func IsSourceDepTagWithOutputTag(depTag blueprint.DependencyTag, outputTag string) bool {
2092 t, ok := depTag.(sourceOrOutputDependencyTag)
2093 return ok && t.tag == outputTag
2094}
2095
Colin Cross366938f2017-12-11 16:29:02 -08002096// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
2097// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002098//
2099// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08002100func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07002101 set := make(map[string]bool)
2102
Colin Cross068e0fe2016-12-13 15:23:47 -08002103 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07002104 if m, t := SrcIsModuleWithTag(s); m != "" {
2105 if _, found := set[s]; found {
2106 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07002107 } else {
Colin Cross41955e82019-05-29 14:40:35 -07002108 set[s] = true
Paul Duffin40131a32021-07-09 17:10:35 +01002109 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07002110 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002111 }
2112 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002113}
2114
Colin Cross366938f2017-12-11 16:29:02 -08002115// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
2116// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002117//
2118// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08002119func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
2120 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07002121 if m, t := SrcIsModuleWithTag(*s); m != "" {
Paul Duffin40131a32021-07-09 17:10:35 +01002122 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
Colin Cross366938f2017-12-11 16:29:02 -08002123 }
2124 }
2125}
2126
Colin Cross41955e82019-05-29 14:40:35 -07002127// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
2128// using the ":module" syntax and provides a list of paths to be used as if they were listed in the property.
Colin Cross068e0fe2016-12-13 15:23:47 -08002129type SourceFileProducer interface {
2130 Srcs() Paths
2131}
2132
Colin Cross41955e82019-05-29 14:40:35 -07002133// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00002134// using the ":module" syntax or ":module{.tag}" syntax and provides a list of output files to be used as if they were
Colin Cross41955e82019-05-29 14:40:35 -07002135// listed in the property.
2136type OutputFileProducer interface {
2137 OutputFiles(tag string) (Paths, error)
2138}
2139
Colin Cross5e708052019-08-06 13:59:50 -07002140// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
2141// module produced zero paths, it reports errors to the ctx and returns nil.
2142func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
2143 paths, err := outputFilesForModule(ctx, module, tag)
2144 if err != nil {
2145 reportPathError(ctx, err)
2146 return nil
2147 }
2148 return paths
2149}
2150
2151// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
2152// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
2153func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
2154 paths, err := outputFilesForModule(ctx, module, tag)
2155 if err != nil {
2156 reportPathError(ctx, err)
2157 return nil
2158 }
Colin Cross14ec66c2022-10-03 21:02:27 -07002159 if len(paths) == 0 {
2160 type addMissingDependenciesIntf interface {
2161 AddMissingDependencies([]string)
2162 OtherModuleName(blueprint.Module) string
2163 }
2164 if mctx, ok := ctx.(addMissingDependenciesIntf); ok && ctx.Config().AllowMissingDependencies() {
2165 mctx.AddMissingDependencies([]string{mctx.OtherModuleName(module)})
2166 } else {
2167 ReportPathErrorf(ctx, "failed to get output files from module %q", pathContextName(ctx, module))
2168 }
2169 // Return a fake output file to avoid nil dereferences of Path objects later.
2170 // This should never get used for an actual build as the error or missing
2171 // dependency has already been reported.
2172 p, err := pathForSource(ctx, filepath.Join("missing_output_file", pathContextName(ctx, module)))
2173 if err != nil {
2174 reportPathError(ctx, err)
2175 return nil
2176 }
2177 return p
2178 }
Colin Cross5e708052019-08-06 13:59:50 -07002179 if len(paths) > 1 {
Ulya Trafimovich5ab276a2020-08-25 12:45:15 +01002180 ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
Colin Cross5e708052019-08-06 13:59:50 -07002181 pathContextName(ctx, module))
Colin Cross5e708052019-08-06 13:59:50 -07002182 }
2183 return paths[0]
2184}
2185
2186func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2187 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2188 paths, err := outputFileProducer.OutputFiles(tag)
2189 if err != nil {
2190 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2191 pathContextName(ctx, module), err.Error())
2192 }
Colin Cross5e708052019-08-06 13:59:50 -07002193 return paths, nil
Colin Cross74b1e2b2020-11-22 20:23:02 -08002194 } else if sourceFileProducer, ok := module.(SourceFileProducer); ok {
2195 if tag != "" {
2196 return nil, fmt.Errorf("module %q is a SourceFileProducer, not an OutputFileProducer, and so does not support tag %q", pathContextName(ctx, module), tag)
2197 }
2198 paths := sourceFileProducer.Srcs()
Colin Cross74b1e2b2020-11-22 20:23:02 -08002199 return paths, nil
Colin Cross5e708052019-08-06 13:59:50 -07002200 } else {
2201 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2202 }
2203}
2204
Colin Cross41589502020-12-01 14:00:21 -08002205// Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to
2206// specify that they can be used as a tool by a genrule module.
Colin Crossfe17f6f2019-03-28 19:30:56 -07002207type HostToolProvider interface {
Colin Crossba9e4032020-11-24 16:32:22 -08002208 Module
Colin Cross41589502020-12-01 14:00:21 -08002209 // HostToolPath returns the path to the host tool for the module if it is one, or an invalid
2210 // OptionalPath.
Colin Crossfe17f6f2019-03-28 19:30:56 -07002211 HostToolPath() OptionalPath
2212}
2213
Colin Cross463a90e2015-06-17 14:20:06 -07002214func init() {
LaMont Jones0c10e4d2023-05-16 00:58:37 +00002215 RegisterParallelSingletonType("buildtarget", BuildTargetSingleton)
Inseob Kim81b00a82023-05-15 18:06:31 +09002216 RegisterParallelSingletonType("soongconfigtrace", soongConfigTraceSingletonFunc)
2217 FinalDepsMutators(registerSoongConfigTraceMutator)
Colin Cross463a90e2015-06-17 14:20:06 -07002218}
2219
Colin Cross0875c522017-11-28 17:34:01 -08002220func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002221 return &buildTargetSingleton{}
2222}
2223
Colin Cross87d8b562017-04-25 10:01:55 -07002224func parentDir(dir string) string {
2225 dir, _ = filepath.Split(dir)
2226 return filepath.Clean(dir)
2227}
2228
Colin Cross1f8c52b2015-06-16 16:38:17 -07002229type buildTargetSingleton struct{}
2230
Chih-Hung Hsieh80783772021-10-11 16:46:56 -07002231func AddAncestors(ctx SingletonContext, dirMap map[string]Paths, mmName func(string) string) ([]string, []string) {
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07002232 // Ensure ancestor directories are in dirMap
2233 // Make directories build their direct subdirectories
Chih-Hung Hsieh80783772021-10-11 16:46:56 -07002234 // Returns a slice of all directories and a slice of top-level directories.
Cole Faust18994c72023-02-28 16:02:16 -08002235 dirs := SortedKeys(dirMap)
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07002236 for _, dir := range dirs {
2237 dir := parentDir(dir)
2238 for dir != "." && dir != "/" {
2239 if _, exists := dirMap[dir]; exists {
2240 break
2241 }
2242 dirMap[dir] = nil
2243 dir = parentDir(dir)
2244 }
2245 }
Cole Faust18994c72023-02-28 16:02:16 -08002246 dirs = SortedKeys(dirMap)
Chih-Hung Hsieh80783772021-10-11 16:46:56 -07002247 var topDirs []string
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07002248 for _, dir := range dirs {
2249 p := parentDir(dir)
2250 if p != "." && p != "/" {
2251 dirMap[p] = append(dirMap[p], PathForPhony(ctx, mmName(dir)))
Chih-Hung Hsieh80783772021-10-11 16:46:56 -07002252 } else if dir != "." && dir != "/" && dir != "" {
2253 topDirs = append(topDirs, dir)
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07002254 }
2255 }
Cole Faust18994c72023-02-28 16:02:16 -08002256 return SortedKeys(dirMap), topDirs
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07002257}
2258
Colin Cross0875c522017-11-28 17:34:01 -08002259func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2260 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002261
Colin Crossc3d87d32020-06-04 13:25:17 -07002262 mmTarget := func(dir string) string {
2263 return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
Colin Cross87d8b562017-04-25 10:01:55 -07002264 }
2265
Colin Cross0875c522017-11-28 17:34:01 -08002266 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002267
Colin Cross0875c522017-11-28 17:34:01 -08002268 ctx.VisitAllModules(func(module Module) {
2269 blueprintDir := module.base().blueprintDir
2270 installTarget := module.base().installTarget
2271 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002272
Colin Cross0875c522017-11-28 17:34:01 -08002273 if checkbuildTarget != nil {
2274 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2275 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2276 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002277
Colin Cross0875c522017-11-28 17:34:01 -08002278 if installTarget != nil {
2279 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002280 }
2281 })
2282
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002283 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05002284 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002285 suffix = "-soong"
2286 }
2287
Colin Cross1f8c52b2015-06-16 16:38:17 -07002288 // Create a top-level checkbuild target that depends on all modules
Colin Crossc3d87d32020-06-04 13:25:17 -07002289 ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002290
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002291 // Make will generate the MODULES-IN-* targets
Jingwen Chencda22c92020-11-23 00:22:30 -05002292 if ctx.Config().KatiEnabled() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002293 return
2294 }
2295
Chih-Hung Hsieh80783772021-10-11 16:46:56 -07002296 dirs, _ := AddAncestors(ctx, modulesInDir, mmTarget)
Colin Cross87d8b562017-04-25 10:01:55 -07002297
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002298 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2299 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2300 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002301 for _, dir := range dirs {
Colin Crossc3d87d32020-06-04 13:25:17 -07002302 ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002303 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002304
2305 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
Jiyong Park1613e552020-09-14 19:43:17 +09002306 type osAndCross struct {
2307 os OsType
2308 hostCross bool
2309 }
2310 osDeps := map[osAndCross]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002311 ctx.VisitAllModules(func(module Module) {
2312 if module.Enabled() {
Jiyong Park1613e552020-09-14 19:43:17 +09002313 key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross}
2314 osDeps[key] = append(osDeps[key], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002315 }
2316 })
2317
Colin Cross0875c522017-11-28 17:34:01 -08002318 osClass := make(map[string]Paths)
Jiyong Park1613e552020-09-14 19:43:17 +09002319 for key, deps := range osDeps {
Dan Willemsen61d88b82017-09-20 17:29:08 -07002320 var className string
2321
Jiyong Park1613e552020-09-14 19:43:17 +09002322 switch key.os.Class {
Dan Willemsen61d88b82017-09-20 17:29:08 -07002323 case Host:
Jiyong Park1613e552020-09-14 19:43:17 +09002324 if key.hostCross {
2325 className = "host-cross"
2326 } else {
2327 className = "host"
2328 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002329 case Device:
2330 className = "target"
2331 default:
2332 continue
2333 }
2334
Jiyong Park1613e552020-09-14 19:43:17 +09002335 name := className + "-" + key.os.Name
Colin Crossc3d87d32020-06-04 13:25:17 -07002336 osClass[className] = append(osClass[className], PathForPhony(ctx, name))
Dan Willemsen61d88b82017-09-20 17:29:08 -07002337
Colin Crossc3d87d32020-06-04 13:25:17 -07002338 ctx.Phony(name, deps...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002339 }
2340
2341 // Wrap those into host|host-cross|target phony rules
Cole Faust18994c72023-02-28 16:02:16 -08002342 for _, class := range SortedKeys(osClass) {
Colin Crossc3d87d32020-06-04 13:25:17 -07002343 ctx.Phony(class, osClass[class]...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002344 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002345}
Colin Crossd779da42015-12-17 18:00:23 -08002346
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002347// Collect information for opening IDE project files in java/jdeps.go.
2348type IDEInfo interface {
2349 IDEInfo(ideInfo *IdeInfo)
2350 BaseModuleName() string
2351}
2352
2353// Extract the base module name from the Import name.
2354// Often the Import name has a prefix "prebuilt_".
2355// Remove the prefix explicitly if needed
2356// until we find a better solution to get the Import name.
2357type IDECustomizedModuleName interface {
2358 IDECustomizedModuleName() string
2359}
2360
2361type IdeInfo struct {
2362 Deps []string `json:"dependencies,omitempty"`
2363 Srcs []string `json:"srcs,omitempty"`
2364 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2365 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2366 Jars []string `json:"jars,omitempty"`
2367 Classes []string `json:"class,omitempty"`
2368 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002369 SrcJars []string `json:"srcjars,omitempty"`
bralee1fbf4402020-05-21 10:11:59 +08002370 Paths []string `json:"path,omitempty"`
Yikef6282022022-04-13 20:41:01 +08002371 Static_libs []string `json:"static_libs,omitempty"`
2372 Libs []string `json:"libs,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002373}
Paul Duffinf88d8e02020-05-07 20:21:34 +01002374
2375func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
2376 bpctx := ctx.blueprintBaseModuleContext()
2377 return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
2378}
Colin Cross5d583952020-11-24 16:21:24 -08002379
Inseob Kim81b00a82023-05-15 18:06:31 +09002380func registerSoongConfigTraceMutator(ctx RegisterMutatorsContext) {
2381 ctx.BottomUp("soongconfigtrace", soongConfigTraceMutator).Parallel()
2382}
2383
2384// soongConfigTraceMutator accumulates recorded soong_config trace from children. Also it normalizes
2385// SoongConfigTrace to make it consistent.
2386func soongConfigTraceMutator(ctx BottomUpMutatorContext) {
2387 trace := &ctx.Module().base().commonProperties.SoongConfigTrace
2388 ctx.VisitDirectDeps(func(m Module) {
2389 childTrace := &m.base().commonProperties.SoongConfigTrace
2390 trace.Bools = append(trace.Bools, childTrace.Bools...)
2391 trace.Strings = append(trace.Strings, childTrace.Strings...)
2392 trace.IsSets = append(trace.IsSets, childTrace.IsSets...)
2393 })
2394 trace.Bools = SortedUniqueStrings(trace.Bools)
2395 trace.Strings = SortedUniqueStrings(trace.Strings)
2396 trace.IsSets = SortedUniqueStrings(trace.IsSets)
2397
2398 ctx.Module().base().commonProperties.SoongConfigTraceHash = trace.hash()
2399}
2400
2401// soongConfigTraceSingleton writes a map from each module's config hash value to trace data.
2402func soongConfigTraceSingletonFunc() Singleton {
2403 return &soongConfigTraceSingleton{}
2404}
2405
2406type soongConfigTraceSingleton struct {
2407}
2408
2409func (s *soongConfigTraceSingleton) GenerateBuildActions(ctx SingletonContext) {
2410 outFile := PathForOutput(ctx, "soong_config_trace.json")
2411
2412 traces := make(map[string]*soongConfigTrace)
2413 ctx.VisitAllModules(func(module Module) {
2414 trace := &module.base().commonProperties.SoongConfigTrace
2415 if !trace.isEmpty() {
2416 hash := module.base().commonProperties.SoongConfigTraceHash
2417 traces[hash] = trace
2418 }
2419 })
2420
2421 j, err := json.Marshal(traces)
2422 if err != nil {
2423 ctx.Errorf("json marshal to %q failed: %#v", outFile, err)
2424 return
2425 }
2426
2427 WriteFileRule(ctx, outFile, string(j))
2428 ctx.Phony("soong_config_trace", outFile)
2429}