Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 18 | "fmt" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 20 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint" |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/pathtools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | var ( |
| 27 | DeviceSharedLibrary = "shared_library" |
| 28 | DeviceStaticLibrary = "static_library" |
| 29 | DeviceExecutable = "executable" |
| 30 | HostSharedLibrary = "host_shared_library" |
| 31 | HostStaticLibrary = "host_static_library" |
| 32 | HostExecutable = "host_executable" |
| 33 | ) |
| 34 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 35 | type ModuleBuildParams struct { |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 36 | Rule blueprint.Rule |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 37 | Deps blueprint.Deps |
| 38 | Depfile WritablePath |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 39 | Description string |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 40 | Output WritablePath |
| 41 | Outputs WritablePaths |
| 42 | ImplicitOutput WritablePath |
| 43 | ImplicitOutputs WritablePaths |
| 44 | Input Path |
| 45 | Inputs Paths |
| 46 | Implicit Path |
| 47 | Implicits Paths |
| 48 | OrderOnly Paths |
| 49 | Default bool |
| 50 | Args map[string]string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 53 | type androidBaseContext interface { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 54 | Target() Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 55 | TargetPrimary() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 56 | Arch() Arch |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 57 | Os() OsType |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 58 | Host() bool |
| 59 | Device() bool |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 60 | Darwin() bool |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 61 | Windows() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 62 | Debug() bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 63 | PrimaryArch() bool |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 64 | Vendor() bool |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 65 | AConfig() Config |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 66 | DeviceConfig() DeviceConfig |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 69 | type BaseContext interface { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 70 | blueprint.BaseModuleContext |
| 71 | androidBaseContext |
| 72 | } |
| 73 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 74 | type ModuleContext interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 75 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 76 | androidBaseContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 77 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 78 | // Similar to Build, but takes Paths instead of []string, |
| 79 | // and performs more verification. |
| 80 | ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 81 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 82 | ExpandSources(srcFiles, excludes []string) Paths |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 83 | ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 84 | Glob(globPattern string, excludes []string) Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 85 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 86 | InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
| 87 | InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 88 | InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 89 | CheckbuildFile(srcPath Path) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 90 | |
| 91 | AddMissingDependencies(deps []string) |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 92 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 93 | InstallInData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 94 | InstallInSanitizerDir() bool |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 95 | |
| 96 | RequiredModuleNames() []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 99 | type Module interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 100 | blueprint.Module |
| 101 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 102 | GenerateAndroidBuildActions(ModuleContext) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 103 | DepsMutator(BottomUpMutatorContext) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 104 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 105 | base() *ModuleBase |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 106 | Enabled() bool |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 107 | Target() Target |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 108 | InstallInData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 109 | InstallInSanitizerDir() bool |
Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 110 | SkipInstall() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 111 | |
| 112 | AddProperties(props ...interface{}) |
| 113 | GetProperties() []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 114 | |
| 115 | BuildParamsForTests() []ModuleBuildParams |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 118 | type nameProperties struct { |
| 119 | // The name of the module. Must be unique across all modules. |
Colin Cross | c77f9d1 | 2015-04-02 13:54:39 -0700 | [diff] [blame] | 120 | Name string |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | type commonProperties struct { |
Colin Cross | c77f9d1 | 2015-04-02 13:54:39 -0700 | [diff] [blame] | 124 | Tags []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 125 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 126 | // emit build rules for this module |
| 127 | Enabled *bool `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 128 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 129 | // 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] | 130 | // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both |
| 131 | // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit |
| 132 | // platform |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 133 | Compile_multilib string `android:"arch_variant"` |
| 134 | |
| 135 | Target struct { |
| 136 | Host struct { |
| 137 | Compile_multilib string |
| 138 | } |
| 139 | Android struct { |
| 140 | Compile_multilib string |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | Default_multilib string `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 145 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 146 | // whether this is a proprietary vendor module, and should be installed into /vendor |
| 147 | Proprietary bool |
| 148 | |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 149 | // vendor who owns this module |
Dan Willemsen | efac4a8 | 2017-07-18 19:42:09 -0700 | [diff] [blame] | 150 | Owner *string |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 151 | |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 152 | // whether this module is device specific and should be installed into /vendor |
| 153 | Vendor bool |
| 154 | |
Dan Willemsen | 0fda89f | 2016-06-01 15:25:32 -0700 | [diff] [blame] | 155 | // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags |
| 156 | // file |
| 157 | Logtags []string |
| 158 | |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 159 | // init.rc files to be installed if this module is installed |
| 160 | Init_rc []string |
| 161 | |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 162 | // names of other modules to install if this module is installed |
Colin Cross | c602b7d | 2017-05-05 13:36:36 -0700 | [diff] [blame] | 163 | Required []string `android:"arch_variant"` |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 164 | |
Colin Cross | 5aac362 | 2017-08-31 15:07:09 -0700 | [diff] [blame^] | 165 | // relative path to a file to include in the list of notices for the device |
| 166 | Notice *string |
| 167 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 168 | // Set by TargetMutator |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 169 | CompileTarget Target `blueprint:"mutated"` |
| 170 | CompilePrimary bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 171 | |
| 172 | // Set by InitAndroidModule |
| 173 | HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 174 | ArchSpecific bool `blueprint:"mutated"` |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 175 | |
| 176 | SkipInstall bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | type hostAndDeviceProperties struct { |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 180 | Host_supported *bool |
| 181 | Device_supported *bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 184 | type Multilib string |
| 185 | |
| 186 | const ( |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 187 | MultilibBoth Multilib = "both" |
| 188 | MultilibFirst Multilib = "first" |
| 189 | MultilibCommon Multilib = "common" |
| 190 | MultilibDefault Multilib = "" |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 191 | ) |
| 192 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 193 | type HostOrDeviceSupported int |
| 194 | |
| 195 | const ( |
| 196 | _ HostOrDeviceSupported = iota |
| 197 | HostSupported |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 198 | HostSupportedNoCross |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 199 | DeviceSupported |
| 200 | HostAndDeviceSupported |
| 201 | HostAndDeviceDefault |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 202 | NeitherHostNorDeviceSupported |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 203 | ) |
| 204 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 205 | func InitAndroidModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 206 | base := m.base() |
| 207 | base.module = m |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 208 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 209 | m.AddProperties( |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 210 | &base.nameProperties, |
| 211 | &base.commonProperties, |
| 212 | &base.variableProperties) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 215 | func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { |
| 216 | InitAndroidModule(m) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 217 | |
| 218 | base := m.base() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 219 | base.commonProperties.HostOrDeviceSupported = hod |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 220 | base.commonProperties.Default_multilib = string(defaultMultilib) |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 221 | base.commonProperties.ArchSpecific = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 222 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 223 | switch hod { |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 224 | case HostAndDeviceSupported, HostAndDeviceDefault: |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 225 | m.AddProperties(&base.hostAndDeviceProperties) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 228 | InitArchModule(m) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 231 | // A ModuleBase object contains the properties that are common to all Android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 232 | // modules. It should be included as an anonymous field in every module |
| 233 | // struct definition. InitAndroidModule should then be called from the module's |
| 234 | // factory function, and the return values from InitAndroidModule should be |
| 235 | // returned from the factory function. |
| 236 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 237 | // The ModuleBase type is responsible for implementing the GenerateBuildActions |
| 238 | // method to support the blueprint.Module interface. This method will then call |
| 239 | // the module's GenerateAndroidBuildActions method once for each build variant |
| 240 | // that is to be built. GenerateAndroidBuildActions is passed a |
| 241 | // AndroidModuleContext rather than the usual blueprint.ModuleContext. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 242 | // AndroidModuleContext exposes extra functionality specific to the Android build |
| 243 | // system including details about the particular build variant that is to be |
| 244 | // generated. |
| 245 | // |
| 246 | // For example: |
| 247 | // |
| 248 | // import ( |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 249 | // "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 250 | // ) |
| 251 | // |
| 252 | // type myModule struct { |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 253 | // android.ModuleBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 254 | // properties struct { |
| 255 | // MyProperty string |
| 256 | // } |
| 257 | // } |
| 258 | // |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 259 | // func NewMyModule() android.Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 260 | // m := &myModule{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 261 | // m.AddProperties(&m.properties) |
| 262 | // android.InitAndroidModule(m) |
| 263 | // return m |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 264 | // } |
| 265 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 266 | // func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 267 | // // Get the CPU architecture for the current build variant. |
| 268 | // variantArch := ctx.Arch() |
| 269 | // |
| 270 | // // ... |
| 271 | // } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 272 | type ModuleBase struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 273 | // Putting the curiously recurring thing pointing to the thing that contains |
| 274 | // the thing pattern to good use. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 275 | // TODO: remove this |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 276 | module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 277 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 278 | nameProperties nameProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 279 | commonProperties commonProperties |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 280 | variableProperties variableProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 281 | hostAndDeviceProperties hostAndDeviceProperties |
| 282 | generalProperties []interface{} |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 283 | archProperties []interface{} |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 284 | customizableProperties []interface{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 285 | |
| 286 | noAddressSanitizer bool |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 287 | installFiles Paths |
| 288 | checkbuildFiles Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 289 | |
| 290 | // Used by buildTargetSingleton to create checkbuild and per-directory build targets |
| 291 | // Only set on the final variant of each module |
| 292 | installTarget string |
| 293 | checkbuildTarget string |
| 294 | blueprintDir string |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 295 | |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 296 | hooks hooks |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 297 | |
| 298 | registerProps []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 299 | |
| 300 | // For tests |
| 301 | buildParams []ModuleBuildParams |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | func (a *ModuleBase) AddProperties(props ...interface{}) { |
| 305 | a.registerProps = append(a.registerProps, props...) |
| 306 | } |
| 307 | |
| 308 | func (a *ModuleBase) GetProperties() []interface{} { |
| 309 | return a.registerProps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 312 | func (a *ModuleBase) BuildParamsForTests() []ModuleBuildParams { |
| 313 | return a.buildParams |
| 314 | } |
| 315 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 316 | // Name returns the name of the module. It may be overridden by individual module types, for |
| 317 | // example prebuilts will prepend prebuilt_ to the name. |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 318 | func (a *ModuleBase) Name() string { |
| 319 | return a.nameProperties.Name |
| 320 | } |
| 321 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 322 | // BaseModuleName returns the name of the module as specified in the blueprints file. |
| 323 | func (a *ModuleBase) BaseModuleName() string { |
| 324 | return a.nameProperties.Name |
| 325 | } |
| 326 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 327 | func (a *ModuleBase) base() *ModuleBase { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 328 | return a |
| 329 | } |
| 330 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 331 | func (a *ModuleBase) SetTarget(target Target, primary bool) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 332 | a.commonProperties.CompileTarget = target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 333 | a.commonProperties.CompilePrimary = primary |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 336 | func (a *ModuleBase) Target() Target { |
| 337 | return a.commonProperties.CompileTarget |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 340 | func (a *ModuleBase) TargetPrimary() bool { |
| 341 | return a.commonProperties.CompilePrimary |
| 342 | } |
| 343 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 344 | func (a *ModuleBase) Os() OsType { |
| 345 | return a.Target().Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 348 | func (a *ModuleBase) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 349 | return a.Os().Class == Host || a.Os().Class == HostCross |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 352 | func (a *ModuleBase) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 353 | return a.Target().Arch |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 356 | func (a *ModuleBase) ArchSpecific() bool { |
| 357 | return a.commonProperties.ArchSpecific |
| 358 | } |
| 359 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 360 | func (a *ModuleBase) OsClassSupported() []OsClass { |
| 361 | switch a.commonProperties.HostOrDeviceSupported { |
| 362 | case HostSupported: |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 363 | return []OsClass{Host, HostCross} |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 364 | case HostSupportedNoCross: |
| 365 | return []OsClass{Host} |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 366 | case DeviceSupported: |
| 367 | return []OsClass{Device} |
| 368 | case HostAndDeviceSupported: |
| 369 | var supported []OsClass |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 370 | if Bool(a.hostAndDeviceProperties.Host_supported) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 371 | supported = append(supported, Host, HostCross) |
| 372 | } |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 373 | if a.hostAndDeviceProperties.Device_supported == nil || |
| 374 | *a.hostAndDeviceProperties.Device_supported { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 375 | supported = append(supported, Device) |
| 376 | } |
| 377 | return supported |
| 378 | default: |
| 379 | return nil |
| 380 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 383 | func (a *ModuleBase) DeviceSupported() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 384 | return a.commonProperties.HostOrDeviceSupported == DeviceSupported || |
| 385 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 386 | (a.hostAndDeviceProperties.Device_supported == nil || |
| 387 | *a.hostAndDeviceProperties.Device_supported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 390 | func (a *ModuleBase) Enabled() bool { |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 391 | if a.commonProperties.Enabled == nil { |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 392 | return !a.Os().DefaultDisabled |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 393 | } |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 394 | return *a.commonProperties.Enabled |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 397 | func (a *ModuleBase) SkipInstall() { |
| 398 | a.commonProperties.SkipInstall = true |
| 399 | } |
| 400 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 401 | func (a *ModuleBase) computeInstallDeps( |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 402 | ctx blueprint.ModuleContext) Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 403 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 404 | result := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 405 | ctx.VisitDepsDepthFirstIf(isFileInstaller, |
| 406 | func(m blueprint.Module) { |
| 407 | fileInstaller := m.(fileInstaller) |
| 408 | files := fileInstaller.filesToInstall() |
| 409 | result = append(result, files...) |
| 410 | }) |
| 411 | |
| 412 | return result |
| 413 | } |
| 414 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 415 | func (a *ModuleBase) filesToInstall() Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 416 | return a.installFiles |
| 417 | } |
| 418 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 419 | func (p *ModuleBase) NoAddressSanitizer() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 420 | return p.noAddressSanitizer |
| 421 | } |
| 422 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 423 | func (p *ModuleBase) InstallInData() bool { |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 424 | return false |
| 425 | } |
| 426 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 427 | func (p *ModuleBase) InstallInSanitizerDir() bool { |
| 428 | return false |
| 429 | } |
| 430 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 431 | func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 432 | allInstalledFiles := Paths{} |
| 433 | allCheckbuildFiles := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 434 | ctx.VisitAllModuleVariants(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 435 | a := module.(Module).base() |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 436 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 437 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 438 | }) |
| 439 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 440 | deps := []string{} |
| 441 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 442 | if len(allInstalledFiles) > 0 { |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 443 | name := ctx.ModuleName() + "-install" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 444 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 445 | Rule: blueprint.Phony, |
| 446 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 447 | Implicits: allInstalledFiles.Strings(), |
Colin Cross | 346aa13 | 2015-12-17 17:19:51 -0800 | [diff] [blame] | 448 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 449 | }) |
| 450 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 451 | a.installTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | if len(allCheckbuildFiles) > 0 { |
| 455 | name := ctx.ModuleName() + "-checkbuild" |
| 456 | ctx.Build(pctx, blueprint.BuildParams{ |
| 457 | Rule: blueprint.Phony, |
| 458 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 459 | Implicits: allCheckbuildFiles.Strings(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 460 | Optional: true, |
| 461 | }) |
| 462 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 463 | a.checkbuildTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | if len(deps) > 0 { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 467 | suffix := "" |
| 468 | if ctx.Config().(Config).EmbeddedInMake() { |
| 469 | suffix = "-soong" |
| 470 | } |
| 471 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 472 | ctx.Build(pctx, blueprint.BuildParams{ |
| 473 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 474 | Outputs: []string{ctx.ModuleName() + suffix}, |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 475 | Implicits: deps, |
| 476 | Optional: true, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 477 | }) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 478 | |
| 479 | a.blueprintDir = ctx.ModuleDir() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 483 | func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 484 | return androidBaseContextImpl{ |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 485 | target: a.commonProperties.CompileTarget, |
| 486 | targetPrimary: a.commonProperties.CompilePrimary, |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 487 | vendor: a.commonProperties.Proprietary || a.commonProperties.Vendor, |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 488 | config: ctx.Config().(Config), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 489 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 492 | func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 493 | androidCtx := &androidModuleContext{ |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 494 | module: a.module, |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 495 | ModuleContext: ctx, |
| 496 | androidBaseContextImpl: a.androidBaseContextFactory(ctx), |
| 497 | installDeps: a.computeInstallDeps(ctx), |
| 498 | installFiles: a.installFiles, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 499 | missingDeps: ctx.GetMissingDependencies(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 502 | desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " " |
| 503 | var suffix []string |
| 504 | if androidCtx.Os().Class != Device && androidCtx.Os().Class != Generic { |
| 505 | suffix = append(suffix, androidCtx.Os().String()) |
| 506 | } |
| 507 | if !androidCtx.PrimaryArch() { |
| 508 | suffix = append(suffix, androidCtx.Arch().ArchType.String()) |
| 509 | } |
| 510 | |
| 511 | ctx.Variable(pctx, "moduleDesc", desc) |
| 512 | |
| 513 | s := "" |
| 514 | if len(suffix) > 0 { |
| 515 | s = " [" + strings.Join(suffix, " ") + "]" |
| 516 | } |
| 517 | ctx.Variable(pctx, "moduleDescSuffix", s) |
| 518 | |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 519 | if a.Enabled() { |
| 520 | a.module.GenerateAndroidBuildActions(androidCtx) |
| 521 | if ctx.Failed() { |
| 522 | return |
| 523 | } |
| 524 | |
| 525 | a.installFiles = append(a.installFiles, androidCtx.installFiles...) |
| 526 | a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 529 | if a == ctx.FinalModule().(Module).base() { |
| 530 | a.generateModuleTarget(ctx) |
| 531 | if ctx.Failed() { |
| 532 | return |
| 533 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 534 | } |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 535 | |
| 536 | a.buildParams = androidCtx.buildParams |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 539 | type androidBaseContextImpl struct { |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 540 | target Target |
| 541 | targetPrimary bool |
| 542 | debug bool |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 543 | vendor bool |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 544 | config Config |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 547 | type androidModuleContext struct { |
| 548 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 549 | androidBaseContextImpl |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 550 | installDeps Paths |
| 551 | installFiles Paths |
| 552 | checkbuildFiles Paths |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 553 | missingDeps []string |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 554 | module Module |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 555 | |
| 556 | // For tests |
| 557 | buildParams []ModuleBuildParams |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 560 | func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) { |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 561 | a.ModuleContext.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 562 | Rule: ErrorRule, |
| 563 | Description: desc, |
| 564 | Outputs: outputs, |
| 565 | Optional: true, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 566 | Args: map[string]string{ |
| 567 | "error": err.Error(), |
| 568 | }, |
| 569 | }) |
| 570 | return |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Dan Willemsen | 14e5c2a | 2015-11-30 13:59:34 -0800 | [diff] [blame] | 573 | func (a *androidModuleContext) Build(pctx blueprint.PackageContext, params blueprint.BuildParams) { |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 574 | if a.missingDeps != nil { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 575 | a.ninjaError(params.Description, params.Outputs, |
| 576 | fmt.Errorf("module %s missing dependencies: %s\n", |
| 577 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 578 | return |
| 579 | } |
| 580 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 581 | params.Optional = true |
| 582 | a.ModuleContext.Build(pctx, params) |
| 583 | } |
| 584 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 585 | func (a *androidModuleContext) ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 586 | if a.config.captureBuild { |
| 587 | a.buildParams = append(a.buildParams, params) |
| 588 | } |
| 589 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 590 | bparams := blueprint.BuildParams{ |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 591 | Rule: params.Rule, |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 592 | Deps: params.Deps, |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 593 | Outputs: params.Outputs.Strings(), |
| 594 | ImplicitOutputs: params.ImplicitOutputs.Strings(), |
| 595 | Inputs: params.Inputs.Strings(), |
| 596 | Implicits: params.Implicits.Strings(), |
| 597 | OrderOnly: params.OrderOnly.Strings(), |
| 598 | Args: params.Args, |
| 599 | Optional: !params.Default, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 602 | if params.Description != "" { |
| 603 | bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}" |
| 604 | } |
| 605 | |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 606 | if params.Depfile != nil { |
| 607 | bparams.Depfile = params.Depfile.String() |
| 608 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 609 | if params.Output != nil { |
| 610 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 611 | } |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 612 | if params.ImplicitOutput != nil { |
| 613 | bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String()) |
| 614 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 615 | if params.Input != nil { |
| 616 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 617 | } |
| 618 | if params.Implicit != nil { |
| 619 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 620 | } |
| 621 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 622 | if a.missingDeps != nil { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 623 | a.ninjaError(bparams.Description, bparams.Outputs, |
| 624 | fmt.Errorf("module %s missing dependencies: %s\n", |
| 625 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 626 | return |
| 627 | } |
| 628 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 629 | a.ModuleContext.Build(pctx, bparams) |
| 630 | } |
| 631 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 632 | func (a *androidModuleContext) GetMissingDependencies() []string { |
| 633 | return a.missingDeps |
| 634 | } |
| 635 | |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 636 | func (a *androidModuleContext) AddMissingDependencies(deps []string) { |
| 637 | if deps != nil { |
| 638 | a.missingDeps = append(a.missingDeps, deps...) |
| 639 | } |
| 640 | } |
| 641 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 642 | func (a *androidBaseContextImpl) Target() Target { |
| 643 | return a.target |
| 644 | } |
| 645 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 646 | func (a *androidBaseContextImpl) TargetPrimary() bool { |
| 647 | return a.targetPrimary |
| 648 | } |
| 649 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 650 | func (a *androidBaseContextImpl) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 651 | return a.target.Arch |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 654 | func (a *androidBaseContextImpl) Os() OsType { |
| 655 | return a.target.Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 656 | } |
| 657 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 658 | func (a *androidBaseContextImpl) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 659 | return a.target.Os.Class == Host || a.target.Os.Class == HostCross |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | func (a *androidBaseContextImpl) Device() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 663 | return a.target.Os.Class == Device |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 666 | func (a *androidBaseContextImpl) Darwin() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 667 | return a.target.Os == Darwin |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 670 | func (a *androidBaseContextImpl) Windows() bool { |
| 671 | return a.target.Os == Windows |
| 672 | } |
| 673 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 674 | func (a *androidBaseContextImpl) Debug() bool { |
| 675 | return a.debug |
| 676 | } |
| 677 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 678 | func (a *androidBaseContextImpl) PrimaryArch() bool { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 679 | if len(a.config.Targets[a.target.Os.Class]) <= 1 { |
| 680 | return true |
| 681 | } |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 682 | return a.target.Arch.ArchType == a.config.Targets[a.target.Os.Class][0].Arch.ArchType |
| 683 | } |
| 684 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 685 | func (a *androidBaseContextImpl) AConfig() Config { |
| 686 | return a.config |
| 687 | } |
| 688 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 689 | func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig { |
| 690 | return DeviceConfig{a.config.deviceConfig} |
| 691 | } |
| 692 | |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 693 | func (a *androidBaseContextImpl) Vendor() bool { |
| 694 | return a.vendor |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 695 | } |
| 696 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 697 | func (a *androidModuleContext) InstallInData() bool { |
| 698 | return a.module.InstallInData() |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 699 | } |
| 700 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 701 | func (a *androidModuleContext) InstallInSanitizerDir() bool { |
| 702 | return a.module.InstallInSanitizerDir() |
| 703 | } |
| 704 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 705 | func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool { |
| 706 | if a.module.base().commonProperties.SkipInstall { |
| 707 | return true |
| 708 | } |
| 709 | |
| 710 | if a.Device() { |
| 711 | if a.AConfig().SkipDeviceInstall() { |
| 712 | return true |
| 713 | } |
| 714 | |
| 715 | if a.AConfig().SkipMegaDeviceInstall(fullInstallPath.String()) { |
| 716 | return true |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | return false |
| 721 | } |
| 722 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 723 | func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path, |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 724 | deps ...Path) OutputPath { |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 725 | return a.installFile(installPath, name, srcPath, Cp, deps) |
| 726 | } |
| 727 | |
| 728 | func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path, |
| 729 | deps ...Path) OutputPath { |
| 730 | return a.installFile(installPath, name, srcPath, CpExecutable, deps) |
| 731 | } |
| 732 | |
| 733 | func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path, |
| 734 | rule blueprint.Rule, deps []Path) OutputPath { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 735 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 736 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 737 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, false) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 738 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 739 | if !a.skipInstall(fullInstallPath) { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 740 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 741 | deps = append(deps, a.installDeps...) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 742 | |
Colin Cross | 89562dc | 2016-10-03 17:47:19 -0700 | [diff] [blame] | 743 | var implicitDeps, orderOnlyDeps Paths |
| 744 | |
| 745 | if a.Host() { |
| 746 | // Installed host modules might be used during the build, depend directly on their |
| 747 | // dependencies so their timestamp is updated whenever their dependency is updated |
| 748 | implicitDeps = deps |
| 749 | } else { |
| 750 | orderOnlyDeps = deps |
| 751 | } |
| 752 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 753 | a.ModuleBuild(pctx, ModuleBuildParams{ |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 754 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 755 | Description: "install " + fullInstallPath.Base(), |
| 756 | Output: fullInstallPath, |
| 757 | Input: srcPath, |
| 758 | Implicits: implicitDeps, |
| 759 | OrderOnly: orderOnlyDeps, |
| 760 | Default: !a.AConfig().EmbeddedInMake(), |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 761 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 762 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 763 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 764 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 765 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 766 | return fullInstallPath |
| 767 | } |
| 768 | |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 769 | func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath { |
| 770 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 771 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, true) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 772 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 773 | if !a.skipInstall(fullInstallPath) { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 774 | |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 775 | a.ModuleBuild(pctx, ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 776 | Rule: Symlink, |
| 777 | Description: "install symlink " + fullInstallPath.Base(), |
| 778 | Output: fullInstallPath, |
| 779 | OrderOnly: Paths{srcPath}, |
| 780 | Default: !a.AConfig().EmbeddedInMake(), |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 781 | Args: map[string]string{ |
| 782 | "fromPath": srcPath.String(), |
| 783 | }, |
| 784 | }) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 785 | |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 786 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 787 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 788 | } |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 789 | return fullInstallPath |
| 790 | } |
| 791 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 792 | func (a *androidModuleContext) CheckbuildFile(srcPath Path) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 793 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 794 | } |
| 795 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 796 | type fileInstaller interface { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 797 | filesToInstall() Paths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | func isFileInstaller(m blueprint.Module) bool { |
| 801 | _, ok := m.(fileInstaller) |
| 802 | return ok |
| 803 | } |
| 804 | |
| 805 | func isAndroidModule(m blueprint.Module) bool { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 806 | _, ok := m.(Module) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 807 | return ok |
| 808 | } |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 809 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 810 | func findStringInSlice(str string, slice []string) int { |
| 811 | for i, s := range slice { |
| 812 | if s == str { |
| 813 | return i |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 816 | return -1 |
| 817 | } |
| 818 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 819 | func SrcIsModule(s string) string { |
| 820 | if len(s) > 1 && s[0] == ':' { |
| 821 | return s[1:] |
| 822 | } |
| 823 | return "" |
| 824 | } |
| 825 | |
| 826 | type sourceDependencyTag struct { |
| 827 | blueprint.BaseDependencyTag |
| 828 | } |
| 829 | |
| 830 | var SourceDepTag sourceDependencyTag |
| 831 | |
| 832 | // Returns a list of modules that must be depended on to satisfy filegroup or generated sources |
| 833 | // modules listed in srcFiles using ":module" syntax |
| 834 | func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) { |
| 835 | var deps []string |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 836 | set := make(map[string]bool) |
| 837 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 838 | for _, s := range srcFiles { |
| 839 | if m := SrcIsModule(s); m != "" { |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 840 | if _, found := set[m]; found { |
| 841 | ctx.ModuleErrorf("found source dependency duplicate: %q!", m) |
| 842 | } else { |
| 843 | set[m] = true |
| 844 | deps = append(deps, m) |
| 845 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
| 849 | ctx.AddDependency(ctx.Module(), SourceDepTag, deps...) |
| 850 | } |
| 851 | |
| 852 | type SourceFileProducer interface { |
| 853 | Srcs() Paths |
| 854 | } |
| 855 | |
| 856 | // 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] | 857 | // ExtractSourcesDeps must have already been called during the dependency resolution phase. |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 858 | func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 859 | return ctx.ExpandSourcesSubDir(srcFiles, excludes, "") |
| 860 | } |
| 861 | |
| 862 | func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 863 | prefix := PathForModuleSrc(ctx).String() |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 864 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 865 | for i, e := range excludes { |
| 866 | j := findStringInSlice(e, srcFiles) |
| 867 | if j != -1 { |
| 868 | srcFiles = append(srcFiles[:j], srcFiles[j+1:]...) |
| 869 | } |
| 870 | |
| 871 | excludes[i] = filepath.Join(prefix, e) |
| 872 | } |
| 873 | |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 874 | expandedSrcFiles := make(Paths, 0, len(srcFiles)) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 875 | for _, s := range srcFiles { |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 876 | if m := SrcIsModule(s); m != "" { |
| 877 | module := ctx.GetDirectDepWithTag(m, SourceDepTag) |
| 878 | if srcProducer, ok := module.(SourceFileProducer); ok { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 879 | expandedSrcFiles = append(expandedSrcFiles, srcProducer.Srcs()...) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 880 | } else { |
| 881 | ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m) |
| 882 | } |
| 883 | } else if pathtools.IsGlob(s) { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 884 | globbedSrcFiles := ctx.Glob(filepath.Join(prefix, s), excludes) |
| 885 | expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...) |
| 886 | for i, s := range expandedSrcFiles { |
| 887 | expandedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir) |
| 888 | } |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 889 | } else { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 890 | s := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir) |
| 891 | expandedSrcFiles = append(expandedSrcFiles, s) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 895 | return expandedSrcFiles |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 898 | func (ctx *androidModuleContext) RequiredModuleNames() []string { |
| 899 | return ctx.module.base().commonProperties.Required |
| 900 | } |
| 901 | |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 902 | func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths { |
| 903 | ret, err := ctx.GlobWithDeps(globPattern, excludes) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 904 | if err != nil { |
| 905 | ctx.ModuleErrorf("glob: %s", err.Error()) |
| 906 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 907 | return pathsForModuleSrcFromFullPath(ctx, ret) |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 908 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 909 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 910 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 911 | RegisterSingletonType("buildtarget", BuildTargetSingleton) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 914 | func BuildTargetSingleton() blueprint.Singleton { |
| 915 | return &buildTargetSingleton{} |
| 916 | } |
| 917 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 918 | func parentDir(dir string) string { |
| 919 | dir, _ = filepath.Split(dir) |
| 920 | return filepath.Clean(dir) |
| 921 | } |
| 922 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 923 | type buildTargetSingleton struct{} |
| 924 | |
| 925 | func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
| 926 | checkbuildDeps := []string{} |
| 927 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 928 | mmTarget := func(dir string) string { |
| 929 | return filepath.Join("mm", dir) |
| 930 | } |
| 931 | |
| 932 | modulesInDir := make(map[string][]string) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 933 | |
| 934 | ctx.VisitAllModules(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 935 | if a, ok := module.(Module); ok { |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 936 | blueprintDir := a.base().blueprintDir |
| 937 | installTarget := a.base().installTarget |
| 938 | checkbuildTarget := a.base().checkbuildTarget |
| 939 | |
| 940 | if checkbuildTarget != "" { |
| 941 | checkbuildDeps = append(checkbuildDeps, checkbuildTarget) |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 942 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | if installTarget != "" { |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 946 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | }) |
| 950 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 951 | suffix := "" |
| 952 | if ctx.Config().(Config).EmbeddedInMake() { |
| 953 | suffix = "-soong" |
| 954 | } |
| 955 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 956 | // Create a top-level checkbuild target that depends on all modules |
| 957 | ctx.Build(pctx, blueprint.BuildParams{ |
| 958 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 959 | Outputs: []string{"checkbuild" + suffix}, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 960 | Implicits: checkbuildDeps, |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 961 | Optional: true, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 962 | }) |
| 963 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 964 | // Ensure ancestor directories are in modulesInDir |
| 965 | dirs := sortedKeys(modulesInDir) |
| 966 | for _, dir := range dirs { |
| 967 | dir := parentDir(dir) |
| 968 | for dir != "." && dir != "/" { |
| 969 | if _, exists := modulesInDir[dir]; exists { |
| 970 | break |
| 971 | } |
| 972 | modulesInDir[dir] = nil |
| 973 | dir = parentDir(dir) |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | // Make directories build their direct subdirectories |
| 978 | dirs = sortedKeys(modulesInDir) |
| 979 | for _, dir := range dirs { |
| 980 | p := parentDir(dir) |
| 981 | if p != "." && p != "/" { |
| 982 | modulesInDir[p] = append(modulesInDir[p], mmTarget(dir)) |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | // Create a mm/<directory> target that depends on all modules in a directory, and depends |
| 987 | // on the mm/* targets of all of its subdirectories that contain Android.bp files. |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 988 | for _, dir := range dirs { |
| 989 | ctx.Build(pctx, blueprint.BuildParams{ |
| 990 | Rule: blueprint.Phony, |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 991 | Outputs: []string{mmTarget(dir)}, |
| 992 | Implicits: modulesInDir[dir], |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 993 | // HACK: checkbuild should be an optional build, but force it |
| 994 | // enabled for now in standalone builds |
Colin Cross | 1604ecf | 2015-12-17 16:33:43 -0800 | [diff] [blame] | 995 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 996 | }) |
| 997 | } |
| 998 | } |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 999 | |
| 1000 | type AndroidModulesByName struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1001 | slice []Module |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 1002 | ctx interface { |
| 1003 | ModuleName(blueprint.Module) string |
| 1004 | ModuleSubDir(blueprint.Module) string |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | func (s AndroidModulesByName) Len() int { return len(s.slice) } |
| 1009 | func (s AndroidModulesByName) Less(i, j int) bool { |
| 1010 | mi, mj := s.slice[i], s.slice[j] |
| 1011 | ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj) |
| 1012 | |
| 1013 | if ni != nj { |
| 1014 | return ni < nj |
| 1015 | } else { |
| 1016 | return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj) |
| 1017 | } |
| 1018 | } |
| 1019 | func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] } |