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