Colin Cross | 69452e1 | 2023-11-15 11:20:53 -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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 19 | "path" |
| 20 | "path/filepath" |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 21 | "slices" |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 22 | "strings" |
Cole Faust | 9a346f6 | 2024-01-18 20:12:02 +0000 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint" |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 25 | "github.com/google/blueprint/depset" |
Cole Faust | 9a346f6 | 2024-01-18 20:12:02 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 27 | "github.com/google/blueprint/uniquelist" |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | // BuildParameters describes the set of potential parameters to build a Ninja rule. |
| 31 | // In general, these correspond to a Ninja concept. |
| 32 | type BuildParams struct { |
| 33 | // A Ninja Rule that will be written to the Ninja file. This allows factoring out common code |
| 34 | // among multiple modules to reduce repetition in the Ninja file of action requirements. A rule |
| 35 | // can contain variables that should be provided in Args. |
| 36 | Rule blueprint.Rule |
| 37 | // Deps represents the depfile format. When using RuleBuilder, this defaults to GCC when depfiles |
| 38 | // are used. |
| 39 | Deps blueprint.Deps |
| 40 | // Depfile is a writeable path that allows correct incremental builds when the inputs have not |
| 41 | // been fully specified by the Ninja rule. Ninja supports a subset of the Makefile depfile syntax. |
| 42 | Depfile WritablePath |
| 43 | // A description of the build action. |
| 44 | Description string |
| 45 | // Output is an output file of the action. When using this field, references to $out in the Ninja |
| 46 | // command will refer to this file. |
| 47 | Output WritablePath |
| 48 | // Outputs is a slice of output file of the action. When using this field, references to $out in |
| 49 | // the Ninja command will refer to these files. |
| 50 | Outputs WritablePaths |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 51 | // ImplicitOutput is an output file generated by the action. Note: references to `$out` in the |
| 52 | // Ninja command will NOT include references to this file. |
| 53 | ImplicitOutput WritablePath |
| 54 | // ImplicitOutputs is a slice of output files generated by the action. Note: references to `$out` |
| 55 | // in the Ninja command will NOT include references to these files. |
| 56 | ImplicitOutputs WritablePaths |
| 57 | // Input is an input file to the Ninja action. When using this field, references to $in in the |
| 58 | // Ninja command will refer to this file. |
| 59 | Input Path |
| 60 | // Inputs is a slice of input files to the Ninja action. When using this field, references to $in |
| 61 | // in the Ninja command will refer to these files. |
| 62 | Inputs Paths |
| 63 | // Implicit is an input file to the Ninja action. Note: references to `$in` in the Ninja command |
| 64 | // will NOT include references to this file. |
| 65 | Implicit Path |
| 66 | // Implicits is a slice of input files to the Ninja action. Note: references to `$in` in the Ninja |
| 67 | // command will NOT include references to these files. |
| 68 | Implicits Paths |
| 69 | // OrderOnly are Ninja order-only inputs to the action. When these are out of date, the output is |
| 70 | // not rebuilt until they are built, but changes in order-only dependencies alone do not cause the |
| 71 | // output to be rebuilt. |
| 72 | OrderOnly Paths |
| 73 | // Validation is an output path for a validation action. Validation outputs imply lower |
| 74 | // non-blocking priority to building non-validation outputs. |
| 75 | Validation Path |
| 76 | // Validations is a slice of output path for a validation action. Validation outputs imply lower |
| 77 | // non-blocking priority to building non-validation outputs. |
| 78 | Validations Paths |
Cole Faust | 451912d | 2025-01-10 11:21:18 -0800 | [diff] [blame] | 79 | // Whether to output a default target statement which will be built by Ninja when no |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 80 | // targets are specified on Ninja's command line. |
| 81 | Default bool |
| 82 | // Args is a key value mapping for replacements of variables within the Rule |
| 83 | Args map[string]string |
| 84 | } |
| 85 | |
| 86 | type ModuleBuildParams BuildParams |
| 87 | |
| 88 | type ModuleContext interface { |
| 89 | BaseModuleContext |
| 90 | |
Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 91 | // BlueprintModuleContext returns the blueprint.ModuleContext that the ModuleContext wraps. It may only be |
| 92 | // used by the golang module types that need to call into the bootstrap module types. |
| 93 | BlueprintModuleContext() blueprint.ModuleContext |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 94 | |
| 95 | // Deprecated: use ModuleContext.Build instead. |
| 96 | ModuleBuild(pctx PackageContext, params ModuleBuildParams) |
| 97 | |
| 98 | // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must |
| 99 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 100 | // |
| 101 | // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead. |
| 102 | ExpandSources(srcFiles, excludes []string) Paths |
| 103 | |
| 104 | // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must |
| 105 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 106 | // |
| 107 | // Deprecated: use PathForModuleSrc instead. |
| 108 | ExpandSource(srcFile, prop string) Path |
| 109 | |
| 110 | ExpandOptionalSource(srcFile *string, prop string) OptionalPath |
| 111 | |
| 112 | // InstallExecutable creates a rule to copy srcPath to name in the installPath directory, |
| 113 | // with the given additional dependencies. The file is marked executable after copying. |
| 114 | // |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 115 | // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec |
| 116 | // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module |
| 117 | // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through |
| 118 | // dependency tags for which IsInstallDepNeeded returns true. |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 119 | InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 120 | |
| 121 | // InstallFile creates a rule to copy srcPath to name in the installPath directory, |
| 122 | // with the given additional dependencies. |
| 123 | // |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 124 | // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec |
| 125 | // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module |
| 126 | // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through |
| 127 | // dependency tags for which IsInstallDepNeeded returns true. |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 128 | InstallFile(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 129 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 130 | // InstallFileWithoutCheckbuild creates a rule to copy srcPath to name in the installPath directory, |
| 131 | // with the given additional dependencies, but does not add the file to the list of files to build |
| 132 | // during `m checkbuild`. |
| 133 | // |
| 134 | // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the |
| 135 | // installed file will be returned by PackagingSpecs() on this module or by |
| 136 | // TransitivePackagingSpecs() on modules that depend on this module through dependency tags |
| 137 | // for which IsInstallDepNeeded returns true. |
| 138 | InstallFileWithoutCheckbuild(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath |
| 139 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 140 | // InstallFileWithExtraFilesZip creates a rule to copy srcPath to name in the installPath |
| 141 | // directory, and also unzip a zip file containing extra files to install into the same |
| 142 | // directory. |
| 143 | // |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 144 | // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec |
| 145 | // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module |
| 146 | // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through |
| 147 | // dependency tags for which IsInstallDepNeeded returns true. |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 148 | InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, extraZip Path, deps ...InstallPath) InstallPath |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 149 | |
| 150 | // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath |
| 151 | // directory. |
| 152 | // |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 153 | // The installed symlink can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec |
| 154 | // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module |
| 155 | // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through |
| 156 | // dependency tags for which IsInstallDepNeeded returns true. |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 157 | InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath |
| 158 | |
| 159 | // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name |
| 160 | // in the installPath directory. |
| 161 | // |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 162 | // The installed symlink can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec |
| 163 | // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module |
| 164 | // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through |
| 165 | // dependency tags for which IsInstallDepNeeded returns true. |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 166 | InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath |
| 167 | |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 168 | // InstallTestData creates rules to install test data (e.g. data files used during a test) into |
| 169 | // the installPath directory. |
| 170 | // |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 171 | // The installed files can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec |
| 172 | // for the installed files can be accessed by InstallFilesInfo.PackagingSpecs on this module |
| 173 | // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through |
| 174 | // dependency tags for which IsInstallDepNeeded returns true. |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 175 | InstallTestData(installPath InstallPath, data []DataPath) InstallPaths |
| 176 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 177 | // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating |
| 178 | // the rule to copy the file. This is useful to define how a module would be packaged |
| 179 | // without installing it into the global installation directories. |
| 180 | // |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 181 | // The created PackagingSpec can be accessed by InstallFilesInfo.PackagingSpecs on this module |
| 182 | // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through |
| 183 | // dependency tags for which IsInstallDepNeeded returns true. |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 184 | PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec |
| 185 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 186 | CheckbuildFile(srcPaths ...Path) |
| 187 | UncheckedModule() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 188 | |
| 189 | InstallInData() bool |
| 190 | InstallInTestcases() bool |
| 191 | InstallInSanitizerDir() bool |
| 192 | InstallInRamdisk() bool |
| 193 | InstallInVendorRamdisk() bool |
| 194 | InstallInDebugRamdisk() bool |
| 195 | InstallInRecovery() bool |
| 196 | InstallInRoot() bool |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 197 | InstallInOdm() bool |
| 198 | InstallInProduct() bool |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 199 | InstallInVendor() bool |
Spandan Das | 27ff767 | 2024-11-06 19:23:57 +0000 | [diff] [blame] | 200 | InstallInSystemDlkm() bool |
| 201 | InstallInVendorDlkm() bool |
| 202 | InstallInOdmDlkm() bool |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 203 | InstallForceOS() (*OsType, *ArchType) |
| 204 | |
Cole Faust | e8a8783 | 2024-09-11 11:35:46 -0700 | [diff] [blame] | 205 | RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 206 | HostRequiredModuleNames() []string |
| 207 | TargetRequiredModuleNames() []string |
| 208 | |
| 209 | ModuleSubDir() string |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 210 | |
| 211 | Variable(pctx PackageContext, name, value string) |
| 212 | Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule |
| 213 | // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string, |
| 214 | // and performs more verification. |
| 215 | Build(pctx PackageContext, params BuildParams) |
| 216 | // Phony creates a Make-style phony rule, a rule with no commands that can depend on other |
| 217 | // phony rules or real files. Phony can be called on the same name multiple times to add |
| 218 | // additional dependencies. |
| 219 | Phony(phony string, deps ...Path) |
| 220 | |
| 221 | // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods, |
| 222 | // but do not exist. |
| 223 | GetMissingDependencies() []string |
| 224 | |
| 225 | // LicenseMetadataFile returns the path where the license metadata for this module will be |
| 226 | // generated. |
| 227 | LicenseMetadataFile() Path |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 228 | |
| 229 | // ModuleInfoJSON returns a pointer to the ModuleInfoJSON struct that can be filled out by |
| 230 | // GenerateAndroidBuildActions. If it is called then the struct will be written out and included in |
| 231 | // the module-info.json generated by Make, and Make will not generate its own data for this module. |
| 232 | ModuleInfoJSON() *ModuleInfoJSON |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 233 | |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 234 | // Simiar to ModuleInfoJSON, ExtraModuleInfoJSON also returns a pointer to the ModuleInfoJSON struct. |
| 235 | // This should only be called by a module that generates multiple AndroidMkEntries struct. |
| 236 | ExtraModuleInfoJSON() *ModuleInfoJSON |
| 237 | |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 238 | // SetOutputFiles stores the outputFiles to outputFiles property, which is used |
| 239 | // to set the OutputFilesProvider later. |
| 240 | SetOutputFiles(outputFiles Paths, tag string) |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 241 | |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 242 | GetOutputFiles() OutputFilesInfo |
| 243 | |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 244 | // SetLicenseInstallMap stores the set of dependency module:location mappings for files in an |
| 245 | // apex container for use when generation the license metadata file. |
| 246 | SetLicenseInstallMap(installMap []string) |
| 247 | |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 248 | // ComplianceMetadataInfo returns a ComplianceMetadataInfo instance for different module types to dump metadata, |
| 249 | // which usually happens in GenerateAndroidBuildActions() of a module type. |
| 250 | // See android.ModuleBase.complianceMetadataInfo |
| 251 | ComplianceMetadataInfo() *ComplianceMetadataInfo |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 252 | |
| 253 | // Get the information about the containers this module belongs to. |
| 254 | getContainersInfo() ContainersInfo |
| 255 | setContainersInfo(info ContainersInfo) |
| 256 | |
| 257 | setAconfigPaths(paths Paths) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | type moduleContext struct { |
| 261 | bp blueprint.ModuleContext |
| 262 | baseModuleContext |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 263 | packagingSpecs []PackagingSpec |
| 264 | installFiles InstallPaths |
| 265 | checkbuildFiles Paths |
| 266 | checkbuildTarget Path |
| 267 | uncheckedModule bool |
| 268 | module Module |
| 269 | phonies map[string]Paths |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 270 | // outputFiles stores the output of a module by tag and is used to set |
| 271 | // the OutputFilesProvider in GenerateBuildActions |
| 272 | outputFiles OutputFilesInfo |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 273 | |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 274 | TransitiveInstallFiles depset.DepSet[InstallPath] |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 275 | |
| 276 | // set of dependency module:location mappings used to populate the license metadata for |
| 277 | // apex containers. |
| 278 | licenseInstallMap []string |
| 279 | |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 280 | // The path to the generated license metadata file for the module. |
| 281 | licenseMetadataFile WritablePath |
| 282 | |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 283 | katiInstalls katiInstalls |
| 284 | katiSymlinks katiInstalls |
Yu Liu | 82a6d14 | 2024-08-27 19:02:29 +0000 | [diff] [blame] | 285 | // katiInitRcInstalls and katiVintfInstalls track the install rules created by Soong that are |
| 286 | // allowed to have duplicates across modules and variants. |
| 287 | katiInitRcInstalls katiInstalls |
| 288 | katiVintfInstalls katiInstalls |
| 289 | initRcPaths Paths |
| 290 | vintfFragmentsPaths Paths |
| 291 | installedInitRcPaths InstallPaths |
| 292 | installedVintfFragmentsPaths InstallPaths |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 293 | |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 294 | testData []DataPath |
| 295 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 296 | // For tests |
| 297 | buildParams []BuildParams |
| 298 | ruleParams map[blueprint.Rule]blueprint.RuleParams |
| 299 | variables map[string]string |
Yu Liu | 4297ad9 | 2024-08-27 19:50:13 +0000 | [diff] [blame] | 300 | |
| 301 | // moduleInfoJSON can be filled out by GenerateAndroidBuildActions to write a JSON file that will |
| 302 | // be included in the final module-info.json produced by Make. |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 303 | moduleInfoJSON []*ModuleInfoJSON |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 304 | |
| 305 | // containersInfo stores the information about the containers and the information of the |
| 306 | // apexes the module belongs to. |
| 307 | containersInfo ContainersInfo |
| 308 | |
| 309 | // Merged Aconfig files for all transitive deps. |
| 310 | aconfigFilePaths Paths |
| 311 | |
| 312 | // complianceMetadataInfo is for different module types to dump metadata. |
| 313 | // See android.ModuleContext interface. |
| 314 | complianceMetadataInfo *ComplianceMetadataInfo |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Cole Faust | 02987bd | 2024-03-21 17:58:43 -0700 | [diff] [blame] | 317 | var _ ModuleContext = &moduleContext{} |
| 318 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 319 | func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) { |
| 320 | return pctx, BuildParams{ |
| 321 | Rule: ErrorRule, |
| 322 | Description: params.Description, |
| 323 | Output: params.Output, |
| 324 | Outputs: params.Outputs, |
| 325 | ImplicitOutput: params.ImplicitOutput, |
| 326 | ImplicitOutputs: params.ImplicitOutputs, |
| 327 | Args: map[string]string{ |
| 328 | "error": err.Error(), |
| 329 | }, |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) { |
| 334 | m.Build(pctx, BuildParams(params)) |
| 335 | } |
| 336 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 337 | // Convert build parameters from their concrete Android types into their string representations, |
| 338 | // and combine the singular and plural fields of the same type (e.g. Output and Outputs). |
| 339 | func convertBuildParams(params BuildParams) blueprint.BuildParams { |
| 340 | bparams := blueprint.BuildParams{ |
| 341 | Rule: params.Rule, |
| 342 | Description: params.Description, |
| 343 | Deps: params.Deps, |
| 344 | Outputs: params.Outputs.Strings(), |
| 345 | ImplicitOutputs: params.ImplicitOutputs.Strings(), |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 346 | Inputs: params.Inputs.Strings(), |
| 347 | Implicits: params.Implicits.Strings(), |
| 348 | OrderOnly: params.OrderOnly.Strings(), |
| 349 | Validations: params.Validations.Strings(), |
| 350 | Args: params.Args, |
Cole Faust | 451912d | 2025-01-10 11:21:18 -0800 | [diff] [blame] | 351 | Default: params.Default, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | if params.Depfile != nil { |
| 355 | bparams.Depfile = params.Depfile.String() |
| 356 | } |
| 357 | if params.Output != nil { |
| 358 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 359 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 360 | if params.ImplicitOutput != nil { |
| 361 | bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String()) |
| 362 | } |
| 363 | if params.Input != nil { |
| 364 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 365 | } |
| 366 | if params.Implicit != nil { |
| 367 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 368 | } |
| 369 | if params.Validation != nil { |
| 370 | bparams.Validations = append(bparams.Validations, params.Validation.String()) |
| 371 | } |
| 372 | |
| 373 | bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs) |
| 374 | bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 375 | bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs) |
| 376 | bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits) |
| 377 | bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly) |
| 378 | bparams.Validations = proptools.NinjaEscapeList(bparams.Validations) |
| 379 | bparams.Depfile = proptools.NinjaEscape(bparams.Depfile) |
| 380 | |
| 381 | return bparams |
| 382 | } |
| 383 | |
| 384 | func (m *moduleContext) Variable(pctx PackageContext, name, value string) { |
| 385 | if m.config.captureBuild { |
| 386 | m.variables[name] = value |
| 387 | } |
| 388 | |
| 389 | m.bp.Variable(pctx.PackageContext, name, value) |
| 390 | } |
| 391 | |
| 392 | func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams, |
| 393 | argNames ...string) blueprint.Rule { |
| 394 | |
| 395 | if m.config.UseRemoteBuild() { |
| 396 | if params.Pool == nil { |
| 397 | // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict |
| 398 | // jobs to the local parallelism value |
| 399 | params.Pool = localPool |
| 400 | } else if params.Pool == remotePool { |
| 401 | // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's |
| 402 | // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS |
| 403 | // parallelism. |
| 404 | params.Pool = nil |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...) |
| 409 | |
| 410 | if m.config.captureBuild { |
| 411 | m.ruleParams[rule] = params |
| 412 | } |
| 413 | |
| 414 | return rule |
| 415 | } |
| 416 | |
| 417 | func (m *moduleContext) Build(pctx PackageContext, params BuildParams) { |
| 418 | if params.Description != "" { |
| 419 | params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}" |
| 420 | } |
| 421 | |
| 422 | if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 { |
| 423 | pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n", |
| 424 | m.ModuleName(), strings.Join(missingDeps, ", "))) |
| 425 | } |
| 426 | |
| 427 | if m.config.captureBuild { |
| 428 | m.buildParams = append(m.buildParams, params) |
| 429 | } |
| 430 | |
| 431 | bparams := convertBuildParams(params) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 432 | m.bp.Build(pctx.PackageContext, bparams) |
| 433 | } |
| 434 | |
| 435 | func (m *moduleContext) Phony(name string, deps ...Path) { |
Yu Liu | 5451362 | 2024-08-19 20:00:32 +0000 | [diff] [blame] | 436 | m.phonies[name] = append(m.phonies[name], deps...) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | func (m *moduleContext) GetMissingDependencies() []string { |
| 440 | var missingDeps []string |
| 441 | missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...) |
| 442 | missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...) |
| 443 | missingDeps = FirstUniqueStrings(missingDeps) |
| 444 | return missingDeps |
| 445 | } |
| 446 | |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 447 | func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) Module { |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 448 | deps := m.getDirectDepsInternal(name, tag) |
| 449 | if len(deps) == 1 { |
| 450 | return deps[0] |
| 451 | } else if len(deps) >= 2 { |
| 452 | panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", |
| 453 | name, m.ModuleName())) |
| 454 | } else { |
| 455 | return nil |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 456 | } |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | func (m *moduleContext) GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) *ModuleProxy { |
| 460 | deps := m.getDirectDepsProxyInternal(name, tag) |
| 461 | if len(deps) == 1 { |
| 462 | return &deps[0] |
| 463 | } else if len(deps) >= 2 { |
| 464 | panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", |
| 465 | name, m.ModuleName())) |
| 466 | } else { |
| 467 | return nil |
| 468 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | func (m *moduleContext) ModuleSubDir() string { |
| 472 | return m.bp.ModuleSubDir() |
| 473 | } |
| 474 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 475 | func (m *moduleContext) InstallInData() bool { |
| 476 | return m.module.InstallInData() |
| 477 | } |
| 478 | |
| 479 | func (m *moduleContext) InstallInTestcases() bool { |
| 480 | return m.module.InstallInTestcases() |
| 481 | } |
| 482 | |
| 483 | func (m *moduleContext) InstallInSanitizerDir() bool { |
| 484 | return m.module.InstallInSanitizerDir() |
| 485 | } |
| 486 | |
| 487 | func (m *moduleContext) InstallInRamdisk() bool { |
| 488 | return m.module.InstallInRamdisk() |
| 489 | } |
| 490 | |
| 491 | func (m *moduleContext) InstallInVendorRamdisk() bool { |
| 492 | return m.module.InstallInVendorRamdisk() |
| 493 | } |
| 494 | |
| 495 | func (m *moduleContext) InstallInDebugRamdisk() bool { |
| 496 | return m.module.InstallInDebugRamdisk() |
| 497 | } |
| 498 | |
| 499 | func (m *moduleContext) InstallInRecovery() bool { |
| 500 | return m.module.InstallInRecovery() |
| 501 | } |
| 502 | |
| 503 | func (m *moduleContext) InstallInRoot() bool { |
| 504 | return m.module.InstallInRoot() |
| 505 | } |
| 506 | |
| 507 | func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) { |
| 508 | return m.module.InstallForceOS() |
| 509 | } |
| 510 | |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 511 | func (m *moduleContext) InstallInOdm() bool { |
| 512 | return m.module.InstallInOdm() |
| 513 | } |
| 514 | |
| 515 | func (m *moduleContext) InstallInProduct() bool { |
| 516 | return m.module.InstallInProduct() |
| 517 | } |
| 518 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 519 | func (m *moduleContext) InstallInVendor() bool { |
| 520 | return m.module.InstallInVendor() |
| 521 | } |
| 522 | |
Spandan Das | 27ff767 | 2024-11-06 19:23:57 +0000 | [diff] [blame] | 523 | func (m *moduleContext) InstallInSystemDlkm() bool { |
| 524 | return m.module.InstallInSystemDlkm() |
| 525 | } |
| 526 | |
| 527 | func (m *moduleContext) InstallInVendorDlkm() bool { |
| 528 | return m.module.InstallInVendorDlkm() |
| 529 | } |
| 530 | |
| 531 | func (m *moduleContext) InstallInOdmDlkm() bool { |
| 532 | return m.module.InstallInOdmDlkm() |
| 533 | } |
| 534 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 535 | func (m *moduleContext) skipInstall() bool { |
| 536 | if m.module.base().commonProperties.SkipInstall { |
| 537 | return true |
| 538 | } |
| 539 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 540 | // We'll need a solution for choosing which of modules with the same name in different |
| 541 | // namespaces to install. For now, reuse the list of namespaces exported to Make as the |
| 542 | // list of namespaces to install in a Soong-only build. |
| 543 | if !m.module.base().commonProperties.NamespaceExportedToMake { |
| 544 | return true |
| 545 | } |
| 546 | |
| 547 | return false |
| 548 | } |
| 549 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 550 | // Tells whether this module is installed to the full install path (ex: |
| 551 | // out/target/product/<name>/<partition>) or not. If this returns false, the install build rule is |
| 552 | // not created and this module can only be installed to packaging modules like android_filesystem. |
| 553 | func (m *moduleContext) requiresFullInstall() bool { |
| 554 | if m.skipInstall() { |
| 555 | return false |
| 556 | } |
| 557 | |
Spandan Das | 034af2c | 2024-10-30 21:45:09 +0000 | [diff] [blame] | 558 | if m.module.base().commonProperties.HideFromMake { |
| 559 | return false |
| 560 | } |
| 561 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 562 | if proptools.Bool(m.module.base().commonProperties.No_full_install) { |
| 563 | return false |
| 564 | } |
| 565 | |
| 566 | return true |
| 567 | } |
| 568 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 569 | func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path, |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 570 | deps ...InstallPath) InstallPath { |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 571 | return m.installFile(installPath, name, srcPath, deps, false, true, true, nil) |
| 572 | } |
| 573 | |
| 574 | func (m *moduleContext) InstallFileWithoutCheckbuild(installPath InstallPath, name string, srcPath Path, |
| 575 | deps ...InstallPath) InstallPath { |
| 576 | return m.installFile(installPath, name, srcPath, deps, false, true, false, nil) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path, |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 580 | deps ...InstallPath) InstallPath { |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 581 | return m.installFile(installPath, name, srcPath, deps, true, true, true, nil) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 585 | extraZip Path, deps ...InstallPath) InstallPath { |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 586 | return m.installFile(installPath, name, srcPath, deps, false, true, true, &extraFilesZip{ |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 587 | zip: extraZip, |
| 588 | dir: installPath, |
| 589 | }) |
| 590 | } |
| 591 | |
| 592 | func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec { |
| 593 | fullInstallPath := installPath.Join(m, name) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 594 | return m.packageFile(fullInstallPath, srcPath, false, false) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 597 | func (m *moduleContext) getAconfigPaths() Paths { |
| 598 | return m.aconfigFilePaths |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | func (m *moduleContext) setAconfigPaths(paths Paths) { |
| 602 | m.aconfigFilePaths = paths |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 603 | } |
| 604 | |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 605 | func (m *moduleContext) getOwnerAndOverrides() (string, []string) { |
| 606 | owner := m.ModuleName() |
| 607 | overrides := slices.Clone(m.Module().base().commonProperties.Overrides) |
| 608 | if b, ok := m.Module().(OverridableModule); ok { |
| 609 | if b.GetOverriddenBy() != "" { |
| 610 | // overriding variant of base module |
| 611 | overrides = append(overrides, m.ModuleName()) // com.android.foo |
| 612 | owner = m.Module().Name() // com.company.android.foo |
| 613 | } |
| 614 | } |
| 615 | return owner, overrides |
| 616 | } |
| 617 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 618 | func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool, requiresFullInstall bool) PackagingSpec { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 619 | licenseFiles := m.Module().EffectiveLicenseFiles() |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 620 | owner, overrides := m.getOwnerAndOverrides() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 621 | spec := PackagingSpec{ |
| 622 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 623 | srcPath: srcPath, |
| 624 | symlinkTarget: "", |
| 625 | executable: executable, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 626 | effectiveLicenseFiles: uniquelist.Make(licenseFiles), |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 627 | partition: fullInstallPath.partition, |
Jiyong Park | 4152b19 | 2024-04-30 21:24:21 +0900 | [diff] [blame] | 628 | skipInstall: m.skipInstall(), |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame] | 629 | aconfigPaths: uniquelist.Make(m.getAconfigPaths()), |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 630 | archType: m.target.Arch.ArchType, |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 631 | overrides: uniquelist.Make(overrides), |
| 632 | owner: owner, |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 633 | requiresFullInstall: requiresFullInstall, |
| 634 | fullInstallPath: fullInstallPath, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 635 | } |
| 636 | m.packagingSpecs = append(m.packagingSpecs, spec) |
| 637 | return spec |
| 638 | } |
| 639 | |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 640 | func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []InstallPath, |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 641 | executable bool, hooks bool, checkbuild bool, extraZip *extraFilesZip) InstallPath { |
Spandan Das | d718aa5 | 2025-02-04 21:18:36 +0000 | [diff] [blame^] | 642 | if _, ok := srcPath.(InstallPath); ok { |
| 643 | m.ModuleErrorf("Src path cannot be another installed file. Please use a path from source or intermediates instead.") |
| 644 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 645 | |
| 646 | fullInstallPath := installPath.Join(m, name) |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 647 | if hooks { |
| 648 | m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false) |
| 649 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 650 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 651 | if m.requiresFullInstall() { |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 652 | deps = append(deps, InstallPaths(m.TransitiveInstallFiles.ToList())...) |
Cole Faust | 74d243c | 2024-12-11 17:57:34 -0800 | [diff] [blame] | 653 | if m.config.KatiEnabled() { |
| 654 | deps = append(deps, m.installedInitRcPaths...) |
| 655 | deps = append(deps, m.installedVintfFragmentsPaths...) |
| 656 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 657 | |
| 658 | var implicitDeps, orderOnlyDeps Paths |
| 659 | |
| 660 | if m.Host() { |
| 661 | // Installed host modules might be used during the build, depend directly on their |
| 662 | // dependencies so their timestamp is updated whenever their dependency is updated |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 663 | implicitDeps = InstallPaths(deps).Paths() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 664 | } else { |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 665 | orderOnlyDeps = InstallPaths(deps).Paths() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 666 | } |
| 667 | |
Cole Faust | 866ab39 | 2025-01-23 12:56:20 -0800 | [diff] [blame] | 668 | // When creating the install rule in Soong but embedding in Make, write the rule to a |
| 669 | // makefile instead of directly to the ninja file so that main.mk can add the |
| 670 | // dependencies from the `required` property that are hard to resolve in Soong. |
| 671 | // In soong-only builds, the katiInstall will still be created for semi-legacy code paths |
| 672 | // such as module-info.json or compliance, but it will not be used for actually installing |
| 673 | // the file. |
| 674 | m.katiInstalls = append(m.katiInstalls, katiInstall{ |
| 675 | from: srcPath, |
| 676 | to: fullInstallPath, |
| 677 | implicitDeps: implicitDeps, |
| 678 | orderOnlyDeps: orderOnlyDeps, |
| 679 | executable: executable, |
| 680 | extraFiles: extraZip, |
| 681 | }) |
| 682 | if !m.Config().KatiEnabled() { |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 683 | rule := CpWithBash |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 684 | if executable { |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 685 | rule = CpExecutableWithBash |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | extraCmds := "" |
| 689 | if extraZip != nil { |
| 690 | extraCmds += fmt.Sprintf(" && ( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} )", |
| 691 | extraZip.dir.String(), extraZip.zip.String()) |
| 692 | extraCmds += " || ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )" |
| 693 | implicitDeps = append(implicitDeps, extraZip.zip) |
| 694 | } |
| 695 | |
| 696 | m.Build(pctx, BuildParams{ |
| 697 | Rule: rule, |
| 698 | Description: "install " + fullInstallPath.Base(), |
| 699 | Output: fullInstallPath, |
| 700 | Input: srcPath, |
| 701 | Implicits: implicitDeps, |
| 702 | OrderOnly: orderOnlyDeps, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 703 | Args: map[string]string{ |
| 704 | "extraCmds": extraCmds, |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 705 | "cpFlags": "-f", |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 706 | }, |
| 707 | }) |
| 708 | } |
| 709 | |
| 710 | m.installFiles = append(m.installFiles, fullInstallPath) |
| 711 | } |
| 712 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 713 | m.packageFile(fullInstallPath, srcPath, executable, m.requiresFullInstall()) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 714 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 715 | if checkbuild { |
| 716 | m.checkbuildFiles = append(m.checkbuildFiles, srcPath) |
| 717 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 718 | |
| 719 | return fullInstallPath |
| 720 | } |
| 721 | |
| 722 | func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath { |
| 723 | fullInstallPath := installPath.Join(m, name) |
| 724 | m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true) |
| 725 | |
| 726 | relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String()) |
| 727 | if err != nil { |
| 728 | panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err)) |
| 729 | } |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 730 | if m.requiresFullInstall() { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 731 | |
Cole Faust | 866ab39 | 2025-01-23 12:56:20 -0800 | [diff] [blame] | 732 | // When creating the symlink rule in Soong but embedding in Make, write the rule to a |
| 733 | // makefile instead of directly to the ninja file so that main.mk can add the |
| 734 | // dependencies from the `required` property that are hard to resolve in Soong. |
| 735 | // In soong-only builds, the katiInstall will still be created for semi-legacy code paths |
| 736 | // such as module-info.json or compliance, but it will not be used for actually installing |
| 737 | // the file. |
| 738 | m.katiSymlinks = append(m.katiSymlinks, katiInstall{ |
| 739 | from: srcPath, |
| 740 | to: fullInstallPath, |
| 741 | }) |
| 742 | if !m.Config().KatiEnabled() { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 743 | // The symlink doesn't need updating when the target is modified, but we sometimes |
| 744 | // have a dependency on a symlink to a binary instead of to the binary directly, and |
| 745 | // the mtime of the symlink must be updated when the binary is modified, so use a |
| 746 | // normal dependency here instead of an order-only dependency. |
| 747 | m.Build(pctx, BuildParams{ |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 748 | Rule: SymlinkWithBash, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 749 | Description: "install symlink " + fullInstallPath.Base(), |
| 750 | Output: fullInstallPath, |
| 751 | Input: srcPath, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 752 | Args: map[string]string{ |
| 753 | "fromPath": relPath, |
| 754 | }, |
| 755 | }) |
| 756 | } |
| 757 | |
| 758 | m.installFiles = append(m.installFiles, fullInstallPath) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 759 | } |
| 760 | |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 761 | owner, overrides := m.getOwnerAndOverrides() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 762 | m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 763 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 764 | srcPath: nil, |
| 765 | symlinkTarget: relPath, |
| 766 | executable: false, |
| 767 | partition: fullInstallPath.partition, |
| 768 | skipInstall: m.skipInstall(), |
| 769 | aconfigPaths: uniquelist.Make(m.getAconfigPaths()), |
| 770 | archType: m.target.Arch.ArchType, |
| 771 | overrides: uniquelist.Make(overrides), |
| 772 | owner: owner, |
| 773 | requiresFullInstall: m.requiresFullInstall(), |
| 774 | fullInstallPath: fullInstallPath, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 775 | }) |
| 776 | |
| 777 | return fullInstallPath |
| 778 | } |
| 779 | |
| 780 | // installPath/name -> absPath where absPath might be a path that is available only at runtime |
| 781 | // (e.g. /apex/...) |
| 782 | func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath { |
| 783 | fullInstallPath := installPath.Join(m, name) |
| 784 | m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true) |
| 785 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 786 | if m.requiresFullInstall() { |
Cole Faust | 866ab39 | 2025-01-23 12:56:20 -0800 | [diff] [blame] | 787 | // When creating the symlink rule in Soong but embedding in Make, write the rule to a |
| 788 | // makefile instead of directly to the ninja file so that main.mk can add the |
| 789 | // dependencies from the `required` property that are hard to resolve in Soong. |
| 790 | // In soong-only builds, the katiInstall will still be created for semi-legacy code paths |
| 791 | // such as module-info.json or compliance, but it will not be used for actually installing |
| 792 | // the file. |
| 793 | m.katiSymlinks = append(m.katiSymlinks, katiInstall{ |
| 794 | absFrom: absPath, |
| 795 | to: fullInstallPath, |
| 796 | }) |
| 797 | if !m.Config().KatiEnabled() { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 798 | m.Build(pctx, BuildParams{ |
| 799 | Rule: Symlink, |
| 800 | Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath, |
| 801 | Output: fullInstallPath, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 802 | Args: map[string]string{ |
| 803 | "fromPath": absPath, |
| 804 | }, |
| 805 | }) |
| 806 | } |
| 807 | |
| 808 | m.installFiles = append(m.installFiles, fullInstallPath) |
| 809 | } |
| 810 | |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 811 | owner, overrides := m.getOwnerAndOverrides() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 812 | m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 813 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 814 | srcPath: nil, |
| 815 | symlinkTarget: absPath, |
| 816 | executable: false, |
| 817 | partition: fullInstallPath.partition, |
| 818 | skipInstall: m.skipInstall(), |
| 819 | aconfigPaths: uniquelist.Make(m.getAconfigPaths()), |
| 820 | archType: m.target.Arch.ArchType, |
| 821 | overrides: uniquelist.Make(overrides), |
| 822 | owner: owner, |
| 823 | requiresFullInstall: m.requiresFullInstall(), |
| 824 | fullInstallPath: fullInstallPath, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 825 | }) |
| 826 | |
| 827 | return fullInstallPath |
| 828 | } |
| 829 | |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 830 | func (m *moduleContext) InstallTestData(installPath InstallPath, data []DataPath) InstallPaths { |
| 831 | m.testData = append(m.testData, data...) |
| 832 | |
| 833 | ret := make(InstallPaths, 0, len(data)) |
| 834 | for _, d := range data { |
| 835 | relPath := d.ToRelativeInstallPath() |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 836 | installed := m.installFile(installPath, relPath, d.SrcPath, nil, false, false, true, nil) |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 837 | ret = append(ret, installed) |
| 838 | } |
| 839 | |
| 840 | return ret |
| 841 | } |
| 842 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 843 | // CheckbuildFile specifies the output files that should be built by checkbuild. |
| 844 | func (m *moduleContext) CheckbuildFile(srcPaths ...Path) { |
| 845 | m.checkbuildFiles = append(m.checkbuildFiles, srcPaths...) |
| 846 | } |
| 847 | |
| 848 | // UncheckedModule marks the current module has having no files that should be built by checkbuild. |
| 849 | func (m *moduleContext) UncheckedModule() { |
| 850 | m.uncheckedModule = true |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 853 | func (m *moduleContext) BlueprintModuleContext() blueprint.ModuleContext { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 854 | return m.bp |
| 855 | } |
| 856 | |
| 857 | func (m *moduleContext) LicenseMetadataFile() Path { |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 858 | return m.licenseMetadataFile |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 859 | } |
| 860 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 861 | func (m *moduleContext) ModuleInfoJSON() *ModuleInfoJSON { |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 862 | if len(m.moduleInfoJSON) == 0 { |
| 863 | moduleInfoJSON := &ModuleInfoJSON{} |
| 864 | m.moduleInfoJSON = append(m.moduleInfoJSON, moduleInfoJSON) |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 865 | } |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 866 | return m.moduleInfoJSON[0] |
| 867 | } |
| 868 | |
| 869 | func (m *moduleContext) ExtraModuleInfoJSON() *ModuleInfoJSON { |
| 870 | if len(m.moduleInfoJSON) == 0 { |
| 871 | panic("call ModuleInfoJSON() instead") |
| 872 | } |
| 873 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 874 | moduleInfoJSON := &ModuleInfoJSON{} |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 875 | m.moduleInfoJSON = append(m.moduleInfoJSON, moduleInfoJSON) |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 876 | return moduleInfoJSON |
| 877 | } |
| 878 | |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 879 | func (m *moduleContext) SetOutputFiles(outputFiles Paths, tag string) { |
Cole Faust | 5146e78 | 2024-11-15 14:47:49 -0800 | [diff] [blame] | 880 | for _, outputFile := range outputFiles { |
| 881 | if outputFile == nil { |
| 882 | panic("outputfiles cannot be nil") |
| 883 | } |
| 884 | } |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 885 | if tag == "" { |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 886 | if len(m.outputFiles.DefaultOutputFiles) > 0 { |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 887 | m.ModuleErrorf("Module %s default OutputFiles cannot be overwritten", m.ModuleName()) |
| 888 | } |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 889 | m.outputFiles.DefaultOutputFiles = outputFiles |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 890 | } else { |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 891 | if m.outputFiles.TaggedOutputFiles == nil { |
| 892 | m.outputFiles.TaggedOutputFiles = make(map[string]Paths) |
mrziwang | 57768d7 | 2024-06-06 11:31:51 -0700 | [diff] [blame] | 893 | } |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 894 | if _, exists := m.outputFiles.TaggedOutputFiles[tag]; exists { |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 895 | m.ModuleErrorf("Module %s OutputFiles at tag %s cannot be overwritten", m.ModuleName(), tag) |
| 896 | } else { |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 897 | m.outputFiles.TaggedOutputFiles[tag] = outputFiles |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 902 | func (m *moduleContext) GetOutputFiles() OutputFilesInfo { |
| 903 | return m.outputFiles |
| 904 | } |
| 905 | |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 906 | func (m *moduleContext) SetLicenseInstallMap(installMap []string) { |
| 907 | m.licenseInstallMap = append(m.licenseInstallMap, installMap...) |
| 908 | } |
| 909 | |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 910 | func (m *moduleContext) ComplianceMetadataInfo() *ComplianceMetadataInfo { |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 911 | if m.complianceMetadataInfo == nil { |
| 912 | m.complianceMetadataInfo = NewComplianceMetadataInfo() |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 913 | } |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 914 | return m.complianceMetadataInfo |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 917 | // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must |
| 918 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 919 | // |
| 920 | // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead. |
| 921 | func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths { |
| 922 | return PathsForModuleSrcExcludes(m, srcFiles, excludes) |
| 923 | } |
| 924 | |
| 925 | // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must |
| 926 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 927 | // |
| 928 | // Deprecated: use PathForModuleSrc instead. |
| 929 | func (m *moduleContext) ExpandSource(srcFile, _ string) Path { |
| 930 | return PathForModuleSrc(m, srcFile) |
| 931 | } |
| 932 | |
| 933 | // Returns an optional single path expanded from globs and modules referenced using ":module" syntax if |
| 934 | // the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module |
| 935 | // dependency resolution. |
| 936 | func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) OptionalPath { |
| 937 | if srcFile != nil { |
| 938 | return OptionalPathForPath(PathForModuleSrc(m, *srcFile)) |
| 939 | } |
| 940 | return OptionalPath{} |
| 941 | } |
| 942 | |
Cole Faust | e8a8783 | 2024-09-11 11:35:46 -0700 | [diff] [blame] | 943 | func (m *moduleContext) RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string { |
Cole Faust | 43ddd08 | 2024-06-17 12:32:40 -0700 | [diff] [blame] | 944 | return m.module.RequiredModuleNames(ctx) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | func (m *moduleContext) HostRequiredModuleNames() []string { |
| 948 | return m.module.HostRequiredModuleNames() |
| 949 | } |
| 950 | |
| 951 | func (m *moduleContext) TargetRequiredModuleNames() []string { |
| 952 | return m.module.TargetRequiredModuleNames() |
| 953 | } |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 954 | |
| 955 | func (m *moduleContext) getContainersInfo() ContainersInfo { |
| 956 | return m.containersInfo |
| 957 | } |
| 958 | |
| 959 | func (m *moduleContext) setContainersInfo(info ContainersInfo) { |
| 960 | m.containersInfo = info |
| 961 | } |