blob: 9d73859b4d482ef00a2b96973b32648c5461bcb8 [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 Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Alex Lightfb4353d2019-01-17 13:57:45 -080019 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "path/filepath"
Colin Cross0875c522017-11-28 17:34:01 -080021 "sort"
Colin Cross6ff51382015-12-17 16:39:19 -080022 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080023 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070024
25 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070026 "github.com/google/blueprint/pathtools"
Colin Crossfe4bc362018-09-12 10:02:13 -070027 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080028)
29
30var (
31 DeviceSharedLibrary = "shared_library"
32 DeviceStaticLibrary = "static_library"
33 DeviceExecutable = "executable"
34 HostSharedLibrary = "host_shared_library"
35 HostStaticLibrary = "host_static_library"
36 HostExecutable = "host_executable"
37)
38
Colin Crossae887032017-10-23 17:16:14 -070039type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070040 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080041 Deps blueprint.Deps
42 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070043 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070044 Output WritablePath
45 Outputs WritablePaths
46 ImplicitOutput WritablePath
47 ImplicitOutputs WritablePaths
48 Input Path
49 Inputs Paths
50 Implicit Path
51 Implicits Paths
52 OrderOnly Paths
53 Default bool
54 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070055}
56
Colin Crossae887032017-10-23 17:16:14 -070057type ModuleBuildParams BuildParams
58
Colin Cross0ea8ba82019-06-06 14:33:29 -070059// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
60// a Config instead of an interface{}, plus some extra methods that return Android-specific information
61// about the current module.
62type BaseModuleContext interface {
63 ModuleName() string
64 ModuleDir() string
65 ModuleType() string
66 Config() Config
67
68 ContainsProperty(name string) bool
69 Errorf(pos scanner.Position, fmt string, args ...interface{})
70 ModuleErrorf(fmt string, args ...interface{})
71 PropertyErrorf(property, fmt string, args ...interface{})
72 Failed() bool
73
74 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
75 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
76 // builder whenever a file matching the pattern as added or removed, without rerunning if a
77 // file that does not match the pattern is added to a searched directory.
78 GlobWithDeps(pattern string, excludes []string) ([]string, error)
79
80 Fs() pathtools.FileSystem
81 AddNinjaFileDeps(deps ...string)
82
Colin Crossa1ad8d12016-06-01 17:09:44 -070083 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -070084 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -070085 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -070086 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -070087 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -070088 Host() bool
89 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -070090 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -080091 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -070092 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070093 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -070094 PrimaryArch() bool
Jiyong Park2db76922017-11-08 16:03:48 +090095 Platform() bool
96 DeviceSpecific() bool
97 SocSpecific() bool
98 ProductSpecific() bool
Dario Frenifd05a742018-05-29 13:28:54 +010099 ProductServicesSpecific() bool
Colin Cross1332b002015-04-07 17:11:30 -0700100 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -0700101 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -0700102}
103
Colin Cross0ea8ba82019-06-06 14:33:29 -0700104// Deprecated: use BaseModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700105type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800106 BaseModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800107}
108
Colin Cross635c3b02016-05-18 15:37:25 -0700109type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800110 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800111
Colin Crossae887032017-10-23 17:16:14 -0700112 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800113 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700114
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800116 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800117 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Colin Cross7f19f372016-11-01 11:10:25 -0700118 Glob(globPattern string, excludes []string) Paths
Nan Zhang581fd212018-01-10 16:06:12 -0800119 GlobFiles(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross5c517922017-08-31 12:29:17 -0700121 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
122 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800123 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Jiyong Parkf1194352019-02-25 11:05:47 +0900124 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800126
127 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700128
Colin Cross8d8f8e22016-08-03 11:57:50 -0700129 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700130 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900131 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800132
133 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700134 HostRequiredModuleNames() []string
135 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700136
137 // android.ModuleContext methods
138 // These are duplicated instead of embedded so that can eventually be wrapped to take an
139 // android.Module instead of a blueprint.Module
140 OtherModuleName(m blueprint.Module) string
141 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
142 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
143
Colin Cross0ef08162019-05-01 15:50:51 -0700144 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross3f68a132017-10-23 17:10:29 -0700145 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
146 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
147
148 ModuleSubDir() string
149
Colin Cross35143d02017-11-16 00:11:20 -0800150 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700151 VisitDirectDeps(visit func(Module))
Colin Crossee6143c2017-12-30 17:54:27 -0800152 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700153 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700154 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700155 VisitDepsDepthFirst(visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700156 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700157 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
158 WalkDeps(visit func(Module, Module) bool)
Alex Light778127a2019-02-27 14:19:50 -0800159 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700160
Colin Cross0875c522017-11-28 17:34:01 -0800161 Variable(pctx PackageContext, name, value string)
162 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700163 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
164 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800165 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700166
Colin Cross0875c522017-11-28 17:34:01 -0800167 PrimaryModule() Module
168 FinalModule() Module
169 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700170
171 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800172 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800173}
174
Colin Cross635c3b02016-05-18 15:37:25 -0700175type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800176 blueprint.Module
177
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700178 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
179 // but GenerateAndroidBuildActions also has access to Android-specific information.
180 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700181 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700182
Colin Cross1e676be2016-10-12 14:38:15 -0700183 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800184
Colin Cross635c3b02016-05-18 15:37:25 -0700185 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800186 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700187 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800188 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700189 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900190 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800191 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900192 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900193 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700194
195 AddProperties(props ...interface{})
196 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700197
Colin Crossae887032017-10-23 17:16:14 -0700198 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800199 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800200 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800201}
202
Colin Crossfc754582016-05-17 16:34:16 -0700203type nameProperties struct {
204 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800205 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700206}
207
208type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800209 // emit build rules for this module
210 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800211
Paul Duffin2e61fa62019-03-28 14:10:57 +0000212 // Controls the visibility of this module to other modules. Allowable values are one or more of
213 // these formats:
214 //
215 // ["//visibility:public"]: Anyone can use this module.
216 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
217 // this module.
218 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
219 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
220 // this module. Note that sub-packages do not have access to the rule; for example,
221 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
222 // is a special module and must be used verbatim. It represents all of the modules in the
223 // package.
224 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
225 // or other or in one of their sub-packages have access to this module. For example,
226 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
227 // to depend on this rule (but not //independent:evil)
228 // ["//project"]: This is shorthand for ["//project:__pkg__"]
229 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
230 // //project is the module's package. e.g. using [":__subpackages__"] in
231 // packages/apps/Settings/Android.bp is equivalent to
232 // //packages/apps/Settings:__subpackages__.
233 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
234 // for now. It is an error if it is used in a module.
235 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
236 // more details.
237 Visibility []string
238
Colin Cross7d5136f2015-05-11 13:39:40 -0700239 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800240 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
241 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
242 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700243 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700244
245 Target struct {
246 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700247 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700248 }
249 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700250 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700251 }
252 }
253
Colin Crossee0bc3b2018-10-02 22:01:37 -0700254 UseTargetVariants bool `blueprint:"mutated"`
255 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800256
Dan Willemsen782a2d12015-12-21 14:55:28 -0800257 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700258 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800259
Colin Cross55708f32017-03-20 13:23:34 -0700260 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700261 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700262
Jiyong Park2db76922017-11-08 16:03:48 +0900263 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
264 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
265 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700266 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700267
Jiyong Park2db76922017-11-08 16:03:48 +0900268 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
269 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
270 Soc_specific *bool
271
272 // whether this module is specific to a device, not only for SoC, but also for off-chip
273 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
274 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
275 // This implies `soc_specific:true`.
276 Device_specific *bool
277
278 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900279 // network operator, etc). When set to true, it is installed into /product (or
280 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900281 Product_specific *bool
282
Dario Frenifd05a742018-05-29 13:28:54 +0100283 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100284 // to true, it is installed into /product_services (or /system/product_services if
285 // product_services partition does not exist).
286 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100287
Jiyong Parkf9332f12018-02-01 00:54:12 +0900288 // Whether this module is installed to recovery partition
289 Recovery *bool
290
dimitry1f33e402019-03-26 12:39:31 +0100291 // Whether this module is built for non-native architecures (also known as native bridge binary)
292 Native_bridge_supported *bool `android:"arch_variant"`
293
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700294 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800295 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700296
Steven Moreland57a23d22018-04-04 15:42:19 -0700297 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800298 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700299
Chris Wolfe998306e2016-08-15 14:47:23 -0400300 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700301 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400302
Sasha Smundakb6d23052019-04-01 18:37:36 -0700303 // names of other modules to install on host if this module is installed
304 Host_required []string `android:"arch_variant"`
305
306 // names of other modules to install on target if this module is installed
307 Target_required []string `android:"arch_variant"`
308
Colin Cross5aac3622017-08-31 15:07:09 -0700309 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800310 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700311
Dan Willemsen569edc52018-11-19 09:33:29 -0800312 Dist struct {
313 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
314 // command line and any of these targets are also on the command line, or otherwise
315 // built
316 Targets []string `android:"arch_variant"`
317
318 // The name of the output artifact. This defaults to the basename of the output of
319 // the module.
320 Dest *string `android:"arch_variant"`
321
322 // The directory within the dist directory to store the artifact. Defaults to the
323 // top level directory ("").
324 Dir *string `android:"arch_variant"`
325
326 // A suffix to add to the artifact file name (before any extension).
327 Suffix *string `android:"arch_variant"`
328 } `android:"arch_variant"`
329
Colin Crossa1ad8d12016-06-01 17:09:44 -0700330 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700331 CompileTarget Target `blueprint:"mutated"`
332 CompileMultiTargets []Target `blueprint:"mutated"`
333 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800334
335 // Set by InitAndroidModule
336 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700337 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700338
339 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800340
341 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800342}
343
344type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800345 // If set to true, build a variant of the module for the host. Defaults to false.
346 Host_supported *bool
347
348 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700349 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800350}
351
Colin Crossc472d572015-03-17 15:06:21 -0700352type Multilib string
353
354const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800355 MultilibBoth Multilib = "both"
356 MultilibFirst Multilib = "first"
357 MultilibCommon Multilib = "common"
358 MultilibCommonFirst Multilib = "common_first"
359 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700360)
361
Colin Crossa1ad8d12016-06-01 17:09:44 -0700362type HostOrDeviceSupported int
363
364const (
365 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700366
367 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700368 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700369
370 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700371 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700372
373 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700374 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700375
376 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700377 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700378
379 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700380 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700381
382 // Nothing is supported. This is not exposed to the user, but used to mark a
383 // host only module as unsupported when the module type is not supported on
384 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700385 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700386)
387
Jiyong Park2db76922017-11-08 16:03:48 +0900388type moduleKind int
389
390const (
391 platformModule moduleKind = iota
392 deviceSpecificModule
393 socSpecificModule
394 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100395 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900396)
397
398func (k moduleKind) String() string {
399 switch k {
400 case platformModule:
401 return "platform"
402 case deviceSpecificModule:
403 return "device-specific"
404 case socSpecificModule:
405 return "soc-specific"
406 case productSpecificModule:
407 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100408 case productServicesSpecificModule:
409 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900410 default:
411 panic(fmt.Errorf("unknown module kind %d", k))
412 }
413}
414
Colin Cross36242852017-06-23 15:06:31 -0700415func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800416 base := m.base()
417 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700418
Colin Cross36242852017-06-23 15:06:31 -0700419 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700420 &base.nameProperties,
421 &base.commonProperties,
422 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700423 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700424 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700425}
426
Colin Cross36242852017-06-23 15:06:31 -0700427func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
428 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700429
430 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800431 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700432 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700433 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700434 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800435
Dan Willemsen218f6562015-07-08 18:13:11 -0700436 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700437 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700438 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800439 }
440
Colin Cross36242852017-06-23 15:06:31 -0700441 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800442}
443
Colin Crossee0bc3b2018-10-02 22:01:37 -0700444func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
445 InitAndroidArchModule(m, hod, defaultMultilib)
446 m.base().commonProperties.UseTargetVariants = false
447}
448
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800449// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800450// modules. It should be included as an anonymous field in every module
451// struct definition. InitAndroidModule should then be called from the module's
452// factory function, and the return values from InitAndroidModule should be
453// returned from the factory function.
454//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800455// The ModuleBase type is responsible for implementing the GenerateBuildActions
456// method to support the blueprint.Module interface. This method will then call
457// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700458// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
459// rather than the usual blueprint.ModuleContext.
460// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800461// system including details about the particular build variant that is to be
462// generated.
463//
464// For example:
465//
466// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800467// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800468// )
469//
470// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800471// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800472// properties struct {
473// MyProperty string
474// }
475// }
476//
Colin Cross36242852017-06-23 15:06:31 -0700477// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800478// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700479// m.AddProperties(&m.properties)
480// android.InitAndroidModule(m)
481// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800482// }
483//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800484// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800485// // Get the CPU architecture for the current build variant.
486// variantArch := ctx.Arch()
487//
488// // ...
489// }
Colin Cross635c3b02016-05-18 15:37:25 -0700490type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800491 // Putting the curiously recurring thing pointing to the thing that contains
492 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700493 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700494 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800495
Colin Crossfc754582016-05-17 16:34:16 -0700496 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800497 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700498 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800499 hostAndDeviceProperties hostAndDeviceProperties
500 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700501 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700502 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800503
504 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700505 installFiles Paths
506 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900507 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700508
509 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
510 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800511 installTarget WritablePath
512 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700513 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700514
Colin Cross178a5092016-09-13 13:42:32 -0700515 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700516
517 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700518
519 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700520 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800521 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800522 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700523
524 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700525}
526
Colin Cross4157e882019-06-06 16:57:04 -0700527func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800528
Colin Cross4157e882019-06-06 16:57:04 -0700529func (m *ModuleBase) AddProperties(props ...interface{}) {
530 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700531}
532
Colin Cross4157e882019-06-06 16:57:04 -0700533func (m *ModuleBase) GetProperties() []interface{} {
534 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800535}
536
Colin Cross4157e882019-06-06 16:57:04 -0700537func (m *ModuleBase) BuildParamsForTests() []BuildParams {
538 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700539}
540
Colin Cross4157e882019-06-06 16:57:04 -0700541func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
542 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800543}
544
Colin Cross4157e882019-06-06 16:57:04 -0700545func (m *ModuleBase) VariablesForTests() map[string]string {
546 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800547}
548
Colin Cross4157e882019-06-06 16:57:04 -0700549func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
550 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700551}
552
Colin Crossce75d2c2016-10-06 16:12:58 -0700553// Name returns the name of the module. It may be overridden by individual module types, for
554// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700555func (m *ModuleBase) Name() string {
556 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700557}
558
Colin Crossce75d2c2016-10-06 16:12:58 -0700559// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700560func (m *ModuleBase) BaseModuleName() string {
561 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700562}
563
Colin Cross4157e882019-06-06 16:57:04 -0700564func (m *ModuleBase) base() *ModuleBase {
565 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800566}
567
Colin Cross4157e882019-06-06 16:57:04 -0700568func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
569 m.commonProperties.CompileTarget = target
570 m.commonProperties.CompileMultiTargets = multiTargets
571 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700572}
573
Colin Cross4157e882019-06-06 16:57:04 -0700574func (m *ModuleBase) Target() Target {
575 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800576}
577
Colin Cross4157e882019-06-06 16:57:04 -0700578func (m *ModuleBase) TargetPrimary() bool {
579 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700580}
581
Colin Cross4157e882019-06-06 16:57:04 -0700582func (m *ModuleBase) MultiTargets() []Target {
583 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700584}
585
Colin Cross4157e882019-06-06 16:57:04 -0700586func (m *ModuleBase) Os() OsType {
587 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800588}
589
Colin Cross4157e882019-06-06 16:57:04 -0700590func (m *ModuleBase) Host() bool {
591 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800592}
593
Colin Cross4157e882019-06-06 16:57:04 -0700594func (m *ModuleBase) Arch() Arch {
595 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800596}
597
Colin Cross4157e882019-06-06 16:57:04 -0700598func (m *ModuleBase) ArchSpecific() bool {
599 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700600}
601
Colin Cross4157e882019-06-06 16:57:04 -0700602func (m *ModuleBase) OsClassSupported() []OsClass {
603 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700604 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700605 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700606 case HostSupportedNoCross:
607 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700608 case DeviceSupported:
609 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700610 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700611 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700612 if Bool(m.hostAndDeviceProperties.Host_supported) ||
613 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
614 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700615 supported = append(supported, Host, HostCross)
616 }
Colin Cross4157e882019-06-06 16:57:04 -0700617 if m.hostAndDeviceProperties.Device_supported == nil ||
618 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700619 supported = append(supported, Device)
620 }
621 return supported
622 default:
623 return nil
624 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800625}
626
Colin Cross4157e882019-06-06 16:57:04 -0700627func (m *ModuleBase) DeviceSupported() bool {
628 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
629 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
630 (m.hostAndDeviceProperties.Device_supported == nil ||
631 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800632}
633
Colin Cross4157e882019-06-06 16:57:04 -0700634func (m *ModuleBase) Platform() bool {
635 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900636}
637
Colin Cross4157e882019-06-06 16:57:04 -0700638func (m *ModuleBase) DeviceSpecific() bool {
639 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900640}
641
Colin Cross4157e882019-06-06 16:57:04 -0700642func (m *ModuleBase) SocSpecific() bool {
643 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900644}
645
Colin Cross4157e882019-06-06 16:57:04 -0700646func (m *ModuleBase) ProductSpecific() bool {
647 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900648}
649
Colin Cross4157e882019-06-06 16:57:04 -0700650func (m *ModuleBase) ProductServicesSpecific() bool {
651 return Bool(m.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100652}
653
Colin Cross4157e882019-06-06 16:57:04 -0700654func (m *ModuleBase) Enabled() bool {
655 if m.commonProperties.Enabled == nil {
656 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800657 }
Colin Cross4157e882019-06-06 16:57:04 -0700658 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800659}
660
Colin Cross4157e882019-06-06 16:57:04 -0700661func (m *ModuleBase) SkipInstall() {
662 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700663}
664
Colin Cross4157e882019-06-06 16:57:04 -0700665func (m *ModuleBase) ExportedToMake() bool {
666 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900667}
668
Colin Cross4157e882019-06-06 16:57:04 -0700669func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700670 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800671
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700672 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700673 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800674 ctx.VisitDepsDepthFirstIf(isFileInstaller,
675 func(m blueprint.Module) {
676 fileInstaller := m.(fileInstaller)
677 files := fileInstaller.filesToInstall()
678 result = append(result, files...)
679 })
680
681 return result
682}
683
Colin Cross4157e882019-06-06 16:57:04 -0700684func (m *ModuleBase) filesToInstall() Paths {
685 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800686}
687
Colin Cross4157e882019-06-06 16:57:04 -0700688func (m *ModuleBase) NoAddressSanitizer() bool {
689 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800690}
691
Colin Cross4157e882019-06-06 16:57:04 -0700692func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800693 return false
694}
695
Colin Cross4157e882019-06-06 16:57:04 -0700696func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700697 return false
698}
699
Colin Cross4157e882019-06-06 16:57:04 -0700700func (m *ModuleBase) InstallInRecovery() bool {
701 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900702}
703
Colin Cross4157e882019-06-06 16:57:04 -0700704func (m *ModuleBase) Owner() string {
705 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900706}
707
Colin Cross4157e882019-06-06 16:57:04 -0700708func (m *ModuleBase) NoticeFile() OptionalPath {
709 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900710}
711
Colin Cross4157e882019-06-06 16:57:04 -0700712func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700713 allInstalledFiles := Paths{}
714 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800715 ctx.VisitAllModuleVariants(func(module Module) {
716 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700717 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
718 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800719 })
720
Colin Cross0875c522017-11-28 17:34:01 -0800721 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700722
Jeff Gaston088e29e2017-11-29 16:47:17 -0800723 namespacePrefix := ctx.Namespace().(*Namespace).id
724 if namespacePrefix != "" {
725 namespacePrefix = namespacePrefix + "-"
726 }
727
Colin Cross3f40fa42015-01-30 17:27:36 -0800728 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800729 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800730 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700731 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800732 Output: name,
733 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800734 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700735 })
736 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700737 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700738 }
739
740 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800741 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800742 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700743 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800744 Output: name,
745 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700746 })
747 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700748 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700749 }
750
751 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800752 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800753 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800754 suffix = "-soong"
755 }
756
Jeff Gaston088e29e2017-11-29 16:47:17 -0800757 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800758 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700759 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800760 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700761 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800762 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700763
Colin Cross4157e882019-06-06 16:57:04 -0700764 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800765 }
766}
767
Colin Cross4157e882019-06-06 16:57:04 -0700768func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
769 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
770 var deviceSpecific = Bool(m.commonProperties.Device_specific)
771 var productSpecific = Bool(m.commonProperties.Product_specific)
772 var productServicesSpecific = Bool(m.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900773
Dario Frenifd05a742018-05-29 13:28:54 +0100774 msg := "conflicting value set here"
775 if socSpecific && deviceSpecific {
776 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700777 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900778 ctx.PropertyErrorf("vendor", msg)
779 }
Colin Cross4157e882019-06-06 16:57:04 -0700780 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900781 ctx.PropertyErrorf("proprietary", msg)
782 }
Colin Cross4157e882019-06-06 16:57:04 -0700783 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900784 ctx.PropertyErrorf("soc_specific", msg)
785 }
786 }
787
Dario Frenifd05a742018-05-29 13:28:54 +0100788 if productSpecific && productServicesSpecific {
789 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
790 ctx.PropertyErrorf("product_services_specific", msg)
791 }
792
793 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
794 if productSpecific {
795 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
796 } else {
797 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
798 }
799 if deviceSpecific {
800 ctx.PropertyErrorf("device_specific", msg)
801 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700802 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100803 ctx.PropertyErrorf("vendor", msg)
804 }
Colin Cross4157e882019-06-06 16:57:04 -0700805 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100806 ctx.PropertyErrorf("proprietary", msg)
807 }
Colin Cross4157e882019-06-06 16:57:04 -0700808 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100809 ctx.PropertyErrorf("soc_specific", msg)
810 }
811 }
812 }
813
Jiyong Park2db76922017-11-08 16:03:48 +0900814 if productSpecific {
815 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100816 } else if productServicesSpecific {
817 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900818 } else if deviceSpecific {
819 return deviceSpecificModule
820 } else if socSpecific {
821 return socSpecificModule
822 } else {
823 return platformModule
824 }
825}
826
Colin Cross0ea8ba82019-06-06 14:33:29 -0700827func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
828 return baseModuleContext{
829 BaseModuleContext: ctx,
830 target: m.commonProperties.CompileTarget,
831 targetPrimary: m.commonProperties.CompilePrimary,
832 multiTargets: m.commonProperties.CompileMultiTargets,
833 kind: determineModuleKind(m, ctx),
834 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800835 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800836}
837
Colin Cross4157e882019-06-06 16:57:04 -0700838func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -0700839 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -0700840 module: m.module,
841 ModuleContext: blueprintCtx,
842 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
843 installDeps: m.computeInstallDeps(blueprintCtx),
844 installFiles: m.installFiles,
845 missingDeps: blueprintCtx.GetMissingDependencies(),
846 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800847 }
848
Colin Cross4c83e5c2019-02-25 14:54:28 -0800849 if ctx.config.captureBuild {
850 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
851 }
852
Colin Cross67a5c132017-05-09 13:45:28 -0700853 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
854 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800855 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
856 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700857 }
Colin Cross0875c522017-11-28 17:34:01 -0800858 if !ctx.PrimaryArch() {
859 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700860 }
861
862 ctx.Variable(pctx, "moduleDesc", desc)
863
864 s := ""
865 if len(suffix) > 0 {
866 s = " [" + strings.Join(suffix, " ") + "]"
867 }
868 ctx.Variable(pctx, "moduleDescSuffix", s)
869
Dan Willemsen569edc52018-11-19 09:33:29 -0800870 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -0700871 if m.commonProperties.Dist.Dest != nil {
872 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -0800873 if err != nil {
874 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
875 }
876 }
Colin Cross4157e882019-06-06 16:57:04 -0700877 if m.commonProperties.Dist.Dir != nil {
878 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -0800879 if err != nil {
880 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
881 }
882 }
Colin Cross4157e882019-06-06 16:57:04 -0700883 if m.commonProperties.Dist.Suffix != nil {
884 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -0800885 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
886 }
887 }
888
Colin Cross4157e882019-06-06 16:57:04 -0700889 if m.Enabled() {
890 m.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700891 if ctx.Failed() {
892 return
893 }
894
Colin Cross4157e882019-06-06 16:57:04 -0700895 m.installFiles = append(m.installFiles, ctx.installFiles...)
896 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800897
Colin Cross4157e882019-06-06 16:57:04 -0700898 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
899 if module := SrcIsModule(notice); module != "" {
900 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +0900901 } else {
902 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -0700903 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800904 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800905 }
906
Colin Cross4157e882019-06-06 16:57:04 -0700907 if m == ctx.FinalModule().(Module).base() {
908 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700909 if ctx.Failed() {
910 return
911 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800912 }
Colin Crosscec81712017-07-13 14:43:27 -0700913
Colin Cross4157e882019-06-06 16:57:04 -0700914 m.buildParams = ctx.buildParams
915 m.ruleParams = ctx.ruleParams
916 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800917}
918
Colin Cross0ea8ba82019-06-06 14:33:29 -0700919type baseModuleContext struct {
920 blueprint.BaseModuleContext
Colin Cross8b74d172016-09-13 09:59:14 -0700921 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700922 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700923 targetPrimary bool
924 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900925 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700926 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700927}
928
Colin Cross25de6c32019-06-06 14:29:25 -0700929type moduleContext struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800930 blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700931 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700932 installDeps Paths
933 installFiles Paths
934 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800935 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700936 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700937
938 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700939 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800940 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800941 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800942}
943
Colin Cross25de6c32019-06-06 14:29:25 -0700944func (m *moduleContext) ninjaError(desc string, outputs []string, err error) {
945 m.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700946 Rule: ErrorRule,
947 Description: desc,
948 Outputs: outputs,
949 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800950 Args: map[string]string{
951 "error": err.Error(),
952 },
953 })
954 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800955}
956
Colin Cross25de6c32019-06-06 14:29:25 -0700957func (m *moduleContext) Config() Config {
958 return m.ModuleContext.Config().(Config)
Colin Crossaabf6792017-11-29 00:27:14 -0800959}
960
Colin Cross25de6c32019-06-06 14:29:25 -0700961func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
962 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800963}
964
Colin Cross0875c522017-11-28 17:34:01 -0800965func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700966 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700967 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800968 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800969 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700970 Outputs: params.Outputs.Strings(),
971 ImplicitOutputs: params.ImplicitOutputs.Strings(),
972 Inputs: params.Inputs.Strings(),
973 Implicits: params.Implicits.Strings(),
974 OrderOnly: params.OrderOnly.Strings(),
975 Args: params.Args,
976 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700977 }
978
Colin Cross33bfb0a2016-11-21 17:23:08 -0800979 if params.Depfile != nil {
980 bparams.Depfile = params.Depfile.String()
981 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700982 if params.Output != nil {
983 bparams.Outputs = append(bparams.Outputs, params.Output.String())
984 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700985 if params.ImplicitOutput != nil {
986 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
987 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700988 if params.Input != nil {
989 bparams.Inputs = append(bparams.Inputs, params.Input.String())
990 }
991 if params.Implicit != nil {
992 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
993 }
994
Colin Cross0b9f31f2019-02-28 11:00:01 -0800995 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
996 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
997 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
998 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
999 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1000 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001001
Colin Cross0875c522017-11-28 17:34:01 -08001002 return bparams
1003}
1004
Colin Cross25de6c32019-06-06 14:29:25 -07001005func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1006 if m.config.captureBuild {
1007 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001008 }
1009
Colin Cross25de6c32019-06-06 14:29:25 -07001010 m.ModuleContext.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001011}
1012
Colin Cross25de6c32019-06-06 14:29:25 -07001013func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001014 argNames ...string) blueprint.Rule {
1015
Colin Cross25de6c32019-06-06 14:29:25 -07001016 rule := m.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001017
Colin Cross25de6c32019-06-06 14:29:25 -07001018 if m.config.captureBuild {
1019 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001020 }
1021
1022 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001023}
1024
Colin Cross25de6c32019-06-06 14:29:25 -07001025func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
1026 if m.config.captureBuild {
1027 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001028 }
1029
1030 bparams := convertBuildParams(params)
1031
1032 if bparams.Description != "" {
1033 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1034 }
1035
Colin Cross25de6c32019-06-06 14:29:25 -07001036 if m.missingDeps != nil {
1037 m.ninjaError(bparams.Description, bparams.Outputs,
Colin Cross67a5c132017-05-09 13:45:28 -07001038 fmt.Errorf("module %s missing dependencies: %s\n",
Colin Cross25de6c32019-06-06 14:29:25 -07001039 m.ModuleName(), strings.Join(m.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -08001040 return
1041 }
1042
Colin Cross25de6c32019-06-06 14:29:25 -07001043 m.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001044}
1045
Colin Cross25de6c32019-06-06 14:29:25 -07001046func (m *moduleContext) GetMissingDependencies() []string {
1047 return m.missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001048}
1049
Colin Cross25de6c32019-06-06 14:29:25 -07001050func (m *moduleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001051 if deps != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001052 m.missingDeps = append(m.missingDeps, deps...)
1053 m.missingDeps = FirstUniqueStrings(m.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001054 }
1055}
1056
Colin Cross25de6c32019-06-06 14:29:25 -07001057func (m *moduleContext) validateAndroidModule(module blueprint.Module) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001058 aModule, _ := module.(Module)
1059 if aModule == nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001060 m.ModuleErrorf("module %q not an android module", m.OtherModuleName(aModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07001061 return nil
1062 }
1063
1064 if !aModule.Enabled() {
Colin Cross25de6c32019-06-06 14:29:25 -07001065 if m.Config().AllowMissingDependencies() {
1066 m.AddMissingDependencies([]string{m.OtherModuleName(aModule)})
Colin Crossd11fcda2017-10-23 17:59:01 -07001067 } else {
Colin Cross25de6c32019-06-06 14:29:25 -07001068 m.ModuleErrorf("depends on disabled module %q", m.OtherModuleName(aModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07001069 }
1070 return nil
1071 }
1072
1073 return aModule
1074}
1075
Colin Cross25de6c32019-06-06 14:29:25 -07001076func (m *moduleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001077 type dep struct {
1078 mod blueprint.Module
1079 tag blueprint.DependencyTag
1080 }
1081 var deps []dep
Colin Cross25de6c32019-06-06 14:29:25 -07001082 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
1083 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
1084 returnedTag := m.ModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001085 if tag == nil || returnedTag == tag {
1086 deps = append(deps, dep{aModule, returnedTag})
1087 }
1088 }
1089 })
1090 if len(deps) == 1 {
1091 return deps[0].mod, deps[0].tag
1092 } else if len(deps) >= 2 {
1093 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Cross25de6c32019-06-06 14:29:25 -07001094 name, m.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001095 } else {
1096 return nil, nil
1097 }
1098}
1099
Colin Cross25de6c32019-06-06 14:29:25 -07001100func (m *moduleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001101 var deps []Module
Colin Cross25de6c32019-06-06 14:29:25 -07001102 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
1103 if aModule, _ := module.(Module); aModule != nil {
1104 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001105 deps = append(deps, aModule)
1106 }
1107 }
1108 })
1109 return deps
1110}
1111
Colin Cross25de6c32019-06-06 14:29:25 -07001112func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1113 module, _ := m.getDirectDepInternal(name, tag)
1114 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001115}
1116
Colin Cross25de6c32019-06-06 14:29:25 -07001117func (m *moduleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1118 return m.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001119}
1120
Colin Cross25de6c32019-06-06 14:29:25 -07001121func (m *moduleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1122 m.ModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001123}
1124
Colin Cross25de6c32019-06-06 14:29:25 -07001125func (m *moduleContext) VisitDirectDeps(visit func(Module)) {
1126 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1127 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001128 visit(aModule)
1129 }
1130 })
1131}
1132
Colin Cross25de6c32019-06-06 14:29:25 -07001133func (m *moduleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1134 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1135 if aModule := m.validateAndroidModule(module); aModule != nil {
1136 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001137 visit(aModule)
1138 }
1139 }
1140 })
1141}
1142
Colin Cross25de6c32019-06-06 14:29:25 -07001143func (m *moduleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1144 m.ModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001145 // pred
1146 func(module blueprint.Module) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001147 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001148 return pred(aModule)
1149 } else {
1150 return false
1151 }
1152 },
1153 // visit
1154 func(module blueprint.Module) {
1155 visit(module.(Module))
1156 })
1157}
1158
Colin Cross25de6c32019-06-06 14:29:25 -07001159func (m *moduleContext) VisitDepsDepthFirst(visit func(Module)) {
1160 m.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1161 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001162 visit(aModule)
1163 }
1164 })
1165}
1166
Colin Cross25de6c32019-06-06 14:29:25 -07001167func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1168 m.ModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001169 // pred
1170 func(module blueprint.Module) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001171 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001172 return pred(aModule)
1173 } else {
1174 return false
1175 }
1176 },
1177 // visit
1178 func(module blueprint.Module) {
1179 visit(module.(Module))
1180 })
1181}
1182
Colin Cross25de6c32019-06-06 14:29:25 -07001183func (m *moduleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1184 m.ModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001185}
1186
Colin Cross25de6c32019-06-06 14:29:25 -07001187func (m *moduleContext) WalkDeps(visit func(Module, Module) bool) {
1188 m.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1189 childAndroidModule := m.validateAndroidModule(child)
1190 parentAndroidModule := m.validateAndroidModule(parent)
Colin Crossd11fcda2017-10-23 17:59:01 -07001191 if childAndroidModule != nil && parentAndroidModule != nil {
1192 return visit(childAndroidModule, parentAndroidModule)
1193 } else {
1194 return false
1195 }
1196 })
1197}
1198
Colin Cross25de6c32019-06-06 14:29:25 -07001199func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
1200 m.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001201 visit(module.(Module))
1202 })
1203}
1204
Colin Cross25de6c32019-06-06 14:29:25 -07001205func (m *moduleContext) PrimaryModule() Module {
1206 return m.ModuleContext.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001207}
1208
Colin Cross25de6c32019-06-06 14:29:25 -07001209func (m *moduleContext) FinalModule() Module {
1210 return m.ModuleContext.FinalModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001211}
1212
Colin Cross0ea8ba82019-06-06 14:33:29 -07001213func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001214 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001215}
1216
Colin Cross0ea8ba82019-06-06 14:33:29 -07001217func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001218 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001219}
1220
Colin Cross0ea8ba82019-06-06 14:33:29 -07001221func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001222 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001223}
1224
Colin Cross0ea8ba82019-06-06 14:33:29 -07001225func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001226 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001227}
1228
Colin Cross0ea8ba82019-06-06 14:33:29 -07001229func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001230 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001231}
1232
Colin Cross0ea8ba82019-06-06 14:33:29 -07001233func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001234 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001235}
1236
Colin Cross0ea8ba82019-06-06 14:33:29 -07001237func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001238 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001239}
1240
Colin Cross0ea8ba82019-06-06 14:33:29 -07001241func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001242 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001243}
1244
Colin Cross0ea8ba82019-06-06 14:33:29 -07001245func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001246 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001247}
1248
Colin Cross0ea8ba82019-06-06 14:33:29 -07001249func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001250 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001251}
1252
Colin Cross0ea8ba82019-06-06 14:33:29 -07001253func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001254 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001255}
1256
Colin Cross0ea8ba82019-06-06 14:33:29 -07001257func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001258 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001259 return true
1260 }
Colin Cross25de6c32019-06-06 14:29:25 -07001261 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001262}
1263
Colin Cross0ea8ba82019-06-06 14:33:29 -07001264func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001265 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001266}
1267
Colin Cross0ea8ba82019-06-06 14:33:29 -07001268func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001269 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001270}
1271
Colin Cross0ea8ba82019-06-06 14:33:29 -07001272func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001273 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001274}
1275
Colin Cross0ea8ba82019-06-06 14:33:29 -07001276func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001277 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001278}
1279
Colin Cross0ea8ba82019-06-06 14:33:29 -07001280func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001281 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001282}
1283
Colin Cross0ea8ba82019-06-06 14:33:29 -07001284func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001285 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001286}
1287
Colin Cross0ea8ba82019-06-06 14:33:29 -07001288func (b *baseModuleContext) ProductServicesSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001289 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001290}
1291
Jiyong Park5baac542018-08-28 09:55:37 +09001292// Makes this module a platform module, i.e. not specific to soc, device,
1293// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001294func (m *ModuleBase) MakeAsPlatform() {
1295 m.commonProperties.Vendor = boolPtr(false)
1296 m.commonProperties.Proprietary = boolPtr(false)
1297 m.commonProperties.Soc_specific = boolPtr(false)
1298 m.commonProperties.Product_specific = boolPtr(false)
1299 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001300}
1301
Colin Cross4157e882019-06-06 16:57:04 -07001302func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1303 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001304}
1305
Colin Cross25de6c32019-06-06 14:29:25 -07001306func (m *moduleContext) InstallInData() bool {
1307 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001308}
1309
Colin Cross25de6c32019-06-06 14:29:25 -07001310func (m *moduleContext) InstallInSanitizerDir() bool {
1311 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001312}
1313
Colin Cross25de6c32019-06-06 14:29:25 -07001314func (m *moduleContext) InstallInRecovery() bool {
1315 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001316}
1317
Colin Cross25de6c32019-06-06 14:29:25 -07001318func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1319 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001320 return true
1321 }
1322
Colin Cross3607f212018-05-07 15:28:05 -07001323 // We'll need a solution for choosing which of modules with the same name in different
1324 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1325 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001326 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001327 return true
1328 }
1329
Colin Cross25de6c32019-06-06 14:29:25 -07001330 if m.Device() {
1331 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001332 return true
1333 }
1334
Colin Cross25de6c32019-06-06 14:29:25 -07001335 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001336 return true
1337 }
1338 }
1339
1340 return false
1341}
1342
Colin Cross25de6c32019-06-06 14:29:25 -07001343func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001344 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001345 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001346}
1347
Colin Cross25de6c32019-06-06 14:29:25 -07001348func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001349 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001350 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001351}
1352
Colin Cross25de6c32019-06-06 14:29:25 -07001353func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001354 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001355
Colin Cross25de6c32019-06-06 14:29:25 -07001356 fullInstallPath := installPath.Join(m, name)
1357 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001358
Colin Cross25de6c32019-06-06 14:29:25 -07001359 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001360
Colin Cross25de6c32019-06-06 14:29:25 -07001361 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001362
Colin Cross89562dc2016-10-03 17:47:19 -07001363 var implicitDeps, orderOnlyDeps Paths
1364
Colin Cross25de6c32019-06-06 14:29:25 -07001365 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001366 // Installed host modules might be used during the build, depend directly on their
1367 // dependencies so their timestamp is updated whenever their dependency is updated
1368 implicitDeps = deps
1369 } else {
1370 orderOnlyDeps = deps
1371 }
1372
Colin Cross25de6c32019-06-06 14:29:25 -07001373 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001374 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001375 Description: "install " + fullInstallPath.Base(),
1376 Output: fullInstallPath,
1377 Input: srcPath,
1378 Implicits: implicitDeps,
1379 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001380 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001381 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001382
Colin Cross25de6c32019-06-06 14:29:25 -07001383 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001384 }
Colin Cross25de6c32019-06-06 14:29:25 -07001385 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001386 return fullInstallPath
1387}
1388
Colin Cross25de6c32019-06-06 14:29:25 -07001389func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1390 fullInstallPath := installPath.Join(m, name)
1391 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001392
Colin Cross25de6c32019-06-06 14:29:25 -07001393 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001394
Alex Lightfb4353d2019-01-17 13:57:45 -08001395 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1396 if err != nil {
1397 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1398 }
Colin Cross25de6c32019-06-06 14:29:25 -07001399 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001400 Rule: Symlink,
1401 Description: "install symlink " + fullInstallPath.Base(),
1402 Output: fullInstallPath,
1403 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001404 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001405 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001406 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001407 },
1408 })
Colin Cross3854a602016-01-11 12:49:11 -08001409
Colin Cross25de6c32019-06-06 14:29:25 -07001410 m.installFiles = append(m.installFiles, fullInstallPath)
1411 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001412 }
Colin Cross3854a602016-01-11 12:49:11 -08001413 return fullInstallPath
1414}
1415
Jiyong Parkf1194352019-02-25 11:05:47 +09001416// installPath/name -> absPath where absPath might be a path that is available only at runtime
1417// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001418func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1419 fullInstallPath := installPath.Join(m, name)
1420 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001421
Colin Cross25de6c32019-06-06 14:29:25 -07001422 if !m.skipInstall(fullInstallPath) {
1423 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001424 Rule: Symlink,
1425 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1426 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001427 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001428 Args: map[string]string{
1429 "fromPath": absPath,
1430 },
1431 })
1432
Colin Cross25de6c32019-06-06 14:29:25 -07001433 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001434 }
1435 return fullInstallPath
1436}
1437
Colin Cross25de6c32019-06-06 14:29:25 -07001438func (m *moduleContext) CheckbuildFile(srcPath Path) {
1439 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001440}
1441
Colin Cross3f40fa42015-01-30 17:27:36 -08001442type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001443 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001444}
1445
1446func isFileInstaller(m blueprint.Module) bool {
1447 _, ok := m.(fileInstaller)
1448 return ok
1449}
1450
1451func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001452 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001453 return ok
1454}
Colin Crossfce53272015-04-08 11:21:40 -07001455
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001456func findStringInSlice(str string, slice []string) int {
1457 for i, s := range slice {
1458 if s == str {
1459 return i
Colin Crossfce53272015-04-08 11:21:40 -07001460 }
1461 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001462 return -1
1463}
1464
Colin Cross41955e82019-05-29 14:40:35 -07001465// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1466// was not a module reference.
1467func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001468 if len(s) > 1 && s[0] == ':' {
1469 return s[1:]
1470 }
1471 return ""
1472}
1473
Colin Cross41955e82019-05-29 14:40:35 -07001474// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1475// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1476func SrcIsModuleWithTag(s string) (module, tag string) {
1477 if len(s) > 1 && s[0] == ':' {
1478 module = s[1:]
1479 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1480 if module[len(module)-1] == '}' {
1481 tag = module[tagStart+1 : len(module)-1]
1482 module = module[:tagStart]
1483 return module, tag
1484 }
1485 }
1486 return module, ""
1487 }
1488 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001489}
1490
Colin Cross41955e82019-05-29 14:40:35 -07001491type sourceOrOutputDependencyTag struct {
1492 blueprint.BaseDependencyTag
1493 tag string
1494}
1495
1496func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1497 return sourceOrOutputDependencyTag{tag: tag}
1498}
1499
1500var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001501
Colin Cross366938f2017-12-11 16:29:02 -08001502// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1503// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001504//
1505// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001506func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001507 set := make(map[string]bool)
1508
Colin Cross068e0fe2016-12-13 15:23:47 -08001509 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001510 if m, t := SrcIsModuleWithTag(s); m != "" {
1511 if _, found := set[s]; found {
1512 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001513 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001514 set[s] = true
1515 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001516 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001517 }
1518 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001519}
1520
Colin Cross366938f2017-12-11 16:29:02 -08001521// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1522// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001523//
1524// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001525func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1526 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001527 if m, t := SrcIsModuleWithTag(*s); m != "" {
1528 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001529 }
1530 }
1531}
1532
Colin Cross41955e82019-05-29 14:40:35 -07001533// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1534// 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 -08001535type SourceFileProducer interface {
1536 Srcs() Paths
1537}
1538
Colin Cross41955e82019-05-29 14:40:35 -07001539// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1540// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1541// listed in the property.
1542type OutputFileProducer interface {
1543 OutputFiles(tag string) (Paths, error)
1544}
1545
Colin Crossfe17f6f2019-03-28 19:30:56 -07001546type HostToolProvider interface {
1547 HostToolPath() OptionalPath
1548}
1549
Colin Cross27b922f2019-03-04 22:35:41 -08001550// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1551// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001552//
1553// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001554func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1555 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001556}
1557
Colin Cross2fafa3e2019-03-05 12:39:51 -08001558// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1559// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001560//
1561// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001562func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1563 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001564}
1565
1566// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1567// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1568// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001569func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001570 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001571 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001572 }
1573 return OptionalPath{}
1574}
1575
Colin Cross25de6c32019-06-06 14:29:25 -07001576func (m *moduleContext) RequiredModuleNames() []string {
1577 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001578}
1579
Colin Cross25de6c32019-06-06 14:29:25 -07001580func (m *moduleContext) HostRequiredModuleNames() []string {
1581 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001582}
1583
Colin Cross25de6c32019-06-06 14:29:25 -07001584func (m *moduleContext) TargetRequiredModuleNames() []string {
1585 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001586}
1587
Colin Cross25de6c32019-06-06 14:29:25 -07001588func (m *moduleContext) Glob(globPattern string, excludes []string) Paths {
1589 ret, err := m.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001590 if err != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001591 m.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001592 }
Colin Cross25de6c32019-06-06 14:29:25 -07001593 return pathsForModuleSrcFromFullPath(m, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001594}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001595
Colin Cross25de6c32019-06-06 14:29:25 -07001596func (m *moduleContext) GlobFiles(globPattern string, excludes []string) Paths {
1597 ret, err := m.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001598 if err != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001599 m.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001600 }
Colin Cross25de6c32019-06-06 14:29:25 -07001601 return pathsForModuleSrcFromFullPath(m, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001602}
1603
Colin Cross463a90e2015-06-17 14:20:06 -07001604func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001605 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001606}
1607
Colin Cross0875c522017-11-28 17:34:01 -08001608func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001609 return &buildTargetSingleton{}
1610}
1611
Colin Cross87d8b562017-04-25 10:01:55 -07001612func parentDir(dir string) string {
1613 dir, _ = filepath.Split(dir)
1614 return filepath.Clean(dir)
1615}
1616
Colin Cross1f8c52b2015-06-16 16:38:17 -07001617type buildTargetSingleton struct{}
1618
Colin Cross0875c522017-11-28 17:34:01 -08001619func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1620 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001621
Colin Cross0875c522017-11-28 17:34:01 -08001622 mmTarget := func(dir string) WritablePath {
1623 return PathForPhony(ctx,
1624 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001625 }
1626
Colin Cross0875c522017-11-28 17:34:01 -08001627 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001628
Colin Cross0875c522017-11-28 17:34:01 -08001629 ctx.VisitAllModules(func(module Module) {
1630 blueprintDir := module.base().blueprintDir
1631 installTarget := module.base().installTarget
1632 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001633
Colin Cross0875c522017-11-28 17:34:01 -08001634 if checkbuildTarget != nil {
1635 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1636 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1637 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001638
Colin Cross0875c522017-11-28 17:34:01 -08001639 if installTarget != nil {
1640 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001641 }
1642 })
1643
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001644 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001645 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001646 suffix = "-soong"
1647 }
1648
Colin Cross1f8c52b2015-06-16 16:38:17 -07001649 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001650 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001651 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001652 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001653 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001654 })
1655
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001656 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001657 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001658 return
1659 }
1660
Colin Cross0875c522017-11-28 17:34:01 -08001661 sortedKeys := func(m map[string]Paths) []string {
1662 s := make([]string, 0, len(m))
1663 for k := range m {
1664 s = append(s, k)
1665 }
1666 sort.Strings(s)
1667 return s
1668 }
1669
Colin Cross87d8b562017-04-25 10:01:55 -07001670 // Ensure ancestor directories are in modulesInDir
1671 dirs := sortedKeys(modulesInDir)
1672 for _, dir := range dirs {
1673 dir := parentDir(dir)
1674 for dir != "." && dir != "/" {
1675 if _, exists := modulesInDir[dir]; exists {
1676 break
1677 }
1678 modulesInDir[dir] = nil
1679 dir = parentDir(dir)
1680 }
1681 }
1682
1683 // Make directories build their direct subdirectories
1684 dirs = sortedKeys(modulesInDir)
1685 for _, dir := range dirs {
1686 p := parentDir(dir)
1687 if p != "." && p != "/" {
1688 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1689 }
1690 }
1691
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001692 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1693 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1694 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001695 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001696 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001697 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001698 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001699 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001700 // HACK: checkbuild should be an optional build, but force it
1701 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001702 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001703 })
1704 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001705
1706 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1707 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001708 ctx.VisitAllModules(func(module Module) {
1709 if module.Enabled() {
1710 os := module.Target().Os
1711 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001712 }
1713 })
1714
Colin Cross0875c522017-11-28 17:34:01 -08001715 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001716 for os, deps := range osDeps {
1717 var className string
1718
1719 switch os.Class {
1720 case Host:
1721 className = "host"
1722 case HostCross:
1723 className = "host-cross"
1724 case Device:
1725 className = "target"
1726 default:
1727 continue
1728 }
1729
Colin Cross0875c522017-11-28 17:34:01 -08001730 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001731 osClass[className] = append(osClass[className], name)
1732
Colin Cross0875c522017-11-28 17:34:01 -08001733 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001734 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001735 Output: name,
1736 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001737 })
1738 }
1739
1740 // Wrap those into host|host-cross|target phony rules
1741 osClasses := sortedKeys(osClass)
1742 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001743 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001744 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001745 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001746 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001747 })
1748 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001749}
Colin Crossd779da42015-12-17 18:00:23 -08001750
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001751// Collect information for opening IDE project files in java/jdeps.go.
1752type IDEInfo interface {
1753 IDEInfo(ideInfo *IdeInfo)
1754 BaseModuleName() string
1755}
1756
1757// Extract the base module name from the Import name.
1758// Often the Import name has a prefix "prebuilt_".
1759// Remove the prefix explicitly if needed
1760// until we find a better solution to get the Import name.
1761type IDECustomizedModuleName interface {
1762 IDECustomizedModuleName() string
1763}
1764
1765type IdeInfo struct {
1766 Deps []string `json:"dependencies,omitempty"`
1767 Srcs []string `json:"srcs,omitempty"`
1768 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1769 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1770 Jars []string `json:"jars,omitempty"`
1771 Classes []string `json:"class,omitempty"`
1772 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001773 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001774}