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