Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 1 | // Copyright 2020 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 | |
| 15 | package android |
| 16 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 17 | import ( |
| 18 | "fmt" |
| 19 | "path/filepath" |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 20 | "sort" |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint" |
Yu Liu | 3cadf7d | 2024-10-24 18:47:06 +0000 | [diff] [blame] | 23 | "github.com/google/blueprint/gobtools" |
Jiyong Park | 105e11c | 2024-05-17 14:58:24 +0900 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 25 | "github.com/google/blueprint/uniquelist" |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
Jiyong Park | cc1157c | 2020-11-25 11:31:13 +0900 | [diff] [blame] | 28 | // PackagingSpec abstracts a request to place a built artifact at a certain path in a package. A |
| 29 | // package can be the traditional <partition>.img, but isn't limited to those. Other examples could |
| 30 | // be a new filesystem image that is a subset of system.img (e.g. for an Android-like mini OS |
| 31 | // running on a VM), or a zip archive for some of the host tools. |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 32 | type PackagingSpec struct { |
| 33 | // Path relative to the root of the package |
| 34 | relPathInPackage string |
| 35 | |
| 36 | // The path to the built artifact |
| 37 | srcPath Path |
| 38 | |
| 39 | // If this is not empty, then relPathInPackage should be a symlink to this target. (Then |
| 40 | // srcPath is of course ignored.) |
| 41 | symlinkTarget string |
| 42 | |
| 43 | // Whether relPathInPackage should be marked as executable or not |
| 44 | executable bool |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 45 | |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 46 | effectiveLicenseFiles uniquelist.UniqueList[Path] |
Jooyung Han | 99c5fe6 | 2022-03-21 15:13:38 +0900 | [diff] [blame] | 47 | |
| 48 | partition string |
Jiyong Park | 4152b19 | 2024-04-30 21:24:21 +0900 | [diff] [blame] | 49 | |
| 50 | // Whether this packaging spec represents an installation of the srcPath (i.e. this struct |
| 51 | // is created via InstallFile or InstallSymlink) or a simple packaging (i.e. created via |
| 52 | // PackageFile). |
| 53 | skipInstall bool |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 54 | |
| 55 | // Paths of aconfig files for the built artifact |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 56 | aconfigPaths uniquelist.UniqueList[Path] |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 57 | |
| 58 | // ArchType of the module which produced this packaging spec |
| 59 | archType ArchType |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 60 | |
| 61 | // List of module names that this packaging spec overrides |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 62 | overrides uniquelist.UniqueList[string] |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 63 | |
| 64 | // Name of the module where this packaging spec is output of |
| 65 | owner string |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 66 | |
| 67 | // If the ninja rule creating the FullInstallPath has already been emitted or not. Do not use, |
| 68 | // for the soong-only migration. |
| 69 | requiresFullInstall bool |
| 70 | |
| 71 | // The path to the installed file in out/target/product. This is for legacy purposes, with |
| 72 | // tools that want to interact with these files outside of the build. You should not use it |
| 73 | // inside of the build. Will be nil if this module doesn't require a "full install". |
| 74 | fullInstallPath InstallPath |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 75 | |
| 76 | // String representation of the variation of the module where this packaging spec is output of |
| 77 | variation string |
Jiyong Park | 073ea55 | 2020-11-09 14:08:34 +0900 | [diff] [blame] | 78 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 79 | |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 80 | type packagingSpecGob struct { |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 81 | RelPathInPackage string |
| 82 | SrcPath Path |
| 83 | SymlinkTarget string |
| 84 | Executable bool |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 85 | EffectiveLicenseFiles Paths |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 86 | Partition string |
| 87 | SkipInstall bool |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 88 | AconfigPaths Paths |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 89 | ArchType ArchType |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 90 | Overrides []string |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 91 | Owner string |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 92 | Variation string |
| 93 | } |
| 94 | |
| 95 | func (p *PackagingSpec) Owner() string { |
| 96 | return p.owner |
| 97 | } |
| 98 | |
| 99 | func (p *PackagingSpec) Variation() string { |
| 100 | return p.variation |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 101 | } |
Yu Liu | 26a716d | 2024-08-30 23:40:32 +0000 | [diff] [blame] | 102 | |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 103 | func (p *PackagingSpec) ToGob() *packagingSpecGob { |
| 104 | return &packagingSpecGob{ |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 105 | RelPathInPackage: p.relPathInPackage, |
| 106 | SrcPath: p.srcPath, |
| 107 | SymlinkTarget: p.symlinkTarget, |
| 108 | Executable: p.executable, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 109 | EffectiveLicenseFiles: p.effectiveLicenseFiles.ToSlice(), |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 110 | Partition: p.partition, |
| 111 | SkipInstall: p.skipInstall, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 112 | AconfigPaths: p.aconfigPaths.ToSlice(), |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 113 | ArchType: p.archType, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 114 | Overrides: p.overrides.ToSlice(), |
Yu Liu | 5246a7e | 2024-10-09 20:04:52 +0000 | [diff] [blame] | 115 | Owner: p.owner, |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 116 | Variation: p.variation, |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | func (p *PackagingSpec) FromGob(data *packagingSpecGob) { |
| 121 | p.relPathInPackage = data.RelPathInPackage |
| 122 | p.srcPath = data.SrcPath |
| 123 | p.symlinkTarget = data.SymlinkTarget |
| 124 | p.executable = data.Executable |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 125 | p.effectiveLicenseFiles = uniquelist.Make(data.EffectiveLicenseFiles) |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 126 | p.partition = data.Partition |
| 127 | p.skipInstall = data.SkipInstall |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 128 | p.aconfigPaths = uniquelist.Make(data.AconfigPaths) |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 129 | p.archType = data.ArchType |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 130 | p.overrides = uniquelist.Make(data.Overrides) |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 131 | p.owner = data.Owner |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 132 | p.variation = data.Variation |
Yu Liu | 467d7c5 | 2024-09-18 21:54:44 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | func (p *PackagingSpec) GobEncode() ([]byte, error) { |
Yu Liu | 3cadf7d | 2024-10-24 18:47:06 +0000 | [diff] [blame] | 136 | return gobtools.CustomGobEncode[packagingSpecGob](p) |
Yu Liu | 26a716d | 2024-08-30 23:40:32 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | func (p *PackagingSpec) GobDecode(data []byte) error { |
Yu Liu | 3cadf7d | 2024-10-24 18:47:06 +0000 | [diff] [blame] | 140 | return gobtools.CustomGobDecode[packagingSpecGob](data, p) |
Yu Liu | 26a716d | 2024-08-30 23:40:32 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Jiyong Park | 16ef7ac | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 143 | func (p *PackagingSpec) Equals(other *PackagingSpec) bool { |
| 144 | if other == nil { |
| 145 | return false |
| 146 | } |
| 147 | if p.relPathInPackage != other.relPathInPackage { |
| 148 | return false |
| 149 | } |
| 150 | if p.srcPath != other.srcPath || p.symlinkTarget != other.symlinkTarget { |
| 151 | return false |
| 152 | } |
| 153 | if p.executable != other.executable { |
| 154 | return false |
| 155 | } |
| 156 | if p.partition != other.partition { |
| 157 | return false |
| 158 | } |
| 159 | return true |
| 160 | } |
| 161 | |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 162 | // Get file name of installed package |
| 163 | func (p *PackagingSpec) FileName() string { |
| 164 | if p.relPathInPackage != "" { |
| 165 | return filepath.Base(p.relPathInPackage) |
| 166 | } |
| 167 | |
| 168 | return "" |
| 169 | } |
| 170 | |
Jiyong Park | 6446b62 | 2021-02-01 20:08:28 +0900 | [diff] [blame] | 171 | // Path relative to the root of the package |
| 172 | func (p *PackagingSpec) RelPathInPackage() string { |
| 173 | return p.relPathInPackage |
| 174 | } |
| 175 | |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 176 | func (p *PackagingSpec) SetRelPathInPackage(relPathInPackage string) { |
| 177 | p.relPathInPackage = relPathInPackage |
| 178 | } |
| 179 | |
| 180 | func (p *PackagingSpec) EffectiveLicenseFiles() Paths { |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 181 | return p.effectiveLicenseFiles.ToSlice() |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Jooyung Han | 99c5fe6 | 2022-03-21 15:13:38 +0900 | [diff] [blame] | 184 | func (p *PackagingSpec) Partition() string { |
| 185 | return p.partition |
| 186 | } |
| 187 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 188 | func (p *PackagingSpec) SetPartition(partition string) { |
| 189 | p.partition = partition |
| 190 | } |
| 191 | |
Jiyong Park | 4152b19 | 2024-04-30 21:24:21 +0900 | [diff] [blame] | 192 | func (p *PackagingSpec) SkipInstall() bool { |
| 193 | return p.skipInstall |
| 194 | } |
| 195 | |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 196 | // Paths of aconfig files for the built artifact |
| 197 | func (p *PackagingSpec) GetAconfigPaths() Paths { |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 198 | return p.aconfigPaths.ToSlice() |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 199 | } |
| 200 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 201 | // The path to the installed file in out/target/product. This is for legacy purposes, with |
| 202 | // tools that want to interact with these files outside of the build. You should not use it |
| 203 | // inside of the build. Will be nil if this module doesn't require a "full install". |
| 204 | func (p *PackagingSpec) FullInstallPath() InstallPath { |
| 205 | return p.fullInstallPath |
| 206 | } |
| 207 | |
| 208 | // If the ninja rule creating the FullInstallPath has already been emitted or not. Do not use, |
| 209 | // for the soong-only migration. |
| 210 | func (p *PackagingSpec) RequiresFullInstall() bool { |
| 211 | return p.requiresFullInstall |
| 212 | } |
| 213 | |
| 214 | // The source file to be copied to the FullInstallPath. Do not use, for the soong-only migration. |
| 215 | func (p *PackagingSpec) SrcPath() Path { |
| 216 | return p.srcPath |
| 217 | } |
| 218 | |
Cole Faust | b052df5 | 2025-02-14 12:47:51 -0800 | [diff] [blame] | 219 | // The symlink target of the PackagingSpec. Do not use, for the soong-only migration. |
| 220 | func (p *PackagingSpec) SymlinkTarget() string { |
| 221 | return p.symlinkTarget |
| 222 | } |
| 223 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 224 | type PackageModule interface { |
| 225 | Module |
| 226 | packagingBase() *PackagingBase |
| 227 | |
| 228 | // AddDeps adds dependencies to the `deps` modules. This should be called in DepsMutator. |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 229 | // When adding the dependencies, depTag is used as the tag. If `deps` modules are meant to |
| 230 | // be copied to a zip in CopyDepsToZip, `depTag` should implement PackagingItem marker interface. |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 231 | AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 232 | |
Jooyung Han | a883428 | 2022-03-25 11:40:12 +0900 | [diff] [blame] | 233 | // GatherPackagingSpecs gathers PackagingSpecs of transitive dependencies. |
| 234 | GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 235 | GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 236 | GatherPackagingSpecsWithFilterAndModifier(ctx ModuleContext, filter func(PackagingSpec) bool, modifier func(*PackagingSpec)) map[string]PackagingSpec |
Jooyung Han | a883428 | 2022-03-25 11:40:12 +0900 | [diff] [blame] | 237 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 238 | // CopyDepsToZip zips the built artifacts of the dependencies into the given zip file and |
Jiyong Park | cc1157c | 2020-11-25 11:31:13 +0900 | [diff] [blame] | 239 | // returns zip entries in it. This is expected to be called in GenerateAndroidBuildActions, |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 240 | // followed by a build rule that unzips it and creates the final output (img, zip, tar.gz, |
| 241 | // etc.) from the extracted files |
Jooyung Han | a883428 | 2022-03-25 11:40:12 +0900 | [diff] [blame] | 242 | CopyDepsToZip(ctx ModuleContext, specs map[string]PackagingSpec, zipOut WritablePath) []string |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | // PackagingBase provides basic functionality for packaging dependencies. A module is expected to |
| 246 | // include this struct and call InitPackageModule. |
| 247 | type PackagingBase struct { |
| 248 | properties PackagingProperties |
| 249 | |
Jiyong Park | cc1157c | 2020-11-25 11:31:13 +0900 | [diff] [blame] | 250 | // Allows this module to skip missing dependencies. In most cases, this is not required, but |
| 251 | // for rare cases like when there's a dependency to a module which exists in certain repo |
| 252 | // checkouts, this is needed. |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 253 | IgnoreMissingDependencies bool |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 254 | |
| 255 | // If this is set to true by a module type inheriting PackagingBase, the deps property |
| 256 | // collects the first target only even with compile_multilib: true. |
| 257 | DepsCollectFirstTargetOnly bool |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 258 | |
| 259 | // If this is set to try by a module type inheriting PackagingBase, the module type is |
| 260 | // allowed to utilize High_priority_deps. |
| 261 | AllowHighPriorityDeps bool |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 262 | } |
| 263 | |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 264 | type DepsProperty struct { |
| 265 | // Deps that have higher priority in packaging when there is a packaging conflict. |
| 266 | // For example, if multiple files are being installed to same filepath, the install file |
| 267 | // of the module listed in this property will have a higher priority over those in other |
| 268 | // deps properties. |
| 269 | High_priority_deps []string `android:"arch_variant"` |
| 270 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 271 | // Modules to include in this package |
Jiyong Park | 105e11c | 2024-05-17 14:58:24 +0900 | [diff] [blame] | 272 | Deps proptools.Configurable[[]string] `android:"arch_variant"` |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | type packagingMultilibProperties struct { |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 276 | First DepsProperty `android:"arch_variant"` |
| 277 | Common DepsProperty `android:"arch_variant"` |
| 278 | Lib32 DepsProperty `android:"arch_variant"` |
| 279 | Lib64 DepsProperty `android:"arch_variant"` |
| 280 | Both DepsProperty `android:"arch_variant"` |
| 281 | Prefer32 DepsProperty `android:"arch_variant"` |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 282 | } |
| 283 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 284 | type packagingArchProperties struct { |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 285 | Arm64 DepsProperty |
| 286 | Arm DepsProperty |
| 287 | X86_64 DepsProperty |
| 288 | X86 DepsProperty |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 289 | } |
| 290 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 291 | type PackagingProperties struct { |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 292 | DepsProperty |
| 293 | |
| 294 | Multilib packagingMultilibProperties `android:"arch_variant"` |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 295 | Arch packagingArchProperties |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 296 | } |
| 297 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 298 | func InitPackageModule(p PackageModule) { |
| 299 | base := p.packagingBase() |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 300 | p.AddProperties(&base.properties, &base.properties.DepsProperty) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | func (p *PackagingBase) packagingBase() *PackagingBase { |
| 304 | return p |
| 305 | } |
| 306 | |
Jiyong Park | cc1157c | 2020-11-25 11:31:13 +0900 | [diff] [blame] | 307 | // From deps and multilib.*.deps, select the dependencies that are for the given arch deps is for |
| 308 | // the current archicture when this module is not configured for multi target. When configured for |
| 309 | // multi target, deps is selected for each of the targets and is NOT selected for the current |
| 310 | // architecture which would be Common. |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 311 | // It returns two lists, the normal and high priority deps, respectively. |
| 312 | func (p *PackagingBase) getDepsForArch(ctx BaseModuleContext, arch ArchType) ([]string, []string) { |
| 313 | var normalDeps []string |
| 314 | var highPriorityDeps []string |
| 315 | |
| 316 | get := func(prop DepsProperty) { |
| 317 | normalDeps = append(normalDeps, prop.Deps.GetOrDefault(ctx, nil)...) |
| 318 | highPriorityDeps = append(highPriorityDeps, prop.High_priority_deps...) |
| 319 | } |
| 320 | has := func(prop DepsProperty) bool { |
| 321 | return len(prop.Deps.GetOrDefault(ctx, nil)) > 0 || len(prop.High_priority_deps) > 0 |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 324 | if arch == ctx.Target().Arch.ArchType && len(ctx.MultiTargets()) == 0 { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 325 | get(p.properties.DepsProperty) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 326 | } else if arch.Multilib == "lib32" { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 327 | get(p.properties.Multilib.Lib32) |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 328 | // multilib.prefer32.deps are added for lib32 only when they support 32-bit arch |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 329 | for _, dep := range p.properties.Multilib.Prefer32.Deps.GetOrDefault(ctx, nil) { |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 330 | if checkIfOtherModuleSupportsLib32(ctx, dep) { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 331 | normalDeps = append(normalDeps, dep) |
| 332 | } |
| 333 | } |
| 334 | for _, dep := range p.properties.Multilib.Prefer32.High_priority_deps { |
| 335 | if checkIfOtherModuleSupportsLib32(ctx, dep) { |
| 336 | highPriorityDeps = append(highPriorityDeps, dep) |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 337 | } |
| 338 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 339 | } else if arch.Multilib == "lib64" { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 340 | get(p.properties.Multilib.Lib64) |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 341 | // multilib.prefer32.deps are added for lib64 only when they don't support 32-bit arch |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 342 | for _, dep := range p.properties.Multilib.Prefer32.Deps.GetOrDefault(ctx, nil) { |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 343 | if !checkIfOtherModuleSupportsLib32(ctx, dep) { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 344 | normalDeps = append(normalDeps, dep) |
| 345 | } |
| 346 | } |
| 347 | for _, dep := range p.properties.Multilib.Prefer32.High_priority_deps { |
| 348 | if !checkIfOtherModuleSupportsLib32(ctx, dep) { |
| 349 | highPriorityDeps = append(highPriorityDeps, dep) |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 350 | } |
| 351 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 352 | } else if arch == Common { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 353 | get(p.properties.Multilib.Common) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 354 | } |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 355 | |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 356 | if p.DepsCollectFirstTargetOnly { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 357 | if has(p.properties.Multilib.First) { |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 358 | ctx.PropertyErrorf("multilib.first.deps", "not supported. use \"deps\" instead") |
| 359 | } |
| 360 | for i, t := range ctx.MultiTargets() { |
| 361 | if t.Arch.ArchType == arch { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 362 | get(p.properties.Multilib.Both) |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 363 | if i == 0 { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 364 | get(p.properties.DepsProperty) |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | } |
| 368 | } else { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 369 | if has(p.properties.Multilib.Both) { |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 370 | ctx.PropertyErrorf("multilib.both.deps", "not supported. use \"deps\" instead") |
| 371 | } |
| 372 | for i, t := range ctx.MultiTargets() { |
| 373 | if t.Arch.ArchType == arch { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 374 | get(p.properties.DepsProperty) |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 375 | if i == 0 { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 376 | get(p.properties.Multilib.First) |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 377 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | } |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 381 | |
| 382 | if ctx.Arch().ArchType == Common { |
| 383 | switch arch { |
| 384 | case Arm64: |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 385 | get(p.properties.Arch.Arm64) |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 386 | case Arm: |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 387 | get(p.properties.Arch.Arm) |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 388 | case X86_64: |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 389 | get(p.properties.Arch.X86_64) |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 390 | case X86: |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 391 | get(p.properties.Arch.X86) |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 395 | if len(highPriorityDeps) > 0 && !p.AllowHighPriorityDeps { |
| 396 | ctx.ModuleErrorf("Usage of high_priority_deps is not allowed for %s module type", ctx.ModuleType()) |
| 397 | } |
| 398 | |
| 399 | return FirstUniqueStrings(normalDeps), FirstUniqueStrings(highPriorityDeps) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 400 | } |
| 401 | |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 402 | func getSupportedTargets(ctx BaseModuleContext) []Target { |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 403 | var ret []Target |
| 404 | // The current and the common OS targets are always supported |
| 405 | ret = append(ret, ctx.Target()) |
| 406 | if ctx.Arch().ArchType != Common { |
| 407 | ret = append(ret, Target{Os: ctx.Os(), Arch: Arch{ArchType: Common}}) |
| 408 | } |
| 409 | // If this module is configured for multi targets, those should be supported as well |
| 410 | ret = append(ret, ctx.MultiTargets()...) |
| 411 | return ret |
| 412 | } |
| 413 | |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 414 | // getLib32Target returns the 32-bit target from the list of targets this module supports. If this |
| 415 | // module doesn't support 32-bit target, nil is returned. |
| 416 | func getLib32Target(ctx BaseModuleContext) *Target { |
| 417 | for _, t := range getSupportedTargets(ctx) { |
| 418 | if t.Arch.ArchType.Multilib == "lib32" { |
| 419 | return &t |
| 420 | } |
| 421 | } |
| 422 | return nil |
| 423 | } |
| 424 | |
| 425 | // checkIfOtherModuleSUpportsLib32 returns true if 32-bit variant of dep exists. |
| 426 | func checkIfOtherModuleSupportsLib32(ctx BaseModuleContext, dep string) bool { |
| 427 | t := getLib32Target(ctx) |
| 428 | if t == nil { |
| 429 | // This packaging module doesn't support 32bit. No point of checking if dep supports 32-bit |
| 430 | // or not. |
| 431 | return false |
| 432 | } |
| 433 | return ctx.OtherModuleFarDependencyVariantExists(t.Variations(), dep) |
| 434 | } |
| 435 | |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 436 | // PackagingItem is a marker interface for dependency tags. |
| 437 | // Direct dependencies with a tag implementing PackagingItem are packaged in CopyDepsToZip(). |
| 438 | type PackagingItem interface { |
| 439 | // IsPackagingItem returns true if the dep is to be packaged |
| 440 | IsPackagingItem() bool |
| 441 | } |
| 442 | |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 443 | var _ PackagingItem = (*PackagingItemAlwaysDepTag)(nil) |
| 444 | |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 445 | // DepTag provides default implementation of PackagingItem interface. |
| 446 | // PackagingBase-derived modules can define their own dependency tag by embedding this, which |
| 447 | // can be passed to AddDeps() or AddDependencies(). |
| 448 | type PackagingItemAlwaysDepTag struct { |
| 449 | } |
| 450 | |
| 451 | // IsPackagingItem returns true if the dep is to be packaged |
| 452 | func (PackagingItemAlwaysDepTag) IsPackagingItem() bool { |
| 453 | return true |
| 454 | } |
| 455 | |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 456 | type highPriorityDepTag struct { |
Jihoon Kang | ade584c | 2024-11-14 19:45:47 +0000 | [diff] [blame] | 457 | blueprint.BaseDependencyTag |
| 458 | PackagingItemAlwaysDepTag |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 461 | // See PackageModule.AddDeps |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 462 | func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag) { |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 463 | addDep := func(t Target, dep string, highPriority bool) { |
| 464 | if p.IgnoreMissingDependencies && !ctx.OtherModuleExists(dep) { |
| 465 | return |
| 466 | } |
| 467 | targetVariation := t.Variations() |
| 468 | sharedVariation := blueprint.Variation{ |
| 469 | Mutator: "link", |
| 470 | Variation: "shared", |
| 471 | } |
| 472 | // If a shared variation exists, use that. Static variants do not provide any standalone files |
| 473 | // for packaging. |
| 474 | if ctx.OtherModuleFarDependencyVariantExists([]blueprint.Variation{sharedVariation}, dep) { |
| 475 | targetVariation = append(targetVariation, sharedVariation) |
| 476 | } |
| 477 | depTagToUse := depTag |
| 478 | if highPriority { |
Jihoon Kang | ade584c | 2024-11-14 19:45:47 +0000 | [diff] [blame] | 479 | depTagToUse = highPriorityDepTag{} |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 480 | } |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 481 | |
Cole Faust | 0c5eaed | 2024-11-01 11:05:00 -0700 | [diff] [blame] | 482 | ctx.AddFarVariationDependencies(targetVariation, depTagToUse, dep) |
| 483 | } |
| 484 | for _, t := range getSupportedTargets(ctx) { |
| 485 | normalDeps, highPriorityDeps := p.getDepsForArch(ctx, t.Arch.ArchType) |
| 486 | for _, dep := range normalDeps { |
| 487 | addDep(t, dep, false) |
| 488 | } |
| 489 | for _, dep := range highPriorityDeps { |
| 490 | addDep(t, dep, true) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 495 | // See PackageModule.GatherPackagingSpecs |
| 496 | func (p *PackagingBase) GatherPackagingSpecsWithFilterAndModifier(ctx ModuleContext, filter func(PackagingSpec) bool, modifier func(*PackagingSpec)) map[string]PackagingSpec { |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 497 | // packaging specs gathered from the dep that are not high priorities. |
| 498 | var regularPriorities []PackagingSpec |
| 499 | |
| 500 | // all packaging specs gathered from the high priority deps. |
| 501 | var highPriorities []PackagingSpec |
| 502 | |
Spandan Das | 6c2b01d | 2024-10-22 22:16:04 +0000 | [diff] [blame] | 503 | // Name of the dependency which requested the packaging spec. |
| 504 | // If this dep is overridden, the packaging spec will not be installed via this dependency chain. |
| 505 | // (the packaging spec might still be installed if there are some other deps which depend on it). |
| 506 | var depNames []string |
| 507 | |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 508 | // list of module names overridden |
| 509 | var overridden []string |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 510 | |
| 511 | var arches []ArchType |
Jiyong Park | e604378 | 2024-05-20 16:17:39 +0900 | [diff] [blame] | 512 | for _, target := range getSupportedTargets(ctx) { |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 513 | arches = append(arches, target.Arch.ArchType) |
| 514 | } |
| 515 | |
| 516 | // filter out packaging specs for unsupported architecture |
| 517 | filterArch := func(ps PackagingSpec) bool { |
| 518 | for _, arch := range arches { |
| 519 | if arch == ps.archType { |
| 520 | return true |
| 521 | } |
| 522 | } |
| 523 | return false |
| 524 | } |
| 525 | |
Yu Liu | ac483e0 | 2024-11-11 22:29:30 +0000 | [diff] [blame] | 526 | ctx.VisitDirectDepsProxy(func(child ModuleProxy) { |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 527 | depTag := ctx.OtherModuleDependencyTag(child) |
| 528 | if pi, ok := depTag.(PackagingItem); !ok || !pi.IsPackagingItem() { |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 529 | return |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 530 | } |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 531 | for _, ps := range OtherModuleProviderOrDefault( |
| 532 | ctx, child, InstallFilesProvider).TransitivePackagingSpecs.ToList() { |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 533 | if !filterArch(ps) { |
| 534 | continue |
| 535 | } |
| 536 | |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 537 | if filter != nil { |
| 538 | if !filter(ps) { |
| 539 | continue |
| 540 | } |
| 541 | } |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 542 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 543 | if modifier != nil { |
| 544 | modifier(&ps) |
| 545 | } |
| 546 | |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 547 | if _, ok := depTag.(highPriorityDepTag); ok { |
| 548 | highPriorities = append(highPriorities, ps) |
| 549 | } else { |
| 550 | regularPriorities = append(regularPriorities, ps) |
| 551 | } |
| 552 | |
Spandan Das | 6c2b01d | 2024-10-22 22:16:04 +0000 | [diff] [blame] | 553 | depNames = append(depNames, child.Name()) |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 554 | overridden = append(overridden, ps.overrides.ToSlice()...) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 555 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 556 | }) |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 557 | |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 558 | filterOverridden := func(input []PackagingSpec) []PackagingSpec { |
| 559 | // input minus packaging specs that are overridden |
| 560 | var filtered []PackagingSpec |
| 561 | for index, ps := range input { |
| 562 | if ps.owner != "" && InList(ps.owner, overridden) { |
| 563 | continue |
| 564 | } |
| 565 | // The dependency which requested this packaging spec has been overridden. |
| 566 | if InList(depNames[index], overridden) { |
| 567 | continue |
| 568 | } |
| 569 | filtered = append(filtered, ps) |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 570 | } |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 571 | return filtered |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 572 | } |
| 573 | |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 574 | filteredRegularPriority := filterOverridden(regularPriorities) |
| 575 | |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 576 | m := make(map[string]PackagingSpec) |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 577 | for _, ps := range filteredRegularPriority { |
Jiyong Park | a574d53 | 2024-08-28 18:06:43 +0900 | [diff] [blame] | 578 | dstPath := ps.relPathInPackage |
| 579 | if existingPs, ok := m[dstPath]; ok { |
| 580 | if !existingPs.Equals(&ps) { |
| 581 | ctx.ModuleErrorf("packaging conflict at %v:\n%v\n%v", dstPath, existingPs, ps) |
| 582 | } |
| 583 | continue |
| 584 | } |
| 585 | m[dstPath] = ps |
| 586 | } |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 587 | |
| 588 | filteredHighPriority := filterOverridden(highPriorities) |
| 589 | highPriorityPs := make(map[string]PackagingSpec) |
| 590 | for _, ps := range filteredHighPriority { |
| 591 | dstPath := ps.relPathInPackage |
| 592 | if existingPs, ok := highPriorityPs[dstPath]; ok { |
| 593 | if !existingPs.Equals(&ps) { |
| 594 | ctx.ModuleErrorf("packaging conflict at %v:\n%v\n%v", dstPath, existingPs, ps) |
| 595 | } |
| 596 | continue |
| 597 | } |
| 598 | highPriorityPs[dstPath] = ps |
| 599 | m[dstPath] = ps |
| 600 | } |
| 601 | |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 602 | return m |
| 603 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 604 | |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 605 | // See PackageModule.GatherPackagingSpecs |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 606 | func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec { |
| 607 | return p.GatherPackagingSpecsWithFilterAndModifier(ctx, filter, nil) |
| 608 | } |
| 609 | |
| 610 | // See PackageModule.GatherPackagingSpecs |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 611 | func (p *PackagingBase) GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec { |
| 612 | return p.GatherPackagingSpecsWithFilter(ctx, nil) |
| 613 | } |
| 614 | |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 615 | // CopySpecsToDir is a helper that will add commands to the rule builder to copy the PackagingSpec |
| 616 | // entries into the specified directory. |
Peter Collingbourne | ff56c01 | 2023-03-15 22:24:03 -0700 | [diff] [blame] | 617 | func (p *PackagingBase) CopySpecsToDir(ctx ModuleContext, builder *RuleBuilder, specs map[string]PackagingSpec, dir WritablePath) (entries []string) { |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 618 | dirsToSpecs := make(map[WritablePath]map[string]PackagingSpec) |
| 619 | dirsToSpecs[dir] = specs |
Cole Faust | e384505 | 2025-02-13 12:45:35 -0800 | [diff] [blame] | 620 | return p.CopySpecsToDirs(ctx, builder, dirsToSpecs, false) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | // CopySpecsToDirs is a helper that will add commands to the rule builder to copy the PackagingSpec |
| 624 | // entries into corresponding directories. |
Cole Faust | e384505 | 2025-02-13 12:45:35 -0800 | [diff] [blame] | 625 | func (p *PackagingBase) CopySpecsToDirs(ctx ModuleContext, builder *RuleBuilder, dirsToSpecs map[WritablePath]map[string]PackagingSpec, preserveTimestamps bool) (entries []string) { |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 626 | empty := true |
| 627 | for _, specs := range dirsToSpecs { |
| 628 | if len(specs) > 0 { |
| 629 | empty = false |
| 630 | break |
| 631 | } |
| 632 | } |
| 633 | if empty { |
Cole Faust | 3b3a011 | 2024-01-03 15:16:55 -0800 | [diff] [blame] | 634 | return entries |
| 635 | } |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 636 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 637 | seenDir := make(map[string]bool) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 638 | |
| 639 | dirs := make([]WritablePath, 0, len(dirsToSpecs)) |
| 640 | for dir, _ := range dirsToSpecs { |
| 641 | dirs = append(dirs, dir) |
| 642 | } |
| 643 | sort.Slice(dirs, func(i, j int) bool { |
| 644 | return dirs[i].String() < dirs[j].String() |
| 645 | }) |
| 646 | |
| 647 | for _, dir := range dirs { |
| 648 | specs := dirsToSpecs[dir] |
| 649 | for _, k := range SortedKeys(specs) { |
| 650 | ps := specs[k] |
| 651 | destPath := filepath.Join(dir.String(), ps.relPathInPackage) |
| 652 | destDir := filepath.Dir(destPath) |
| 653 | entries = append(entries, ps.relPathInPackage) |
| 654 | if _, ok := seenDir[destDir]; !ok { |
| 655 | seenDir[destDir] = true |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 656 | builder.Command().Textf("mkdir -p %s", destDir) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 657 | } |
| 658 | if ps.symlinkTarget == "" { |
Cole Faust | e384505 | 2025-02-13 12:45:35 -0800 | [diff] [blame] | 659 | cmd := builder.Command().Text("cp") |
| 660 | if preserveTimestamps { |
| 661 | cmd.Flag("-p") |
| 662 | } |
| 663 | cmd.Input(ps.srcPath).Text(destPath) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 664 | } else { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 665 | builder.Command().Textf("ln -sf %s %s", ps.symlinkTarget, destPath) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 666 | } |
| 667 | if ps.executable { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 668 | builder.Command().Textf("chmod a+x %s", destPath) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 669 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 673 | return entries |
| 674 | } |
| 675 | |
| 676 | // See PackageModule.CopyDepsToZip |
Jooyung Han | a883428 | 2022-03-25 11:40:12 +0900 | [diff] [blame] | 677 | func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, specs map[string]PackagingSpec, zipOut WritablePath) (entries []string) { |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 678 | builder := NewRuleBuilder(pctx, ctx) |
| 679 | |
| 680 | dir := PathForModuleOut(ctx, ".zip") |
| 681 | builder.Command().Text("rm").Flag("-rf").Text(dir.String()) |
| 682 | builder.Command().Text("mkdir").Flag("-p").Text(dir.String()) |
Jooyung Han | a883428 | 2022-03-25 11:40:12 +0900 | [diff] [blame] | 683 | entries = p.CopySpecsToDir(ctx, builder, specs, dir) |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 684 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 685 | builder.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 686 | BuiltTool("soong_zip"). |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 687 | FlagWithOutput("-o ", zipOut). |
| 688 | FlagWithArg("-C ", dir.String()). |
| 689 | Flag("-L 0"). // no compression because this will be unzipped soon |
| 690 | FlagWithArg("-D ", dir.String()) |
| 691 | builder.Command().Text("rm").Flag("-rf").Text(dir.String()) |
| 692 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 693 | builder.Build("zip_deps", fmt.Sprintf("Zipping deps for %s", ctx.ModuleName())) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 694 | return entries |
| 695 | } |