Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // 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 Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 18 | "fmt" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 20 | "sort" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 21 | "strings" |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 22 | "text/scanner" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint" |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint/pathtools" |
Colin Cross | fe4bc36 | 2018-09-12 10:02:13 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | var ( |
| 30 | DeviceSharedLibrary = "shared_library" |
| 31 | DeviceStaticLibrary = "static_library" |
| 32 | DeviceExecutable = "executable" |
| 33 | HostSharedLibrary = "host_shared_library" |
| 34 | HostStaticLibrary = "host_static_library" |
| 35 | HostExecutable = "host_executable" |
| 36 | ) |
| 37 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 38 | type BuildParams struct { |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 39 | Rule blueprint.Rule |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 40 | Deps blueprint.Deps |
| 41 | Depfile WritablePath |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 42 | Description string |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 43 | Output WritablePath |
| 44 | Outputs WritablePaths |
| 45 | ImplicitOutput WritablePath |
| 46 | ImplicitOutputs WritablePaths |
| 47 | Input Path |
| 48 | Inputs Paths |
| 49 | Implicit Path |
| 50 | Implicits Paths |
| 51 | OrderOnly Paths |
| 52 | Default bool |
| 53 | Args map[string]string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 56 | type ModuleBuildParams BuildParams |
| 57 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 58 | type androidBaseContext interface { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 59 | Target() Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 60 | TargetPrimary() bool |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 61 | MultiTargets() []Target |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 62 | Arch() Arch |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 63 | Os() OsType |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 64 | Host() bool |
| 65 | Device() bool |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 66 | Darwin() bool |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 67 | Windows() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 68 | Debug() bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 69 | PrimaryArch() bool |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 70 | Platform() bool |
| 71 | DeviceSpecific() bool |
| 72 | SocSpecific() bool |
| 73 | ProductSpecific() bool |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 74 | ProductServicesSpecific() bool |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 75 | AConfig() Config |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 76 | DeviceConfig() DeviceConfig |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 79 | type BaseContext interface { |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 80 | BaseModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 81 | androidBaseContext |
| 82 | } |
| 83 | |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 84 | // BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns |
| 85 | // a Config instead of an interface{}. |
| 86 | type BaseModuleContext interface { |
| 87 | ModuleName() string |
| 88 | ModuleDir() string |
| 89 | Config() Config |
| 90 | |
| 91 | ContainsProperty(name string) bool |
| 92 | Errorf(pos scanner.Position, fmt string, args ...interface{}) |
| 93 | ModuleErrorf(fmt string, args ...interface{}) |
| 94 | PropertyErrorf(property, fmt string, args ...interface{}) |
| 95 | Failed() bool |
| 96 | |
| 97 | // GlobWithDeps returns a list of files that match the specified pattern but do not match any |
| 98 | // of the patterns in excludes. It also adds efficient dependencies to rerun the primary |
| 99 | // builder whenever a file matching the pattern as added or removed, without rerunning if a |
| 100 | // file that does not match the pattern is added to a searched directory. |
| 101 | GlobWithDeps(pattern string, excludes []string) ([]string, error) |
| 102 | |
| 103 | Fs() pathtools.FileSystem |
| 104 | AddNinjaFileDeps(deps ...string) |
| 105 | } |
| 106 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 107 | type ModuleContext interface { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 108 | androidBaseContext |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 109 | BaseModuleContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 110 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 111 | // Deprecated: use ModuleContext.Build instead. |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 112 | ModuleBuild(pctx PackageContext, params ModuleBuildParams) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 113 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 114 | ExpandSources(srcFiles, excludes []string) Paths |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 115 | ExpandSource(srcFile, prop string) Path |
Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 116 | ExpandOptionalSource(srcFile *string, prop string) OptionalPath |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 117 | ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 118 | Glob(globPattern string, excludes []string) Paths |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 119 | GlobFiles(globPattern string, excludes []string) Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 120 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 121 | InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
| 122 | InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 123 | InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 124 | CheckbuildFile(srcPath Path) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 125 | |
| 126 | AddMissingDependencies(deps []string) |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 127 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 128 | InstallInData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 129 | InstallInSanitizerDir() bool |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 130 | InstallInRecovery() bool |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 131 | |
| 132 | RequiredModuleNames() []string |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 133 | |
| 134 | // android.ModuleContext methods |
| 135 | // These are duplicated instead of embedded so that can eventually be wrapped to take an |
| 136 | // android.Module instead of a blueprint.Module |
| 137 | OtherModuleName(m blueprint.Module) string |
| 138 | OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) |
| 139 | OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag |
| 140 | |
| 141 | GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module |
| 142 | GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) |
| 143 | |
| 144 | ModuleSubDir() string |
| 145 | |
Colin Cross | 35143d0 | 2017-11-16 00:11:20 -0800 | [diff] [blame] | 146 | VisitDirectDepsBlueprint(visit func(blueprint.Module)) |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 147 | VisitDirectDeps(visit func(Module)) |
Colin Cross | ee6143c | 2017-12-30 17:54:27 -0800 | [diff] [blame] | 148 | VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 149 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 150 | // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 151 | VisitDepsDepthFirst(visit func(Module)) |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 152 | // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 153 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
| 154 | WalkDeps(visit func(Module, Module) bool) |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 155 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 156 | Variable(pctx PackageContext, name, value string) |
| 157 | Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 158 | // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string, |
| 159 | // and performs more verification. |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 160 | Build(pctx PackageContext, params BuildParams) |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 161 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 162 | PrimaryModule() Module |
| 163 | FinalModule() Module |
| 164 | VisitAllModuleVariants(visit func(Module)) |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 165 | |
| 166 | GetMissingDependencies() []string |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 167 | Namespace() blueprint.Namespace |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 170 | type Module interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 171 | blueprint.Module |
| 172 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 173 | // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions, |
| 174 | // but GenerateAndroidBuildActions also has access to Android-specific information. |
| 175 | // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 176 | GenerateAndroidBuildActions(ModuleContext) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 177 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 178 | DepsMutator(BottomUpMutatorContext) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 179 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 180 | base() *ModuleBase |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 181 | Enabled() bool |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 182 | Target() Target |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 183 | InstallInData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 184 | InstallInSanitizerDir() bool |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 185 | InstallInRecovery() bool |
Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 186 | SkipInstall() |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 187 | ExportedToMake() bool |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 188 | |
| 189 | AddProperties(props ...interface{}) |
| 190 | GetProperties() []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 191 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 192 | BuildParamsForTests() []BuildParams |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 195 | type nameProperties struct { |
| 196 | // The name of the module. Must be unique across all modules. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 197 | Name *string |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | type commonProperties struct { |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 201 | // emit build rules for this module |
| 202 | Enabled *bool `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 203 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 204 | // control whether this module compiles for 32-bit, 64-bit, or both. Possible values |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 205 | // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both |
| 206 | // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit |
| 207 | // platform |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 208 | Compile_multilib *string `android:"arch_variant"` |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 209 | |
| 210 | Target struct { |
| 211 | Host struct { |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 212 | Compile_multilib *string |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 213 | } |
| 214 | Android struct { |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 215 | Compile_multilib *string |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 219 | UseTargetVariants bool `blueprint:"mutated"` |
| 220 | Default_multilib string `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 221 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 222 | // whether this is a proprietary vendor module, and should be installed into /vendor |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 223 | Proprietary *bool |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 224 | |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 225 | // vendor who owns this module |
Dan Willemsen | efac4a8 | 2017-07-18 19:42:09 -0700 | [diff] [blame] | 226 | Owner *string |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 227 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 228 | // whether this module is specific to an SoC (System-On-a-Chip). When set to true, |
| 229 | // it is installed into /vendor (or /system/vendor if vendor partition does not exist). |
| 230 | // Use `soc_specific` instead for better meaning. |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 231 | Vendor *bool |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 232 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 233 | // whether this module is specific to an SoC (System-On-a-Chip). When set to true, |
| 234 | // it is installed into /vendor (or /system/vendor if vendor partition does not exist). |
| 235 | Soc_specific *bool |
| 236 | |
| 237 | // whether this module is specific to a device, not only for SoC, but also for off-chip |
| 238 | // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition |
| 239 | // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist). |
| 240 | // This implies `soc_specific:true`. |
| 241 | Device_specific *bool |
| 242 | |
| 243 | // whether this module is specific to a software configuration of a product (e.g. country, |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 244 | // network operator, etc). When set to true, it is installed into /product (or |
| 245 | // /system/product if product partition does not exist). |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 246 | Product_specific *bool |
| 247 | |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 248 | // whether this module provides services owned by the OS provider to the core platform. When set |
Dario Freni | 95cf767 | 2018-08-17 00:57:57 +0100 | [diff] [blame] | 249 | // to true, it is installed into /product_services (or /system/product_services if |
| 250 | // product_services partition does not exist). |
| 251 | Product_services_specific *bool |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 252 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 253 | // Whether this module is installed to recovery partition |
| 254 | Recovery *bool |
| 255 | |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 256 | // init.rc files to be installed if this module is installed |
| 257 | Init_rc []string |
| 258 | |
Steven Moreland | 57a23d2 | 2018-04-04 15:42:19 -0700 | [diff] [blame] | 259 | // VINTF manifest fragments to be installed if this module is installed |
| 260 | Vintf_fragments []string |
| 261 | |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 262 | // names of other modules to install if this module is installed |
Colin Cross | c602b7d | 2017-05-05 13:36:36 -0700 | [diff] [blame] | 263 | Required []string `android:"arch_variant"` |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 264 | |
Colin Cross | 5aac362 | 2017-08-31 15:07:09 -0700 | [diff] [blame] | 265 | // relative path to a file to include in the list of notices for the device |
| 266 | Notice *string |
| 267 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 268 | // Set by TargetMutator |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 269 | CompileTarget Target `blueprint:"mutated"` |
| 270 | CompileMultiTargets []Target `blueprint:"mutated"` |
| 271 | CompilePrimary bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 272 | |
| 273 | // Set by InitAndroidModule |
| 274 | HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 275 | ArchSpecific bool `blueprint:"mutated"` |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 276 | |
| 277 | SkipInstall bool `blueprint:"mutated"` |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 278 | |
| 279 | NamespaceExportedToMake bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | type hostAndDeviceProperties struct { |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 283 | Host_supported *bool |
| 284 | Device_supported *bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 287 | type Multilib string |
| 288 | |
| 289 | const ( |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 290 | MultilibBoth Multilib = "both" |
| 291 | MultilibFirst Multilib = "first" |
| 292 | MultilibCommon Multilib = "common" |
| 293 | MultilibCommonFirst Multilib = "common_first" |
| 294 | MultilibDefault Multilib = "" |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 295 | ) |
| 296 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 297 | type HostOrDeviceSupported int |
| 298 | |
| 299 | const ( |
| 300 | _ HostOrDeviceSupported = iota |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 301 | |
| 302 | // Host and HostCross are built by default. Device is not supported. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 303 | HostSupported |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 304 | |
| 305 | // Host is built by default. HostCross and Device are not supported. |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 306 | HostSupportedNoCross |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 307 | |
| 308 | // Device is built by default. Host and HostCross are not supported. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 309 | DeviceSupported |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 310 | |
| 311 | // Device is built by default. Host and HostCross are supported. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 312 | HostAndDeviceSupported |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 313 | |
| 314 | // Host, HostCross, and Device are built by default. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 315 | HostAndDeviceDefault |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 316 | |
| 317 | // Nothing is supported. This is not exposed to the user, but used to mark a |
| 318 | // host only module as unsupported when the module type is not supported on |
| 319 | // the host OS. E.g. benchmarks are supported on Linux but not Darwin. |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 320 | NeitherHostNorDeviceSupported |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 321 | ) |
| 322 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 323 | type moduleKind int |
| 324 | |
| 325 | const ( |
| 326 | platformModule moduleKind = iota |
| 327 | deviceSpecificModule |
| 328 | socSpecificModule |
| 329 | productSpecificModule |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 330 | productServicesSpecificModule |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 331 | ) |
| 332 | |
| 333 | func (k moduleKind) String() string { |
| 334 | switch k { |
| 335 | case platformModule: |
| 336 | return "platform" |
| 337 | case deviceSpecificModule: |
| 338 | return "device-specific" |
| 339 | case socSpecificModule: |
| 340 | return "soc-specific" |
| 341 | case productSpecificModule: |
| 342 | return "product-specific" |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 343 | case productServicesSpecificModule: |
| 344 | return "productservices-specific" |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 345 | default: |
| 346 | panic(fmt.Errorf("unknown module kind %d", k)) |
| 347 | } |
| 348 | } |
| 349 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 350 | func InitAndroidModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 351 | base := m.base() |
| 352 | base.module = m |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 353 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 354 | m.AddProperties( |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 355 | &base.nameProperties, |
| 356 | &base.commonProperties, |
| 357 | &base.variableProperties) |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 358 | base.customizableProperties = m.GetProperties() |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 361 | func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { |
| 362 | InitAndroidModule(m) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 363 | |
| 364 | base := m.base() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 365 | base.commonProperties.HostOrDeviceSupported = hod |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 366 | base.commonProperties.Default_multilib = string(defaultMultilib) |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 367 | base.commonProperties.ArchSpecific = true |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 368 | base.commonProperties.UseTargetVariants = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 369 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 370 | switch hod { |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 371 | case HostAndDeviceSupported, HostAndDeviceDefault: |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 372 | m.AddProperties(&base.hostAndDeviceProperties) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 375 | InitArchModule(m) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 378 | func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { |
| 379 | InitAndroidArchModule(m, hod, defaultMultilib) |
| 380 | m.base().commonProperties.UseTargetVariants = false |
| 381 | } |
| 382 | |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 383 | // A ModuleBase object contains the properties that are common to all Android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 384 | // modules. It should be included as an anonymous field in every module |
| 385 | // struct definition. InitAndroidModule should then be called from the module's |
| 386 | // factory function, and the return values from InitAndroidModule should be |
| 387 | // returned from the factory function. |
| 388 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 389 | // The ModuleBase type is responsible for implementing the GenerateBuildActions |
| 390 | // method to support the blueprint.Module interface. This method will then call |
| 391 | // the module's GenerateAndroidBuildActions method once for each build variant |
| 392 | // that is to be built. GenerateAndroidBuildActions is passed a |
| 393 | // AndroidModuleContext rather than the usual blueprint.ModuleContext. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 394 | // AndroidModuleContext exposes extra functionality specific to the Android build |
| 395 | // system including details about the particular build variant that is to be |
| 396 | // generated. |
| 397 | // |
| 398 | // For example: |
| 399 | // |
| 400 | // import ( |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 401 | // "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 402 | // ) |
| 403 | // |
| 404 | // type myModule struct { |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 405 | // android.ModuleBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 406 | // properties struct { |
| 407 | // MyProperty string |
| 408 | // } |
| 409 | // } |
| 410 | // |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 411 | // func NewMyModule() android.Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 412 | // m := &myModule{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 413 | // m.AddProperties(&m.properties) |
| 414 | // android.InitAndroidModule(m) |
| 415 | // return m |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 416 | // } |
| 417 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 418 | // func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 419 | // // Get the CPU architecture for the current build variant. |
| 420 | // variantArch := ctx.Arch() |
| 421 | // |
| 422 | // // ... |
| 423 | // } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 424 | type ModuleBase struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 425 | // Putting the curiously recurring thing pointing to the thing that contains |
| 426 | // the thing pattern to good use. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 427 | // TODO: remove this |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 428 | module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 429 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 430 | nameProperties nameProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 431 | commonProperties commonProperties |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 432 | variableProperties variableProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 433 | hostAndDeviceProperties hostAndDeviceProperties |
| 434 | generalProperties []interface{} |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 435 | archProperties []interface{} |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 436 | customizableProperties []interface{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 437 | |
| 438 | noAddressSanitizer bool |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 439 | installFiles Paths |
| 440 | checkbuildFiles Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 441 | |
| 442 | // Used by buildTargetSingleton to create checkbuild and per-directory build targets |
| 443 | // Only set on the final variant of each module |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 444 | installTarget WritablePath |
| 445 | checkbuildTarget WritablePath |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 446 | blueprintDir string |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 447 | |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 448 | hooks hooks |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 449 | |
| 450 | registerProps []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 451 | |
| 452 | // For tests |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 453 | buildParams []BuildParams |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 454 | |
| 455 | prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | func (a *ModuleBase) AddProperties(props ...interface{}) { |
| 459 | a.registerProps = append(a.registerProps, props...) |
| 460 | } |
| 461 | |
| 462 | func (a *ModuleBase) GetProperties() []interface{} { |
| 463 | return a.registerProps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 466 | func (a *ModuleBase) BuildParamsForTests() []BuildParams { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 467 | return a.buildParams |
| 468 | } |
| 469 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 470 | func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) { |
| 471 | a.prefer32 = prefer32 |
| 472 | } |
| 473 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 474 | // Name returns the name of the module. It may be overridden by individual module types, for |
| 475 | // example prebuilts will prepend prebuilt_ to the name. |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 476 | func (a *ModuleBase) Name() string { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 477 | return String(a.nameProperties.Name) |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 480 | // BaseModuleName returns the name of the module as specified in the blueprints file. |
| 481 | func (a *ModuleBase) BaseModuleName() string { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 482 | return String(a.nameProperties.Name) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 485 | func (a *ModuleBase) base() *ModuleBase { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 486 | return a |
| 487 | } |
| 488 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 489 | func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 490 | a.commonProperties.CompileTarget = target |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 491 | a.commonProperties.CompileMultiTargets = multiTargets |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 492 | a.commonProperties.CompilePrimary = primary |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 495 | func (a *ModuleBase) Target() Target { |
| 496 | return a.commonProperties.CompileTarget |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 499 | func (a *ModuleBase) TargetPrimary() bool { |
| 500 | return a.commonProperties.CompilePrimary |
| 501 | } |
| 502 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 503 | func (a *ModuleBase) MultiTargets() []Target { |
| 504 | return a.commonProperties.CompileMultiTargets |
| 505 | } |
| 506 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 507 | func (a *ModuleBase) Os() OsType { |
| 508 | return a.Target().Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 511 | func (a *ModuleBase) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 512 | return a.Os().Class == Host || a.Os().Class == HostCross |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 515 | func (a *ModuleBase) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 516 | return a.Target().Arch |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 519 | func (a *ModuleBase) ArchSpecific() bool { |
| 520 | return a.commonProperties.ArchSpecific |
| 521 | } |
| 522 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 523 | func (a *ModuleBase) OsClassSupported() []OsClass { |
| 524 | switch a.commonProperties.HostOrDeviceSupported { |
| 525 | case HostSupported: |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 526 | return []OsClass{Host, HostCross} |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 527 | case HostSupportedNoCross: |
| 528 | return []OsClass{Host} |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 529 | case DeviceSupported: |
| 530 | return []OsClass{Device} |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 531 | case HostAndDeviceSupported, HostAndDeviceDefault: |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 532 | var supported []OsClass |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 533 | if Bool(a.hostAndDeviceProperties.Host_supported) || |
| 534 | (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault && |
| 535 | a.hostAndDeviceProperties.Host_supported == nil) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 536 | supported = append(supported, Host, HostCross) |
| 537 | } |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 538 | if a.hostAndDeviceProperties.Device_supported == nil || |
| 539 | *a.hostAndDeviceProperties.Device_supported { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 540 | supported = append(supported, Device) |
| 541 | } |
| 542 | return supported |
| 543 | default: |
| 544 | return nil |
| 545 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 548 | func (a *ModuleBase) DeviceSupported() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 549 | return a.commonProperties.HostOrDeviceSupported == DeviceSupported || |
| 550 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 551 | (a.hostAndDeviceProperties.Device_supported == nil || |
| 552 | *a.hostAndDeviceProperties.Device_supported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 555 | func (a *ModuleBase) Platform() bool { |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 556 | return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | func (a *ModuleBase) DeviceSpecific() bool { |
| 560 | return Bool(a.commonProperties.Device_specific) |
| 561 | } |
| 562 | |
| 563 | func (a *ModuleBase) SocSpecific() bool { |
| 564 | return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific) |
| 565 | } |
| 566 | |
| 567 | func (a *ModuleBase) ProductSpecific() bool { |
| 568 | return Bool(a.commonProperties.Product_specific) |
| 569 | } |
| 570 | |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 571 | func (a *ModuleBase) ProductServicesSpecific() bool { |
Dario Freni | 95cf767 | 2018-08-17 00:57:57 +0100 | [diff] [blame] | 572 | return Bool(a.commonProperties.Product_services_specific) |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 573 | } |
| 574 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 575 | func (a *ModuleBase) Enabled() bool { |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 576 | if a.commonProperties.Enabled == nil { |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 577 | return !a.Os().DefaultDisabled |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 578 | } |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 579 | return *a.commonProperties.Enabled |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 580 | } |
| 581 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 582 | func (a *ModuleBase) SkipInstall() { |
| 583 | a.commonProperties.SkipInstall = true |
| 584 | } |
| 585 | |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 586 | func (a *ModuleBase) ExportedToMake() bool { |
| 587 | return a.commonProperties.NamespaceExportedToMake |
| 588 | } |
| 589 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 590 | func (a *ModuleBase) computeInstallDeps( |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 591 | ctx blueprint.ModuleContext) Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 592 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 593 | result := Paths{} |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 594 | // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 595 | ctx.VisitDepsDepthFirstIf(isFileInstaller, |
| 596 | func(m blueprint.Module) { |
| 597 | fileInstaller := m.(fileInstaller) |
| 598 | files := fileInstaller.filesToInstall() |
| 599 | result = append(result, files...) |
| 600 | }) |
| 601 | |
| 602 | return result |
| 603 | } |
| 604 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 605 | func (a *ModuleBase) filesToInstall() Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 606 | return a.installFiles |
| 607 | } |
| 608 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 609 | func (p *ModuleBase) NoAddressSanitizer() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 610 | return p.noAddressSanitizer |
| 611 | } |
| 612 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 613 | func (p *ModuleBase) InstallInData() bool { |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 614 | return false |
| 615 | } |
| 616 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 617 | func (p *ModuleBase) InstallInSanitizerDir() bool { |
| 618 | return false |
| 619 | } |
| 620 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 621 | func (p *ModuleBase) InstallInRecovery() bool { |
| 622 | return Bool(p.commonProperties.Recovery) |
| 623 | } |
| 624 | |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 625 | func (a *ModuleBase) Owner() string { |
| 626 | return String(a.commonProperties.Owner) |
| 627 | } |
| 628 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 629 | func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 630 | allInstalledFiles := Paths{} |
| 631 | allCheckbuildFiles := Paths{} |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 632 | ctx.VisitAllModuleVariants(func(module Module) { |
| 633 | a := module.base() |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 634 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 635 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 636 | }) |
| 637 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 638 | var deps Paths |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 639 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 640 | namespacePrefix := ctx.Namespace().(*Namespace).id |
| 641 | if namespacePrefix != "" { |
| 642 | namespacePrefix = namespacePrefix + "-" |
| 643 | } |
| 644 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 645 | if len(allInstalledFiles) > 0 { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 646 | name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install") |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 647 | ctx.Build(pctx, BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 648 | Rule: blueprint.Phony, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 649 | Output: name, |
| 650 | Implicits: allInstalledFiles, |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 651 | Default: !ctx.Config().EmbeddedInMake(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 652 | }) |
| 653 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 654 | a.installTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | if len(allCheckbuildFiles) > 0 { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 658 | name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild") |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 659 | ctx.Build(pctx, BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 660 | Rule: blueprint.Phony, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 661 | Output: name, |
| 662 | Implicits: allCheckbuildFiles, |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 663 | }) |
| 664 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 665 | a.checkbuildTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | if len(deps) > 0 { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 669 | suffix := "" |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 670 | if ctx.Config().EmbeddedInMake() { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 671 | suffix = "-soong" |
| 672 | } |
| 673 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 674 | name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 675 | ctx.Build(pctx, BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 676 | Rule: blueprint.Phony, |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 677 | Outputs: []WritablePath{name}, |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 678 | Implicits: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 679 | }) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 680 | |
| 681 | a.blueprintDir = ctx.ModuleDir() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 685 | func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind { |
| 686 | var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific) |
| 687 | var deviceSpecific = Bool(a.commonProperties.Device_specific) |
| 688 | var productSpecific = Bool(a.commonProperties.Product_specific) |
Dario Freni | 95cf767 | 2018-08-17 00:57:57 +0100 | [diff] [blame] | 689 | var productServicesSpecific = Bool(a.commonProperties.Product_services_specific) |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 690 | |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 691 | msg := "conflicting value set here" |
| 692 | if socSpecific && deviceSpecific { |
| 693 | ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.") |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 694 | if Bool(a.commonProperties.Vendor) { |
| 695 | ctx.PropertyErrorf("vendor", msg) |
| 696 | } |
| 697 | if Bool(a.commonProperties.Proprietary) { |
| 698 | ctx.PropertyErrorf("proprietary", msg) |
| 699 | } |
| 700 | if Bool(a.commonProperties.Soc_specific) { |
| 701 | ctx.PropertyErrorf("soc_specific", msg) |
| 702 | } |
| 703 | } |
| 704 | |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 705 | if productSpecific && productServicesSpecific { |
| 706 | ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.") |
| 707 | ctx.PropertyErrorf("product_services_specific", msg) |
| 708 | } |
| 709 | |
| 710 | if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) { |
| 711 | if productSpecific { |
| 712 | ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.") |
| 713 | } else { |
| 714 | ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.") |
| 715 | } |
| 716 | if deviceSpecific { |
| 717 | ctx.PropertyErrorf("device_specific", msg) |
| 718 | } else { |
| 719 | if Bool(a.commonProperties.Vendor) { |
| 720 | ctx.PropertyErrorf("vendor", msg) |
| 721 | } |
| 722 | if Bool(a.commonProperties.Proprietary) { |
| 723 | ctx.PropertyErrorf("proprietary", msg) |
| 724 | } |
| 725 | if Bool(a.commonProperties.Soc_specific) { |
| 726 | ctx.PropertyErrorf("soc_specific", msg) |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 731 | if productSpecific { |
| 732 | return productSpecificModule |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 733 | } else if productServicesSpecific { |
| 734 | return productServicesSpecificModule |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 735 | } else if deviceSpecific { |
| 736 | return deviceSpecificModule |
| 737 | } else if socSpecific { |
| 738 | return socSpecificModule |
| 739 | } else { |
| 740 | return platformModule |
| 741 | } |
| 742 | } |
| 743 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 744 | func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 745 | return androidBaseContextImpl{ |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 746 | target: a.commonProperties.CompileTarget, |
| 747 | targetPrimary: a.commonProperties.CompilePrimary, |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 748 | multiTargets: a.commonProperties.CompileMultiTargets, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 749 | kind: determineModuleKind(a, ctx), |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 750 | config: ctx.Config().(Config), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 751 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 752 | } |
| 753 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 754 | func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) { |
| 755 | ctx := &androidModuleContext{ |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 756 | module: a.module, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 757 | ModuleContext: blueprintCtx, |
| 758 | androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx), |
| 759 | installDeps: a.computeInstallDeps(blueprintCtx), |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 760 | installFiles: a.installFiles, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 761 | missingDeps: blueprintCtx.GetMissingDependencies(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 762 | } |
| 763 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 764 | desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " " |
| 765 | var suffix []string |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 766 | if ctx.Os().Class != Device && ctx.Os().Class != Generic { |
| 767 | suffix = append(suffix, ctx.Os().String()) |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 768 | } |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 769 | if !ctx.PrimaryArch() { |
| 770 | suffix = append(suffix, ctx.Arch().ArchType.String()) |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | ctx.Variable(pctx, "moduleDesc", desc) |
| 774 | |
| 775 | s := "" |
| 776 | if len(suffix) > 0 { |
| 777 | s = " [" + strings.Join(suffix, " ") + "]" |
| 778 | } |
| 779 | ctx.Variable(pctx, "moduleDescSuffix", s) |
| 780 | |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 781 | if a.Enabled() { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 782 | a.module.GenerateAndroidBuildActions(ctx) |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 783 | if ctx.Failed() { |
| 784 | return |
| 785 | } |
| 786 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 787 | a.installFiles = append(a.installFiles, ctx.installFiles...) |
| 788 | a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 789 | } |
| 790 | |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 791 | if a == ctx.FinalModule().(Module).base() { |
| 792 | a.generateModuleTarget(ctx) |
| 793 | if ctx.Failed() { |
| 794 | return |
| 795 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 796 | } |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 797 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 798 | a.buildParams = ctx.buildParams |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 799 | } |
| 800 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 801 | type androidBaseContextImpl struct { |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 802 | target Target |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 803 | multiTargets []Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 804 | targetPrimary bool |
| 805 | debug bool |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 806 | kind moduleKind |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 807 | config Config |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 810 | type androidModuleContext struct { |
| 811 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 812 | androidBaseContextImpl |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 813 | installDeps Paths |
| 814 | installFiles Paths |
| 815 | checkbuildFiles Paths |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 816 | missingDeps []string |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 817 | module Module |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 818 | |
| 819 | // For tests |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 820 | buildParams []BuildParams |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 821 | } |
| 822 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 823 | func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 824 | a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 825 | Rule: ErrorRule, |
| 826 | Description: desc, |
| 827 | Outputs: outputs, |
| 828 | Optional: true, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 829 | Args: map[string]string{ |
| 830 | "error": err.Error(), |
| 831 | }, |
| 832 | }) |
| 833 | return |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 834 | } |
| 835 | |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 836 | func (a *androidModuleContext) Config() Config { |
| 837 | return a.ModuleContext.Config().(Config) |
| 838 | } |
| 839 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 840 | func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) { |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 841 | a.Build(pctx, BuildParams(params)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 844 | func convertBuildParams(params BuildParams) blueprint.BuildParams { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 845 | bparams := blueprint.BuildParams{ |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 846 | Rule: params.Rule, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 847 | Description: params.Description, |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 848 | Deps: params.Deps, |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 849 | Outputs: params.Outputs.Strings(), |
| 850 | ImplicitOutputs: params.ImplicitOutputs.Strings(), |
| 851 | Inputs: params.Inputs.Strings(), |
| 852 | Implicits: params.Implicits.Strings(), |
| 853 | OrderOnly: params.OrderOnly.Strings(), |
| 854 | Args: params.Args, |
| 855 | Optional: !params.Default, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 858 | if params.Depfile != nil { |
| 859 | bparams.Depfile = params.Depfile.String() |
| 860 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 861 | if params.Output != nil { |
| 862 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 863 | } |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 864 | if params.ImplicitOutput != nil { |
| 865 | bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String()) |
| 866 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 867 | if params.Input != nil { |
| 868 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 869 | } |
| 870 | if params.Implicit != nil { |
| 871 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 872 | } |
| 873 | |
Colin Cross | fe4bc36 | 2018-09-12 10:02:13 -0700 | [diff] [blame] | 874 | bparams.Outputs = proptools.NinjaEscape(bparams.Outputs) |
| 875 | bparams.ImplicitOutputs = proptools.NinjaEscape(bparams.ImplicitOutputs) |
| 876 | bparams.Inputs = proptools.NinjaEscape(bparams.Inputs) |
| 877 | bparams.Implicits = proptools.NinjaEscape(bparams.Implicits) |
| 878 | bparams.OrderOnly = proptools.NinjaEscape(bparams.OrderOnly) |
| 879 | bparams.Depfile = proptools.NinjaEscape([]string{bparams.Depfile})[0] |
| 880 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 881 | return bparams |
| 882 | } |
| 883 | |
| 884 | func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) { |
| 885 | a.ModuleContext.Variable(pctx.PackageContext, name, value) |
| 886 | } |
| 887 | |
| 888 | func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams, |
| 889 | argNames ...string) blueprint.Rule { |
| 890 | |
| 891 | return a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...) |
| 892 | } |
| 893 | |
| 894 | func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) { |
| 895 | if a.config.captureBuild { |
| 896 | a.buildParams = append(a.buildParams, params) |
| 897 | } |
| 898 | |
| 899 | bparams := convertBuildParams(params) |
| 900 | |
| 901 | if bparams.Description != "" { |
| 902 | bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}" |
| 903 | } |
| 904 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 905 | if a.missingDeps != nil { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 906 | a.ninjaError(bparams.Description, bparams.Outputs, |
| 907 | fmt.Errorf("module %s missing dependencies: %s\n", |
| 908 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 909 | return |
| 910 | } |
| 911 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 912 | a.ModuleContext.Build(pctx.PackageContext, bparams) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 915 | func (a *androidModuleContext) GetMissingDependencies() []string { |
| 916 | return a.missingDeps |
| 917 | } |
| 918 | |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 919 | func (a *androidModuleContext) AddMissingDependencies(deps []string) { |
| 920 | if deps != nil { |
| 921 | a.missingDeps = append(a.missingDeps, deps...) |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 922 | a.missingDeps = FirstUniqueStrings(a.missingDeps) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 926 | func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module { |
| 927 | aModule, _ := module.(Module) |
| 928 | if aModule == nil { |
| 929 | a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule)) |
| 930 | return nil |
| 931 | } |
| 932 | |
| 933 | if !aModule.Enabled() { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 934 | if a.Config().AllowMissingDependencies() { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 935 | a.AddMissingDependencies([]string{a.OtherModuleName(aModule)}) |
| 936 | } else { |
| 937 | a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule)) |
| 938 | } |
| 939 | return nil |
| 940 | } |
| 941 | |
| 942 | return aModule |
| 943 | } |
| 944 | |
Colin Cross | 35143d0 | 2017-11-16 00:11:20 -0800 | [diff] [blame] | 945 | func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { |
| 946 | a.ModuleContext.VisitDirectDeps(visit) |
| 947 | } |
| 948 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 949 | func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) { |
| 950 | a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) { |
| 951 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 952 | visit(aModule) |
| 953 | } |
| 954 | }) |
| 955 | } |
| 956 | |
Colin Cross | ee6143c | 2017-12-30 17:54:27 -0800 | [diff] [blame] | 957 | func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) { |
| 958 | a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) { |
| 959 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 960 | if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag { |
| 961 | visit(aModule) |
| 962 | } |
| 963 | } |
| 964 | }) |
| 965 | } |
| 966 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 967 | func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { |
| 968 | a.ModuleContext.VisitDirectDepsIf( |
| 969 | // pred |
| 970 | func(module blueprint.Module) bool { |
| 971 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 972 | return pred(aModule) |
| 973 | } else { |
| 974 | return false |
| 975 | } |
| 976 | }, |
| 977 | // visit |
| 978 | func(module blueprint.Module) { |
| 979 | visit(module.(Module)) |
| 980 | }) |
| 981 | } |
| 982 | |
| 983 | func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) { |
| 984 | a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) { |
| 985 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 986 | visit(aModule) |
| 987 | } |
| 988 | }) |
| 989 | } |
| 990 | |
| 991 | func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) { |
| 992 | a.ModuleContext.VisitDepsDepthFirstIf( |
| 993 | // pred |
| 994 | func(module blueprint.Module) bool { |
| 995 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 996 | return pred(aModule) |
| 997 | } else { |
| 998 | return false |
| 999 | } |
| 1000 | }, |
| 1001 | // visit |
| 1002 | func(module blueprint.Module) { |
| 1003 | visit(module.(Module)) |
| 1004 | }) |
| 1005 | } |
| 1006 | |
| 1007 | func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) { |
| 1008 | a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool { |
| 1009 | childAndroidModule := a.validateAndroidModule(child) |
| 1010 | parentAndroidModule := a.validateAndroidModule(parent) |
| 1011 | if childAndroidModule != nil && parentAndroidModule != nil { |
| 1012 | return visit(childAndroidModule, parentAndroidModule) |
| 1013 | } else { |
| 1014 | return false |
| 1015 | } |
| 1016 | }) |
| 1017 | } |
| 1018 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1019 | func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) { |
| 1020 | a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) { |
| 1021 | visit(module.(Module)) |
| 1022 | }) |
| 1023 | } |
| 1024 | |
| 1025 | func (a *androidModuleContext) PrimaryModule() Module { |
| 1026 | return a.ModuleContext.PrimaryModule().(Module) |
| 1027 | } |
| 1028 | |
| 1029 | func (a *androidModuleContext) FinalModule() Module { |
| 1030 | return a.ModuleContext.FinalModule().(Module) |
| 1031 | } |
| 1032 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1033 | func (a *androidBaseContextImpl) Target() Target { |
| 1034 | return a.target |
| 1035 | } |
| 1036 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1037 | func (a *androidBaseContextImpl) TargetPrimary() bool { |
| 1038 | return a.targetPrimary |
| 1039 | } |
| 1040 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame^] | 1041 | func (a *androidBaseContextImpl) MultiTargets() []Target { |
| 1042 | return a.multiTargets |
| 1043 | } |
| 1044 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1045 | func (a *androidBaseContextImpl) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1046 | return a.target.Arch |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1049 | func (a *androidBaseContextImpl) Os() OsType { |
| 1050 | return a.target.Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1053 | func (a *androidBaseContextImpl) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1054 | return a.target.Os.Class == Host || a.target.Os.Class == HostCross |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | func (a *androidBaseContextImpl) Device() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1058 | return a.target.Os.Class == Device |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1061 | func (a *androidBaseContextImpl) Darwin() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1062 | return a.target.Os == Darwin |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 1065 | func (a *androidBaseContextImpl) Windows() bool { |
| 1066 | return a.target.Os == Windows |
| 1067 | } |
| 1068 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1069 | func (a *androidBaseContextImpl) Debug() bool { |
| 1070 | return a.debug |
| 1071 | } |
| 1072 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 1073 | func (a *androidBaseContextImpl) PrimaryArch() bool { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1074 | if len(a.config.Targets[a.target.Os.Class]) <= 1 { |
| 1075 | return true |
| 1076 | } |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 1077 | return a.target.Arch.ArchType == a.config.Targets[a.target.Os.Class][0].Arch.ArchType |
| 1078 | } |
| 1079 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 1080 | func (a *androidBaseContextImpl) AConfig() Config { |
| 1081 | return a.config |
| 1082 | } |
| 1083 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 1084 | func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig { |
| 1085 | return DeviceConfig{a.config.deviceConfig} |
| 1086 | } |
| 1087 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1088 | func (a *androidBaseContextImpl) Platform() bool { |
| 1089 | return a.kind == platformModule |
| 1090 | } |
| 1091 | |
| 1092 | func (a *androidBaseContextImpl) DeviceSpecific() bool { |
| 1093 | return a.kind == deviceSpecificModule |
| 1094 | } |
| 1095 | |
| 1096 | func (a *androidBaseContextImpl) SocSpecific() bool { |
| 1097 | return a.kind == socSpecificModule |
| 1098 | } |
| 1099 | |
| 1100 | func (a *androidBaseContextImpl) ProductSpecific() bool { |
| 1101 | return a.kind == productSpecificModule |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1104 | func (a *androidBaseContextImpl) ProductServicesSpecific() bool { |
| 1105 | return a.kind == productServicesSpecificModule |
| 1106 | } |
| 1107 | |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 1108 | // Makes this module a platform module, i.e. not specific to soc, device, |
| 1109 | // product, or product_services. |
| 1110 | func (a *ModuleBase) MakeAsPlatform() { |
| 1111 | a.commonProperties.Vendor = boolPtr(false) |
| 1112 | a.commonProperties.Proprietary = boolPtr(false) |
| 1113 | a.commonProperties.Soc_specific = boolPtr(false) |
| 1114 | a.commonProperties.Product_specific = boolPtr(false) |
| 1115 | a.commonProperties.Product_services_specific = boolPtr(false) |
| 1116 | } |
| 1117 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 1118 | func (a *androidModuleContext) InstallInData() bool { |
| 1119 | return a.module.InstallInData() |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1122 | func (a *androidModuleContext) InstallInSanitizerDir() bool { |
| 1123 | return a.module.InstallInSanitizerDir() |
| 1124 | } |
| 1125 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1126 | func (a *androidModuleContext) InstallInRecovery() bool { |
| 1127 | return a.module.InstallInRecovery() |
| 1128 | } |
| 1129 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 1130 | func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool { |
| 1131 | if a.module.base().commonProperties.SkipInstall { |
| 1132 | return true |
| 1133 | } |
| 1134 | |
Colin Cross | 3607f21 | 2018-05-07 15:28:05 -0700 | [diff] [blame] | 1135 | // We'll need a solution for choosing which of modules with the same name in different |
| 1136 | // namespaces to install. For now, reuse the list of namespaces exported to Make as the |
| 1137 | // list of namespaces to install in a Soong-only build. |
| 1138 | if !a.module.base().commonProperties.NamespaceExportedToMake { |
| 1139 | return true |
| 1140 | } |
| 1141 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 1142 | if a.Device() { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1143 | if a.Config().SkipDeviceInstall() { |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 1144 | return true |
| 1145 | } |
| 1146 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1147 | if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) { |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 1148 | return true |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | return false |
| 1153 | } |
| 1154 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 1155 | func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path, |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 1156 | deps ...Path) OutputPath { |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 1157 | return a.installFile(installPath, name, srcPath, Cp, deps) |
| 1158 | } |
| 1159 | |
| 1160 | func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path, |
| 1161 | deps ...Path) OutputPath { |
| 1162 | return a.installFile(installPath, name, srcPath, CpExecutable, deps) |
| 1163 | } |
| 1164 | |
| 1165 | func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path, |
| 1166 | rule blueprint.Rule, deps []Path) OutputPath { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 1167 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 1168 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 1169 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, false) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1170 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 1171 | if !a.skipInstall(fullInstallPath) { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1172 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1173 | deps = append(deps, a.installDeps...) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 1174 | |
Colin Cross | 89562dc | 2016-10-03 17:47:19 -0700 | [diff] [blame] | 1175 | var implicitDeps, orderOnlyDeps Paths |
| 1176 | |
| 1177 | if a.Host() { |
| 1178 | // Installed host modules might be used during the build, depend directly on their |
| 1179 | // dependencies so their timestamp is updated whenever their dependency is updated |
| 1180 | implicitDeps = deps |
| 1181 | } else { |
| 1182 | orderOnlyDeps = deps |
| 1183 | } |
| 1184 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 1185 | a.Build(pctx, BuildParams{ |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 1186 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1187 | Description: "install " + fullInstallPath.Base(), |
| 1188 | Output: fullInstallPath, |
| 1189 | Input: srcPath, |
| 1190 | Implicits: implicitDeps, |
| 1191 | OrderOnly: orderOnlyDeps, |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1192 | Default: !a.Config().EmbeddedInMake(), |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1193 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1194 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1195 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 1196 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1197 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 1198 | return fullInstallPath |
| 1199 | } |
| 1200 | |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 1201 | func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath { |
| 1202 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 1203 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, true) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 1204 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 1205 | if !a.skipInstall(fullInstallPath) { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1206 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 1207 | a.Build(pctx, BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1208 | Rule: Symlink, |
| 1209 | Description: "install symlink " + fullInstallPath.Base(), |
| 1210 | Output: fullInstallPath, |
| 1211 | OrderOnly: Paths{srcPath}, |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1212 | Default: !a.Config().EmbeddedInMake(), |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 1213 | Args: map[string]string{ |
| 1214 | "fromPath": srcPath.String(), |
| 1215 | }, |
| 1216 | }) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 1217 | |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 1218 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 1219 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 1220 | } |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 1221 | return fullInstallPath |
| 1222 | } |
| 1223 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1224 | func (a *androidModuleContext) CheckbuildFile(srcPath Path) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1225 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 1226 | } |
| 1227 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1228 | type fileInstaller interface { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1229 | filesToInstall() Paths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | func isFileInstaller(m blueprint.Module) bool { |
| 1233 | _, ok := m.(fileInstaller) |
| 1234 | return ok |
| 1235 | } |
| 1236 | |
| 1237 | func isAndroidModule(m blueprint.Module) bool { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1238 | _, ok := m.(Module) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1239 | return ok |
| 1240 | } |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 1241 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 1242 | func findStringInSlice(str string, slice []string) int { |
| 1243 | for i, s := range slice { |
| 1244 | if s == str { |
| 1245 | return i |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 1246 | } |
| 1247 | } |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 1248 | return -1 |
| 1249 | } |
| 1250 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1251 | func SrcIsModule(s string) string { |
| 1252 | if len(s) > 1 && s[0] == ':' { |
| 1253 | return s[1:] |
| 1254 | } |
| 1255 | return "" |
| 1256 | } |
| 1257 | |
| 1258 | type sourceDependencyTag struct { |
| 1259 | blueprint.BaseDependencyTag |
| 1260 | } |
| 1261 | |
| 1262 | var SourceDepTag sourceDependencyTag |
| 1263 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1264 | // Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles |
| 1265 | // using ":module" syntax, if any. |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1266 | func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) { |
| 1267 | var deps []string |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 1268 | set := make(map[string]bool) |
| 1269 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1270 | for _, s := range srcFiles { |
| 1271 | if m := SrcIsModule(s); m != "" { |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 1272 | if _, found := set[m]; found { |
| 1273 | ctx.ModuleErrorf("found source dependency duplicate: %q!", m) |
| 1274 | } else { |
| 1275 | set[m] = true |
| 1276 | deps = append(deps, m) |
| 1277 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | ctx.AddDependency(ctx.Module(), SourceDepTag, deps...) |
| 1282 | } |
| 1283 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1284 | // Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s |
| 1285 | // using ":module" syntax, if any. |
| 1286 | func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) { |
| 1287 | if s != nil { |
| 1288 | if m := SrcIsModule(*s); m != "" { |
| 1289 | ctx.AddDependency(ctx.Module(), SourceDepTag, m) |
| 1290 | } |
| 1291 | } |
| 1292 | } |
| 1293 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1294 | type SourceFileProducer interface { |
| 1295 | Srcs() Paths |
| 1296 | } |
| 1297 | |
| 1298 | // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1299 | // ExtractSourcesDeps must have already been called during the dependency resolution phase. |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1300 | func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1301 | return ctx.ExpandSourcesSubDir(srcFiles, excludes, "") |
| 1302 | } |
| 1303 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1304 | // Returns a single path expanded from globs and modules referenced using ":module" syntax. |
| 1305 | // ExtractSourceDeps must have already been called during the dependency resolution phase. |
| 1306 | func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path { |
| 1307 | srcFiles := ctx.ExpandSourcesSubDir([]string{srcFile}, nil, "") |
| 1308 | if len(srcFiles) == 1 { |
| 1309 | return srcFiles[0] |
| 1310 | } else { |
| 1311 | ctx.PropertyErrorf(prop, "module providing %s must produce exactly one file", prop) |
| 1312 | return nil |
| 1313 | } |
| 1314 | } |
| 1315 | |
Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 1316 | // Returns an optional single path expanded from globs and modules referenced using ":module" syntax if |
| 1317 | // the srcFile is non-nil. |
| 1318 | // ExtractSourceDeps must have already been called during the dependency resolution phase. |
| 1319 | func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath { |
| 1320 | if srcFile != nil { |
| 1321 | return OptionalPathForPath(ctx.ExpandSource(*srcFile, prop)) |
| 1322 | } |
| 1323 | return OptionalPath{} |
| 1324 | } |
| 1325 | |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1326 | func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1327 | prefix := PathForModuleSrc(ctx).String() |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1328 | |
Colin Cross | 461b445 | 2018-02-23 09:22:42 -0800 | [diff] [blame] | 1329 | var expandedExcludes []string |
| 1330 | if excludes != nil { |
| 1331 | expandedExcludes = make([]string, 0, len(excludes)) |
| 1332 | } |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1333 | |
| 1334 | for _, e := range excludes { |
| 1335 | if m := SrcIsModule(e); m != "" { |
| 1336 | module := ctx.GetDirectDepWithTag(m, SourceDepTag) |
| 1337 | if module == nil { |
| 1338 | // Error will have been handled by ExtractSourcesDeps |
| 1339 | continue |
| 1340 | } |
| 1341 | if srcProducer, ok := module.(SourceFileProducer); ok { |
| 1342 | expandedExcludes = append(expandedExcludes, srcProducer.Srcs().Strings()...) |
| 1343 | } else { |
| 1344 | ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m) |
| 1345 | } |
| 1346 | } else { |
| 1347 | expandedExcludes = append(expandedExcludes, filepath.Join(prefix, e)) |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 1348 | } |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 1349 | } |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1350 | expandedSrcFiles := make(Paths, 0, len(srcFiles)) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1351 | for _, s := range srcFiles { |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1352 | if m := SrcIsModule(s); m != "" { |
| 1353 | module := ctx.GetDirectDepWithTag(m, SourceDepTag) |
Colin Cross | 0617bb8 | 2017-10-24 13:01:18 -0700 | [diff] [blame] | 1354 | if module == nil { |
| 1355 | // Error will have been handled by ExtractSourcesDeps |
| 1356 | continue |
| 1357 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1358 | if srcProducer, ok := module.(SourceFileProducer); ok { |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1359 | moduleSrcs := srcProducer.Srcs() |
| 1360 | for _, e := range expandedExcludes { |
| 1361 | for j, ms := range moduleSrcs { |
| 1362 | if ms.String() == e { |
| 1363 | moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...) |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 | expandedSrcFiles = append(expandedSrcFiles, moduleSrcs...) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1368 | } else { |
| 1369 | ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m) |
| 1370 | } |
| 1371 | } else if pathtools.IsGlob(s) { |
Dan Willemsen | 540a78c | 2018-02-26 21:50:08 -0800 | [diff] [blame] | 1372 | globbedSrcFiles := ctx.GlobFiles(filepath.Join(prefix, s), expandedExcludes) |
Colin Cross | 05a39cb | 2017-10-09 13:35:19 -0700 | [diff] [blame] | 1373 | for i, s := range globbedSrcFiles { |
| 1374 | globbedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir) |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1375 | } |
Colin Cross | 05a39cb | 2017-10-09 13:35:19 -0700 | [diff] [blame] | 1376 | expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1377 | } else { |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1378 | p := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir) |
| 1379 | j := findStringInSlice(p.String(), expandedExcludes) |
| 1380 | if j == -1 { |
| 1381 | expandedSrcFiles = append(expandedSrcFiles, p) |
| 1382 | } |
| 1383 | |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1384 | } |
| 1385 | } |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1386 | return expandedSrcFiles |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 1389 | func (ctx *androidModuleContext) RequiredModuleNames() []string { |
| 1390 | return ctx.module.base().commonProperties.Required |
| 1391 | } |
| 1392 | |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 1393 | func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths { |
| 1394 | ret, err := ctx.GlobWithDeps(globPattern, excludes) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1395 | if err != nil { |
| 1396 | ctx.ModuleErrorf("glob: %s", err.Error()) |
| 1397 | } |
Dan Willemsen | 540a78c | 2018-02-26 21:50:08 -0800 | [diff] [blame] | 1398 | return pathsForModuleSrcFromFullPath(ctx, ret, true) |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 1399 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1400 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1401 | func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths { |
Dan Willemsen | 540a78c | 2018-02-26 21:50:08 -0800 | [diff] [blame] | 1402 | ret, err := ctx.GlobWithDeps(globPattern, excludes) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1403 | if err != nil { |
| 1404 | ctx.ModuleErrorf("glob: %s", err.Error()) |
| 1405 | } |
Dan Willemsen | 540a78c | 2018-02-26 21:50:08 -0800 | [diff] [blame] | 1406 | return pathsForModuleSrcFromFullPath(ctx, ret, false) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1407 | } |
| 1408 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 1409 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 1410 | RegisterSingletonType("buildtarget", BuildTargetSingleton) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1413 | func BuildTargetSingleton() Singleton { |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1414 | return &buildTargetSingleton{} |
| 1415 | } |
| 1416 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1417 | func parentDir(dir string) string { |
| 1418 | dir, _ = filepath.Split(dir) |
| 1419 | return filepath.Clean(dir) |
| 1420 | } |
| 1421 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1422 | type buildTargetSingleton struct{} |
| 1423 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1424 | func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) { |
| 1425 | var checkbuildDeps Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1426 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1427 | mmTarget := func(dir string) WritablePath { |
| 1428 | return PathForPhony(ctx, |
| 1429 | "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1)) |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1432 | modulesInDir := make(map[string]Paths) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1433 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1434 | ctx.VisitAllModules(func(module Module) { |
| 1435 | blueprintDir := module.base().blueprintDir |
| 1436 | installTarget := module.base().installTarget |
| 1437 | checkbuildTarget := module.base().checkbuildTarget |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1438 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1439 | if checkbuildTarget != nil { |
| 1440 | checkbuildDeps = append(checkbuildDeps, checkbuildTarget) |
| 1441 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget) |
| 1442 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1443 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1444 | if installTarget != nil { |
| 1445 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1446 | } |
| 1447 | }) |
| 1448 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1449 | suffix := "" |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1450 | if ctx.Config().EmbeddedInMake() { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1451 | suffix = "-soong" |
| 1452 | } |
| 1453 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1454 | // Create a top-level checkbuild target that depends on all modules |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1455 | ctx.Build(pctx, BuildParams{ |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1456 | Rule: blueprint.Phony, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1457 | Output: PathForPhony(ctx, "checkbuild"+suffix), |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1458 | Implicits: checkbuildDeps, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1459 | }) |
| 1460 | |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 1461 | // Make will generate the MODULES-IN-* targets |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1462 | if ctx.Config().EmbeddedInMake() { |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 1463 | return |
| 1464 | } |
| 1465 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1466 | sortedKeys := func(m map[string]Paths) []string { |
| 1467 | s := make([]string, 0, len(m)) |
| 1468 | for k := range m { |
| 1469 | s = append(s, k) |
| 1470 | } |
| 1471 | sort.Strings(s) |
| 1472 | return s |
| 1473 | } |
| 1474 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1475 | // Ensure ancestor directories are in modulesInDir |
| 1476 | dirs := sortedKeys(modulesInDir) |
| 1477 | for _, dir := range dirs { |
| 1478 | dir := parentDir(dir) |
| 1479 | for dir != "." && dir != "/" { |
| 1480 | if _, exists := modulesInDir[dir]; exists { |
| 1481 | break |
| 1482 | } |
| 1483 | modulesInDir[dir] = nil |
| 1484 | dir = parentDir(dir) |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | // Make directories build their direct subdirectories |
| 1489 | dirs = sortedKeys(modulesInDir) |
| 1490 | for _, dir := range dirs { |
| 1491 | p := parentDir(dir) |
| 1492 | if p != "." && p != "/" { |
| 1493 | modulesInDir[p] = append(modulesInDir[p], mmTarget(dir)) |
| 1494 | } |
| 1495 | } |
| 1496 | |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 1497 | // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and |
| 1498 | // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp |
| 1499 | // files. |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1500 | for _, dir := range dirs { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1501 | ctx.Build(pctx, BuildParams{ |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1502 | Rule: blueprint.Phony, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1503 | Output: mmTarget(dir), |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1504 | Implicits: modulesInDir[dir], |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1505 | // HACK: checkbuild should be an optional build, but force it |
| 1506 | // enabled for now in standalone builds |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1507 | Default: !ctx.Config().EmbeddedInMake(), |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1508 | }) |
| 1509 | } |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1510 | |
| 1511 | // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild. |
| 1512 | osDeps := map[OsType]Paths{} |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1513 | ctx.VisitAllModules(func(module Module) { |
| 1514 | if module.Enabled() { |
| 1515 | os := module.Target().Os |
| 1516 | osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...) |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1517 | } |
| 1518 | }) |
| 1519 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1520 | osClass := make(map[string]Paths) |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1521 | for os, deps := range osDeps { |
| 1522 | var className string |
| 1523 | |
| 1524 | switch os.Class { |
| 1525 | case Host: |
| 1526 | className = "host" |
| 1527 | case HostCross: |
| 1528 | className = "host-cross" |
| 1529 | case Device: |
| 1530 | className = "target" |
| 1531 | default: |
| 1532 | continue |
| 1533 | } |
| 1534 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1535 | name := PathForPhony(ctx, className+"-"+os.Name) |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1536 | osClass[className] = append(osClass[className], name) |
| 1537 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1538 | ctx.Build(pctx, BuildParams{ |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1539 | Rule: blueprint.Phony, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1540 | Output: name, |
| 1541 | Implicits: deps, |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1542 | }) |
| 1543 | } |
| 1544 | |
| 1545 | // Wrap those into host|host-cross|target phony rules |
| 1546 | osClasses := sortedKeys(osClass) |
| 1547 | for _, class := range osClasses { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1548 | ctx.Build(pctx, BuildParams{ |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1549 | Rule: blueprint.Phony, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1550 | Output: PathForPhony(ctx, class), |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1551 | Implicits: osClass[class], |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1552 | }) |
| 1553 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1554 | } |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 1555 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 1556 | type ModulesByName struct { |
| 1557 | slice []blueprint.Module |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 1558 | ctx interface { |
| 1559 | ModuleName(blueprint.Module) string |
| 1560 | ModuleSubDir(blueprint.Module) string |
| 1561 | } |
| 1562 | } |
| 1563 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 1564 | func (s ModulesByName) Len() int { return len(s.slice) } |
| 1565 | func (s ModulesByName) Less(i, j int) bool { |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 1566 | mi, mj := s.slice[i], s.slice[j] |
| 1567 | ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj) |
| 1568 | |
| 1569 | if ni != nj { |
| 1570 | return ni < nj |
| 1571 | } else { |
| 1572 | return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj) |
| 1573 | } |
| 1574 | } |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 1575 | func (s ModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] } |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1576 | |
| 1577 | // Collect information for opening IDE project files in java/jdeps.go. |
| 1578 | type IDEInfo interface { |
| 1579 | IDEInfo(ideInfo *IdeInfo) |
| 1580 | BaseModuleName() string |
| 1581 | } |
| 1582 | |
| 1583 | // Extract the base module name from the Import name. |
| 1584 | // Often the Import name has a prefix "prebuilt_". |
| 1585 | // Remove the prefix explicitly if needed |
| 1586 | // until we find a better solution to get the Import name. |
| 1587 | type IDECustomizedModuleName interface { |
| 1588 | IDECustomizedModuleName() string |
| 1589 | } |
| 1590 | |
| 1591 | type IdeInfo struct { |
| 1592 | Deps []string `json:"dependencies,omitempty"` |
| 1593 | Srcs []string `json:"srcs,omitempty"` |
| 1594 | Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"` |
| 1595 | Jarjar_rules []string `json:"jarjar_rules,omitempty"` |
| 1596 | Jars []string `json:"jars,omitempty"` |
| 1597 | Classes []string `json:"class,omitempty"` |
| 1598 | Installed_paths []string `json:"installed,omitempty"` |
| 1599 | } |