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 ( |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 18 | "android/soong/bazel" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 19 | "fmt" |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 20 | "os" |
Alex Light | fb4353d | 2019-01-17 13:57:45 -0800 | [diff] [blame] | 21 | "path" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 22 | "path/filepath" |
Jiyong Park | 1c7e962 | 2020-05-07 16:12:13 +0900 | [diff] [blame] | 23 | "regexp" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 24 | "strings" |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 25 | "text/scanner" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint" |
Colin Cross | fe4bc36 | 2018-09-12 10:02:13 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | var ( |
| 32 | DeviceSharedLibrary = "shared_library" |
| 33 | DeviceStaticLibrary = "static_library" |
| 34 | DeviceExecutable = "executable" |
| 35 | HostSharedLibrary = "host_shared_library" |
| 36 | HostStaticLibrary = "host_static_library" |
| 37 | HostExecutable = "host_executable" |
| 38 | ) |
| 39 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 40 | type BuildParams struct { |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 41 | Rule blueprint.Rule |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 42 | Deps blueprint.Deps |
| 43 | Depfile WritablePath |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 44 | Description string |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 45 | Output WritablePath |
| 46 | Outputs WritablePaths |
Jingwen Chen | ce679d2 | 2020-09-23 04:30:02 +0000 | [diff] [blame] | 47 | SymlinkOutput WritablePath |
| 48 | SymlinkOutputs WritablePaths |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 49 | ImplicitOutput WritablePath |
| 50 | ImplicitOutputs WritablePaths |
| 51 | Input Path |
| 52 | Inputs Paths |
| 53 | Implicit Path |
| 54 | Implicits Paths |
| 55 | OrderOnly Paths |
Colin Cross | 824f116 | 2020-07-16 13:07:51 -0700 | [diff] [blame] | 56 | Validation Path |
| 57 | Validations Paths |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 58 | Default bool |
| 59 | Args map[string]string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 62 | type ModuleBuildParams BuildParams |
| 63 | |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 64 | // EarlyModuleContext provides methods that can be called early, as soon as the properties have |
| 65 | // been parsed into the module and before any mutators have run. |
| 66 | type EarlyModuleContext interface { |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 67 | // Module returns the current module as a Module. It should rarely be necessary, as the module already has a |
| 68 | // reference to itself. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 69 | Module() Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 70 | |
| 71 | // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when |
| 72 | // the module was created, but may have been modified by calls to BaseMutatorContext.Rename. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 73 | ModuleName() string |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 74 | |
| 75 | // ModuleDir returns the path to the directory that contains the definition of the module. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 76 | ModuleDir() string |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 77 | |
| 78 | // ModuleType returns the name of the module type that was used to create the module, as specified in |
| 79 | // RegisterModuleType. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 80 | ModuleType() string |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 81 | |
| 82 | // BlueprintFile returns the name of the blueprint file that contains the definition of this |
| 83 | // module. |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 84 | BlueprintsFile() string |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 85 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 86 | // ContainsProperty returns true if the specified property name was set in the module definition. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 87 | ContainsProperty(name string) bool |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 88 | |
| 89 | // Errorf reports an error at the specified position of the module definition file. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 90 | Errorf(pos scanner.Position, fmt string, args ...interface{}) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 91 | |
| 92 | // ModuleErrorf reports an error at the line number of the module type in the module definition. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 93 | ModuleErrorf(fmt string, args ...interface{}) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 94 | |
| 95 | // PropertyErrorf reports an error at the line number of a property in the module definition. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 96 | PropertyErrorf(property, fmt string, args ...interface{}) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 97 | |
| 98 | // Failed returns true if any errors have been reported. In most cases the module can continue with generating |
| 99 | // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error |
| 100 | // has prevented the module from creating necessary data it can return early when Failed returns true. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 101 | Failed() bool |
| 102 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 103 | // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The |
| 104 | // primary builder will be rerun whenever the specified files are modified. |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 105 | AddNinjaFileDeps(deps ...string) |
| 106 | |
| 107 | DeviceSpecific() bool |
| 108 | SocSpecific() bool |
| 109 | ProductSpecific() bool |
| 110 | SystemExtSpecific() bool |
| 111 | Platform() bool |
| 112 | |
| 113 | Config() Config |
| 114 | DeviceConfig() DeviceConfig |
| 115 | |
| 116 | // Deprecated: use Config() |
| 117 | AConfig() Config |
| 118 | |
| 119 | // GlobWithDeps returns a list of files that match the specified pattern but do not match any |
| 120 | // of the patterns in excludes. It also adds efficient dependencies to rerun the primary |
| 121 | // builder whenever a file matching the pattern as added or removed, without rerunning if a |
| 122 | // file that does not match the pattern is added to a searched directory. |
| 123 | GlobWithDeps(pattern string, excludes []string) ([]string, error) |
| 124 | |
| 125 | Glob(globPattern string, excludes []string) Paths |
| 126 | GlobFiles(globPattern string, excludes []string) Paths |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 127 | IsSymlink(path Path) bool |
| 128 | Readlink(path Path) string |
Colin Cross | 133ebef | 2020-08-14 17:38:45 -0700 | [diff] [blame] | 129 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 130 | // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the |
| 131 | // default SimpleNameInterface if Context.SetNameInterface was not called. |
Colin Cross | 133ebef | 2020-08-14 17:38:45 -0700 | [diff] [blame] | 132 | Namespace() *Namespace |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 135 | // BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 136 | // a Config instead of an interface{}, and some methods have been wrapped to use an android.Module |
| 137 | // instead of a blueprint.Module, plus some extra methods that return Android-specific information |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 138 | // about the current module. |
| 139 | type BaseModuleContext interface { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 140 | EarlyModuleContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 141 | |
Paul Duffin | f88d8e0 | 2020-05-07 20:21:34 +0100 | [diff] [blame] | 142 | blueprintBaseModuleContext() blueprint.BaseModuleContext |
| 143 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 144 | // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information. |
| 145 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 146 | OtherModuleName(m blueprint.Module) string |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 147 | |
| 148 | // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information. |
| 149 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 150 | OtherModuleDir(m blueprint.Module) string |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 151 | |
| 152 | // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information. |
| 153 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 154 | OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 155 | |
| 156 | // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency |
| 157 | // on the module. When called inside a Visit* method with current module being visited, and there are multiple |
| 158 | // dependencies on the module being visited, it returns the dependency tag used for the current dependency. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 159 | OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 160 | |
| 161 | // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface |
| 162 | // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 163 | OtherModuleExists(name string) bool |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 164 | |
| 165 | // OtherModuleDependencyVariantExists returns true if a module with the |
| 166 | // specified name and variant exists. The variant must match the given |
| 167 | // variations. It must also match all the non-local variations of the current |
Martin Stjernholm | 408ffd8 | 2021-05-05 15:27:31 +0100 | [diff] [blame] | 168 | // module. In other words, it checks for the module that AddVariationDependencies |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 169 | // would add a dependency on with the same arguments. |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 170 | OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 171 | |
Martin Stjernholm | 408ffd8 | 2021-05-05 15:27:31 +0100 | [diff] [blame] | 172 | // OtherModuleFarDependencyVariantExists returns true if a module with the |
| 173 | // specified name and variant exists. The variant must match the given |
| 174 | // variations, but not the non-local variations of the current module. In |
| 175 | // other words, it checks for the module that AddFarVariationDependencies |
| 176 | // would add a dependency on with the same arguments. |
| 177 | OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool |
| 178 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 179 | // OtherModuleReverseDependencyVariantExists returns true if a module with the |
| 180 | // specified name exists with the same variations as the current module. In |
Martin Stjernholm | 408ffd8 | 2021-05-05 15:27:31 +0100 | [diff] [blame] | 181 | // other words, it checks for the module that AddReverseDependency would add a |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 182 | // dependency on with the same argument. |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 183 | OtherModuleReverseDependencyVariantExists(name string) bool |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 184 | |
| 185 | // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information. |
| 186 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 187 | OtherModuleType(m blueprint.Module) string |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 188 | |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 189 | // OtherModuleProvider returns the value for a provider for the given module. If the value is |
| 190 | // not set it returns the zero value of the type of the provider, so the return value can always |
| 191 | // be type asserted to the type of the provider. The value returned may be a deep copy of the |
| 192 | // value originally passed to SetProvider. |
| 193 | OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} |
| 194 | |
| 195 | // OtherModuleHasProvider returns true if the provider for the given module has been set. |
| 196 | OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool |
| 197 | |
| 198 | // Provider returns the value for a provider for the current module. If the value is |
| 199 | // not set it returns the zero value of the type of the provider, so the return value can always |
| 200 | // be type asserted to the type of the provider. It panics if called before the appropriate |
| 201 | // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep |
| 202 | // copy of the value originally passed to SetProvider. |
| 203 | Provider(provider blueprint.ProviderKey) interface{} |
| 204 | |
| 205 | // HasProvider returns true if the provider for the current module has been set. |
| 206 | HasProvider(provider blueprint.ProviderKey) bool |
| 207 | |
| 208 | // SetProvider sets the value for a provider for the current module. It panics if not called |
| 209 | // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value |
| 210 | // is not of the appropriate type, or if the value has already been set. The value should not |
| 211 | // be modified after being passed to SetProvider. |
| 212 | SetProvider(provider blueprint.ProviderKey, value interface{}) |
| 213 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 214 | GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 215 | |
| 216 | // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if |
| 217 | // none exists. It panics if the dependency does not have the specified tag. It skips any |
| 218 | // dependencies that are not an android.Module. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 219 | GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 220 | |
| 221 | // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified |
| 222 | // name, or nil if none exists. If there are multiple dependencies on the same module it returns |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 223 | // the first DependencyTag. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 224 | GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) |
| 225 | |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 226 | ModuleFromName(name string) (blueprint.Module, bool) |
| 227 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 228 | // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple |
| 229 | // direct dependencies on the same module visit will be called multiple times on that module |
| 230 | // and OtherModuleDependencyTag will return a different tag for each. |
| 231 | // |
| 232 | // The Module passed to the visit function should not be retained outside of the visit |
| 233 | // function, it may be invalidated by future mutators. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 234 | VisitDirectDepsBlueprint(visit func(blueprint.Module)) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 235 | |
| 236 | // VisitDirectDeps calls visit for each direct dependency. If there are multiple |
| 237 | // direct dependencies on the same module visit will be called multiple times on that module |
Spandan Das | da7f362 | 2021-08-04 20:50:04 +0000 | [diff] [blame] | 238 | // and OtherModuleDependencyTag will return a different tag for each. It raises an error if any of the |
| 239 | // dependencies are not an android.Module. |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 240 | // |
| 241 | // The Module passed to the visit function should not be retained outside of the visit |
| 242 | // function, it may be invalidated by future mutators. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 243 | VisitDirectDeps(visit func(Module)) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 244 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 245 | VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 246 | |
| 247 | // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are |
| 248 | // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and |
| 249 | // OtherModuleDependencyTag will return a different tag for each. It skips any |
| 250 | // dependencies that are not an android.Module. |
| 251 | // |
| 252 | // The Module passed to the visit function should not be retained outside of the visit function, it may be |
| 253 | // invalidated by future mutators. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 254 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
| 255 | // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module |
| 256 | VisitDepsDepthFirst(visit func(Module)) |
| 257 | // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module |
| 258 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 259 | |
| 260 | // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may |
| 261 | // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the |
| 262 | // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited |
| 263 | // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips |
| 264 | // any dependencies that are not an android.Module. |
| 265 | // |
| 266 | // The Modules passed to the visit function should not be retained outside of the visit function, they may be |
| 267 | // invalidated by future mutators. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 268 | WalkDeps(visit func(Module, Module) bool) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 269 | |
| 270 | // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency |
| 271 | // tree in top down order. visit may be called multiple times for the same (child, parent) |
| 272 | // pair if there are multiple direct dependencies between the child and parent with different |
| 273 | // tags. OtherModuleDependencyTag will return the tag for the currently visited |
| 274 | // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down |
| 275 | // to child. |
| 276 | // |
| 277 | // The Modules passed to the visit function should not be retained outside of the visit function, they may be |
| 278 | // invalidated by future mutators. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 279 | WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 280 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 281 | // GetWalkPath is supposed to be called in visit function passed in WalkDeps() |
| 282 | // and returns a top-down dependency path from a start module to current child module. |
| 283 | GetWalkPath() []Module |
| 284 | |
Colin Cross | 4dfacf9 | 2020-09-16 19:22:27 -0700 | [diff] [blame] | 285 | // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in |
| 286 | // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the |
| 287 | // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are |
| 288 | // only done once for all variants of a module. |
| 289 | PrimaryModule() Module |
| 290 | |
| 291 | // FinalModule returns the last variant of the current module. Variants of a module are always visited in |
| 292 | // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all |
| 293 | // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform |
| 294 | // singleton actions that are only done once for all variants of a module. |
| 295 | FinalModule() Module |
| 296 | |
| 297 | // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always |
| 298 | // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read |
| 299 | // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any |
| 300 | // data modified by the current mutator. |
| 301 | VisitAllModuleVariants(visit func(Module)) |
| 302 | |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 303 | // GetTagPath is supposed to be called in visit function passed in WalkDeps() |
| 304 | // and returns a top-down dependency tags path from a start module to current child module. |
| 305 | // It has one less entry than GetWalkPath() as it contains the dependency tags that |
| 306 | // exist between each adjacent pair of modules in the GetWalkPath(). |
| 307 | // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1] |
| 308 | GetTagPath() []blueprint.DependencyTag |
| 309 | |
Jiyong Park | 1c7e962 | 2020-05-07 16:12:13 +0900 | [diff] [blame] | 310 | // GetPathString is supposed to be called in visit function passed in WalkDeps() |
| 311 | // and returns a multi-line string showing the modules and dependency tags |
| 312 | // among them along the top-down dependency path from a start module to current child module. |
| 313 | // skipFirst when set to true, the output doesn't include the start module, |
| 314 | // which is already printed when this function is used along with ModuleErrorf(). |
| 315 | GetPathString(skipFirst bool) string |
| 316 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 317 | AddMissingDependencies(missingDeps []string) |
| 318 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 319 | Target() Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 320 | TargetPrimary() bool |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 321 | |
| 322 | // The additional arch specific targets (e.g. 32/64 bit) that this module variant is |
| 323 | // responsible for creating. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 324 | MultiTargets() []Target |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 325 | Arch() Arch |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 326 | Os() OsType |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 327 | Host() bool |
| 328 | Device() bool |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 329 | Darwin() bool |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 330 | Windows() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 331 | Debug() bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 332 | PrimaryArch() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 335 | // Deprecated: use EarlyModuleContext instead |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 336 | type BaseContext interface { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 337 | EarlyModuleContext |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 340 | type ModuleContext interface { |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 341 | BaseModuleContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 342 | |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 343 | blueprintModuleContext() blueprint.ModuleContext |
| 344 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 345 | // Deprecated: use ModuleContext.Build instead. |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 346 | ModuleBuild(pctx PackageContext, params ModuleBuildParams) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 347 | |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 348 | // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must |
| 349 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 350 | // |
| 351 | // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead. |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 352 | ExpandSources(srcFiles, excludes []string) Paths |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 353 | |
| 354 | // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must |
| 355 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 356 | // |
| 357 | // Deprecated: use PathForModuleSrc instead. |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 358 | ExpandSource(srcFile, prop string) Path |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 359 | |
Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 360 | ExpandOptionalSource(srcFile *string, prop string) OptionalPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 361 | |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 362 | // InstallExecutable creates a rule to copy srcPath to name in the installPath directory, |
| 363 | // with the given additional dependencies. The file is marked executable after copying. |
| 364 | // |
| 365 | // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the |
| 366 | // installed file will be returned by PackagingSpecs() on this module or by |
| 367 | // TransitivePackagingSpecs() on modules that depend on this module through dependency tags |
| 368 | // for which IsInstallDepNeeded returns true. |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 369 | InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 370 | |
| 371 | // InstallFile creates a rule to copy srcPath to name in the installPath directory, |
| 372 | // with the given additional dependencies. |
| 373 | // |
| 374 | // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the |
| 375 | // installed file will be returned by PackagingSpecs() on this module or by |
| 376 | // TransitivePackagingSpecs() on modules that depend on this module through dependency tags |
| 377 | // for which IsInstallDepNeeded returns true. |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 378 | InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 379 | |
| 380 | // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath |
| 381 | // directory. |
| 382 | // |
| 383 | // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the |
| 384 | // installed file will be returned by PackagingSpecs() on this module or by |
| 385 | // TransitivePackagingSpecs() on modules that depend on this module through dependency tags |
| 386 | // for which IsInstallDepNeeded returns true. |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 387 | InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 388 | |
| 389 | // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name |
| 390 | // in the installPath directory. |
| 391 | // |
| 392 | // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the |
| 393 | // installed file will be returned by PackagingSpecs() on this module or by |
| 394 | // TransitivePackagingSpecs() on modules that depend on this module through dependency tags |
| 395 | // for which IsInstallDepNeeded returns true. |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 396 | InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 397 | |
| 398 | // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating |
| 399 | // the rule to copy the file. This is useful to define how a module would be packaged |
| 400 | // without installing it into the global installation directories. |
| 401 | // |
| 402 | // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by |
| 403 | // TransitivePackagingSpecs() on modules that depend on this module through dependency tags |
| 404 | // for which IsInstallDepNeeded returns true. |
| 405 | PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec |
| 406 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 407 | CheckbuildFile(srcPath Path) |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 408 | TidyFile(srcPath Path) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 409 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 410 | InstallInData() bool |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 411 | InstallInTestcases() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 412 | InstallInSanitizerDir() bool |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 413 | InstallInRamdisk() bool |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 414 | InstallInVendorRamdisk() bool |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 415 | InstallInDebugRamdisk() bool |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 416 | InstallInRecovery() bool |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 417 | InstallInRoot() bool |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 418 | InstallInVendor() bool |
Colin Cross | 607d858 | 2019-07-29 16:44:46 -0700 | [diff] [blame] | 419 | InstallBypassMake() bool |
Jiyong Park | 87788b5 | 2020-09-01 12:37:45 +0900 | [diff] [blame] | 420 | InstallForceOS() (*OsType, *ArchType) |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 421 | |
| 422 | RequiredModuleNames() []string |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 423 | HostRequiredModuleNames() []string |
| 424 | TargetRequiredModuleNames() []string |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 425 | |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 426 | ModuleSubDir() string |
| 427 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 428 | Variable(pctx PackageContext, name, value string) |
| 429 | Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 430 | // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string, |
| 431 | // and performs more verification. |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 432 | Build(pctx PackageContext, params BuildParams) |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 433 | // Phony creates a Make-style phony rule, a rule with no commands that can depend on other |
| 434 | // phony rules or real files. Phony can be called on the same name multiple times to add |
| 435 | // additional dependencies. |
| 436 | Phony(phony string, deps ...Path) |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 437 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 438 | // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods, |
| 439 | // but do not exist. |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 440 | GetMissingDependencies() []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 443 | type Module interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 444 | blueprint.Module |
| 445 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 446 | // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions, |
| 447 | // but GenerateAndroidBuildActions also has access to Android-specific information. |
| 448 | // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 449 | GenerateAndroidBuildActions(ModuleContext) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 450 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 451 | // Add dependencies to the components of a module, i.e. modules that are created |
| 452 | // by the module and which are considered to be part of the creating module. |
| 453 | // |
| 454 | // This is called before prebuilts are renamed so as to allow a dependency to be |
| 455 | // added directly to a prebuilt child module instead of depending on a source module |
| 456 | // and relying on prebuilt processing to switch to the prebuilt module if preferred. |
| 457 | // |
| 458 | // A dependency on a prebuilt must include the "prebuilt_" prefix. |
| 459 | ComponentDepsMutator(ctx BottomUpMutatorContext) |
| 460 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 461 | DepsMutator(BottomUpMutatorContext) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 462 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 463 | base() *ModuleBase |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 464 | Disable() |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 465 | Enabled() bool |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 466 | Target() Target |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 467 | MultiTargets() []Target |
Anton Hansson | 1ee62c0 | 2020-06-30 11:51:53 +0100 | [diff] [blame] | 468 | Owner() string |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 469 | InstallInData() bool |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 470 | InstallInTestcases() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 471 | InstallInSanitizerDir() bool |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 472 | InstallInRamdisk() bool |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 473 | InstallInVendorRamdisk() bool |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 474 | InstallInDebugRamdisk() bool |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 475 | InstallInRecovery() bool |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 476 | InstallInRoot() bool |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 477 | InstallInVendor() bool |
Colin Cross | 607d858 | 2019-07-29 16:44:46 -0700 | [diff] [blame] | 478 | InstallBypassMake() bool |
Jiyong Park | 87788b5 | 2020-09-01 12:37:45 +0900 | [diff] [blame] | 479 | InstallForceOS() (*OsType, *ArchType) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 480 | HideFromMake() |
| 481 | IsHideFromMake() bool |
Martin Stjernholm | 9e7f45e | 2020-12-23 03:50:30 +0000 | [diff] [blame] | 482 | IsSkipInstall() bool |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 483 | MakeUninstallable() |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 484 | ReplacedByPrebuilt() |
| 485 | IsReplacedByPrebuilt() bool |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 486 | ExportedToMake() bool |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 487 | InitRc() Paths |
| 488 | VintfFragments() Paths |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 489 | NoticeFiles() Paths |
Justin Yun | 885a7de | 2021-06-29 20:34:53 +0900 | [diff] [blame] | 490 | EffectiveLicenseFiles() Paths |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 491 | |
| 492 | AddProperties(props ...interface{}) |
| 493 | GetProperties() []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 494 | |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 495 | // IsConvertedByBp2build returns whether this module was converted via bp2build |
| 496 | IsConvertedByBp2build() bool |
| 497 | // Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module |
| 498 | Bp2buildTargets() []bp2buildInfo |
| 499 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 500 | BuildParamsForTests() []BuildParams |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 501 | RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 502 | VariablesForTests() map[string]string |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 503 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 504 | // String returns a string that includes the module name and variants for printing during debugging. |
| 505 | String() string |
| 506 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 507 | // Get the qualified module id for this module. |
| 508 | qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName |
| 509 | |
| 510 | // Get information about the properties that can contain visibility rules. |
| 511 | visibilityProperties() []visibilityProperty |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 512 | |
Jiyong Park | 6a8cf5f | 2019-12-30 16:31:09 +0900 | [diff] [blame] | 513 | RequiredModuleNames() []string |
| 514 | HostRequiredModuleNames() []string |
| 515 | TargetRequiredModuleNames() []string |
Colin Cross | 897266e | 2020-02-13 13:22:08 -0800 | [diff] [blame] | 516 | |
Jiyong Park | 4dc2a1a | 2020-09-28 17:46:22 +0900 | [diff] [blame] | 517 | FilesToInstall() InstallPaths |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 518 | PackagingSpecs() []PackagingSpec |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 519 | |
| 520 | // TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive |
| 521 | // dependencies with dependency tags for which IsInstallDepNeeded() returns true. |
| 522 | TransitivePackagingSpecs() []PackagingSpec |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Jingwen Chen | ab60f12 | 2021-01-24 21:21:45 -0500 | [diff] [blame] | 525 | // BazelTargetModule is a lightweight wrapper interface around Module for |
| 526 | // bp2build conversion purposes. |
| 527 | // |
| 528 | // In bp2build's bootstrap.Main execution, Soong runs an alternate pipeline of |
| 529 | // mutators that creates BazelTargetModules from regular Module objects, |
| 530 | // performing the mapping from Soong properties to Bazel rule attributes in the |
| 531 | // process. This process may optionally create additional BazelTargetModules, |
| 532 | // resulting in a 1:many mapping. |
| 533 | // |
| 534 | // bp2build.Codegen is then responsible for visiting all modules in the graph, |
| 535 | // filtering for BazelTargetModules, and code-generating BUILD targets from |
| 536 | // them. |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 537 | type BazelTargetModule interface { |
| 538 | Module |
| 539 | |
Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 540 | bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties |
| 541 | SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties) |
| 542 | |
| 543 | RuleClass() string |
| 544 | BzlLoadLocation() string |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 545 | } |
| 546 | |
Jingwen Chen | ab60f12 | 2021-01-24 21:21:45 -0500 | [diff] [blame] | 547 | // InitBazelTargetModule is a wrapper function that decorates BazelTargetModule |
| 548 | // with property structs containing metadata for bp2build conversion. |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 549 | func InitBazelTargetModule(module BazelTargetModule) { |
Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 550 | module.AddProperties(module.bazelTargetModuleProperties()) |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 551 | InitAndroidModule(module) |
| 552 | } |
| 553 | |
Jingwen Chen | ab60f12 | 2021-01-24 21:21:45 -0500 | [diff] [blame] | 554 | // BazelTargetModuleBase contains the property structs with metadata for |
| 555 | // bp2build conversion. |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 556 | type BazelTargetModuleBase struct { |
| 557 | ModuleBase |
| 558 | Properties bazel.BazelTargetModuleProperties |
| 559 | } |
| 560 | |
Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 561 | // bazelTargetModuleProperties getter. |
| 562 | func (btmb *BazelTargetModuleBase) bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties { |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 563 | return &btmb.Properties |
| 564 | } |
| 565 | |
Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 566 | // SetBazelTargetModuleProperties setter for BazelTargetModuleProperties |
| 567 | func (btmb *BazelTargetModuleBase) SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties) { |
| 568 | btmb.Properties = props |
| 569 | } |
| 570 | |
| 571 | // RuleClass returns the rule class for this Bazel target |
| 572 | func (b *BazelTargetModuleBase) RuleClass() string { |
| 573 | return b.bazelTargetModuleProperties().Rule_class |
| 574 | } |
| 575 | |
| 576 | // BzlLoadLocation returns the rule class for this Bazel target |
| 577 | func (b *BazelTargetModuleBase) BzlLoadLocation() string { |
| 578 | return b.bazelTargetModuleProperties().Bzl_load_location |
| 579 | } |
| 580 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 581 | // Qualified id for a module |
| 582 | type qualifiedModuleName struct { |
| 583 | // The package (i.e. directory) in which the module is defined, without trailing / |
| 584 | pkg string |
| 585 | |
| 586 | // The name of the module, empty string if package. |
| 587 | name string |
| 588 | } |
| 589 | |
| 590 | func (q qualifiedModuleName) String() string { |
| 591 | if q.name == "" { |
| 592 | return "//" + q.pkg |
| 593 | } |
| 594 | return "//" + q.pkg + ":" + q.name |
| 595 | } |
| 596 | |
Paul Duffin | e484f47 | 2019-06-20 16:38:08 +0100 | [diff] [blame] | 597 | func (q qualifiedModuleName) isRootPackage() bool { |
| 598 | return q.pkg == "" && q.name == "" |
| 599 | } |
| 600 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 601 | // Get the id for the package containing this module. |
| 602 | func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName { |
| 603 | pkg := q.pkg |
| 604 | if q.name == "" { |
Paul Duffin | e484f47 | 2019-06-20 16:38:08 +0100 | [diff] [blame] | 605 | if pkg == "" { |
| 606 | panic(fmt.Errorf("Cannot get containing package id of root package")) |
| 607 | } |
| 608 | |
| 609 | index := strings.LastIndex(pkg, "/") |
| 610 | if index == -1 { |
| 611 | pkg = "" |
| 612 | } else { |
| 613 | pkg = pkg[:index] |
| 614 | } |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 615 | } |
| 616 | return newPackageId(pkg) |
| 617 | } |
| 618 | |
| 619 | func newPackageId(pkg string) qualifiedModuleName { |
| 620 | // A qualified id for a package module has no name. |
| 621 | return qualifiedModuleName{pkg: pkg, name: ""} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 622 | } |
| 623 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 624 | type Dist struct { |
| 625 | // Copy the output of this module to the $DIST_DIR when `dist` is specified on the |
| 626 | // command line and any of these targets are also on the command line, or otherwise |
| 627 | // built |
| 628 | Targets []string `android:"arch_variant"` |
| 629 | |
| 630 | // The name of the output artifact. This defaults to the basename of the output of |
| 631 | // the module. |
| 632 | Dest *string `android:"arch_variant"` |
| 633 | |
| 634 | // The directory within the dist directory to store the artifact. Defaults to the |
| 635 | // top level directory (""). |
| 636 | Dir *string `android:"arch_variant"` |
| 637 | |
| 638 | // A suffix to add to the artifact file name (before any extension). |
| 639 | Suffix *string `android:"arch_variant"` |
| 640 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 641 | // A string tag to select the OutputFiles associated with the tag. |
| 642 | // |
| 643 | // If no tag is specified then it will select the default dist paths provided |
| 644 | // by the module type. If a tag of "" is specified then it will return the |
| 645 | // default output files provided by the modules, i.e. the result of calling |
| 646 | // OutputFiles(""). |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 647 | Tag *string `android:"arch_variant"` |
| 648 | } |
| 649 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 650 | type nameProperties struct { |
| 651 | // The name of the module. Must be unique across all modules. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 652 | Name *string |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Colin Cross | 08d6f8f | 2020-11-19 02:33:19 +0000 | [diff] [blame] | 655 | type commonProperties struct { |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 656 | // emit build rules for this module |
Paul Duffin | 54d9bb7 | 2020-02-12 10:20:56 +0000 | [diff] [blame] | 657 | // |
| 658 | // Disabling a module should only be done for those modules that cannot be built |
| 659 | // in the current environment. Modules that can build in the current environment |
| 660 | // but are not usually required (e.g. superceded by a prebuilt) should not be |
| 661 | // disabled as that will prevent them from being built by the checkbuild target |
| 662 | // and so prevent early detection of changes that have broken those modules. |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 663 | Enabled *bool `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 664 | |
Paul Duffin | 2e61fa6 | 2019-03-28 14:10:57 +0000 | [diff] [blame] | 665 | // Controls the visibility of this module to other modules. Allowable values are one or more of |
| 666 | // these formats: |
| 667 | // |
| 668 | // ["//visibility:public"]: Anyone can use this module. |
| 669 | // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use |
| 670 | // this module. |
Paul Duffin | 51084ff | 2020-05-05 19:19:22 +0100 | [diff] [blame] | 671 | // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module. |
| 672 | // Can only be used at the beginning of a list of visibility rules. |
Paul Duffin | 2e61fa6 | 2019-03-28 14:10:57 +0000 | [diff] [blame] | 673 | // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and |
| 674 | // other/package (defined in some/package/*.bp and other/package/*.bp) have access to |
| 675 | // this module. Note that sub-packages do not have access to the rule; for example, |
| 676 | // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__ |
| 677 | // is a special module and must be used verbatim. It represents all of the modules in the |
| 678 | // package. |
| 679 | // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project |
| 680 | // or other or in one of their sub-packages have access to this module. For example, |
| 681 | // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed |
| 682 | // to depend on this rule (but not //independent:evil) |
| 683 | // ["//project"]: This is shorthand for ["//project:__pkg__"] |
| 684 | // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where |
| 685 | // //project is the module's package. e.g. using [":__subpackages__"] in |
| 686 | // packages/apps/Settings/Android.bp is equivalent to |
| 687 | // //packages/apps/Settings:__subpackages__. |
| 688 | // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public |
| 689 | // for now. It is an error if it is used in a module. |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 690 | // |
| 691 | // If a module does not specify the `visibility` property then it uses the |
| 692 | // `default_visibility` property of the `package` module in the module's package. |
| 693 | // |
| 694 | // If the `default_visibility` property is not set for the module's package then |
Paul Duffin | e484f47 | 2019-06-20 16:38:08 +0100 | [diff] [blame] | 695 | // it will use the `default_visibility` of its closest ancestor package for which |
| 696 | // a `default_visibility` property is specified. |
| 697 | // |
| 698 | // If no `default_visibility` property can be found then the module uses the |
| 699 | // global default of `//visibility:legacy_public`. |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 700 | // |
Paul Duffin | 95d53b5 | 2019-07-24 13:45:05 +0100 | [diff] [blame] | 701 | // The `visibility` property has no effect on a defaults module although it does |
| 702 | // apply to any non-defaults module that uses it. To set the visibility of a |
| 703 | // defaults module, use the `defaults_visibility` property on the defaults module; |
| 704 | // not to be confused with the `default_visibility` property on the package module. |
| 705 | // |
Paul Duffin | 2e61fa6 | 2019-03-28 14:10:57 +0000 | [diff] [blame] | 706 | // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for |
| 707 | // more details. |
| 708 | Visibility []string |
| 709 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 710 | // Describes the licenses applicable to this module. Must reference license modules. |
| 711 | Licenses []string |
| 712 | |
| 713 | // Flattened from direct license dependencies. Equal to Licenses unless particular module adds more. |
| 714 | Effective_licenses []string `blueprint:"mutated"` |
| 715 | // Override of module name when reporting licenses |
| 716 | Effective_package_name *string `blueprint:"mutated"` |
| 717 | // Notice files |
Paul Duffin | ec0836a | 2021-05-10 22:53:30 +0100 | [diff] [blame] | 718 | Effective_license_text Paths `blueprint:"mutated"` |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 719 | // License names |
| 720 | Effective_license_kinds []string `blueprint:"mutated"` |
| 721 | // License conditions |
| 722 | Effective_license_conditions []string `blueprint:"mutated"` |
| 723 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 724 | // 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] | 725 | // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both |
| 726 | // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit |
Roland Levillain | 24bb2e6 | 2020-09-22 11:18:38 +0000 | [diff] [blame] | 727 | // platform). |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 728 | Compile_multilib *string `android:"arch_variant"` |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 729 | |
| 730 | Target struct { |
| 731 | Host struct { |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 732 | Compile_multilib *string |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 733 | } |
| 734 | Android struct { |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 735 | Compile_multilib *string |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 739 | // If set to true then the archMutator will create variants for each arch specific target |
| 740 | // (e.g. 32/64) that the module is required to produce. If set to false then it will only |
| 741 | // create a variant for the architecture and will list the additional arch specific targets |
| 742 | // that the variant needs to produce in the CompileMultiTargets property. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 743 | UseTargetVariants bool `blueprint:"mutated"` |
| 744 | Default_multilib string `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 745 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 746 | // whether this is a proprietary vendor module, and should be installed into /vendor |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 747 | Proprietary *bool |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 748 | |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 749 | // vendor who owns this module |
Dan Willemsen | efac4a8 | 2017-07-18 19:42:09 -0700 | [diff] [blame] | 750 | Owner *string |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 751 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 752 | // whether this module is specific to an SoC (System-On-a-Chip). When set to true, |
| 753 | // it is installed into /vendor (or /system/vendor if vendor partition does not exist). |
| 754 | // Use `soc_specific` instead for better meaning. |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 755 | Vendor *bool |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 756 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 757 | // whether this module is specific to an SoC (System-On-a-Chip). When set to true, |
| 758 | // it is installed into /vendor (or /system/vendor if vendor partition does not exist). |
| 759 | Soc_specific *bool |
| 760 | |
| 761 | // whether this module is specific to a device, not only for SoC, but also for off-chip |
| 762 | // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition |
| 763 | // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist). |
| 764 | // This implies `soc_specific:true`. |
| 765 | Device_specific *bool |
| 766 | |
| 767 | // whether this module is specific to a software configuration of a product (e.g. country, |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 768 | // network operator, etc). When set to true, it is installed into /product (or |
| 769 | // /system/product if product partition does not exist). |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 770 | Product_specific *bool |
| 771 | |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 772 | // whether this module extends system. When set to true, it is installed into /system_ext |
| 773 | // (or /system/system_ext if system_ext partition does not exist). |
| 774 | System_ext_specific *bool |
| 775 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 776 | // Whether this module is installed to recovery partition |
| 777 | Recovery *bool |
| 778 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 779 | // Whether this module is installed to ramdisk |
| 780 | Ramdisk *bool |
| 781 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 782 | // Whether this module is installed to vendor ramdisk |
| 783 | Vendor_ramdisk *bool |
| 784 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 785 | // Whether this module is installed to debug ramdisk |
| 786 | Debug_ramdisk *bool |
| 787 | |
Jaewoong Jung | 8e93aba | 2021-03-02 16:58:08 -0800 | [diff] [blame] | 788 | // Whether this module is built for non-native architectures (also known as native bridge binary) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 789 | Native_bridge_supported *bool `android:"arch_variant"` |
| 790 | |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 791 | // init.rc files to be installed if this module is installed |
Colin Cross | 0bab877 | 2020-09-25 14:01:21 -0700 | [diff] [blame] | 792 | Init_rc []string `android:"arch_variant,path"` |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 793 | |
Steven Moreland | 57a23d2 | 2018-04-04 15:42:19 -0700 | [diff] [blame] | 794 | // VINTF manifest fragments to be installed if this module is installed |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 795 | Vintf_fragments []string `android:"path"` |
Steven Moreland | 57a23d2 | 2018-04-04 15:42:19 -0700 | [diff] [blame] | 796 | |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 797 | // names of other modules to install if this module is installed |
Colin Cross | c602b7d | 2017-05-05 13:36:36 -0700 | [diff] [blame] | 798 | Required []string `android:"arch_variant"` |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 799 | |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 800 | // names of other modules to install on host if this module is installed |
| 801 | Host_required []string `android:"arch_variant"` |
| 802 | |
| 803 | // names of other modules to install on target if this module is installed |
| 804 | Target_required []string `android:"arch_variant"` |
| 805 | |
Colin Cross | 5aac362 | 2017-08-31 15:07:09 -0700 | [diff] [blame] | 806 | // relative path to a file to include in the list of notices for the device |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 807 | Notice *string `android:"path"` |
Colin Cross | 5aac362 | 2017-08-31 15:07:09 -0700 | [diff] [blame] | 808 | |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 809 | // The OsType of artifacts that this module variant is responsible for creating. |
| 810 | // |
| 811 | // Set by osMutator |
| 812 | CompileOS OsType `blueprint:"mutated"` |
| 813 | |
| 814 | // The Target of artifacts that this module variant is responsible for creating. |
| 815 | // |
| 816 | // Set by archMutator |
| 817 | CompileTarget Target `blueprint:"mutated"` |
| 818 | |
| 819 | // The additional arch specific targets (e.g. 32/64 bit) that this module variant is |
| 820 | // responsible for creating. |
| 821 | // |
| 822 | // By default this is nil as, where necessary, separate variants are created for the |
| 823 | // different multilib types supported and that information is encapsulated in the |
| 824 | // CompileTarget so the module variant simply needs to create artifacts for that. |
| 825 | // |
| 826 | // However, if UseTargetVariants is set to false (e.g. by |
| 827 | // InitAndroidMultiTargetsArchModule) then no separate variants are created for the |
| 828 | // multilib targets. Instead a single variant is created for the architecture and |
| 829 | // this contains the multilib specific targets that this variant should create. |
| 830 | // |
| 831 | // Set by archMutator |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 832 | CompileMultiTargets []Target `blueprint:"mutated"` |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 833 | |
| 834 | // True if the module variant's CompileTarget is the primary target |
| 835 | // |
| 836 | // Set by archMutator |
| 837 | CompilePrimary bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 838 | |
| 839 | // Set by InitAndroidModule |
| 840 | HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 841 | ArchSpecific bool `blueprint:"mutated"` |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 842 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 843 | // If set to true then a CommonOS variant will be created which will have dependencies |
| 844 | // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot |
| 845 | // that covers all os and architecture variants. |
| 846 | // |
| 847 | // The OsType specific variants can be retrieved by calling |
| 848 | // GetOsSpecificVariantsOfCommonOSVariant |
| 849 | // |
| 850 | // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule |
| 851 | CreateCommonOSVariant bool `blueprint:"mutated"` |
| 852 | |
| 853 | // If set to true then this variant is the CommonOS variant that has dependencies on its |
| 854 | // OsType specific variants. |
| 855 | // |
| 856 | // Set by osMutator. |
| 857 | CommonOSVariant bool `blueprint:"mutated"` |
| 858 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 859 | // When HideFromMake is set to true, no entry for this variant will be emitted in the |
| 860 | // generated Android.mk file. |
| 861 | HideFromMake bool `blueprint:"mutated"` |
| 862 | |
| 863 | // When SkipInstall is set to true, calls to ctx.InstallFile, ctx.InstallExecutable, |
| 864 | // ctx.InstallSymlink and ctx.InstallAbsoluteSymlink act like calls to ctx.PackageFile |
| 865 | // and don't create a rule to install the file. |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 866 | SkipInstall bool `blueprint:"mutated"` |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 867 | |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 868 | // Whether the module has been replaced by a prebuilt |
| 869 | ReplacedByPrebuilt bool `blueprint:"mutated"` |
| 870 | |
Justin Yun | 32f053b | 2020-07-31 23:07:17 +0900 | [diff] [blame] | 871 | // Disabled by mutators. If set to true, it overrides Enabled property. |
| 872 | ForcedDisabled bool `blueprint:"mutated"` |
| 873 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 874 | NamespaceExportedToMake bool `blueprint:"mutated"` |
Colin Cross | 6c4f21f | 2019-06-06 15:41:36 -0700 | [diff] [blame] | 875 | |
| 876 | MissingDeps []string `blueprint:"mutated"` |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 877 | |
| 878 | // Name and variant strings stored by mutators to enable Module.String() |
| 879 | DebugName string `blueprint:"mutated"` |
| 880 | DebugMutators []string `blueprint:"mutated"` |
| 881 | DebugVariations []string `blueprint:"mutated"` |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 882 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 883 | // ImageVariation is set by ImageMutator to specify which image this variation is for, |
| 884 | // for example "" for core or "recovery" for recovery. It will often be set to one of the |
| 885 | // constants in image.go, but can also be set to a custom value by individual module types. |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 886 | ImageVariation string `blueprint:"mutated"` |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 887 | |
| 888 | // Information about _all_ bp2build targets generated by this module. Multiple targets are |
| 889 | // supported as Soong handles some things within a single target that we may choose to split into |
| 890 | // multiple targets, e.g. renderscript, protos, yacc within a cc module. |
| 891 | Bp2buildInfo []bp2buildInfo `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 892 | } |
| 893 | |
Paul Duffin | ed87513 | 2020-09-02 13:08:57 +0100 | [diff] [blame] | 894 | type distProperties struct { |
| 895 | // configuration to distribute output files from this module to the distribution |
| 896 | // directory (default: $OUT/dist, configurable with $DIST_DIR) |
| 897 | Dist Dist `android:"arch_variant"` |
| 898 | |
| 899 | // a list of configurations to distribute output files from this module to the |
| 900 | // distribution directory (default: $OUT/dist, configurable with $DIST_DIR) |
| 901 | Dists []Dist `android:"arch_variant"` |
| 902 | } |
| 903 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 904 | // The key to use in TaggedDistFiles when a Dist structure does not specify a |
| 905 | // tag property. This intentionally does not use "" as the default because that |
| 906 | // would mean that an empty tag would have a different meaning when used in a dist |
| 907 | // structure that when used to reference a specific set of output paths using the |
| 908 | // :module{tag} syntax, which passes tag to the OutputFiles(tag) method. |
| 909 | const DefaultDistTag = "<default-dist-tag>" |
| 910 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 911 | // A map of OutputFile tag keys to Paths, for disting purposes. |
| 912 | type TaggedDistFiles map[string]Paths |
| 913 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 914 | // addPathsForTag adds a mapping from the tag to the paths. If the map is nil |
| 915 | // then it will create a map, update it and then return it. If a mapping already |
| 916 | // exists for the tag then the paths are appended to the end of the current list |
| 917 | // of paths, ignoring any duplicates. |
| 918 | func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles { |
| 919 | if t == nil { |
| 920 | t = make(TaggedDistFiles) |
| 921 | } |
| 922 | |
| 923 | for _, distFile := range paths { |
| 924 | if distFile != nil && !t[tag].containsPath(distFile) { |
| 925 | t[tag] = append(t[tag], distFile) |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | return t |
| 930 | } |
| 931 | |
| 932 | // merge merges the entries from the other TaggedDistFiles object into this one. |
| 933 | // If the TaggedDistFiles is nil then it will create a new instance, merge the |
| 934 | // other into it, and then return it. |
| 935 | func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles { |
| 936 | for tag, paths := range other { |
| 937 | t = t.addPathsForTag(tag, paths...) |
| 938 | } |
| 939 | |
| 940 | return t |
| 941 | } |
| 942 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 943 | func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles { |
Jingwen Chen | 7b27ca7 | 2020-07-24 09:13:49 +0000 | [diff] [blame] | 944 | for _, path := range paths { |
| 945 | if path == nil { |
| 946 | panic("The path to a dist file cannot be nil.") |
| 947 | } |
| 948 | } |
| 949 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 950 | // The default OutputFile tag is the empty "" string. |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 951 | return TaggedDistFiles{DefaultDistTag: paths} |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 954 | type hostAndDeviceProperties struct { |
Colin Cross | 4e81d70 | 2018-11-09 10:36:55 -0800 | [diff] [blame] | 955 | // If set to true, build a variant of the module for the host. Defaults to false. |
| 956 | Host_supported *bool |
| 957 | |
| 958 | // If set to true, build a variant of the module for the device. Defaults to true. |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 959 | Device_supported *bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 960 | } |
| 961 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 962 | type Multilib string |
| 963 | |
| 964 | const ( |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 965 | MultilibBoth Multilib = "both" |
| 966 | MultilibFirst Multilib = "first" |
| 967 | MultilibCommon Multilib = "common" |
| 968 | MultilibCommonFirst Multilib = "common_first" |
| 969 | MultilibDefault Multilib = "" |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 970 | ) |
| 971 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 972 | type HostOrDeviceSupported int |
| 973 | |
| 974 | const ( |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 975 | hostSupported = 1 << iota |
| 976 | hostCrossSupported |
| 977 | deviceSupported |
| 978 | hostDefault |
| 979 | deviceDefault |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 980 | |
| 981 | // Host and HostCross are built by default. Device is not supported. |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 982 | HostSupported = hostSupported | hostCrossSupported | hostDefault |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 983 | |
| 984 | // Host is built by default. HostCross and Device are not supported. |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 985 | HostSupportedNoCross = hostSupported | hostDefault |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 986 | |
| 987 | // Device is built by default. Host and HostCross are not supported. |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 988 | DeviceSupported = deviceSupported | deviceDefault |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 989 | |
Liz Kammer | 8631cc7 | 2021-08-23 21:12:07 +0000 | [diff] [blame] | 990 | // By default, _only_ device variant is built. Device variant can be disabled with `device_supported: false` |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 991 | // Host and HostCross are disabled by default and can be enabled with `host_supported: true` |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 992 | HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 993 | |
| 994 | // Host, HostCross, and Device are built by default. |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 995 | // Building Device can be disabled with `device_supported: false` |
| 996 | // Building Host and HostCross can be disabled with `host_supported: false` |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 997 | HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault | |
| 998 | deviceSupported | deviceDefault |
Dan Albert | 0981b5c | 2018-08-02 13:46:35 -0700 | [diff] [blame] | 999 | |
| 1000 | // Nothing is supported. This is not exposed to the user, but used to mark a |
| 1001 | // host only module as unsupported when the module type is not supported on |
| 1002 | // the host OS. E.g. benchmarks are supported on Linux but not Darwin. |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1003 | NeitherHostNorDeviceSupported = 0 |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1004 | ) |
| 1005 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1006 | type moduleKind int |
| 1007 | |
| 1008 | const ( |
| 1009 | platformModule moduleKind = iota |
| 1010 | deviceSpecificModule |
| 1011 | socSpecificModule |
| 1012 | productSpecificModule |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1013 | systemExtSpecificModule |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1014 | ) |
| 1015 | |
| 1016 | func (k moduleKind) String() string { |
| 1017 | switch k { |
| 1018 | case platformModule: |
| 1019 | return "platform" |
| 1020 | case deviceSpecificModule: |
| 1021 | return "device-specific" |
| 1022 | case socSpecificModule: |
| 1023 | return "soc-specific" |
| 1024 | case productSpecificModule: |
| 1025 | return "product-specific" |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1026 | case systemExtSpecificModule: |
| 1027 | return "systemext-specific" |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1028 | default: |
| 1029 | panic(fmt.Errorf("unknown module kind %d", k)) |
| 1030 | } |
| 1031 | } |
| 1032 | |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 1033 | func initAndroidModuleBase(m Module) { |
| 1034 | m.base().module = m |
| 1035 | } |
| 1036 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1037 | // InitAndroidModule initializes the Module as an Android module that is not architecture-specific. |
| 1038 | // It adds the common properties, for example "name" and "enabled". |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1039 | func InitAndroidModule(m Module) { |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 1040 | initAndroidModuleBase(m) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1041 | base := m.base() |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1042 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1043 | m.AddProperties( |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 1044 | &base.nameProperties, |
Paul Duffin | ed87513 | 2020-09-02 13:08:57 +0100 | [diff] [blame] | 1045 | &base.commonProperties, |
| 1046 | &base.distProperties) |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 1047 | |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 1048 | initProductVariableModule(m) |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 1049 | |
Colin Cross | a3a9741 | 2019-03-18 12:24:29 -0700 | [diff] [blame] | 1050 | base.generalProperties = m.GetProperties() |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 1051 | base.customizableProperties = m.GetProperties() |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 1052 | |
| 1053 | // The default_visibility property needs to be checked and parsed by the visibility module during |
Paul Duffin | 5ec73ec | 2020-05-01 17:52:01 +0100 | [diff] [blame] | 1054 | // its checking and parsing phases so make it the primary visibility property. |
| 1055 | setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility) |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1056 | |
| 1057 | // The default_applicable_licenses property needs to be checked and parsed by the licenses module during |
| 1058 | // its checking and parsing phases so make it the primary licenses property. |
| 1059 | setPrimaryLicensesProperty(m, "licenses", &base.commonProperties.Licenses) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1062 | // InitAndroidArchModule initializes the Module as an Android module that is architecture-specific. |
| 1063 | // It adds the common properties, for example "name" and "enabled", as well as runtime generated |
| 1064 | // property structs for architecture-specific versions of generic properties tagged with |
| 1065 | // `android:"arch_variant"`. |
| 1066 | // |
| 1067 | // InitAndroidModule should not be called if InitAndroidArchModule was called. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1068 | func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { |
| 1069 | InitAndroidModule(m) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1070 | |
| 1071 | base := m.base() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1072 | base.commonProperties.HostOrDeviceSupported = hod |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1073 | base.commonProperties.Default_multilib = string(defaultMultilib) |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 1074 | base.commonProperties.ArchSpecific = true |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1075 | base.commonProperties.UseTargetVariants = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1076 | |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1077 | if hod&hostSupported != 0 && hod&deviceSupported != 0 { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1078 | m.AddProperties(&base.hostAndDeviceProperties) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1079 | } |
| 1080 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1081 | initArchModule(m) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1084 | // InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is |
| 1085 | // architecture-specific, but will only have a single variant per OS that handles all the |
| 1086 | // architectures simultaneously. The list of Targets that it must handle will be available from |
| 1087 | // ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as |
| 1088 | // well as runtime generated property structs for architecture-specific versions of generic |
| 1089 | // properties tagged with `android:"arch_variant"`. |
| 1090 | // |
| 1091 | // InitAndroidModule or InitAndroidArchModule should not be called if |
| 1092 | // InitAndroidMultiTargetsArchModule was called. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1093 | func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { |
| 1094 | InitAndroidArchModule(m, hod, defaultMultilib) |
| 1095 | m.base().commonProperties.UseTargetVariants = false |
| 1096 | } |
| 1097 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1098 | // InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is |
| 1099 | // architecture-specific, but will only have a single variant per OS that handles all the |
| 1100 | // architectures simultaneously, and will also have an additional CommonOS variant that has |
| 1101 | // dependencies on all the OS-specific variants. The list of Targets that it must handle will be |
| 1102 | // available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and |
| 1103 | // "enabled", as well as runtime generated property structs for architecture-specific versions of |
| 1104 | // generic properties tagged with `android:"arch_variant"`. |
| 1105 | // |
| 1106 | // InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be |
| 1107 | // called if InitCommonOSAndroidMultiTargetsArchModule was called. |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 1108 | func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { |
| 1109 | InitAndroidArchModule(m, hod, defaultMultilib) |
| 1110 | m.base().commonProperties.UseTargetVariants = false |
| 1111 | m.base().commonProperties.CreateCommonOSVariant = true |
| 1112 | } |
| 1113 | |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 1114 | // A ModuleBase object contains the properties that are common to all Android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1115 | // modules. It should be included as an anonymous field in every module |
| 1116 | // struct definition. InitAndroidModule should then be called from the module's |
| 1117 | // factory function, and the return values from InitAndroidModule should be |
| 1118 | // returned from the factory function. |
| 1119 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 1120 | // The ModuleBase type is responsible for implementing the GenerateBuildActions |
| 1121 | // method to support the blueprint.Module interface. This method will then call |
| 1122 | // the module's GenerateAndroidBuildActions method once for each build variant |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 1123 | // that is to be built. GenerateAndroidBuildActions is passed a ModuleContext |
| 1124 | // rather than the usual blueprint.ModuleContext. |
| 1125 | // ModuleContext exposes extra functionality specific to the Android build |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1126 | // system including details about the particular build variant that is to be |
| 1127 | // generated. |
| 1128 | // |
| 1129 | // For example: |
| 1130 | // |
| 1131 | // import ( |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 1132 | // "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1133 | // ) |
| 1134 | // |
| 1135 | // type myModule struct { |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 1136 | // android.ModuleBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1137 | // properties struct { |
| 1138 | // MyProperty string |
| 1139 | // } |
| 1140 | // } |
| 1141 | // |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1142 | // func NewMyModule() android.Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1143 | // m := &myModule{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1144 | // m.AddProperties(&m.properties) |
| 1145 | // android.InitAndroidModule(m) |
| 1146 | // return m |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1147 | // } |
| 1148 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 1149 | // func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1150 | // // Get the CPU architecture for the current build variant. |
| 1151 | // variantArch := ctx.Arch() |
| 1152 | // |
| 1153 | // // ... |
| 1154 | // } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1155 | type ModuleBase struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1156 | // Putting the curiously recurring thing pointing to the thing that contains |
| 1157 | // the thing pattern to good use. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1158 | // TODO: remove this |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1159 | module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1160 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 1161 | nameProperties nameProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1162 | commonProperties commonProperties |
Paul Duffin | ed87513 | 2020-09-02 13:08:57 +0100 | [diff] [blame] | 1163 | distProperties distProperties |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 1164 | variableProperties interface{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1165 | hostAndDeviceProperties hostAndDeviceProperties |
| 1166 | generalProperties []interface{} |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1167 | |
| 1168 | // Arch specific versions of structs in generalProperties. The outer index |
| 1169 | // has the same order as generalProperties as initialized in |
| 1170 | // InitAndroidArchModule, and the inner index chooses the props specific to |
| 1171 | // the architecture. The interface{} value is an archPropRoot that is |
| 1172 | // filled with arch specific values by the arch mutator. |
| 1173 | archProperties [][]interface{} |
| 1174 | |
| 1175 | customizableProperties []interface{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1176 | |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 1177 | // Properties specific to the Blueprint to BUILD migration. |
| 1178 | bazelTargetModuleProperties bazel.BazelTargetModuleProperties |
| 1179 | |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 1180 | // Information about all the properties on the module that contains visibility rules that need |
| 1181 | // checking. |
| 1182 | visibilityPropertyInfo []visibilityProperty |
| 1183 | |
| 1184 | // The primary visibility property, may be nil, that controls access to the module. |
| 1185 | primaryVisibilityProperty visibilityProperty |
| 1186 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1187 | // The primary licenses property, may be nil, records license metadata for the module. |
| 1188 | primaryLicensesProperty applicableLicensesProperty |
| 1189 | |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1190 | noAddressSanitizer bool |
| 1191 | installFiles InstallPaths |
| 1192 | installFilesDepSet *installPathsDepSet |
| 1193 | checkbuildFiles Paths |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 1194 | tidyFiles Paths |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1195 | packagingSpecs []PackagingSpec |
| 1196 | packagingSpecsDepSet *packagingSpecsDepSet |
| 1197 | noticeFiles Paths |
| 1198 | phonies map[string]Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1199 | |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 1200 | // The files to copy to the dist as explicitly specified in the .bp file. |
| 1201 | distFiles TaggedDistFiles |
| 1202 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1203 | // Used by buildTargetSingleton to create checkbuild and per-directory build targets |
| 1204 | // Only set on the final variant of each module |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1205 | installTarget WritablePath |
| 1206 | checkbuildTarget WritablePath |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 1207 | tidyTarget WritablePath |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1208 | blueprintDir string |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 1209 | |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 1210 | hooks hooks |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1211 | |
| 1212 | registerProps []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 1213 | |
| 1214 | // For tests |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 1215 | buildParams []BuildParams |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 1216 | ruleParams map[blueprint.Rule]blueprint.RuleParams |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1217 | variables map[string]string |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 1218 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1219 | initRcPaths Paths |
| 1220 | vintfFragmentsPaths Paths |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 1223 | // A struct containing all relevant information about a Bazel target converted via bp2build. |
| 1224 | type bp2buildInfo struct { |
| 1225 | Name string |
| 1226 | Dir string |
| 1227 | BazelProps bazel.BazelTargetModuleProperties |
| 1228 | Attrs interface{} |
| 1229 | } |
| 1230 | |
| 1231 | // TargetName returns the Bazel target name of a bp2build converted target. |
| 1232 | func (b bp2buildInfo) TargetName() string { |
| 1233 | return b.Name |
| 1234 | } |
| 1235 | |
| 1236 | // TargetPackage returns the Bazel package of a bp2build converted target. |
| 1237 | func (b bp2buildInfo) TargetPackage() string { |
| 1238 | return b.Dir |
| 1239 | } |
| 1240 | |
| 1241 | // BazelRuleClass returns the Bazel rule class of a bp2build converted target. |
| 1242 | func (b bp2buildInfo) BazelRuleClass() string { |
| 1243 | return b.BazelProps.Rule_class |
| 1244 | } |
| 1245 | |
| 1246 | // BazelRuleLoadLocation returns the location of the Bazel rule of a bp2build converted target. |
| 1247 | // This may be empty as native Bazel rules do not need to be loaded. |
| 1248 | func (b bp2buildInfo) BazelRuleLoadLocation() string { |
| 1249 | return b.BazelProps.Bzl_load_location |
| 1250 | } |
| 1251 | |
| 1252 | // BazelAttributes returns the Bazel attributes of a bp2build converted target. |
| 1253 | func (b bp2buildInfo) BazelAttributes() interface{} { |
| 1254 | return b.Attrs |
| 1255 | } |
| 1256 | |
| 1257 | func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) { |
| 1258 | m.commonProperties.Bp2buildInfo = append(m.commonProperties.Bp2buildInfo, info) |
| 1259 | } |
| 1260 | |
| 1261 | // IsConvertedByBp2build returns whether this module was converted via bp2build. |
| 1262 | func (m *ModuleBase) IsConvertedByBp2build() bool { |
| 1263 | return len(m.commonProperties.Bp2buildInfo) > 0 |
| 1264 | } |
| 1265 | |
| 1266 | // Bp2buildTargets returns the Bazel targets bp2build generated for this module. |
| 1267 | func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo { |
| 1268 | return m.commonProperties.Bp2buildInfo |
| 1269 | } |
| 1270 | |
Lukacs T. Berki | d18d8ca | 2021-06-25 09:11:22 +0200 | [diff] [blame] | 1271 | func (m *ModuleBase) AddJSONData(d *map[string]interface{}) { |
| 1272 | (*d)["Android"] = map[string]interface{}{} |
| 1273 | } |
| 1274 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1275 | func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {} |
| 1276 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1277 | func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {} |
Colin Cross | 5f692ec | 2019-02-01 16:53:07 -0800 | [diff] [blame] | 1278 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1279 | func (m *ModuleBase) AddProperties(props ...interface{}) { |
| 1280 | m.registerProps = append(m.registerProps, props...) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1283 | func (m *ModuleBase) GetProperties() []interface{} { |
| 1284 | return m.registerProps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1287 | func (m *ModuleBase) BuildParamsForTests() []BuildParams { |
| 1288 | return m.buildParams |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1291 | func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams { |
| 1292 | return m.ruleParams |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 1293 | } |
| 1294 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1295 | func (m *ModuleBase) VariablesForTests() map[string]string { |
| 1296 | return m.variables |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1299 | // Name returns the name of the module. It may be overridden by individual module types, for |
| 1300 | // example prebuilts will prepend prebuilt_ to the name. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1301 | func (m *ModuleBase) Name() string { |
| 1302 | return String(m.nameProperties.Name) |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 1305 | // String returns a string that includes the module name and variants for printing during debugging. |
| 1306 | func (m *ModuleBase) String() string { |
| 1307 | sb := strings.Builder{} |
| 1308 | sb.WriteString(m.commonProperties.DebugName) |
| 1309 | sb.WriteString("{") |
| 1310 | for i := range m.commonProperties.DebugMutators { |
| 1311 | if i != 0 { |
| 1312 | sb.WriteString(",") |
| 1313 | } |
| 1314 | sb.WriteString(m.commonProperties.DebugMutators[i]) |
| 1315 | sb.WriteString(":") |
| 1316 | sb.WriteString(m.commonProperties.DebugVariations[i]) |
| 1317 | } |
| 1318 | sb.WriteString("}") |
| 1319 | return sb.String() |
| 1320 | } |
| 1321 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1322 | // BaseModuleName returns the name of the module as specified in the blueprints file. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1323 | func (m *ModuleBase) BaseModuleName() string { |
| 1324 | return String(m.nameProperties.Name) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1327 | func (m *ModuleBase) base() *ModuleBase { |
| 1328 | return m |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 1331 | func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName { |
| 1332 | return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()} |
| 1333 | } |
| 1334 | |
| 1335 | func (m *ModuleBase) visibilityProperties() []visibilityProperty { |
Paul Duffin | 63c6e18 | 2019-07-24 14:24:38 +0100 | [diff] [blame] | 1336 | return m.visibilityPropertyInfo |
| 1337 | } |
| 1338 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1339 | func (m *ModuleBase) Dists() []Dist { |
Paul Duffin | ed87513 | 2020-09-02 13:08:57 +0100 | [diff] [blame] | 1340 | if len(m.distProperties.Dist.Targets) > 0 { |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1341 | // Make a copy of the underlying Dists slice to protect against |
| 1342 | // backing array modifications with repeated calls to this method. |
Paul Duffin | ed87513 | 2020-09-02 13:08:57 +0100 | [diff] [blame] | 1343 | distsCopy := append([]Dist(nil), m.distProperties.Dists...) |
| 1344 | return append(distsCopy, m.distProperties.Dist) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1345 | } else { |
Paul Duffin | ed87513 | 2020-09-02 13:08:57 +0100 | [diff] [blame] | 1346 | return m.distProperties.Dists |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 1351 | var distFiles TaggedDistFiles |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1352 | for _, dist := range m.Dists() { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 1353 | // If no tag is specified then it means to use the default dist paths so use |
| 1354 | // the special tag name which represents that. |
| 1355 | tag := proptools.StringDefault(dist.Tag, DefaultDistTag) |
| 1356 | |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 1357 | if outputFileProducer, ok := m.module.(OutputFileProducer); ok { |
| 1358 | // Call the OutputFiles(tag) method to get the paths associated with the tag. |
| 1359 | distFilesForTag, err := outputFileProducer.OutputFiles(tag) |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 1360 | |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 1361 | // If the tag was not supported and is not DefaultDistTag then it is an error. |
| 1362 | // Failing to find paths for DefaultDistTag is not an error. It just means |
| 1363 | // that the module type requires the legacy behavior. |
| 1364 | if err != nil && tag != DefaultDistTag { |
| 1365 | ctx.PropertyErrorf("dist.tag", "%s", err.Error()) |
| 1366 | } |
| 1367 | |
| 1368 | distFiles = distFiles.addPathsForTag(tag, distFilesForTag...) |
| 1369 | } else if tag != DefaultDistTag { |
| 1370 | // If the tag was specified then it is an error if the module does not |
| 1371 | // implement OutputFileProducer because there is no other way of accessing |
| 1372 | // the paths for the specified tag. |
| 1373 | ctx.PropertyErrorf("dist.tag", |
| 1374 | "tag %s not supported because the module does not implement OutputFileProducer", tag) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1375 | } |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | return distFiles |
| 1379 | } |
| 1380 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1381 | func (m *ModuleBase) Target() Target { |
| 1382 | return m.commonProperties.CompileTarget |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1383 | } |
| 1384 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1385 | func (m *ModuleBase) TargetPrimary() bool { |
| 1386 | return m.commonProperties.CompilePrimary |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1389 | func (m *ModuleBase) MultiTargets() []Target { |
| 1390 | return m.commonProperties.CompileMultiTargets |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1393 | func (m *ModuleBase) Os() OsType { |
| 1394 | return m.Target().Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1395 | } |
| 1396 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1397 | func (m *ModuleBase) Host() bool { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1398 | return m.Os().Class == Host |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 1401 | func (m *ModuleBase) Device() bool { |
| 1402 | return m.Os().Class == Device |
| 1403 | } |
| 1404 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1405 | func (m *ModuleBase) Arch() Arch { |
| 1406 | return m.Target().Arch |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 1407 | } |
| 1408 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1409 | func (m *ModuleBase) ArchSpecific() bool { |
| 1410 | return m.commonProperties.ArchSpecific |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 1413 | // True if the current variant is a CommonOS variant, false otherwise. |
| 1414 | func (m *ModuleBase) IsCommonOSVariant() bool { |
| 1415 | return m.commonProperties.CommonOSVariant |
| 1416 | } |
| 1417 | |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1418 | // supportsTarget returns true if the given Target is supported by the current module. |
| 1419 | func (m *ModuleBase) supportsTarget(target Target) bool { |
| 1420 | switch target.Os.Class { |
| 1421 | case Host: |
| 1422 | if target.HostCross { |
| 1423 | return m.HostCrossSupported() |
| 1424 | } else { |
| 1425 | return m.HostSupported() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1426 | } |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1427 | case Device: |
| 1428 | return m.DeviceSupported() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1429 | default: |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1430 | return false |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1431 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1434 | // DeviceSupported returns true if the current module is supported and enabled for device targets, |
| 1435 | // i.e. the factory method set the HostOrDeviceSupported value to include device support and |
| 1436 | // the device support is enabled by default or enabled by the device_supported property. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1437 | func (m *ModuleBase) DeviceSupported() bool { |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1438 | hod := m.commonProperties.HostOrDeviceSupported |
| 1439 | // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported |
| 1440 | // value has the deviceDefault bit set. |
| 1441 | deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0) |
| 1442 | return hod&deviceSupported != 0 && deviceEnabled |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1443 | } |
| 1444 | |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1445 | // HostSupported returns true if the current module is supported and enabled for host targets, |
| 1446 | // i.e. the factory method set the HostOrDeviceSupported value to include host support and |
| 1447 | // the host support is enabled by default or enabled by the host_supported property. |
Paul Duffin | e44358f | 2019-11-26 18:04:12 +0000 | [diff] [blame] | 1448 | func (m *ModuleBase) HostSupported() bool { |
Colin Cross | 34037c6 | 2020-11-17 13:19:17 -0800 | [diff] [blame] | 1449 | hod := m.commonProperties.HostOrDeviceSupported |
| 1450 | // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported |
| 1451 | // value has the hostDefault bit set. |
| 1452 | hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0) |
| 1453 | return hod&hostSupported != 0 && hostEnabled |
| 1454 | } |
| 1455 | |
| 1456 | // HostCrossSupported returns true if the current module is supported and enabled for host cross |
| 1457 | // targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross |
| 1458 | // support and the host cross support is enabled by default or enabled by the |
| 1459 | // host_supported property. |
| 1460 | func (m *ModuleBase) HostCrossSupported() bool { |
| 1461 | hod := m.commonProperties.HostOrDeviceSupported |
| 1462 | // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported |
| 1463 | // value has the hostDefault bit set. |
| 1464 | hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0) |
| 1465 | return hod&hostCrossSupported != 0 && hostEnabled |
Paul Duffin | e44358f | 2019-11-26 18:04:12 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1468 | func (m *ModuleBase) Platform() bool { |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1469 | return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1470 | } |
| 1471 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1472 | func (m *ModuleBase) DeviceSpecific() bool { |
| 1473 | return Bool(m.commonProperties.Device_specific) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1474 | } |
| 1475 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1476 | func (m *ModuleBase) SocSpecific() bool { |
| 1477 | return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1478 | } |
| 1479 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1480 | func (m *ModuleBase) ProductSpecific() bool { |
| 1481 | return Bool(m.commonProperties.Product_specific) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1482 | } |
| 1483 | |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1484 | func (m *ModuleBase) SystemExtSpecific() bool { |
| 1485 | return Bool(m.commonProperties.System_ext_specific) |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1486 | } |
| 1487 | |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1488 | // RequiresStableAPIs returns true if the module will be installed to a partition that may |
| 1489 | // be updated separately from the system image. |
| 1490 | func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool { |
| 1491 | return m.SocSpecific() || m.DeviceSpecific() || |
| 1492 | (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) |
| 1493 | } |
| 1494 | |
Bill Peckham | fff3f8a | 2020-03-20 18:33:20 -0700 | [diff] [blame] | 1495 | func (m *ModuleBase) PartitionTag(config DeviceConfig) string { |
| 1496 | partition := "system" |
| 1497 | if m.SocSpecific() { |
| 1498 | // A SoC-specific module could be on the vendor partition at |
| 1499 | // "vendor" or the system partition at "system/vendor". |
| 1500 | if config.VendorPath() == "vendor" { |
| 1501 | partition = "vendor" |
| 1502 | } |
| 1503 | } else if m.DeviceSpecific() { |
| 1504 | // A device-specific module could be on the odm partition at |
| 1505 | // "odm", the vendor partition at "vendor/odm", or the system |
| 1506 | // partition at "system/vendor/odm". |
| 1507 | if config.OdmPath() == "odm" { |
| 1508 | partition = "odm" |
Ramy Medhat | 944839a | 2020-03-31 22:14:52 -0400 | [diff] [blame] | 1509 | } else if strings.HasPrefix(config.OdmPath(), "vendor/") { |
Bill Peckham | fff3f8a | 2020-03-20 18:33:20 -0700 | [diff] [blame] | 1510 | partition = "vendor" |
| 1511 | } |
| 1512 | } else if m.ProductSpecific() { |
| 1513 | // A product-specific module could be on the product partition |
| 1514 | // at "product" or the system partition at "system/product". |
| 1515 | if config.ProductPath() == "product" { |
| 1516 | partition = "product" |
| 1517 | } |
| 1518 | } else if m.SystemExtSpecific() { |
| 1519 | // A system_ext-specific module could be on the system_ext |
| 1520 | // partition at "system_ext" or the system partition at |
| 1521 | // "system/system_ext". |
| 1522 | if config.SystemExtPath() == "system_ext" { |
| 1523 | partition = "system_ext" |
| 1524 | } |
| 1525 | } |
| 1526 | return partition |
| 1527 | } |
| 1528 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1529 | func (m *ModuleBase) Enabled() bool { |
Justin Yun | 32f053b | 2020-07-31 23:07:17 +0900 | [diff] [blame] | 1530 | if m.commonProperties.ForcedDisabled { |
| 1531 | return false |
| 1532 | } |
Colin Cross | 08d6f8f | 2020-11-19 02:33:19 +0000 | [diff] [blame] | 1533 | if m.commonProperties.Enabled == nil { |
| 1534 | return !m.Os().DefaultDisabled |
| 1535 | } |
| 1536 | return *m.commonProperties.Enabled |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1537 | } |
| 1538 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1539 | func (m *ModuleBase) Disable() { |
Justin Yun | 32f053b | 2020-07-31 23:07:17 +0900 | [diff] [blame] | 1540 | m.commonProperties.ForcedDisabled = true |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1541 | } |
| 1542 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 1543 | // HideFromMake marks this variant so that it is not emitted in the generated Android.mk file. |
| 1544 | func (m *ModuleBase) HideFromMake() { |
| 1545 | m.commonProperties.HideFromMake = true |
| 1546 | } |
| 1547 | |
| 1548 | // IsHideFromMake returns true if HideFromMake was previously called. |
| 1549 | func (m *ModuleBase) IsHideFromMake() bool { |
| 1550 | return m.commonProperties.HideFromMake == true |
| 1551 | } |
| 1552 | |
| 1553 | // SkipInstall marks this variant to not create install rules when ctx.Install* are called. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1554 | func (m *ModuleBase) SkipInstall() { |
| 1555 | m.commonProperties.SkipInstall = true |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Martin Stjernholm | 9e7f45e | 2020-12-23 03:50:30 +0000 | [diff] [blame] | 1558 | // IsSkipInstall returns true if this variant is marked to not create install |
| 1559 | // rules when ctx.Install* are called. |
| 1560 | func (m *ModuleBase) IsSkipInstall() bool { |
| 1561 | return m.commonProperties.SkipInstall |
| 1562 | } |
| 1563 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 1564 | // Similar to HideFromMake, but if the AndroidMk entry would set |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 1565 | // LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry |
| 1566 | // rather than leaving it out altogether. That happens in cases where it would |
| 1567 | // have other side effects, in particular when it adds a NOTICE file target, |
| 1568 | // which other install targets might depend on. |
| 1569 | func (m *ModuleBase) MakeUninstallable() { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 1570 | m.HideFromMake() |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 1571 | } |
| 1572 | |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1573 | func (m *ModuleBase) ReplacedByPrebuilt() { |
| 1574 | m.commonProperties.ReplacedByPrebuilt = true |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 1575 | m.HideFromMake() |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | func (m *ModuleBase) IsReplacedByPrebuilt() bool { |
| 1579 | return m.commonProperties.ReplacedByPrebuilt |
| 1580 | } |
| 1581 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1582 | func (m *ModuleBase) ExportedToMake() bool { |
| 1583 | return m.commonProperties.NamespaceExportedToMake |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1584 | } |
| 1585 | |
Justin Yun | 885a7de | 2021-06-29 20:34:53 +0900 | [diff] [blame] | 1586 | func (m *ModuleBase) EffectiveLicenseFiles() Paths { |
| 1587 | return m.commonProperties.Effective_license_text |
| 1588 | } |
| 1589 | |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 1590 | // computeInstallDeps finds the installed paths of all dependencies that have a dependency |
| 1591 | // tag that is annotated as needing installation via the IsInstallDepNeeded method. |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1592 | func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*installPathsDepSet, []*packagingSpecsDepSet) { |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 1593 | var installDeps []*installPathsDepSet |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1594 | var packagingSpecs []*packagingSpecsDepSet |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 1595 | ctx.VisitDirectDeps(func(dep Module) { |
Jooyung Han | 8707cd7 | 2021-07-23 02:49:46 +0900 | [diff] [blame] | 1596 | if IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) && !dep.IsHideFromMake() && !dep.IsSkipInstall() { |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 1597 | installDeps = append(installDeps, dep.base().installFilesDepSet) |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1598 | packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet) |
Colin Cross | 897266e | 2020-02-13 13:22:08 -0800 | [diff] [blame] | 1599 | } |
| 1600 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1601 | |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1602 | return installDeps, packagingSpecs |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1603 | } |
| 1604 | |
Jiyong Park | 4dc2a1a | 2020-09-28 17:46:22 +0900 | [diff] [blame] | 1605 | func (m *ModuleBase) FilesToInstall() InstallPaths { |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1606 | return m.installFiles |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1607 | } |
| 1608 | |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 1609 | func (m *ModuleBase) PackagingSpecs() []PackagingSpec { |
| 1610 | return m.packagingSpecs |
| 1611 | } |
| 1612 | |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1613 | func (m *ModuleBase) TransitivePackagingSpecs() []PackagingSpec { |
| 1614 | return m.packagingSpecsDepSet.ToList() |
| 1615 | } |
| 1616 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1617 | func (m *ModuleBase) NoAddressSanitizer() bool { |
| 1618 | return m.noAddressSanitizer |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1619 | } |
| 1620 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1621 | func (m *ModuleBase) InstallInData() bool { |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 1622 | return false |
| 1623 | } |
| 1624 | |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 1625 | func (m *ModuleBase) InstallInTestcases() bool { |
| 1626 | return false |
| 1627 | } |
| 1628 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1629 | func (m *ModuleBase) InstallInSanitizerDir() bool { |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1630 | return false |
| 1631 | } |
| 1632 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 1633 | func (m *ModuleBase) InstallInRamdisk() bool { |
| 1634 | return Bool(m.commonProperties.Ramdisk) |
| 1635 | } |
| 1636 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 1637 | func (m *ModuleBase) InstallInVendorRamdisk() bool { |
| 1638 | return Bool(m.commonProperties.Vendor_ramdisk) |
| 1639 | } |
| 1640 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 1641 | func (m *ModuleBase) InstallInDebugRamdisk() bool { |
| 1642 | return Bool(m.commonProperties.Debug_ramdisk) |
| 1643 | } |
| 1644 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1645 | func (m *ModuleBase) InstallInRecovery() bool { |
| 1646 | return Bool(m.commonProperties.Recovery) |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1647 | } |
| 1648 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 1649 | func (m *ModuleBase) InstallInVendor() bool { |
| 1650 | return Bool(m.commonProperties.Vendor) |
| 1651 | } |
| 1652 | |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 1653 | func (m *ModuleBase) InstallInRoot() bool { |
| 1654 | return false |
| 1655 | } |
| 1656 | |
Colin Cross | 607d858 | 2019-07-29 16:44:46 -0700 | [diff] [blame] | 1657 | func (m *ModuleBase) InstallBypassMake() bool { |
| 1658 | return false |
| 1659 | } |
| 1660 | |
Jiyong Park | 87788b5 | 2020-09-01 12:37:45 +0900 | [diff] [blame] | 1661 | func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) { |
| 1662 | return nil, nil |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 1663 | } |
| 1664 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1665 | func (m *ModuleBase) Owner() string { |
| 1666 | return String(m.commonProperties.Owner) |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 1667 | } |
| 1668 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 1669 | func (m *ModuleBase) NoticeFiles() Paths { |
| 1670 | return m.noticeFiles |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1671 | } |
| 1672 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 1673 | func (m *ModuleBase) setImageVariation(variant string) { |
| 1674 | m.commonProperties.ImageVariation = variant |
| 1675 | } |
| 1676 | |
| 1677 | func (m *ModuleBase) ImageVariation() blueprint.Variation { |
| 1678 | return blueprint.Variation{ |
| 1679 | Mutator: "image", |
| 1680 | Variation: m.base().commonProperties.ImageVariation, |
| 1681 | } |
| 1682 | } |
| 1683 | |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 1684 | func (m *ModuleBase) getVariationByMutatorName(mutator string) string { |
| 1685 | for i, v := range m.commonProperties.DebugMutators { |
| 1686 | if v == mutator { |
| 1687 | return m.commonProperties.DebugVariations[i] |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | return "" |
| 1692 | } |
| 1693 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 1694 | func (m *ModuleBase) InRamdisk() bool { |
| 1695 | return m.base().commonProperties.ImageVariation == RamdiskVariation |
| 1696 | } |
| 1697 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 1698 | func (m *ModuleBase) InVendorRamdisk() bool { |
| 1699 | return m.base().commonProperties.ImageVariation == VendorRamdiskVariation |
| 1700 | } |
| 1701 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 1702 | func (m *ModuleBase) InDebugRamdisk() bool { |
| 1703 | return m.base().commonProperties.ImageVariation == DebugRamdiskVariation |
| 1704 | } |
| 1705 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 1706 | func (m *ModuleBase) InRecovery() bool { |
| 1707 | return m.base().commonProperties.ImageVariation == RecoveryVariation |
| 1708 | } |
| 1709 | |
Jiyong Park | 6a8cf5f | 2019-12-30 16:31:09 +0900 | [diff] [blame] | 1710 | func (m *ModuleBase) RequiredModuleNames() []string { |
| 1711 | return m.base().commonProperties.Required |
| 1712 | } |
| 1713 | |
| 1714 | func (m *ModuleBase) HostRequiredModuleNames() []string { |
| 1715 | return m.base().commonProperties.Host_required |
| 1716 | } |
| 1717 | |
| 1718 | func (m *ModuleBase) TargetRequiredModuleNames() []string { |
| 1719 | return m.base().commonProperties.Target_required |
| 1720 | } |
| 1721 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1722 | func (m *ModuleBase) InitRc() Paths { |
| 1723 | return append(Paths{}, m.initRcPaths...) |
| 1724 | } |
| 1725 | |
| 1726 | func (m *ModuleBase) VintfFragments() Paths { |
| 1727 | return append(Paths{}, m.vintfFragmentsPaths...) |
| 1728 | } |
| 1729 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1730 | func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) { |
Colin Cross | 897266e | 2020-02-13 13:22:08 -0800 | [diff] [blame] | 1731 | var allInstalledFiles InstallPaths |
| 1732 | var allCheckbuildFiles Paths |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 1733 | var allTidyFiles Paths |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1734 | ctx.VisitAllModuleVariants(func(module Module) { |
| 1735 | a := module.base() |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 1736 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 1737 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 1738 | allTidyFiles = append(allTidyFiles, a.tidyFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1739 | }) |
| 1740 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1741 | var deps Paths |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 1742 | |
Colin Cross | 133ebef | 2020-08-14 17:38:45 -0700 | [diff] [blame] | 1743 | namespacePrefix := ctx.Namespace().id |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 1744 | if namespacePrefix != "" { |
| 1745 | namespacePrefix = namespacePrefix + "-" |
| 1746 | } |
| 1747 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1748 | if len(allInstalledFiles) > 0 { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 1749 | name := namespacePrefix + ctx.ModuleName() + "-install" |
| 1750 | ctx.Phony(name, allInstalledFiles.Paths()...) |
| 1751 | m.installTarget = PathForPhony(ctx, name) |
| 1752 | deps = append(deps, m.installTarget) |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | if len(allCheckbuildFiles) > 0 { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 1756 | name := namespacePrefix + ctx.ModuleName() + "-checkbuild" |
| 1757 | ctx.Phony(name, allCheckbuildFiles...) |
| 1758 | m.checkbuildTarget = PathForPhony(ctx, name) |
| 1759 | deps = append(deps, m.checkbuildTarget) |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 1762 | if len(allTidyFiles) > 0 { |
| 1763 | name := namespacePrefix + ctx.ModuleName() + "-tidy" |
| 1764 | ctx.Phony(name, allTidyFiles...) |
| 1765 | m.tidyTarget = PathForPhony(ctx, name) |
| 1766 | deps = append(deps, m.tidyTarget) |
| 1767 | } |
| 1768 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 1769 | if len(deps) > 0 { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1770 | suffix := "" |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 1771 | if ctx.Config().KatiEnabled() { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1772 | suffix = "-soong" |
| 1773 | } |
| 1774 | |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 1775 | ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1776 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1777 | m.blueprintDir = ctx.ModuleDir() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | |
Colin Cross | c34d232 | 2020-01-03 15:23:27 -0800 | [diff] [blame] | 1781 | func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind { |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1782 | var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific) |
| 1783 | var deviceSpecific = Bool(m.commonProperties.Device_specific) |
| 1784 | var productSpecific = Bool(m.commonProperties.Product_specific) |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1785 | var systemExtSpecific = Bool(m.commonProperties.System_ext_specific) |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1786 | |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1787 | msg := "conflicting value set here" |
| 1788 | if socSpecific && deviceSpecific { |
| 1789 | ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.") |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1790 | if Bool(m.commonProperties.Vendor) { |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1791 | ctx.PropertyErrorf("vendor", msg) |
| 1792 | } |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1793 | if Bool(m.commonProperties.Proprietary) { |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1794 | ctx.PropertyErrorf("proprietary", msg) |
| 1795 | } |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1796 | if Bool(m.commonProperties.Soc_specific) { |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1797 | ctx.PropertyErrorf("soc_specific", msg) |
| 1798 | } |
| 1799 | } |
| 1800 | |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1801 | if productSpecific && systemExtSpecific { |
| 1802 | ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.") |
| 1803 | ctx.PropertyErrorf("system_ext_specific", msg) |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1804 | } |
| 1805 | |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1806 | if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) { |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1807 | if productSpecific { |
| 1808 | ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.") |
| 1809 | } else { |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1810 | ctx.PropertyErrorf("system_ext_specific", "a module cannot be specific to SoC or device and system_ext at the same time.") |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1811 | } |
| 1812 | if deviceSpecific { |
| 1813 | ctx.PropertyErrorf("device_specific", msg) |
| 1814 | } else { |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1815 | if Bool(m.commonProperties.Vendor) { |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1816 | ctx.PropertyErrorf("vendor", msg) |
| 1817 | } |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1818 | if Bool(m.commonProperties.Proprietary) { |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1819 | ctx.PropertyErrorf("proprietary", msg) |
| 1820 | } |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1821 | if Bool(m.commonProperties.Soc_specific) { |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1822 | ctx.PropertyErrorf("soc_specific", msg) |
| 1823 | } |
| 1824 | } |
| 1825 | } |
| 1826 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1827 | if productSpecific { |
| 1828 | return productSpecificModule |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1829 | } else if systemExtSpecific { |
| 1830 | return systemExtSpecificModule |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1831 | } else if deviceSpecific { |
| 1832 | return deviceSpecificModule |
| 1833 | } else if socSpecific { |
| 1834 | return socSpecificModule |
| 1835 | } else { |
| 1836 | return platformModule |
| 1837 | } |
| 1838 | } |
| 1839 | |
Colin Cross | c34d232 | 2020-01-03 15:23:27 -0800 | [diff] [blame] | 1840 | func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 1841 | return earlyModuleContext{ |
Colin Cross | c34d232 | 2020-01-03 15:23:27 -0800 | [diff] [blame] | 1842 | EarlyModuleContext: ctx, |
| 1843 | kind: determineModuleKind(m, ctx), |
| 1844 | config: ctx.Config().(Config), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1845 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1846 | } |
| 1847 | |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 1848 | func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext { |
| 1849 | return baseModuleContext{ |
| 1850 | bp: ctx, |
| 1851 | earlyModuleContext: m.earlyModuleContextFactory(ctx), |
| 1852 | os: m.commonProperties.CompileOS, |
| 1853 | target: m.commonProperties.CompileTarget, |
| 1854 | targetPrimary: m.commonProperties.CompilePrimary, |
| 1855 | multiTargets: m.commonProperties.CompileMultiTargets, |
| 1856 | } |
| 1857 | } |
| 1858 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1859 | func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 1860 | ctx := &moduleContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1861 | module: m.module, |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 1862 | bp: blueprintCtx, |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1863 | baseModuleContext: m.baseModuleContextFactory(blueprintCtx), |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1864 | variables: make(map[string]string), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1867 | dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx) |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 1868 | // set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies |
| 1869 | // of installed files of this module. It will be replaced by a depset including the installed |
| 1870 | // files of this module at the end for use by modules that depend on this one. |
| 1871 | m.installFilesDepSet = newInstallPathsDepSet(nil, dependencyInstallFiles) |
| 1872 | |
Colin Cross | 6c4f21f | 2019-06-06 15:41:36 -0700 | [diff] [blame] | 1873 | // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never |
| 1874 | // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true. |
| 1875 | // TODO: This will be removed once defaults modules handle missing dependency errors |
| 1876 | blueprintCtx.GetMissingDependencies() |
| 1877 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 1878 | // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 1879 | // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants |
| 1880 | // (because the dependencies are added before the modules are disabled). The |
| 1881 | // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are |
| 1882 | // ignored. |
| 1883 | ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant() |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 1884 | |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 1885 | if ctx.config.captureBuild { |
| 1886 | ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams) |
| 1887 | } |
| 1888 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1889 | desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " " |
| 1890 | var suffix []string |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1891 | if ctx.Os().Class != Device && ctx.Os().Class != Generic { |
| 1892 | suffix = append(suffix, ctx.Os().String()) |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1893 | } |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 1894 | if !ctx.PrimaryArch() { |
| 1895 | suffix = append(suffix, ctx.Arch().ArchType.String()) |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1896 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1897 | if apexInfo := ctx.Provider(ApexInfoProvider).(ApexInfo); !apexInfo.IsForPlatform() { |
| 1898 | suffix = append(suffix, apexInfo.ApexVariationName) |
Dan Willemsen | b13a948 | 2020-02-14 11:25:54 -0800 | [diff] [blame] | 1899 | } |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1900 | |
| 1901 | ctx.Variable(pctx, "moduleDesc", desc) |
| 1902 | |
| 1903 | s := "" |
| 1904 | if len(suffix) > 0 { |
| 1905 | s = " [" + strings.Join(suffix, " ") + "]" |
| 1906 | } |
| 1907 | ctx.Variable(pctx, "moduleDescSuffix", s) |
| 1908 | |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 1909 | // Some common property checks for properties that will be used later in androidmk.go |
Paul Duffin | 89968e3 | 2020-11-23 18:17:03 +0000 | [diff] [blame] | 1910 | checkDistProperties(ctx, "dist", &m.distProperties.Dist) |
| 1911 | for i, _ := range m.distProperties.Dists { |
| 1912 | checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i]) |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 1913 | } |
| 1914 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1915 | if m.Enabled() { |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 1916 | // ensure all direct android.Module deps are enabled |
| 1917 | ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) { |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 1918 | if m, ok := bm.(Module); ok { |
| 1919 | ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps) |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 1920 | } |
| 1921 | }) |
| 1922 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 1923 | m.noticeFiles = make([]Path, 0) |
| 1924 | optPath := OptionalPath{} |
| 1925 | notice := proptools.StringDefault(m.commonProperties.Notice, "") |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1926 | if module := SrcIsModule(notice); module != "" { |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 1927 | optPath = ctx.ExpandOptionalSource(¬ice, "notice") |
| 1928 | } else if notice != "" { |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1929 | noticePath := filepath.Join(ctx.ModuleDir(), notice) |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 1930 | optPath = ExistentPathForSource(ctx, noticePath) |
| 1931 | } |
| 1932 | if optPath.Valid() { |
| 1933 | m.noticeFiles = append(m.noticeFiles, optPath.Path()) |
| 1934 | } else { |
| 1935 | for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} { |
| 1936 | noticePath := filepath.Join(ctx.ModuleDir(), notice) |
| 1937 | optPath = ExistentPathForSource(ctx, noticePath) |
| 1938 | if optPath.Valid() { |
| 1939 | m.noticeFiles = append(m.noticeFiles, optPath.Path()) |
| 1940 | } |
| 1941 | } |
Jaewoong Jung | 62707f7 | 2018-11-16 13:26:43 -0800 | [diff] [blame] | 1942 | } |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1943 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1944 | licensesPropertyFlattener(ctx) |
| 1945 | if ctx.Failed() { |
| 1946 | return |
| 1947 | } |
| 1948 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1949 | m.module.GenerateAndroidBuildActions(ctx) |
| 1950 | if ctx.Failed() { |
| 1951 | return |
| 1952 | } |
| 1953 | |
Jiyong Park | 4d86107 | 2021-03-03 20:02:42 +0900 | [diff] [blame] | 1954 | m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc) |
| 1955 | rcDir := PathForModuleInstall(ctx, "etc", "init") |
| 1956 | for _, src := range m.initRcPaths { |
| 1957 | ctx.PackageFile(rcDir, filepath.Base(src.String()), src) |
| 1958 | } |
| 1959 | |
| 1960 | m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments) |
| 1961 | vintfDir := PathForModuleInstall(ctx, "etc", "vintf", "manifest") |
| 1962 | for _, src := range m.vintfFragmentsPaths { |
| 1963 | ctx.PackageFile(vintfDir, filepath.Base(src.String()), src) |
| 1964 | } |
| 1965 | |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 1966 | // Create the set of tagged dist files after calling GenerateAndroidBuildActions |
| 1967 | // as GenerateTaggedDistFiles() calls OutputFiles(tag) and so relies on the |
| 1968 | // output paths being set which must be done before or during |
| 1969 | // GenerateAndroidBuildActions. |
| 1970 | m.distFiles = m.GenerateTaggedDistFiles(ctx) |
| 1971 | if ctx.Failed() { |
| 1972 | return |
| 1973 | } |
| 1974 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1975 | m.installFiles = append(m.installFiles, ctx.installFiles...) |
| 1976 | m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...) |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 1977 | m.tidyFiles = append(m.tidyFiles, ctx.tidyFiles...) |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 1978 | m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...) |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 1979 | for k, v := range ctx.phonies { |
| 1980 | m.phonies[k] = append(m.phonies[k], v...) |
| 1981 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 1982 | } else if ctx.Config().AllowMissingDependencies() { |
| 1983 | // If the module is not enabled it will not create any build rules, nothing will call |
| 1984 | // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled |
| 1985 | // and report them as an error even when AllowMissingDependencies = true. Call |
| 1986 | // ctx.GetMissingDependencies() here to tell blueprint not to handle them. |
| 1987 | ctx.GetMissingDependencies() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1990 | if m == ctx.FinalModule().(Module).base() { |
| 1991 | m.generateModuleTarget(ctx) |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 1992 | if ctx.Failed() { |
| 1993 | return |
| 1994 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1995 | } |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 1996 | |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 1997 | m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles) |
Colin Cross | ffe6b9d | 2020-12-01 15:40:06 -0800 | [diff] [blame] | 1998 | m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs) |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 1999 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 2000 | m.buildParams = ctx.buildParams |
| 2001 | m.ruleParams = ctx.ruleParams |
| 2002 | m.variables = ctx.variables |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
Paul Duffin | 89968e3 | 2020-11-23 18:17:03 +0000 | [diff] [blame] | 2005 | // Check the supplied dist structure to make sure that it is valid. |
| 2006 | // |
| 2007 | // property - the base property, e.g. dist or dists[1], which is combined with the |
| 2008 | // name of the nested property to produce the full property, e.g. dist.dest or |
| 2009 | // dists[1].dir. |
| 2010 | func checkDistProperties(ctx *moduleContext, property string, dist *Dist) { |
| 2011 | if dist.Dest != nil { |
| 2012 | _, err := validateSafePath(*dist.Dest) |
| 2013 | if err != nil { |
| 2014 | ctx.PropertyErrorf(property+".dest", "%s", err.Error()) |
| 2015 | } |
| 2016 | } |
| 2017 | if dist.Dir != nil { |
| 2018 | _, err := validateSafePath(*dist.Dir) |
| 2019 | if err != nil { |
| 2020 | ctx.PropertyErrorf(property+".dir", "%s", err.Error()) |
| 2021 | } |
| 2022 | } |
| 2023 | if dist.Suffix != nil { |
| 2024 | if strings.Contains(*dist.Suffix, "/") { |
| 2025 | ctx.PropertyErrorf(property+".suffix", "Suffix may not contain a '/' character.") |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | } |
| 2030 | |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2031 | type earlyModuleContext struct { |
Colin Cross | c34d232 | 2020-01-03 15:23:27 -0800 | [diff] [blame] | 2032 | blueprint.EarlyModuleContext |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2033 | |
| 2034 | kind moduleKind |
| 2035 | config Config |
| 2036 | } |
| 2037 | |
| 2038 | func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths { |
Liz Kammer | a830f3a | 2020-11-10 10:50:34 -0800 | [diff] [blame] | 2039 | return Glob(e, globPattern, excludes) |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths { |
Liz Kammer | a830f3a | 2020-11-10 10:50:34 -0800 | [diff] [blame] | 2043 | return GlobFiles(e, globPattern, excludes) |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 2046 | func (b *earlyModuleContext) IsSymlink(path Path) bool { |
| 2047 | fileInfo, err := b.config.fs.Lstat(path.String()) |
| 2048 | if err != nil { |
| 2049 | b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err) |
| 2050 | } |
| 2051 | return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink |
| 2052 | } |
| 2053 | |
| 2054 | func (b *earlyModuleContext) Readlink(path Path) string { |
| 2055 | dest, err := b.config.fs.Readlink(path.String()) |
| 2056 | if err != nil { |
| 2057 | b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err) |
| 2058 | } |
| 2059 | return dest |
| 2060 | } |
| 2061 | |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2062 | func (e *earlyModuleContext) Module() Module { |
Colin Cross | c34d232 | 2020-01-03 15:23:27 -0800 | [diff] [blame] | 2063 | module, _ := e.EarlyModuleContext.Module().(Module) |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2064 | return module |
| 2065 | } |
| 2066 | |
| 2067 | func (e *earlyModuleContext) Config() Config { |
Colin Cross | c34d232 | 2020-01-03 15:23:27 -0800 | [diff] [blame] | 2068 | return e.EarlyModuleContext.Config().(Config) |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | func (e *earlyModuleContext) AConfig() Config { |
| 2072 | return e.config |
| 2073 | } |
| 2074 | |
| 2075 | func (e *earlyModuleContext) DeviceConfig() DeviceConfig { |
| 2076 | return DeviceConfig{e.config.deviceConfig} |
| 2077 | } |
| 2078 | |
| 2079 | func (e *earlyModuleContext) Platform() bool { |
| 2080 | return e.kind == platformModule |
| 2081 | } |
| 2082 | |
| 2083 | func (e *earlyModuleContext) DeviceSpecific() bool { |
| 2084 | return e.kind == deviceSpecificModule |
| 2085 | } |
| 2086 | |
| 2087 | func (e *earlyModuleContext) SocSpecific() bool { |
| 2088 | return e.kind == socSpecificModule |
| 2089 | } |
| 2090 | |
| 2091 | func (e *earlyModuleContext) ProductSpecific() bool { |
| 2092 | return e.kind == productSpecificModule |
| 2093 | } |
| 2094 | |
| 2095 | func (e *earlyModuleContext) SystemExtSpecific() bool { |
| 2096 | return e.kind == systemExtSpecificModule |
| 2097 | } |
| 2098 | |
Colin Cross | 133ebef | 2020-08-14 17:38:45 -0700 | [diff] [blame] | 2099 | func (e *earlyModuleContext) Namespace() *Namespace { |
| 2100 | return e.EarlyModuleContext.Namespace().(*Namespace) |
| 2101 | } |
| 2102 | |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2103 | type baseModuleContext struct { |
| 2104 | bp blueprint.BaseModuleContext |
| 2105 | earlyModuleContext |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2106 | os OsType |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 2107 | target Target |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 2108 | multiTargets []Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 2109 | targetPrimary bool |
| 2110 | debug bool |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2111 | |
| 2112 | walkPath []Module |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 2113 | tagPath []blueprint.DependencyTag |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2114 | |
| 2115 | strictVisitDeps bool // If true, enforce that all dependencies are enabled |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 2116 | |
| 2117 | bazelConversionMode bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 2120 | func (b *baseModuleContext) BazelConversionMode() bool { |
| 2121 | return b.bazelConversionMode |
| 2122 | } |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 2123 | func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { |
| 2124 | return b.bp.OtherModuleName(m) |
| 2125 | } |
| 2126 | func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) } |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2127 | func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) { |
Jooyung Han | cd87c69 | 2020-02-26 02:05:18 +0900 | [diff] [blame] | 2128 | b.bp.OtherModuleErrorf(m, fmt, args...) |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2129 | } |
| 2130 | func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag { |
| 2131 | return b.bp.OtherModuleDependencyTag(m) |
| 2132 | } |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 2133 | func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) } |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 2134 | func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool { |
| 2135 | return b.bp.OtherModuleDependencyVariantExists(variations, name) |
| 2136 | } |
Martin Stjernholm | 408ffd8 | 2021-05-05 15:27:31 +0100 | [diff] [blame] | 2137 | func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool { |
| 2138 | return b.bp.OtherModuleFarDependencyVariantExists(variations, name) |
| 2139 | } |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 2140 | func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool { |
| 2141 | return b.bp.OtherModuleReverseDependencyVariantExists(name) |
| 2142 | } |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 2143 | func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { |
| 2144 | return b.bp.OtherModuleType(m) |
| 2145 | } |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 2146 | func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} { |
| 2147 | return b.bp.OtherModuleProvider(m, provider) |
| 2148 | } |
| 2149 | func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool { |
| 2150 | return b.bp.OtherModuleHasProvider(m, provider) |
| 2151 | } |
| 2152 | func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} { |
| 2153 | return b.bp.Provider(provider) |
| 2154 | } |
| 2155 | func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool { |
| 2156 | return b.bp.HasProvider(provider) |
| 2157 | } |
| 2158 | func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) { |
| 2159 | b.bp.SetProvider(provider, value) |
| 2160 | } |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2161 | |
| 2162 | func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module { |
| 2163 | return b.bp.GetDirectDepWithTag(name, tag) |
| 2164 | } |
| 2165 | |
Paul Duffin | f88d8e0 | 2020-05-07 20:21:34 +0100 | [diff] [blame] | 2166 | func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext { |
| 2167 | return b.bp |
| 2168 | } |
| 2169 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2170 | type moduleContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2171 | bp blueprint.ModuleContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2172 | baseModuleContext |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2173 | packagingSpecs []PackagingSpec |
Colin Cross | 897266e | 2020-02-13 13:22:08 -0800 | [diff] [blame] | 2174 | installFiles InstallPaths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2175 | checkbuildFiles Paths |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 2176 | tidyFiles Paths |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 2177 | module Module |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 2178 | phonies map[string]Paths |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 2179 | |
| 2180 | // For tests |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 2181 | buildParams []BuildParams |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 2182 | ruleParams map[blueprint.Rule]blueprint.RuleParams |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2183 | variables map[string]string |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 2184 | } |
| 2185 | |
Colin Cross | b88b3c5 | 2019-06-10 15:15:17 -0700 | [diff] [blame] | 2186 | func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) { |
| 2187 | return pctx, BuildParams{ |
Colin Cross | 4b69c49 | 2019-06-07 13:06:06 -0700 | [diff] [blame] | 2188 | Rule: ErrorRule, |
| 2189 | Description: params.Description, |
| 2190 | Output: params.Output, |
| 2191 | Outputs: params.Outputs, |
| 2192 | ImplicitOutput: params.ImplicitOutput, |
| 2193 | ImplicitOutputs: params.ImplicitOutputs, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 2194 | Args: map[string]string{ |
| 2195 | "error": err.Error(), |
| 2196 | }, |
Colin Cross | b88b3c5 | 2019-06-10 15:15:17 -0700 | [diff] [blame] | 2197 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2198 | } |
| 2199 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2200 | func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) { |
| 2201 | m.Build(pctx, BuildParams(params)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2202 | } |
| 2203 | |
Jingwen Chen | ce679d2 | 2020-09-23 04:30:02 +0000 | [diff] [blame] | 2204 | func validateBuildParams(params blueprint.BuildParams) error { |
| 2205 | // Validate that the symlink outputs are declared outputs or implicit outputs |
| 2206 | allOutputs := map[string]bool{} |
| 2207 | for _, output := range params.Outputs { |
| 2208 | allOutputs[output] = true |
| 2209 | } |
| 2210 | for _, output := range params.ImplicitOutputs { |
| 2211 | allOutputs[output] = true |
| 2212 | } |
| 2213 | for _, symlinkOutput := range params.SymlinkOutputs { |
| 2214 | if !allOutputs[symlinkOutput] { |
| 2215 | return fmt.Errorf( |
| 2216 | "Symlink output %s is not a declared output or implicit output", |
| 2217 | symlinkOutput) |
| 2218 | } |
| 2219 | } |
| 2220 | return nil |
| 2221 | } |
| 2222 | |
| 2223 | // Convert build parameters from their concrete Android types into their string representations, |
| 2224 | // and combine the singular and plural fields of the same type (e.g. Output and Outputs). |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2225 | func convertBuildParams(params BuildParams) blueprint.BuildParams { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2226 | bparams := blueprint.BuildParams{ |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 2227 | Rule: params.Rule, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2228 | Description: params.Description, |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 2229 | Deps: params.Deps, |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 2230 | Outputs: params.Outputs.Strings(), |
| 2231 | ImplicitOutputs: params.ImplicitOutputs.Strings(), |
Jingwen Chen | ce679d2 | 2020-09-23 04:30:02 +0000 | [diff] [blame] | 2232 | SymlinkOutputs: params.SymlinkOutputs.Strings(), |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 2233 | Inputs: params.Inputs.Strings(), |
| 2234 | Implicits: params.Implicits.Strings(), |
| 2235 | OrderOnly: params.OrderOnly.Strings(), |
Colin Cross | 824f116 | 2020-07-16 13:07:51 -0700 | [diff] [blame] | 2236 | Validations: params.Validations.Strings(), |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 2237 | Args: params.Args, |
| 2238 | Optional: !params.Default, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 2241 | if params.Depfile != nil { |
| 2242 | bparams.Depfile = params.Depfile.String() |
| 2243 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2244 | if params.Output != nil { |
| 2245 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 2246 | } |
Jingwen Chen | ce679d2 | 2020-09-23 04:30:02 +0000 | [diff] [blame] | 2247 | if params.SymlinkOutput != nil { |
| 2248 | bparams.SymlinkOutputs = append(bparams.SymlinkOutputs, params.SymlinkOutput.String()) |
| 2249 | } |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 2250 | if params.ImplicitOutput != nil { |
| 2251 | bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String()) |
| 2252 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2253 | if params.Input != nil { |
| 2254 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 2255 | } |
| 2256 | if params.Implicit != nil { |
| 2257 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 2258 | } |
Colin Cross | 824f116 | 2020-07-16 13:07:51 -0700 | [diff] [blame] | 2259 | if params.Validation != nil { |
| 2260 | bparams.Validations = append(bparams.Validations, params.Validation.String()) |
| 2261 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2262 | |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 2263 | bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs) |
| 2264 | bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs) |
Jingwen Chen | ce679d2 | 2020-09-23 04:30:02 +0000 | [diff] [blame] | 2265 | bparams.SymlinkOutputs = proptools.NinjaEscapeList(bparams.SymlinkOutputs) |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 2266 | bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs) |
| 2267 | bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits) |
| 2268 | bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly) |
Colin Cross | 824f116 | 2020-07-16 13:07:51 -0700 | [diff] [blame] | 2269 | bparams.Validations = proptools.NinjaEscapeList(bparams.Validations) |
| 2270 | bparams.Depfile = proptools.NinjaEscape(bparams.Depfile) |
Colin Cross | fe4bc36 | 2018-09-12 10:02:13 -0700 | [diff] [blame] | 2271 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2272 | return bparams |
| 2273 | } |
| 2274 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2275 | func (m *moduleContext) Variable(pctx PackageContext, name, value string) { |
| 2276 | if m.config.captureBuild { |
| 2277 | m.variables[name] = value |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2278 | } |
| 2279 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2280 | m.bp.Variable(pctx.PackageContext, name, value) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2281 | } |
| 2282 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2283 | func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams, |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2284 | argNames ...string) blueprint.Rule { |
| 2285 | |
Ramy Medhat | 944839a | 2020-03-31 22:14:52 -0400 | [diff] [blame] | 2286 | if m.config.UseRemoteBuild() { |
| 2287 | if params.Pool == nil { |
| 2288 | // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict |
| 2289 | // jobs to the local parallelism value |
| 2290 | params.Pool = localPool |
| 2291 | } else if params.Pool == remotePool { |
| 2292 | // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's |
| 2293 | // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS |
| 2294 | // parallelism. |
| 2295 | params.Pool = nil |
| 2296 | } |
Colin Cross | 2e2dbc2 | 2019-09-25 13:31:46 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2299 | rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...) |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 2300 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2301 | if m.config.captureBuild { |
| 2302 | m.ruleParams[rule] = params |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | return rule |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2306 | } |
| 2307 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2308 | func (m *moduleContext) Build(pctx PackageContext, params BuildParams) { |
Colin Cross | b88b3c5 | 2019-06-10 15:15:17 -0700 | [diff] [blame] | 2309 | if params.Description != "" { |
| 2310 | params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}" |
| 2311 | } |
| 2312 | |
| 2313 | if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 { |
| 2314 | pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n", |
| 2315 | m.ModuleName(), strings.Join(missingDeps, ", "))) |
| 2316 | } |
| 2317 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2318 | if m.config.captureBuild { |
| 2319 | m.buildParams = append(m.buildParams, params) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2320 | } |
| 2321 | |
Jingwen Chen | ce679d2 | 2020-09-23 04:30:02 +0000 | [diff] [blame] | 2322 | bparams := convertBuildParams(params) |
| 2323 | err := validateBuildParams(bparams) |
| 2324 | if err != nil { |
| 2325 | m.ModuleErrorf( |
| 2326 | "%s: build parameter validation failed: %s", |
| 2327 | m.ModuleName(), |
| 2328 | err.Error()) |
| 2329 | } |
| 2330 | m.bp.Build(pctx.PackageContext, bparams) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2331 | } |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 2332 | |
| 2333 | func (m *moduleContext) Phony(name string, deps ...Path) { |
| 2334 | addPhony(m.config, name, deps...) |
| 2335 | } |
| 2336 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2337 | func (m *moduleContext) GetMissingDependencies() []string { |
Colin Cross | 6c4f21f | 2019-06-06 15:41:36 -0700 | [diff] [blame] | 2338 | var missingDeps []string |
| 2339 | missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2340 | missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...) |
Colin Cross | 6c4f21f | 2019-06-06 15:41:36 -0700 | [diff] [blame] | 2341 | missingDeps = FirstUniqueStrings(missingDeps) |
| 2342 | return missingDeps |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 2343 | } |
| 2344 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2345 | func (b *baseModuleContext) AddMissingDependencies(deps []string) { |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 2346 | if deps != nil { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2347 | missingDeps := &b.Module().base().commonProperties.MissingDeps |
Colin Cross | 6c4f21f | 2019-06-06 15:41:36 -0700 | [diff] [blame] | 2348 | *missingDeps = append(*missingDeps, deps...) |
| 2349 | *missingDeps = FirstUniqueStrings(*missingDeps) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 2353 | type AllowDisabledModuleDependency interface { |
| 2354 | blueprint.DependencyTag |
| 2355 | AllowDisabledModuleDependency(target Module) bool |
| 2356 | } |
| 2357 | |
| 2358 | func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2359 | aModule, _ := module.(Module) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2360 | |
| 2361 | if !strict { |
| 2362 | return aModule |
| 2363 | } |
| 2364 | |
Colin Cross | 380c69a | 2019-06-10 17:49:58 +0000 | [diff] [blame] | 2365 | if aModule == nil { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2366 | b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module)) |
Colin Cross | 380c69a | 2019-06-10 17:49:58 +0000 | [diff] [blame] | 2367 | return nil |
| 2368 | } |
| 2369 | |
| 2370 | if !aModule.Enabled() { |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 2371 | if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) { |
| 2372 | if b.Config().AllowMissingDependencies() { |
| 2373 | b.AddMissingDependencies([]string{b.OtherModuleName(aModule)}) |
| 2374 | } else { |
| 2375 | b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule)) |
| 2376 | } |
Colin Cross | 380c69a | 2019-06-10 17:49:58 +0000 | [diff] [blame] | 2377 | } |
| 2378 | return nil |
| 2379 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2380 | return aModule |
| 2381 | } |
| 2382 | |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 2383 | type dep struct { |
| 2384 | mod blueprint.Module |
| 2385 | tag blueprint.DependencyTag |
| 2386 | } |
| 2387 | |
| 2388 | func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []dep { |
Jiyong Park | f297630 | 2019-04-17 21:47:37 +0900 | [diff] [blame] | 2389 | var deps []dep |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2390 | b.VisitDirectDepsBlueprint(func(module blueprint.Module) { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 2391 | if aModule, _ := module.(Module); aModule != nil { |
| 2392 | if aModule.base().BaseModuleName() == name { |
| 2393 | returnedTag := b.bp.OtherModuleDependencyTag(aModule) |
| 2394 | if tag == nil || returnedTag == tag { |
| 2395 | deps = append(deps, dep{aModule, returnedTag}) |
| 2396 | } |
| 2397 | } |
| 2398 | } else if b.bp.OtherModuleName(module) == name { |
| 2399 | returnedTag := b.bp.OtherModuleDependencyTag(module) |
Jiyong Park | f297630 | 2019-04-17 21:47:37 +0900 | [diff] [blame] | 2400 | if tag == nil || returnedTag == tag { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 2401 | deps = append(deps, dep{module, returnedTag}) |
Jiyong Park | f297630 | 2019-04-17 21:47:37 +0900 | [diff] [blame] | 2402 | } |
| 2403 | } |
| 2404 | }) |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 2405 | return deps |
| 2406 | } |
| 2407 | |
| 2408 | func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) { |
| 2409 | deps := b.getDirectDepsInternal(name, tag) |
Jiyong Park | f297630 | 2019-04-17 21:47:37 +0900 | [diff] [blame] | 2410 | if len(deps) == 1 { |
| 2411 | return deps[0].mod, deps[0].tag |
| 2412 | } else if len(deps) >= 2 { |
| 2413 | panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2414 | name, b.ModuleName())) |
Jiyong Park | f297630 | 2019-04-17 21:47:37 +0900 | [diff] [blame] | 2415 | } else { |
| 2416 | return nil, nil |
| 2417 | } |
| 2418 | } |
| 2419 | |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 2420 | func (b *baseModuleContext) getDirectDepFirstTag(name string) (blueprint.Module, blueprint.DependencyTag) { |
| 2421 | foundDeps := b.getDirectDepsInternal(name, nil) |
| 2422 | deps := map[blueprint.Module]bool{} |
| 2423 | for _, dep := range foundDeps { |
| 2424 | deps[dep.mod] = true |
| 2425 | } |
| 2426 | if len(deps) == 1 { |
| 2427 | return foundDeps[0].mod, foundDeps[0].tag |
| 2428 | } else if len(deps) >= 2 { |
| 2429 | // this could happen if two dependencies have the same name in different namespaces |
| 2430 | // TODO(b/186554727): this should not occur if namespaces are handled within |
| 2431 | // getDirectDepsInternal. |
| 2432 | panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", |
| 2433 | name, b.ModuleName())) |
| 2434 | } else { |
| 2435 | return nil, nil |
| 2436 | } |
| 2437 | } |
| 2438 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2439 | func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module { |
Colin Cross | 0ef0816 | 2019-05-01 15:50:51 -0700 | [diff] [blame] | 2440 | var deps []Module |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2441 | b.VisitDirectDepsBlueprint(func(module blueprint.Module) { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2442 | if aModule, _ := module.(Module); aModule != nil { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2443 | if b.bp.OtherModuleDependencyTag(aModule) == tag { |
Colin Cross | 0ef0816 | 2019-05-01 15:50:51 -0700 | [diff] [blame] | 2444 | deps = append(deps, aModule) |
| 2445 | } |
| 2446 | } |
| 2447 | }) |
| 2448 | return deps |
| 2449 | } |
| 2450 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2451 | func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module { |
| 2452 | module, _ := m.getDirectDepInternal(name, tag) |
| 2453 | return module |
Jiyong Park | f297630 | 2019-04-17 21:47:37 +0900 | [diff] [blame] | 2454 | } |
| 2455 | |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 2456 | // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified |
| 2457 | // name, or nil if none exists. If there are multiple dependencies on the same module it returns the |
| 2458 | // first DependencyTag. |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2459 | func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) { |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 2460 | return b.getDirectDepFirstTag(name) |
Jiyong Park | f297630 | 2019-04-17 21:47:37 +0900 | [diff] [blame] | 2461 | } |
| 2462 | |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 2463 | func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) { |
| 2464 | if !b.BazelConversionMode() { |
| 2465 | panic("cannot call ModuleFromName if not in bazel conversion mode") |
| 2466 | } |
Chris Parsons | a66c0b5 | 2021-07-23 11:02:07 -0400 | [diff] [blame] | 2467 | if moduleName, _ := SrcIsModuleWithTag(name); moduleName != "" { |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 2468 | return b.bp.ModuleFromName(moduleName) |
| 2469 | } else { |
| 2470 | return b.bp.ModuleFromName(name) |
| 2471 | } |
| 2472 | } |
| 2473 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2474 | func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2475 | b.bp.VisitDirectDeps(visit) |
Colin Cross | 35143d0 | 2017-11-16 00:11:20 -0800 | [diff] [blame] | 2476 | } |
| 2477 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2478 | func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2479 | b.bp.VisitDirectDeps(func(module blueprint.Module) { |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 2480 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2481 | visit(aModule) |
| 2482 | } |
| 2483 | }) |
| 2484 | } |
| 2485 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2486 | func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2487 | b.bp.VisitDirectDeps(func(module blueprint.Module) { |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 2488 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2489 | if b.bp.OtherModuleDependencyTag(aModule) == tag { |
Colin Cross | ee6143c | 2017-12-30 17:54:27 -0800 | [diff] [blame] | 2490 | visit(aModule) |
| 2491 | } |
| 2492 | } |
| 2493 | }) |
| 2494 | } |
| 2495 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2496 | func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2497 | b.bp.VisitDirectDepsIf( |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2498 | // pred |
| 2499 | func(module blueprint.Module) bool { |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 2500 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2501 | return pred(aModule) |
| 2502 | } else { |
| 2503 | return false |
| 2504 | } |
| 2505 | }, |
| 2506 | // visit |
| 2507 | func(module blueprint.Module) { |
| 2508 | visit(module.(Module)) |
| 2509 | }) |
| 2510 | } |
| 2511 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2512 | func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2513 | b.bp.VisitDepsDepthFirst(func(module blueprint.Module) { |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 2514 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2515 | visit(aModule) |
| 2516 | } |
| 2517 | }) |
| 2518 | } |
| 2519 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2520 | func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2521 | b.bp.VisitDepsDepthFirstIf( |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2522 | // pred |
| 2523 | func(module blueprint.Module) bool { |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 2524 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2525 | return pred(aModule) |
| 2526 | } else { |
| 2527 | return false |
| 2528 | } |
| 2529 | }, |
| 2530 | // visit |
| 2531 | func(module blueprint.Module) { |
| 2532 | visit(module.(Module)) |
| 2533 | }) |
| 2534 | } |
| 2535 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2536 | func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) { |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2537 | b.bp.WalkDeps(visit) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2540 | func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) { |
| 2541 | b.walkPath = []Module{b.Module()} |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 2542 | b.tagPath = []blueprint.DependencyTag{} |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 2543 | b.bp.WalkDeps(func(child, parent blueprint.Module) bool { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2544 | childAndroidModule, _ := child.(Module) |
| 2545 | parentAndroidModule, _ := parent.(Module) |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2546 | if childAndroidModule != nil && parentAndroidModule != nil { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2547 | // record walkPath before visit |
| 2548 | for b.walkPath[len(b.walkPath)-1] != parentAndroidModule { |
| 2549 | b.walkPath = b.walkPath[0 : len(b.walkPath)-1] |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 2550 | b.tagPath = b.tagPath[0 : len(b.tagPath)-1] |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2551 | } |
| 2552 | b.walkPath = append(b.walkPath, childAndroidModule) |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 2553 | b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule)) |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2554 | return visit(childAndroidModule, parentAndroidModule) |
| 2555 | } else { |
| 2556 | return false |
| 2557 | } |
| 2558 | }) |
| 2559 | } |
| 2560 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2561 | func (b *baseModuleContext) GetWalkPath() []Module { |
| 2562 | return b.walkPath |
| 2563 | } |
| 2564 | |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 2565 | func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag { |
| 2566 | return b.tagPath |
| 2567 | } |
| 2568 | |
Colin Cross | 4dfacf9 | 2020-09-16 19:22:27 -0700 | [diff] [blame] | 2569 | func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) { |
| 2570 | b.bp.VisitAllModuleVariants(func(module blueprint.Module) { |
| 2571 | visit(module.(Module)) |
| 2572 | }) |
| 2573 | } |
| 2574 | |
| 2575 | func (b *baseModuleContext) PrimaryModule() Module { |
| 2576 | return b.bp.PrimaryModule().(Module) |
| 2577 | } |
| 2578 | |
| 2579 | func (b *baseModuleContext) FinalModule() Module { |
| 2580 | return b.bp.FinalModule().(Module) |
| 2581 | } |
| 2582 | |
Bob Badour | 07065cd | 2021-02-05 19:59:11 -0800 | [diff] [blame] | 2583 | // IsMetaDependencyTag returns true for cross-cutting metadata dependencies. |
| 2584 | func IsMetaDependencyTag(tag blueprint.DependencyTag) bool { |
| 2585 | if tag == licenseKindTag { |
| 2586 | return true |
| 2587 | } else if tag == licensesTag { |
| 2588 | return true |
| 2589 | } |
| 2590 | return false |
| 2591 | } |
| 2592 | |
Jiyong Park | 1c7e962 | 2020-05-07 16:12:13 +0900 | [diff] [blame] | 2593 | // A regexp for removing boilerplate from BaseDependencyTag from the string representation of |
| 2594 | // a dependency tag. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2595 | var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`) |
Jiyong Park | 1c7e962 | 2020-05-07 16:12:13 +0900 | [diff] [blame] | 2596 | |
| 2597 | // PrettyPrintTag returns string representation of the tag, but prefers |
| 2598 | // custom String() method if available. |
| 2599 | func PrettyPrintTag(tag blueprint.DependencyTag) string { |
| 2600 | // Use tag's custom String() method if available. |
| 2601 | if stringer, ok := tag.(fmt.Stringer); ok { |
| 2602 | return stringer.String() |
| 2603 | } |
| 2604 | |
| 2605 | // Otherwise, get a default string representation of the tag's struct. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2606 | tagString := fmt.Sprintf("%T: %+v", tag, tag) |
Jiyong Park | 1c7e962 | 2020-05-07 16:12:13 +0900 | [diff] [blame] | 2607 | |
| 2608 | // Remove the boilerplate from BaseDependencyTag as it adds no value. |
| 2609 | tagString = tagCleaner.ReplaceAllString(tagString, "") |
| 2610 | return tagString |
| 2611 | } |
| 2612 | |
| 2613 | func (b *baseModuleContext) GetPathString(skipFirst bool) string { |
| 2614 | sb := strings.Builder{} |
| 2615 | tagPath := b.GetTagPath() |
| 2616 | walkPath := b.GetWalkPath() |
| 2617 | if !skipFirst { |
| 2618 | sb.WriteString(walkPath[0].String()) |
| 2619 | } |
| 2620 | for i, m := range walkPath[1:] { |
| 2621 | sb.WriteString("\n") |
| 2622 | sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i]))) |
| 2623 | sb.WriteString(fmt.Sprintf(" -> %s", m.String())) |
| 2624 | } |
| 2625 | return sb.String() |
| 2626 | } |
| 2627 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 2628 | func (m *moduleContext) ModuleSubDir() string { |
| 2629 | return m.bp.ModuleSubDir() |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 2630 | } |
| 2631 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2632 | func (b *baseModuleContext) Target() Target { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2633 | return b.target |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2636 | func (b *baseModuleContext) TargetPrimary() bool { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2637 | return b.targetPrimary |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2640 | func (b *baseModuleContext) MultiTargets() []Target { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2641 | return b.multiTargets |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2644 | func (b *baseModuleContext) Arch() Arch { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2645 | return b.target.Arch |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2646 | } |
| 2647 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2648 | func (b *baseModuleContext) Os() OsType { |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2649 | return b.os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2650 | } |
| 2651 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2652 | func (b *baseModuleContext) Host() bool { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 2653 | return b.os.Class == Host |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2656 | func (b *baseModuleContext) Device() bool { |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2657 | return b.os.Class == Device |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2660 | func (b *baseModuleContext) Darwin() bool { |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2661 | return b.os == Darwin |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2664 | func (b *baseModuleContext) Windows() bool { |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2665 | return b.os == Windows |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2668 | func (b *baseModuleContext) Debug() bool { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2669 | return b.debug |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 2672 | func (b *baseModuleContext) PrimaryArch() bool { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2673 | if len(b.config.Targets[b.target.Os]) <= 1 { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 2674 | return true |
| 2675 | } |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2676 | return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2679 | // Makes this module a platform module, i.e. not specific to soc, device, |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 2680 | // product, or system_ext. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 2681 | func (m *ModuleBase) MakeAsPlatform() { |
| 2682 | m.commonProperties.Vendor = boolPtr(false) |
| 2683 | m.commonProperties.Proprietary = boolPtr(false) |
| 2684 | m.commonProperties.Soc_specific = boolPtr(false) |
| 2685 | m.commonProperties.Product_specific = boolPtr(false) |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 2686 | m.commonProperties.System_ext_specific = boolPtr(false) |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2687 | } |
| 2688 | |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 2689 | func (m *ModuleBase) MakeAsSystemExt() { |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2690 | m.commonProperties.Vendor = boolPtr(false) |
| 2691 | m.commonProperties.Proprietary = boolPtr(false) |
| 2692 | m.commonProperties.Soc_specific = boolPtr(false) |
| 2693 | m.commonProperties.Product_specific = boolPtr(false) |
| 2694 | m.commonProperties.System_ext_specific = boolPtr(true) |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 2695 | } |
| 2696 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2697 | // IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true" |
| 2698 | func (m *ModuleBase) IsNativeBridgeSupported() bool { |
| 2699 | return proptools.Bool(m.commonProperties.Native_bridge_supported) |
| 2700 | } |
| 2701 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2702 | func (m *moduleContext) InstallInData() bool { |
| 2703 | return m.module.InstallInData() |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 2704 | } |
| 2705 | |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 2706 | func (m *moduleContext) InstallInTestcases() bool { |
| 2707 | return m.module.InstallInTestcases() |
| 2708 | } |
| 2709 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2710 | func (m *moduleContext) InstallInSanitizerDir() bool { |
| 2711 | return m.module.InstallInSanitizerDir() |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 2714 | func (m *moduleContext) InstallInRamdisk() bool { |
| 2715 | return m.module.InstallInRamdisk() |
| 2716 | } |
| 2717 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 2718 | func (m *moduleContext) InstallInVendorRamdisk() bool { |
| 2719 | return m.module.InstallInVendorRamdisk() |
| 2720 | } |
| 2721 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 2722 | func (m *moduleContext) InstallInDebugRamdisk() bool { |
| 2723 | return m.module.InstallInDebugRamdisk() |
| 2724 | } |
| 2725 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2726 | func (m *moduleContext) InstallInRecovery() bool { |
| 2727 | return m.module.InstallInRecovery() |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2728 | } |
| 2729 | |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 2730 | func (m *moduleContext) InstallInRoot() bool { |
| 2731 | return m.module.InstallInRoot() |
| 2732 | } |
| 2733 | |
Colin Cross | 607d858 | 2019-07-29 16:44:46 -0700 | [diff] [blame] | 2734 | func (m *moduleContext) InstallBypassMake() bool { |
| 2735 | return m.module.InstallBypassMake() |
| 2736 | } |
| 2737 | |
Jiyong Park | 87788b5 | 2020-09-01 12:37:45 +0900 | [diff] [blame] | 2738 | func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) { |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 2739 | return m.module.InstallForceOS() |
| 2740 | } |
| 2741 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 2742 | func (m *moduleContext) InstallInVendor() bool { |
| 2743 | return m.module.InstallInVendor() |
| 2744 | } |
| 2745 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 2746 | func (m *moduleContext) skipInstall() bool { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2747 | if m.module.base().commonProperties.SkipInstall { |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 2748 | return true |
| 2749 | } |
| 2750 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 2751 | if m.module.base().commonProperties.HideFromMake { |
| 2752 | return true |
| 2753 | } |
| 2754 | |
Colin Cross | 3607f21 | 2018-05-07 15:28:05 -0700 | [diff] [blame] | 2755 | // We'll need a solution for choosing which of modules with the same name in different |
| 2756 | // namespaces to install. For now, reuse the list of namespaces exported to Make as the |
| 2757 | // list of namespaces to install in a Soong-only build. |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2758 | if !m.module.base().commonProperties.NamespaceExportedToMake { |
Colin Cross | 3607f21 | 2018-05-07 15:28:05 -0700 | [diff] [blame] | 2759 | return true |
| 2760 | } |
| 2761 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2762 | if m.Device() { |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 2763 | if m.Config().KatiEnabled() && !m.InstallBypassMake() { |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 2764 | return true |
| 2765 | } |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | return false |
| 2769 | } |
| 2770 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 2771 | func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path, |
| 2772 | deps ...Path) InstallPath { |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2773 | return m.installFile(installPath, name, srcPath, deps, false) |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 2776 | func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path, |
| 2777 | deps ...Path) InstallPath { |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2778 | return m.installFile(installPath, name, srcPath, deps, true) |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 2781 | func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec { |
| 2782 | fullInstallPath := installPath.Join(m, name) |
| 2783 | return m.packageFile(fullInstallPath, srcPath, false) |
| 2784 | } |
| 2785 | |
| 2786 | func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec { |
| 2787 | spec := PackagingSpec{ |
| 2788 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 2789 | srcPath: srcPath, |
| 2790 | symlinkTarget: "", |
| 2791 | executable: executable, |
| 2792 | } |
| 2793 | m.packagingSpecs = append(m.packagingSpecs, spec) |
| 2794 | return spec |
| 2795 | } |
| 2796 | |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2797 | func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 2798 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2799 | fullInstallPath := installPath.Join(m, name) |
David Srbecky | 0765641 | 2020-06-04 01:26:16 +0100 | [diff] [blame] | 2800 | m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2801 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 2802 | if !m.skipInstall() { |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 2803 | deps = append(deps, m.module.base().installFilesDepSet.ToList().Paths()...) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 2804 | |
Colin Cross | 89562dc | 2016-10-03 17:47:19 -0700 | [diff] [blame] | 2805 | var implicitDeps, orderOnlyDeps Paths |
| 2806 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2807 | if m.Host() { |
Colin Cross | 89562dc | 2016-10-03 17:47:19 -0700 | [diff] [blame] | 2808 | // Installed host modules might be used during the build, depend directly on their |
| 2809 | // dependencies so their timestamp is updated whenever their dependency is updated |
| 2810 | implicitDeps = deps |
| 2811 | } else { |
| 2812 | orderOnlyDeps = deps |
| 2813 | } |
| 2814 | |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2815 | rule := Cp |
| 2816 | if executable { |
| 2817 | rule = CpExecutable |
| 2818 | } |
| 2819 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2820 | m.Build(pctx, BuildParams{ |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 2821 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 2822 | Description: "install " + fullInstallPath.Base(), |
| 2823 | Output: fullInstallPath, |
| 2824 | Input: srcPath, |
| 2825 | Implicits: implicitDeps, |
| 2826 | OrderOnly: orderOnlyDeps, |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 2827 | Default: !m.Config().KatiEnabled(), |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 2828 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2829 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2830 | m.installFiles = append(m.installFiles, fullInstallPath) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 2831 | } |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2832 | |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 2833 | m.packageFile(fullInstallPath, srcPath, executable) |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2834 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2835 | m.checkbuildFiles = append(m.checkbuildFiles, srcPath) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 2836 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 2837 | return fullInstallPath |
| 2838 | } |
| 2839 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 2840 | func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2841 | fullInstallPath := installPath.Join(m, name) |
David Srbecky | 0765641 | 2020-06-04 01:26:16 +0100 | [diff] [blame] | 2842 | m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 2843 | |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2844 | relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String()) |
| 2845 | if err != nil { |
| 2846 | panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err)) |
| 2847 | } |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 2848 | if !m.skipInstall() { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 2849 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2850 | m.Build(pctx, BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 2851 | Rule: Symlink, |
| 2852 | Description: "install symlink " + fullInstallPath.Base(), |
| 2853 | Output: fullInstallPath, |
Dan Willemsen | 40efa1c | 2020-01-14 15:19:52 -0800 | [diff] [blame] | 2854 | Input: srcPath, |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 2855 | Default: !m.Config().KatiEnabled(), |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 2856 | Args: map[string]string{ |
Alex Light | fb4353d | 2019-01-17 13:57:45 -0800 | [diff] [blame] | 2857 | "fromPath": relPath, |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 2858 | }, |
| 2859 | }) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 2860 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2861 | m.installFiles = append(m.installFiles, fullInstallPath) |
| 2862 | m.checkbuildFiles = append(m.checkbuildFiles, srcPath) |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 2863 | } |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2864 | |
| 2865 | m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ |
| 2866 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 2867 | srcPath: nil, |
| 2868 | symlinkTarget: relPath, |
| 2869 | executable: false, |
| 2870 | }) |
| 2871 | |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 2872 | return fullInstallPath |
| 2873 | } |
| 2874 | |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 2875 | // installPath/name -> absPath where absPath might be a path that is available only at runtime |
| 2876 | // (e.g. /apex/...) |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 2877 | func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2878 | fullInstallPath := installPath.Join(m, name) |
David Srbecky | 0765641 | 2020-06-04 01:26:16 +0100 | [diff] [blame] | 2879 | m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true) |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 2880 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 2881 | if !m.skipInstall() { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2882 | m.Build(pctx, BuildParams{ |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 2883 | Rule: Symlink, |
| 2884 | Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath, |
| 2885 | Output: fullInstallPath, |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 2886 | Default: !m.Config().KatiEnabled(), |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 2887 | Args: map[string]string{ |
| 2888 | "fromPath": absPath, |
| 2889 | }, |
| 2890 | }) |
| 2891 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2892 | m.installFiles = append(m.installFiles, fullInstallPath) |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 2893 | } |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 2894 | |
| 2895 | m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ |
| 2896 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 2897 | srcPath: nil, |
| 2898 | symlinkTarget: absPath, |
| 2899 | executable: false, |
| 2900 | }) |
| 2901 | |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 2902 | return fullInstallPath |
| 2903 | } |
| 2904 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 2905 | func (m *moduleContext) CheckbuildFile(srcPath Path) { |
| 2906 | m.checkbuildFiles = append(m.checkbuildFiles, srcPath) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2907 | } |
| 2908 | |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 2909 | func (m *moduleContext) TidyFile(srcPath Path) { |
| 2910 | m.tidyFiles = append(m.tidyFiles, srcPath) |
| 2911 | } |
| 2912 | |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 2913 | func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext { |
| 2914 | return m.bp |
| 2915 | } |
| 2916 | |
Paul Duffin | e6ba072 | 2021-07-12 20:12:12 +0100 | [diff] [blame] | 2917 | // SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name" |
| 2918 | // into the module name, or empty string if the input was not a module reference. |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2919 | func SrcIsModule(s string) (module string) { |
Paul Duffin | e6ba072 | 2021-07-12 20:12:12 +0100 | [diff] [blame] | 2920 | if len(s) > 1 { |
| 2921 | if s[0] == ':' { |
| 2922 | module = s[1:] |
| 2923 | if !isUnqualifiedModuleName(module) { |
| 2924 | // The module name should be unqualified but is not so do not treat it as a module. |
| 2925 | module = "" |
| 2926 | } |
| 2927 | } else if s[0] == '/' && s[1] == '/' { |
| 2928 | module = s |
| 2929 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 2930 | } |
Paul Duffin | e6ba072 | 2021-07-12 20:12:12 +0100 | [diff] [blame] | 2931 | return module |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 2932 | } |
| 2933 | |
Yi-Yo Chiang | ba9ea32 | 2021-07-15 17:18:21 +0800 | [diff] [blame] | 2934 | // SrcIsModuleWithTag decodes module references in the format ":unqualified-name{.tag}" or |
| 2935 | // "//namespace:name{.tag}" into the module name and tag, ":unqualified-name" or "//namespace:name" |
| 2936 | // into the module name and an empty string for the tag, or empty strings if the input was not a |
| 2937 | // module reference. |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2938 | func SrcIsModuleWithTag(s string) (module, tag string) { |
Paul Duffin | e6ba072 | 2021-07-12 20:12:12 +0100 | [diff] [blame] | 2939 | if len(s) > 1 { |
| 2940 | if s[0] == ':' { |
| 2941 | module = s[1:] |
| 2942 | } else if s[0] == '/' && s[1] == '/' { |
| 2943 | module = s |
| 2944 | } |
| 2945 | |
| 2946 | if module != "" { |
| 2947 | if tagStart := strings.IndexByte(module, '{'); tagStart > 0 { |
| 2948 | if module[len(module)-1] == '}' { |
| 2949 | tag = module[tagStart+1 : len(module)-1] |
| 2950 | module = module[:tagStart] |
| 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | if s[0] == ':' && !isUnqualifiedModuleName(module) { |
| 2955 | // The module name should be unqualified but is not so do not treat it as a module. |
| 2956 | module = "" |
| 2957 | tag = "" |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2958 | } |
| 2959 | } |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2960 | } |
Paul Duffin | e6ba072 | 2021-07-12 20:12:12 +0100 | [diff] [blame] | 2961 | |
| 2962 | return module, tag |
| 2963 | } |
| 2964 | |
| 2965 | // isUnqualifiedModuleName makes sure that the supplied module is an unqualified module name, i.e. |
| 2966 | // does not contain any /. |
| 2967 | func isUnqualifiedModuleName(module string) bool { |
| 2968 | return strings.IndexByte(module, '/') == -1 |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 2969 | } |
| 2970 | |
Paul Duffin | 40131a3 | 2021-07-09 17:10:35 +0100 | [diff] [blame] | 2971 | // sourceOrOutputDependencyTag is the dependency tag added automatically by pathDepsMutator for any |
| 2972 | // module reference in a property annotated with `android:"path"` or passed to ExtractSourceDeps |
| 2973 | // or ExtractSourcesDeps. |
| 2974 | // |
| 2975 | // If uniquely identifies the dependency that was added as it contains both the module name used to |
| 2976 | // add the dependency as well as the tag. That makes it very simple to find the matching dependency |
| 2977 | // in GetModuleFromPathDep as all it needs to do is find the dependency whose tag matches the tag |
| 2978 | // used to add it. It does not need to check that the module name as returned by one of |
| 2979 | // Module.Name(), BaseModuleContext.OtherModuleName() or ModuleBase.BaseModuleName() matches the |
| 2980 | // name supplied in the tag. That means it does not need to handle differences in module names |
| 2981 | // caused by prebuilt_ prefix, or fully qualified module names. |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2982 | type sourceOrOutputDependencyTag struct { |
| 2983 | blueprint.BaseDependencyTag |
Paul Duffin | 40131a3 | 2021-07-09 17:10:35 +0100 | [diff] [blame] | 2984 | |
| 2985 | // The name of the module. |
| 2986 | moduleName string |
| 2987 | |
| 2988 | // The tag that will be passed to the module's OutputFileProducer.OutputFiles(tag) method. |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2989 | tag string |
| 2990 | } |
| 2991 | |
Paul Duffin | 40131a3 | 2021-07-09 17:10:35 +0100 | [diff] [blame] | 2992 | func sourceOrOutputDepTag(moduleName, tag string) blueprint.DependencyTag { |
| 2993 | return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag} |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 2996 | // IsSourceDepTag returns true if the supplied blueprint.DependencyTag is one that was used to add |
| 2997 | // dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for properties |
| 2998 | // tagged with `android:"path"`. |
| 2999 | func IsSourceDepTag(depTag blueprint.DependencyTag) bool { |
| 3000 | _, ok := depTag.(sourceOrOutputDependencyTag) |
| 3001 | return ok |
| 3002 | } |
| 3003 | |
| 3004 | // IsSourceDepTagWithOutputTag returns true if the supplied blueprint.DependencyTag is one that was |
| 3005 | // used to add dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for |
| 3006 | // properties tagged with `android:"path"` AND it was added using a module reference of |
| 3007 | // :moduleName{outputTag}. |
| 3008 | func IsSourceDepTagWithOutputTag(depTag blueprint.DependencyTag, outputTag string) bool { |
| 3009 | t, ok := depTag.(sourceOrOutputDependencyTag) |
| 3010 | return ok && t.tag == outputTag |
| 3011 | } |
| 3012 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 3013 | // Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles |
| 3014 | // using ":module" syntax, if any. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 3015 | // |
| 3016 | // Deprecated: tag the property with `android:"path"` instead. |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 3017 | func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) { |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 3018 | set := make(map[string]bool) |
| 3019 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 3020 | for _, s := range srcFiles { |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 3021 | if m, t := SrcIsModuleWithTag(s); m != "" { |
| 3022 | if _, found := set[s]; found { |
| 3023 | ctx.ModuleErrorf("found source dependency duplicate: %q!", s) |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 3024 | } else { |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 3025 | set[s] = true |
Paul Duffin | 40131a3 | 2021-07-09 17:10:35 +0100 | [diff] [blame] | 3026 | ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m) |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 3027 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 3028 | } |
| 3029 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 3030 | } |
| 3031 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 3032 | // Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s |
| 3033 | // using ":module" syntax, if any. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 3034 | // |
| 3035 | // Deprecated: tag the property with `android:"path"` instead. |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 3036 | func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) { |
| 3037 | if s != nil { |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 3038 | if m, t := SrcIsModuleWithTag(*s); m != "" { |
Paul Duffin | 40131a3 | 2021-07-09 17:10:35 +0100 | [diff] [blame] | 3039 | ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m) |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 3040 | } |
| 3041 | } |
| 3042 | } |
| 3043 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 3044 | // A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"` |
| 3045 | // using the ":module" syntax and provides a list of paths to be used as if they were listed in the property. |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 3046 | type SourceFileProducer interface { |
| 3047 | Srcs() Paths |
| 3048 | } |
| 3049 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 3050 | // A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"` |
Roland Levillain | 97c1f34 | 2019-11-22 14:20:54 +0000 | [diff] [blame] | 3051 | // using the ":module" syntax or ":module{.tag}" syntax and provides a list of output files to be used as if they were |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 3052 | // listed in the property. |
| 3053 | type OutputFileProducer interface { |
| 3054 | OutputFiles(tag string) (Paths, error) |
| 3055 | } |
| 3056 | |
Colin Cross | 5e70805 | 2019-08-06 13:59:50 -0700 | [diff] [blame] | 3057 | // OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the |
| 3058 | // module produced zero paths, it reports errors to the ctx and returns nil. |
| 3059 | func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths { |
| 3060 | paths, err := outputFilesForModule(ctx, module, tag) |
| 3061 | if err != nil { |
| 3062 | reportPathError(ctx, err) |
| 3063 | return nil |
| 3064 | } |
| 3065 | return paths |
| 3066 | } |
| 3067 | |
| 3068 | // OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the |
| 3069 | // module produced zero or multiple paths, it reports errors to the ctx and returns nil. |
| 3070 | func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path { |
| 3071 | paths, err := outputFilesForModule(ctx, module, tag) |
| 3072 | if err != nil { |
| 3073 | reportPathError(ctx, err) |
| 3074 | return nil |
| 3075 | } |
| 3076 | if len(paths) > 1 { |
Ulya Trafimovich | 5ab276a | 2020-08-25 12:45:15 +0100 | [diff] [blame] | 3077 | ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one", |
Colin Cross | 5e70805 | 2019-08-06 13:59:50 -0700 | [diff] [blame] | 3078 | pathContextName(ctx, module)) |
| 3079 | return nil |
| 3080 | } |
| 3081 | return paths[0] |
| 3082 | } |
| 3083 | |
| 3084 | func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) { |
| 3085 | if outputFileProducer, ok := module.(OutputFileProducer); ok { |
| 3086 | paths, err := outputFileProducer.OutputFiles(tag) |
| 3087 | if err != nil { |
| 3088 | return nil, fmt.Errorf("failed to get output file from module %q: %s", |
| 3089 | pathContextName(ctx, module), err.Error()) |
| 3090 | } |
| 3091 | if len(paths) == 0 { |
| 3092 | return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module)) |
| 3093 | } |
| 3094 | return paths, nil |
Colin Cross | 74b1e2b | 2020-11-22 20:23:02 -0800 | [diff] [blame] | 3095 | } else if sourceFileProducer, ok := module.(SourceFileProducer); ok { |
| 3096 | if tag != "" { |
| 3097 | return nil, fmt.Errorf("module %q is a SourceFileProducer, not an OutputFileProducer, and so does not support tag %q", pathContextName(ctx, module), tag) |
| 3098 | } |
| 3099 | paths := sourceFileProducer.Srcs() |
| 3100 | if len(paths) == 0 { |
| 3101 | return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module)) |
| 3102 | } |
| 3103 | return paths, nil |
Colin Cross | 5e70805 | 2019-08-06 13:59:50 -0700 | [diff] [blame] | 3104 | } else { |
| 3105 | return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module)) |
| 3106 | } |
| 3107 | } |
| 3108 | |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 3109 | // Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to |
| 3110 | // specify that they can be used as a tool by a genrule module. |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 3111 | type HostToolProvider interface { |
Colin Cross | ba9e403 | 2020-11-24 16:32:22 -0800 | [diff] [blame] | 3112 | Module |
Colin Cross | 4158950 | 2020-12-01 14:00:21 -0800 | [diff] [blame] | 3113 | // HostToolPath returns the path to the host tool for the module if it is one, or an invalid |
| 3114 | // OptionalPath. |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 3115 | HostToolPath() OptionalPath |
| 3116 | } |
| 3117 | |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 3118 | // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must |
| 3119 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 3120 | // |
| 3121 | // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead. |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 3122 | func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths { |
| 3123 | return PathsForModuleSrcExcludes(m, srcFiles, excludes) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
Colin Cross | 2fafa3e | 2019-03-05 12:39:51 -0800 | [diff] [blame] | 3126 | // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must |
| 3127 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 3128 | // |
| 3129 | // Deprecated: use PathForModuleSrc instead. |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 3130 | func (m *moduleContext) ExpandSource(srcFile, prop string) Path { |
| 3131 | return PathForModuleSrc(m, srcFile) |
Colin Cross | 2fafa3e | 2019-03-05 12:39:51 -0800 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | // Returns an optional single path expanded from globs and modules referenced using ":module" syntax if |
| 3135 | // the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module |
| 3136 | // dependency resolution. |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 3137 | func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath { |
Colin Cross | 2fafa3e | 2019-03-05 12:39:51 -0800 | [diff] [blame] | 3138 | if srcFile != nil { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 3139 | return OptionalPathForPath(PathForModuleSrc(m, *srcFile)) |
Colin Cross | 2fafa3e | 2019-03-05 12:39:51 -0800 | [diff] [blame] | 3140 | } |
| 3141 | return OptionalPath{} |
| 3142 | } |
| 3143 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 3144 | func (m *moduleContext) RequiredModuleNames() []string { |
Jiyong Park | 6a8cf5f | 2019-12-30 16:31:09 +0900 | [diff] [blame] | 3145 | return m.module.RequiredModuleNames() |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 3146 | } |
| 3147 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 3148 | func (m *moduleContext) HostRequiredModuleNames() []string { |
Jiyong Park | 6a8cf5f | 2019-12-30 16:31:09 +0900 | [diff] [blame] | 3149 | return m.module.HostRequiredModuleNames() |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 3152 | func (m *moduleContext) TargetRequiredModuleNames() []string { |
Jiyong Park | 6a8cf5f | 2019-12-30 16:31:09 +0900 | [diff] [blame] | 3153 | return m.module.TargetRequiredModuleNames() |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 3156 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 3157 | RegisterSingletonType("buildtarget", BuildTargetSingleton) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 3158 | } |
| 3159 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3160 | func BuildTargetSingleton() Singleton { |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3161 | return &buildTargetSingleton{} |
| 3162 | } |
| 3163 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 3164 | func parentDir(dir string) string { |
| 3165 | dir, _ = filepath.Split(dir) |
| 3166 | return filepath.Clean(dir) |
| 3167 | } |
| 3168 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3169 | type buildTargetSingleton struct{} |
| 3170 | |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3171 | func addAncestors(ctx SingletonContext, dirMap map[string]Paths, mmName func(string) string) []string { |
| 3172 | // Ensure ancestor directories are in dirMap |
| 3173 | // Make directories build their direct subdirectories |
| 3174 | dirs := SortedStringKeys(dirMap) |
| 3175 | for _, dir := range dirs { |
| 3176 | dir := parentDir(dir) |
| 3177 | for dir != "." && dir != "/" { |
| 3178 | if _, exists := dirMap[dir]; exists { |
| 3179 | break |
| 3180 | } |
| 3181 | dirMap[dir] = nil |
| 3182 | dir = parentDir(dir) |
| 3183 | } |
| 3184 | } |
| 3185 | dirs = SortedStringKeys(dirMap) |
| 3186 | for _, dir := range dirs { |
| 3187 | p := parentDir(dir) |
| 3188 | if p != "." && p != "/" { |
| 3189 | dirMap[p] = append(dirMap[p], PathForPhony(ctx, mmName(dir))) |
| 3190 | } |
| 3191 | } |
| 3192 | return SortedStringKeys(dirMap) |
| 3193 | } |
| 3194 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3195 | func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) { |
| 3196 | var checkbuildDeps Paths |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3197 | var tidyDeps Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3198 | |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 3199 | mmTarget := func(dir string) string { |
| 3200 | return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1) |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 3201 | } |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3202 | mmTidyTarget := func(dir string) string { |
| 3203 | return "tidy-" + strings.Replace(filepath.Clean(dir), "/", "-", -1) |
| 3204 | } |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 3205 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3206 | modulesInDir := make(map[string]Paths) |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3207 | tidyModulesInDir := make(map[string]Paths) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3208 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3209 | ctx.VisitAllModules(func(module Module) { |
| 3210 | blueprintDir := module.base().blueprintDir |
| 3211 | installTarget := module.base().installTarget |
| 3212 | checkbuildTarget := module.base().checkbuildTarget |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3213 | tidyTarget := module.base().tidyTarget |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3214 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3215 | if checkbuildTarget != nil { |
| 3216 | checkbuildDeps = append(checkbuildDeps, checkbuildTarget) |
| 3217 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget) |
| 3218 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3219 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3220 | if installTarget != nil { |
| 3221 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3222 | } |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3223 | |
| 3224 | if tidyTarget != nil { |
| 3225 | tidyDeps = append(tidyDeps, tidyTarget) |
| 3226 | // tidyTarget is in modulesInDir so it will be built with "mm". |
| 3227 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], tidyTarget) |
| 3228 | // tidyModulesInDir contains tidyTarget but not checkbuildTarget |
| 3229 | // or installTarget, so tidy targets in a directory can be built |
| 3230 | // without other checkbuild or install targets. |
| 3231 | tidyModulesInDir[blueprintDir] = append(tidyModulesInDir[blueprintDir], tidyTarget) |
| 3232 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3233 | }) |
| 3234 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 3235 | suffix := "" |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 3236 | if ctx.Config().KatiEnabled() { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 3237 | suffix = "-soong" |
| 3238 | } |
| 3239 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3240 | // Create a top-level checkbuild target that depends on all modules |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 3241 | ctx.Phony("checkbuild"+suffix, checkbuildDeps...) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3242 | |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3243 | // Create a top-level tidy target that depends on all modules |
| 3244 | ctx.Phony("tidy"+suffix, tidyDeps...) |
| 3245 | |
| 3246 | dirs := addAncestors(ctx, tidyModulesInDir, mmTidyTarget) |
| 3247 | |
| 3248 | // Kati does not generate tidy-* phony targets yet. |
| 3249 | // Create a tidy-<directory> target that depends on all subdirectories |
| 3250 | // and modules in the directory. |
| 3251 | for _, dir := range dirs { |
| 3252 | ctx.Phony(mmTidyTarget(dir), tidyModulesInDir[dir]...) |
| 3253 | } |
| 3254 | |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 3255 | // Make will generate the MODULES-IN-* targets |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 3256 | if ctx.Config().KatiEnabled() { |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 3257 | return |
| 3258 | } |
| 3259 | |
Chih-Hung Hsieh | d0f82fe | 2021-09-05 20:15:38 -0700 | [diff] [blame^] | 3260 | dirs = addAncestors(ctx, modulesInDir, mmTarget) |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 3261 | |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 3262 | // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and |
| 3263 | // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp |
| 3264 | // files. |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3265 | for _, dir := range dirs { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 3266 | ctx.Phony(mmTarget(dir), modulesInDir[dir]...) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3267 | } |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3268 | |
| 3269 | // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild. |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 3270 | type osAndCross struct { |
| 3271 | os OsType |
| 3272 | hostCross bool |
| 3273 | } |
| 3274 | osDeps := map[osAndCross]Paths{} |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3275 | ctx.VisitAllModules(func(module Module) { |
| 3276 | if module.Enabled() { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 3277 | key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross} |
| 3278 | osDeps[key] = append(osDeps[key], module.base().checkbuildFiles...) |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3279 | } |
| 3280 | }) |
| 3281 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 3282 | osClass := make(map[string]Paths) |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 3283 | for key, deps := range osDeps { |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3284 | var className string |
| 3285 | |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 3286 | switch key.os.Class { |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3287 | case Host: |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 3288 | if key.hostCross { |
| 3289 | className = "host-cross" |
| 3290 | } else { |
| 3291 | className = "host" |
| 3292 | } |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3293 | case Device: |
| 3294 | className = "target" |
| 3295 | default: |
| 3296 | continue |
| 3297 | } |
| 3298 | |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 3299 | name := className + "-" + key.os.Name |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 3300 | osClass[className] = append(osClass[className], PathForPhony(ctx, name)) |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3301 | |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 3302 | ctx.Phony(name, deps...) |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | // Wrap those into host|host-cross|target phony rules |
Inseob Kim | 1a365c6 | 2019-06-08 15:47:51 +0900 | [diff] [blame] | 3306 | for _, class := range SortedStringKeys(osClass) { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 3307 | ctx.Phony(class, osClass[class]...) |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 3308 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 3309 | } |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 3310 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 3311 | // Collect information for opening IDE project files in java/jdeps.go. |
| 3312 | type IDEInfo interface { |
| 3313 | IDEInfo(ideInfo *IdeInfo) |
| 3314 | BaseModuleName() string |
| 3315 | } |
| 3316 | |
| 3317 | // Extract the base module name from the Import name. |
| 3318 | // Often the Import name has a prefix "prebuilt_". |
| 3319 | // Remove the prefix explicitly if needed |
| 3320 | // until we find a better solution to get the Import name. |
| 3321 | type IDECustomizedModuleName interface { |
| 3322 | IDECustomizedModuleName() string |
| 3323 | } |
| 3324 | |
| 3325 | type IdeInfo struct { |
| 3326 | Deps []string `json:"dependencies,omitempty"` |
| 3327 | Srcs []string `json:"srcs,omitempty"` |
| 3328 | Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"` |
| 3329 | Jarjar_rules []string `json:"jarjar_rules,omitempty"` |
| 3330 | Jars []string `json:"jars,omitempty"` |
| 3331 | Classes []string `json:"class,omitempty"` |
| 3332 | Installed_paths []string `json:"installed,omitempty"` |
patricktu | 18c82ff | 2019-05-10 15:48:50 +0800 | [diff] [blame] | 3333 | SrcJars []string `json:"srcjars,omitempty"` |
bralee | 1fbf440 | 2020-05-21 10:11:59 +0800 | [diff] [blame] | 3334 | Paths []string `json:"path,omitempty"` |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 3335 | } |
Paul Duffin | f88d8e0 | 2020-05-07 20:21:34 +0100 | [diff] [blame] | 3336 | |
| 3337 | func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error { |
| 3338 | bpctx := ctx.blueprintBaseModuleContext() |
| 3339 | return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents) |
| 3340 | } |
Colin Cross | 5d58395 | 2020-11-24 16:21:24 -0800 | [diff] [blame] | 3341 | |
| 3342 | // installPathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses |
| 3343 | // topological order. |
| 3344 | type installPathsDepSet struct { |
| 3345 | depSet |
| 3346 | } |
| 3347 | |
| 3348 | // newInstallPathsDepSet returns an immutable packagingSpecsDepSet with the given direct and |
| 3349 | // transitive contents. |
| 3350 | func newInstallPathsDepSet(direct InstallPaths, transitive []*installPathsDepSet) *installPathsDepSet { |
| 3351 | return &installPathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)} |
| 3352 | } |
| 3353 | |
| 3354 | // ToList returns the installPathsDepSet flattened to a list in topological order. |
| 3355 | func (d *installPathsDepSet) ToList() InstallPaths { |
| 3356 | if d == nil { |
| 3357 | return nil |
| 3358 | } |
| 3359 | return d.depSet.ToList().(InstallPaths) |
| 3360 | } |