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