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