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 | |
| 234 | // SetOutputFiles stores the outputFiles to outputFiles property, which is used |
| 235 | // to set the OutputFilesProvider later. |
| 236 | SetOutputFiles(outputFiles Paths, tag string) |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 237 | |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 238 | GetOutputFiles() OutputFilesInfo |
| 239 | |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 240 | // SetLicenseInstallMap stores the set of dependency module:location mappings for files in an |
| 241 | // apex container for use when generation the license metadata file. |
| 242 | SetLicenseInstallMap(installMap []string) |
| 243 | |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 244 | // ComplianceMetadataInfo returns a ComplianceMetadataInfo instance for different module types to dump metadata, |
| 245 | // which usually happens in GenerateAndroidBuildActions() of a module type. |
| 246 | // See android.ModuleBase.complianceMetadataInfo |
| 247 | ComplianceMetadataInfo() *ComplianceMetadataInfo |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 248 | |
| 249 | // Get the information about the containers this module belongs to. |
| 250 | getContainersInfo() ContainersInfo |
| 251 | setContainersInfo(info ContainersInfo) |
| 252 | |
| 253 | setAconfigPaths(paths Paths) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | type moduleContext struct { |
| 257 | bp blueprint.ModuleContext |
| 258 | baseModuleContext |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 259 | packagingSpecs []PackagingSpec |
| 260 | installFiles InstallPaths |
| 261 | checkbuildFiles Paths |
| 262 | checkbuildTarget Path |
| 263 | uncheckedModule bool |
| 264 | module Module |
| 265 | phonies map[string]Paths |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 266 | // outputFiles stores the output of a module by tag and is used to set |
| 267 | // the OutputFilesProvider in GenerateBuildActions |
| 268 | outputFiles OutputFilesInfo |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 269 | |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 270 | TransitiveInstallFiles depset.DepSet[InstallPath] |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 271 | |
| 272 | // set of dependency module:location mappings used to populate the license metadata for |
| 273 | // apex containers. |
| 274 | licenseInstallMap []string |
| 275 | |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 276 | // The path to the generated license metadata file for the module. |
| 277 | licenseMetadataFile WritablePath |
| 278 | |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 279 | katiInstalls katiInstalls |
| 280 | katiSymlinks katiInstalls |
Yu Liu | 82a6d14 | 2024-08-27 19:02:29 +0000 | [diff] [blame] | 281 | // katiInitRcInstalls and katiVintfInstalls track the install rules created by Soong that are |
| 282 | // allowed to have duplicates across modules and variants. |
| 283 | katiInitRcInstalls katiInstalls |
| 284 | katiVintfInstalls katiInstalls |
| 285 | initRcPaths Paths |
| 286 | vintfFragmentsPaths Paths |
| 287 | installedInitRcPaths InstallPaths |
| 288 | installedVintfFragmentsPaths InstallPaths |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 289 | |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 290 | testData []DataPath |
| 291 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 292 | // For tests |
| 293 | buildParams []BuildParams |
| 294 | ruleParams map[blueprint.Rule]blueprint.RuleParams |
| 295 | variables map[string]string |
Yu Liu | 4297ad9 | 2024-08-27 19:50:13 +0000 | [diff] [blame] | 296 | |
| 297 | // moduleInfoJSON can be filled out by GenerateAndroidBuildActions to write a JSON file that will |
| 298 | // be included in the final module-info.json produced by Make. |
| 299 | moduleInfoJSON *ModuleInfoJSON |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 300 | |
| 301 | // containersInfo stores the information about the containers and the information of the |
| 302 | // apexes the module belongs to. |
| 303 | containersInfo ContainersInfo |
| 304 | |
| 305 | // Merged Aconfig files for all transitive deps. |
| 306 | aconfigFilePaths Paths |
| 307 | |
| 308 | // complianceMetadataInfo is for different module types to dump metadata. |
| 309 | // See android.ModuleContext interface. |
| 310 | complianceMetadataInfo *ComplianceMetadataInfo |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Cole Faust | 02987bd | 2024-03-21 17:58:43 -0700 | [diff] [blame] | 313 | var _ ModuleContext = &moduleContext{} |
| 314 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 315 | func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) { |
| 316 | return pctx, BuildParams{ |
| 317 | Rule: ErrorRule, |
| 318 | Description: params.Description, |
| 319 | Output: params.Output, |
| 320 | Outputs: params.Outputs, |
| 321 | ImplicitOutput: params.ImplicitOutput, |
| 322 | ImplicitOutputs: params.ImplicitOutputs, |
| 323 | Args: map[string]string{ |
| 324 | "error": err.Error(), |
| 325 | }, |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) { |
| 330 | m.Build(pctx, BuildParams(params)) |
| 331 | } |
| 332 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 333 | // Convert build parameters from their concrete Android types into their string representations, |
| 334 | // and combine the singular and plural fields of the same type (e.g. Output and Outputs). |
| 335 | func convertBuildParams(params BuildParams) blueprint.BuildParams { |
| 336 | bparams := blueprint.BuildParams{ |
| 337 | Rule: params.Rule, |
| 338 | Description: params.Description, |
| 339 | Deps: params.Deps, |
| 340 | Outputs: params.Outputs.Strings(), |
| 341 | ImplicitOutputs: params.ImplicitOutputs.Strings(), |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 342 | Inputs: params.Inputs.Strings(), |
| 343 | Implicits: params.Implicits.Strings(), |
| 344 | OrderOnly: params.OrderOnly.Strings(), |
| 345 | Validations: params.Validations.Strings(), |
| 346 | Args: params.Args, |
Cole Faust | 451912d | 2025-01-10 11:21:18 -0800 | [diff] [blame] | 347 | Default: params.Default, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | if params.Depfile != nil { |
| 351 | bparams.Depfile = params.Depfile.String() |
| 352 | } |
| 353 | if params.Output != nil { |
| 354 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 355 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 356 | if params.ImplicitOutput != nil { |
| 357 | bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String()) |
| 358 | } |
| 359 | if params.Input != nil { |
| 360 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 361 | } |
| 362 | if params.Implicit != nil { |
| 363 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 364 | } |
| 365 | if params.Validation != nil { |
| 366 | bparams.Validations = append(bparams.Validations, params.Validation.String()) |
| 367 | } |
| 368 | |
| 369 | bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs) |
| 370 | bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 371 | bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs) |
| 372 | bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits) |
| 373 | bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly) |
| 374 | bparams.Validations = proptools.NinjaEscapeList(bparams.Validations) |
| 375 | bparams.Depfile = proptools.NinjaEscape(bparams.Depfile) |
| 376 | |
| 377 | return bparams |
| 378 | } |
| 379 | |
| 380 | func (m *moduleContext) Variable(pctx PackageContext, name, value string) { |
| 381 | if m.config.captureBuild { |
| 382 | m.variables[name] = value |
| 383 | } |
| 384 | |
| 385 | m.bp.Variable(pctx.PackageContext, name, value) |
| 386 | } |
| 387 | |
| 388 | func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams, |
| 389 | argNames ...string) blueprint.Rule { |
| 390 | |
| 391 | if m.config.UseRemoteBuild() { |
| 392 | if params.Pool == nil { |
| 393 | // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict |
| 394 | // jobs to the local parallelism value |
| 395 | params.Pool = localPool |
| 396 | } else if params.Pool == remotePool { |
| 397 | // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's |
| 398 | // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS |
| 399 | // parallelism. |
| 400 | params.Pool = nil |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...) |
| 405 | |
| 406 | if m.config.captureBuild { |
| 407 | m.ruleParams[rule] = params |
| 408 | } |
| 409 | |
| 410 | return rule |
| 411 | } |
| 412 | |
| 413 | func (m *moduleContext) Build(pctx PackageContext, params BuildParams) { |
| 414 | if params.Description != "" { |
| 415 | params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}" |
| 416 | } |
| 417 | |
| 418 | if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 { |
| 419 | pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n", |
| 420 | m.ModuleName(), strings.Join(missingDeps, ", "))) |
| 421 | } |
| 422 | |
| 423 | if m.config.captureBuild { |
| 424 | m.buildParams = append(m.buildParams, params) |
| 425 | } |
| 426 | |
| 427 | bparams := convertBuildParams(params) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 428 | m.bp.Build(pctx.PackageContext, bparams) |
| 429 | } |
| 430 | |
| 431 | func (m *moduleContext) Phony(name string, deps ...Path) { |
Yu Liu | 5451362 | 2024-08-19 20:00:32 +0000 | [diff] [blame] | 432 | m.phonies[name] = append(m.phonies[name], deps...) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | func (m *moduleContext) GetMissingDependencies() []string { |
| 436 | var missingDeps []string |
| 437 | missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...) |
| 438 | missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...) |
| 439 | missingDeps = FirstUniqueStrings(missingDeps) |
| 440 | return missingDeps |
| 441 | } |
| 442 | |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 443 | func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) Module { |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 444 | deps := m.getDirectDepsInternal(name, tag) |
| 445 | if len(deps) == 1 { |
| 446 | return deps[0] |
| 447 | } else if len(deps) >= 2 { |
| 448 | panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", |
| 449 | name, m.ModuleName())) |
| 450 | } else { |
| 451 | return nil |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 452 | } |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | func (m *moduleContext) GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) *ModuleProxy { |
| 456 | deps := m.getDirectDepsProxyInternal(name, tag) |
| 457 | if len(deps) == 1 { |
| 458 | return &deps[0] |
| 459 | } else if len(deps) >= 2 { |
| 460 | panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", |
| 461 | name, m.ModuleName())) |
| 462 | } else { |
| 463 | return nil |
| 464 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | func (m *moduleContext) ModuleSubDir() string { |
| 468 | return m.bp.ModuleSubDir() |
| 469 | } |
| 470 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 471 | func (m *moduleContext) InstallInData() bool { |
| 472 | return m.module.InstallInData() |
| 473 | } |
| 474 | |
| 475 | func (m *moduleContext) InstallInTestcases() bool { |
| 476 | return m.module.InstallInTestcases() |
| 477 | } |
| 478 | |
| 479 | func (m *moduleContext) InstallInSanitizerDir() bool { |
| 480 | return m.module.InstallInSanitizerDir() |
| 481 | } |
| 482 | |
| 483 | func (m *moduleContext) InstallInRamdisk() bool { |
| 484 | return m.module.InstallInRamdisk() |
| 485 | } |
| 486 | |
| 487 | func (m *moduleContext) InstallInVendorRamdisk() bool { |
| 488 | return m.module.InstallInVendorRamdisk() |
| 489 | } |
| 490 | |
| 491 | func (m *moduleContext) InstallInDebugRamdisk() bool { |
| 492 | return m.module.InstallInDebugRamdisk() |
| 493 | } |
| 494 | |
| 495 | func (m *moduleContext) InstallInRecovery() bool { |
| 496 | return m.module.InstallInRecovery() |
| 497 | } |
| 498 | |
| 499 | func (m *moduleContext) InstallInRoot() bool { |
| 500 | return m.module.InstallInRoot() |
| 501 | } |
| 502 | |
| 503 | func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) { |
| 504 | return m.module.InstallForceOS() |
| 505 | } |
| 506 | |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 507 | func (m *moduleContext) InstallInOdm() bool { |
| 508 | return m.module.InstallInOdm() |
| 509 | } |
| 510 | |
| 511 | func (m *moduleContext) InstallInProduct() bool { |
| 512 | return m.module.InstallInProduct() |
| 513 | } |
| 514 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 515 | func (m *moduleContext) InstallInVendor() bool { |
| 516 | return m.module.InstallInVendor() |
| 517 | } |
| 518 | |
Spandan Das | 27ff767 | 2024-11-06 19:23:57 +0000 | [diff] [blame] | 519 | func (m *moduleContext) InstallInSystemDlkm() bool { |
| 520 | return m.module.InstallInSystemDlkm() |
| 521 | } |
| 522 | |
| 523 | func (m *moduleContext) InstallInVendorDlkm() bool { |
| 524 | return m.module.InstallInVendorDlkm() |
| 525 | } |
| 526 | |
| 527 | func (m *moduleContext) InstallInOdmDlkm() bool { |
| 528 | return m.module.InstallInOdmDlkm() |
| 529 | } |
| 530 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 531 | func (m *moduleContext) skipInstall() bool { |
| 532 | if m.module.base().commonProperties.SkipInstall { |
| 533 | return true |
| 534 | } |
| 535 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 536 | // We'll need a solution for choosing which of modules with the same name in different |
| 537 | // namespaces to install. For now, reuse the list of namespaces exported to Make as the |
| 538 | // list of namespaces to install in a Soong-only build. |
| 539 | if !m.module.base().commonProperties.NamespaceExportedToMake { |
| 540 | return true |
| 541 | } |
| 542 | |
| 543 | return false |
| 544 | } |
| 545 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 546 | // Tells whether this module is installed to the full install path (ex: |
| 547 | // out/target/product/<name>/<partition>) or not. If this returns false, the install build rule is |
| 548 | // not created and this module can only be installed to packaging modules like android_filesystem. |
| 549 | func (m *moduleContext) requiresFullInstall() bool { |
| 550 | if m.skipInstall() { |
| 551 | return false |
| 552 | } |
| 553 | |
Spandan Das | 034af2c | 2024-10-30 21:45:09 +0000 | [diff] [blame] | 554 | if m.module.base().commonProperties.HideFromMake { |
| 555 | return false |
| 556 | } |
| 557 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 558 | if proptools.Bool(m.module.base().commonProperties.No_full_install) { |
| 559 | return false |
| 560 | } |
| 561 | |
| 562 | return true |
| 563 | } |
| 564 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 565 | func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path, |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 566 | deps ...InstallPath) InstallPath { |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 567 | return m.installFile(installPath, name, srcPath, deps, false, true, true, nil) |
| 568 | } |
| 569 | |
| 570 | func (m *moduleContext) InstallFileWithoutCheckbuild(installPath InstallPath, name string, srcPath Path, |
| 571 | deps ...InstallPath) InstallPath { |
| 572 | return m.installFile(installPath, name, srcPath, deps, false, true, false, nil) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path, |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 576 | deps ...InstallPath) InstallPath { |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 577 | return m.installFile(installPath, name, srcPath, deps, true, true, true, nil) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 581 | extraZip Path, deps ...InstallPath) InstallPath { |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 582 | return m.installFile(installPath, name, srcPath, deps, false, true, true, &extraFilesZip{ |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 583 | zip: extraZip, |
| 584 | dir: installPath, |
| 585 | }) |
| 586 | } |
| 587 | |
| 588 | func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec { |
| 589 | fullInstallPath := installPath.Join(m, name) |
| 590 | return m.packageFile(fullInstallPath, srcPath, false) |
| 591 | } |
| 592 | |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 593 | func (m *moduleContext) getAconfigPaths() Paths { |
| 594 | return m.aconfigFilePaths |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | func (m *moduleContext) setAconfigPaths(paths Paths) { |
| 598 | m.aconfigFilePaths = paths |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 599 | } |
| 600 | |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 601 | func (m *moduleContext) getOwnerAndOverrides() (string, []string) { |
| 602 | owner := m.ModuleName() |
| 603 | overrides := slices.Clone(m.Module().base().commonProperties.Overrides) |
| 604 | if b, ok := m.Module().(OverridableModule); ok { |
| 605 | if b.GetOverriddenBy() != "" { |
| 606 | // overriding variant of base module |
| 607 | overrides = append(overrides, m.ModuleName()) // com.android.foo |
| 608 | owner = m.Module().Name() // com.company.android.foo |
| 609 | } |
| 610 | } |
| 611 | return owner, overrides |
| 612 | } |
| 613 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 614 | func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec { |
| 615 | licenseFiles := m.Module().EffectiveLicenseFiles() |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 616 | owner, overrides := m.getOwnerAndOverrides() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 617 | spec := PackagingSpec{ |
| 618 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 619 | srcPath: srcPath, |
| 620 | symlinkTarget: "", |
| 621 | executable: executable, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 622 | effectiveLicenseFiles: uniquelist.Make(licenseFiles), |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 623 | partition: fullInstallPath.partition, |
Jiyong Park | 4152b19 | 2024-04-30 21:24:21 +0900 | [diff] [blame] | 624 | skipInstall: m.skipInstall(), |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 625 | aconfigPaths: uniquelist.Make(m.getAconfigPaths()), |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 626 | archType: m.target.Arch.ArchType, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 627 | overrides: uniquelist.Make(overrides), |
| 628 | owner: owner, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 629 | } |
| 630 | m.packagingSpecs = append(m.packagingSpecs, spec) |
| 631 | return spec |
| 632 | } |
| 633 | |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 634 | func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []InstallPath, |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 635 | executable bool, hooks bool, checkbuild bool, extraZip *extraFilesZip) InstallPath { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 636 | |
| 637 | fullInstallPath := installPath.Join(m, name) |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 638 | if hooks { |
| 639 | m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false) |
| 640 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 641 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 642 | if m.requiresFullInstall() { |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 643 | deps = append(deps, InstallPaths(m.TransitiveInstallFiles.ToList())...) |
Cole Faust | 74d243c | 2024-12-11 17:57:34 -0800 | [diff] [blame] | 644 | if m.config.KatiEnabled() { |
| 645 | deps = append(deps, m.installedInitRcPaths...) |
| 646 | deps = append(deps, m.installedVintfFragmentsPaths...) |
| 647 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 648 | |
| 649 | var implicitDeps, orderOnlyDeps Paths |
| 650 | |
| 651 | if m.Host() { |
| 652 | // Installed host modules might be used during the build, depend directly on their |
| 653 | // dependencies so their timestamp is updated whenever their dependency is updated |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 654 | implicitDeps = InstallPaths(deps).Paths() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 655 | } else { |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 656 | orderOnlyDeps = InstallPaths(deps).Paths() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | if m.Config().KatiEnabled() { |
| 660 | // When creating the install rule in Soong but embedding in Make, write the rule to a |
| 661 | // makefile instead of directly to the ninja file so that main.mk can add the |
| 662 | // dependencies from the `required` property that are hard to resolve in Soong. |
| 663 | m.katiInstalls = append(m.katiInstalls, katiInstall{ |
| 664 | from: srcPath, |
| 665 | to: fullInstallPath, |
| 666 | implicitDeps: implicitDeps, |
| 667 | orderOnlyDeps: orderOnlyDeps, |
| 668 | executable: executable, |
| 669 | extraFiles: extraZip, |
| 670 | }) |
| 671 | } else { |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 672 | rule := CpWithBash |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 673 | if executable { |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 674 | rule = CpExecutableWithBash |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | extraCmds := "" |
| 678 | if extraZip != nil { |
| 679 | extraCmds += fmt.Sprintf(" && ( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} )", |
| 680 | extraZip.dir.String(), extraZip.zip.String()) |
| 681 | extraCmds += " || ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )" |
| 682 | implicitDeps = append(implicitDeps, extraZip.zip) |
| 683 | } |
| 684 | |
| 685 | m.Build(pctx, BuildParams{ |
| 686 | Rule: rule, |
| 687 | Description: "install " + fullInstallPath.Base(), |
| 688 | Output: fullInstallPath, |
| 689 | Input: srcPath, |
| 690 | Implicits: implicitDeps, |
| 691 | OrderOnly: orderOnlyDeps, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 692 | Args: map[string]string{ |
| 693 | "extraCmds": extraCmds, |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 694 | "cpFlags": "-f", |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 695 | }, |
| 696 | }) |
| 697 | } |
| 698 | |
| 699 | m.installFiles = append(m.installFiles, fullInstallPath) |
| 700 | } |
| 701 | |
| 702 | m.packageFile(fullInstallPath, srcPath, executable) |
| 703 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 704 | if checkbuild { |
| 705 | m.checkbuildFiles = append(m.checkbuildFiles, srcPath) |
| 706 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 707 | |
| 708 | return fullInstallPath |
| 709 | } |
| 710 | |
| 711 | func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath { |
| 712 | fullInstallPath := installPath.Join(m, name) |
| 713 | m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true) |
| 714 | |
| 715 | relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String()) |
| 716 | if err != nil { |
| 717 | panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err)) |
| 718 | } |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 719 | if m.requiresFullInstall() { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 720 | |
| 721 | if m.Config().KatiEnabled() { |
| 722 | // When creating the symlink rule in Soong but embedding in Make, write the rule to a |
| 723 | // makefile instead of directly to the ninja file so that main.mk can add the |
| 724 | // dependencies from the `required` property that are hard to resolve in Soong. |
| 725 | m.katiSymlinks = append(m.katiSymlinks, katiInstall{ |
| 726 | from: srcPath, |
| 727 | to: fullInstallPath, |
| 728 | }) |
| 729 | } else { |
| 730 | // The symlink doesn't need updating when the target is modified, but we sometimes |
| 731 | // have a dependency on a symlink to a binary instead of to the binary directly, and |
| 732 | // the mtime of the symlink must be updated when the binary is modified, so use a |
| 733 | // normal dependency here instead of an order-only dependency. |
| 734 | m.Build(pctx, BuildParams{ |
Spandan Das | 4d78e01 | 2025-01-22 23:25:39 +0000 | [diff] [blame] | 735 | Rule: SymlinkWithBash, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 736 | Description: "install symlink " + fullInstallPath.Base(), |
| 737 | Output: fullInstallPath, |
| 738 | Input: srcPath, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 739 | Args: map[string]string{ |
| 740 | "fromPath": relPath, |
| 741 | }, |
| 742 | }) |
| 743 | } |
| 744 | |
| 745 | m.installFiles = append(m.installFiles, fullInstallPath) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 748 | owner, overrides := m.getOwnerAndOverrides() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 749 | m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ |
| 750 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 751 | srcPath: nil, |
| 752 | symlinkTarget: relPath, |
| 753 | executable: false, |
| 754 | partition: fullInstallPath.partition, |
Jiyong Park | 4152b19 | 2024-04-30 21:24:21 +0900 | [diff] [blame] | 755 | skipInstall: m.skipInstall(), |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 756 | aconfigPaths: uniquelist.Make(m.getAconfigPaths()), |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 757 | archType: m.target.Arch.ArchType, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 758 | overrides: uniquelist.Make(overrides), |
| 759 | owner: owner, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 760 | }) |
| 761 | |
| 762 | return fullInstallPath |
| 763 | } |
| 764 | |
| 765 | // installPath/name -> absPath where absPath might be a path that is available only at runtime |
| 766 | // (e.g. /apex/...) |
| 767 | func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath { |
| 768 | fullInstallPath := installPath.Join(m, name) |
| 769 | m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true) |
| 770 | |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 771 | if m.requiresFullInstall() { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 772 | if m.Config().KatiEnabled() { |
| 773 | // When creating the symlink rule in Soong but embedding in Make, write the rule to a |
| 774 | // makefile instead of directly to the ninja file so that main.mk can add the |
| 775 | // dependencies from the `required` property that are hard to resolve in Soong. |
| 776 | m.katiSymlinks = append(m.katiSymlinks, katiInstall{ |
| 777 | absFrom: absPath, |
| 778 | to: fullInstallPath, |
| 779 | }) |
| 780 | } else { |
| 781 | m.Build(pctx, BuildParams{ |
| 782 | Rule: Symlink, |
| 783 | Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath, |
| 784 | Output: fullInstallPath, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 785 | Args: map[string]string{ |
| 786 | "fromPath": absPath, |
| 787 | }, |
| 788 | }) |
| 789 | } |
| 790 | |
| 791 | m.installFiles = append(m.installFiles, fullInstallPath) |
| 792 | } |
| 793 | |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 794 | owner, overrides := m.getOwnerAndOverrides() |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 795 | m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ |
| 796 | relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), |
| 797 | srcPath: nil, |
| 798 | symlinkTarget: absPath, |
| 799 | executable: false, |
| 800 | partition: fullInstallPath.partition, |
Jiyong Park | 4152b19 | 2024-04-30 21:24:21 +0900 | [diff] [blame] | 801 | skipInstall: m.skipInstall(), |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 802 | aconfigPaths: uniquelist.Make(m.getAconfigPaths()), |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 803 | archType: m.target.Arch.ArchType, |
Colin Cross | f0c1ede | 2025-01-23 13:30:36 -0800 | [diff] [blame^] | 804 | overrides: uniquelist.Make(overrides), |
| 805 | owner: owner, |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 806 | }) |
| 807 | |
| 808 | return fullInstallPath |
| 809 | } |
| 810 | |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 811 | func (m *moduleContext) InstallTestData(installPath InstallPath, data []DataPath) InstallPaths { |
| 812 | m.testData = append(m.testData, data...) |
| 813 | |
| 814 | ret := make(InstallPaths, 0, len(data)) |
| 815 | for _, d := range data { |
| 816 | relPath := d.ToRelativeInstallPath() |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 817 | installed := m.installFile(installPath, relPath, d.SrcPath, nil, false, false, true, nil) |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 818 | ret = append(ret, installed) |
| 819 | } |
| 820 | |
| 821 | return ret |
| 822 | } |
| 823 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 824 | // CheckbuildFile specifies the output files that should be built by checkbuild. |
| 825 | func (m *moduleContext) CheckbuildFile(srcPaths ...Path) { |
| 826 | m.checkbuildFiles = append(m.checkbuildFiles, srcPaths...) |
| 827 | } |
| 828 | |
| 829 | // UncheckedModule marks the current module has having no files that should be built by checkbuild. |
| 830 | func (m *moduleContext) UncheckedModule() { |
| 831 | m.uncheckedModule = true |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 834 | func (m *moduleContext) BlueprintModuleContext() blueprint.ModuleContext { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 835 | return m.bp |
| 836 | } |
| 837 | |
| 838 | func (m *moduleContext) LicenseMetadataFile() Path { |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 839 | return m.licenseMetadataFile |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 842 | func (m *moduleContext) ModuleInfoJSON() *ModuleInfoJSON { |
Yu Liu | 4297ad9 | 2024-08-27 19:50:13 +0000 | [diff] [blame] | 843 | if moduleInfoJSON := m.moduleInfoJSON; moduleInfoJSON != nil { |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 844 | return moduleInfoJSON |
| 845 | } |
| 846 | moduleInfoJSON := &ModuleInfoJSON{} |
Yu Liu | 4297ad9 | 2024-08-27 19:50:13 +0000 | [diff] [blame] | 847 | m.moduleInfoJSON = moduleInfoJSON |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 848 | return moduleInfoJSON |
| 849 | } |
| 850 | |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 851 | func (m *moduleContext) SetOutputFiles(outputFiles Paths, tag string) { |
Cole Faust | 5146e78 | 2024-11-15 14:47:49 -0800 | [diff] [blame] | 852 | for _, outputFile := range outputFiles { |
| 853 | if outputFile == nil { |
| 854 | panic("outputfiles cannot be nil") |
| 855 | } |
| 856 | } |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 857 | if tag == "" { |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 858 | if len(m.outputFiles.DefaultOutputFiles) > 0 { |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 859 | m.ModuleErrorf("Module %s default OutputFiles cannot be overwritten", m.ModuleName()) |
| 860 | } |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 861 | m.outputFiles.DefaultOutputFiles = outputFiles |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 862 | } else { |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 863 | if m.outputFiles.TaggedOutputFiles == nil { |
| 864 | m.outputFiles.TaggedOutputFiles = make(map[string]Paths) |
mrziwang | 57768d7 | 2024-06-06 11:31:51 -0700 | [diff] [blame] | 865 | } |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 866 | if _, exists := m.outputFiles.TaggedOutputFiles[tag]; exists { |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 867 | m.ModuleErrorf("Module %s OutputFiles at tag %s cannot be overwritten", m.ModuleName(), tag) |
| 868 | } else { |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 869 | m.outputFiles.TaggedOutputFiles[tag] = outputFiles |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
Yu Liu | 876b7ce | 2024-08-21 18:20:13 +0000 | [diff] [blame] | 874 | func (m *moduleContext) GetOutputFiles() OutputFilesInfo { |
| 875 | return m.outputFiles |
| 876 | } |
| 877 | |
Yu Liu | bad1eef | 2024-08-21 22:37:35 +0000 | [diff] [blame] | 878 | func (m *moduleContext) SetLicenseInstallMap(installMap []string) { |
| 879 | m.licenseInstallMap = append(m.licenseInstallMap, installMap...) |
| 880 | } |
| 881 | |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 882 | func (m *moduleContext) ComplianceMetadataInfo() *ComplianceMetadataInfo { |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 883 | if m.complianceMetadataInfo == nil { |
| 884 | m.complianceMetadataInfo = NewComplianceMetadataInfo() |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 885 | } |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 886 | return m.complianceMetadataInfo |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 889 | // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must |
| 890 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 891 | // |
| 892 | // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead. |
| 893 | func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths { |
| 894 | return PathsForModuleSrcExcludes(m, srcFiles, excludes) |
| 895 | } |
| 896 | |
| 897 | // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must |
| 898 | // be tagged with `android:"path" to support automatic source module dependency resolution. |
| 899 | // |
| 900 | // Deprecated: use PathForModuleSrc instead. |
| 901 | func (m *moduleContext) ExpandSource(srcFile, _ string) Path { |
| 902 | return PathForModuleSrc(m, srcFile) |
| 903 | } |
| 904 | |
| 905 | // Returns an optional single path expanded from globs and modules referenced using ":module" syntax if |
| 906 | // the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module |
| 907 | // dependency resolution. |
| 908 | func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) OptionalPath { |
| 909 | if srcFile != nil { |
| 910 | return OptionalPathForPath(PathForModuleSrc(m, *srcFile)) |
| 911 | } |
| 912 | return OptionalPath{} |
| 913 | } |
| 914 | |
Cole Faust | e8a8783 | 2024-09-11 11:35:46 -0700 | [diff] [blame] | 915 | func (m *moduleContext) RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string { |
Cole Faust | 43ddd08 | 2024-06-17 12:32:40 -0700 | [diff] [blame] | 916 | return m.module.RequiredModuleNames(ctx) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | func (m *moduleContext) HostRequiredModuleNames() []string { |
| 920 | return m.module.HostRequiredModuleNames() |
| 921 | } |
| 922 | |
| 923 | func (m *moduleContext) TargetRequiredModuleNames() []string { |
| 924 | return m.module.TargetRequiredModuleNames() |
| 925 | } |
Yu Liu | 9a99313 | 2024-08-27 23:21:06 +0000 | [diff] [blame] | 926 | |
| 927 | func (m *moduleContext) getContainersInfo() ContainersInfo { |
| 928 | return m.containersInfo |
| 929 | } |
| 930 | |
| 931 | func (m *moduleContext) setContainersInfo(info ContainersInfo) { |
| 932 | m.containersInfo = info |
| 933 | } |