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