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