blob: c677f9482ff35127eab8a1211dac7c473ff99e51 [file] [log] [blame]
Colin Cross69452e12023-11-15 11:20:53 -08001// 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
15package android
16
17import (
18 "fmt"
Colin Cross69452e12023-11-15 11:20:53 -080019 "path"
20 "path/filepath"
21 "strings"
Cole Faust9a346f62024-01-18 20:12:02 +000022
23 "github.com/google/blueprint"
24 "github.com/google/blueprint/proptools"
Colin Cross69452e12023-11-15 11:20:53 -080025)
26
27// BuildParameters describes the set of potential parameters to build a Ninja rule.
28// In general, these correspond to a Ninja concept.
29type BuildParams struct {
30 // A Ninja Rule that will be written to the Ninja file. This allows factoring out common code
31 // among multiple modules to reduce repetition in the Ninja file of action requirements. A rule
32 // can contain variables that should be provided in Args.
33 Rule blueprint.Rule
34 // Deps represents the depfile format. When using RuleBuilder, this defaults to GCC when depfiles
35 // are used.
36 Deps blueprint.Deps
37 // Depfile is a writeable path that allows correct incremental builds when the inputs have not
38 // been fully specified by the Ninja rule. Ninja supports a subset of the Makefile depfile syntax.
39 Depfile WritablePath
40 // A description of the build action.
41 Description string
42 // Output is an output file of the action. When using this field, references to $out in the Ninja
43 // command will refer to this file.
44 Output WritablePath
45 // Outputs is a slice of output file of the action. When using this field, references to $out in
46 // the Ninja command will refer to these files.
47 Outputs WritablePaths
Colin Cross69452e12023-11-15 11:20:53 -080048 // ImplicitOutput is an output file generated by the action. Note: references to `$out` in the
49 // Ninja command will NOT include references to this file.
50 ImplicitOutput WritablePath
51 // ImplicitOutputs is a slice of output files generated by the action. Note: references to `$out`
52 // in the Ninja command will NOT include references to these files.
53 ImplicitOutputs WritablePaths
54 // Input is an input file to the Ninja action. When using this field, references to $in in the
55 // Ninja command will refer to this file.
56 Input Path
57 // Inputs is a slice of input files to the Ninja action. When using this field, references to $in
58 // in the Ninja command will refer to these files.
59 Inputs Paths
60 // Implicit is an input file to the Ninja action. Note: references to `$in` in the Ninja command
61 // will NOT include references to this file.
62 Implicit Path
63 // Implicits is a slice of input files to the Ninja action. Note: references to `$in` in the Ninja
64 // command will NOT include references to these files.
65 Implicits Paths
66 // OrderOnly are Ninja order-only inputs to the action. When these are out of date, the output is
67 // not rebuilt until they are built, but changes in order-only dependencies alone do not cause the
68 // output to be rebuilt.
69 OrderOnly Paths
70 // Validation is an output path for a validation action. Validation outputs imply lower
71 // non-blocking priority to building non-validation outputs.
72 Validation Path
73 // Validations is a slice of output path for a validation action. Validation outputs imply lower
74 // non-blocking priority to building non-validation outputs.
75 Validations Paths
76 // Whether to skip outputting a default target statement which will be built by Ninja when no
77 // targets are specified on Ninja's command line.
78 Default bool
79 // Args is a key value mapping for replacements of variables within the Rule
80 Args map[string]string
81}
82
83type ModuleBuildParams BuildParams
84
85type ModuleContext interface {
86 BaseModuleContext
87
88 blueprintModuleContext() blueprint.ModuleContext
89
90 // Deprecated: use ModuleContext.Build instead.
91 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
92
93 // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
94 // be tagged with `android:"path" to support automatic source module dependency resolution.
95 //
96 // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
97 ExpandSources(srcFiles, excludes []string) Paths
98
99 // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
100 // be tagged with `android:"path" to support automatic source module dependency resolution.
101 //
102 // Deprecated: use PathForModuleSrc instead.
103 ExpandSource(srcFile, prop string) Path
104
105 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
106
107 // InstallExecutable creates a rule to copy srcPath to name in the installPath directory,
108 // with the given additional dependencies. The file is marked executable after copying.
109 //
Yu Liubad1eef2024-08-21 22:37:35 +0000110 // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec
111 // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module
112 // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through
113 // dependency tags for which IsInstallDepNeeded returns true.
Colin Cross09ad3a62023-11-15 12:29:33 -0800114 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath
Colin Cross69452e12023-11-15 11:20:53 -0800115
116 // InstallFile creates a rule to copy srcPath to name in the installPath directory,
117 // with the given additional dependencies.
118 //
Yu Liubad1eef2024-08-21 22:37:35 +0000119 // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec
120 // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module
121 // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through
122 // dependency tags for which IsInstallDepNeeded returns true.
Colin Cross09ad3a62023-11-15 12:29:33 -0800123 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath
Colin Cross69452e12023-11-15 11:20:53 -0800124
125 // InstallFileWithExtraFilesZip creates a rule to copy srcPath to name in the installPath
126 // directory, and also unzip a zip file containing extra files to install into the same
127 // directory.
128 //
Yu Liubad1eef2024-08-21 22:37:35 +0000129 // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec
130 // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module
131 // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through
132 // dependency tags for which IsInstallDepNeeded returns true.
Colin Cross09ad3a62023-11-15 12:29:33 -0800133 InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, extraZip Path, deps ...InstallPath) InstallPath
Colin Cross69452e12023-11-15 11:20:53 -0800134
135 // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath
136 // directory.
137 //
Yu Liubad1eef2024-08-21 22:37:35 +0000138 // The installed symlink can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec
139 // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module
140 // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through
141 // dependency tags for which IsInstallDepNeeded returns true.
Colin Cross69452e12023-11-15 11:20:53 -0800142 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
143
144 // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name
145 // in the installPath directory.
146 //
Yu Liubad1eef2024-08-21 22:37:35 +0000147 // The installed symlink can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec
148 // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module
149 // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through
150 // dependency tags for which IsInstallDepNeeded returns true.
Colin Cross69452e12023-11-15 11:20:53 -0800151 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
152
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800153 // InstallTestData creates rules to install test data (e.g. data files used during a test) into
154 // the installPath directory.
155 //
Yu Liubad1eef2024-08-21 22:37:35 +0000156 // The installed files can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec
157 // for the installed files can be accessed by InstallFilesInfo.PackagingSpecs on this module
158 // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through
159 // dependency tags for which IsInstallDepNeeded returns true.
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800160 InstallTestData(installPath InstallPath, data []DataPath) InstallPaths
161
Colin Cross69452e12023-11-15 11:20:53 -0800162 // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
163 // the rule to copy the file. This is useful to define how a module would be packaged
164 // without installing it into the global installation directories.
165 //
Yu Liubad1eef2024-08-21 22:37:35 +0000166 // The created PackagingSpec can be accessed by InstallFilesInfo.PackagingSpecs on this module
167 // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through
168 // dependency tags for which IsInstallDepNeeded returns true.
Colin Cross69452e12023-11-15 11:20:53 -0800169 PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
170
171 CheckbuildFile(srcPath Path)
172
173 InstallInData() bool
174 InstallInTestcases() bool
175 InstallInSanitizerDir() bool
176 InstallInRamdisk() bool
177 InstallInVendorRamdisk() bool
178 InstallInDebugRamdisk() bool
179 InstallInRecovery() bool
180 InstallInRoot() bool
Colin Crossea30d852023-11-29 16:00:16 -0800181 InstallInOdm() bool
182 InstallInProduct() bool
Colin Cross69452e12023-11-15 11:20:53 -0800183 InstallInVendor() bool
184 InstallForceOS() (*OsType, *ArchType)
185
Cole Faust43ddd082024-06-17 12:32:40 -0700186 RequiredModuleNames(ctx ConfigAndErrorContext) []string
Colin Cross69452e12023-11-15 11:20:53 -0800187 HostRequiredModuleNames() []string
188 TargetRequiredModuleNames() []string
189
190 ModuleSubDir() string
Colin Cross69452e12023-11-15 11:20:53 -0800191
192 Variable(pctx PackageContext, name, value string)
193 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
194 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
195 // and performs more verification.
196 Build(pctx PackageContext, params BuildParams)
197 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
198 // phony rules or real files. Phony can be called on the same name multiple times to add
199 // additional dependencies.
200 Phony(phony string, deps ...Path)
201
202 // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
203 // but do not exist.
204 GetMissingDependencies() []string
205
206 // LicenseMetadataFile returns the path where the license metadata for this module will be
207 // generated.
208 LicenseMetadataFile() Path
Colin Crossd6fd0132023-11-06 13:54:06 -0800209
210 // ModuleInfoJSON returns a pointer to the ModuleInfoJSON struct that can be filled out by
211 // GenerateAndroidBuildActions. If it is called then the struct will be written out and included in
212 // the module-info.json generated by Make, and Make will not generate its own data for this module.
213 ModuleInfoJSON() *ModuleInfoJSON
mrziwange6c85812024-05-22 14:36:09 -0700214
215 // SetOutputFiles stores the outputFiles to outputFiles property, which is used
216 // to set the OutputFilesProvider later.
217 SetOutputFiles(outputFiles Paths, tag string)
Wei Lia1aa2972024-06-21 13:08:51 -0700218
Yu Liu876b7ce2024-08-21 18:20:13 +0000219 GetOutputFiles() OutputFilesInfo
220
Yu Liubad1eef2024-08-21 22:37:35 +0000221 // SetLicenseInstallMap stores the set of dependency module:location mappings for files in an
222 // apex container for use when generation the license metadata file.
223 SetLicenseInstallMap(installMap []string)
224
Wei Lia1aa2972024-06-21 13:08:51 -0700225 // ComplianceMetadataInfo returns a ComplianceMetadataInfo instance for different module types to dump metadata,
226 // which usually happens in GenerateAndroidBuildActions() of a module type.
227 // See android.ModuleBase.complianceMetadataInfo
228 ComplianceMetadataInfo() *ComplianceMetadataInfo
Yu Liu9a993132024-08-27 23:21:06 +0000229
230 // Get the information about the containers this module belongs to.
231 getContainersInfo() ContainersInfo
232 setContainersInfo(info ContainersInfo)
233
234 setAconfigPaths(paths Paths)
Colin Cross69452e12023-11-15 11:20:53 -0800235}
236
237type moduleContext struct {
238 bp blueprint.ModuleContext
239 baseModuleContext
240 packagingSpecs []PackagingSpec
241 installFiles InstallPaths
242 checkbuildFiles Paths
243 module Module
244 phonies map[string]Paths
Yu Liu876b7ce2024-08-21 18:20:13 +0000245 // outputFiles stores the output of a module by tag and is used to set
246 // the OutputFilesProvider in GenerateBuildActions
247 outputFiles OutputFilesInfo
Colin Cross69452e12023-11-15 11:20:53 -0800248
Yu Liubad1eef2024-08-21 22:37:35 +0000249 TransitiveInstallFiles *DepSet[InstallPath]
250
251 // set of dependency module:location mappings used to populate the license metadata for
252 // apex containers.
253 licenseInstallMap []string
254
Yu Liuec810542024-08-26 18:09:15 +0000255 // The path to the generated license metadata file for the module.
256 licenseMetadataFile WritablePath
257
Yu Liud46e5ae2024-08-15 18:46:17 +0000258 katiInstalls katiInstalls
259 katiSymlinks katiInstalls
Yu Liu82a6d142024-08-27 19:02:29 +0000260 // katiInitRcInstalls and katiVintfInstalls track the install rules created by Soong that are
261 // allowed to have duplicates across modules and variants.
262 katiInitRcInstalls katiInstalls
263 katiVintfInstalls katiInstalls
264 initRcPaths Paths
265 vintfFragmentsPaths Paths
266 installedInitRcPaths InstallPaths
267 installedVintfFragmentsPaths InstallPaths
Colin Cross69452e12023-11-15 11:20:53 -0800268
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800269 testData []DataPath
270
Colin Cross69452e12023-11-15 11:20:53 -0800271 // For tests
272 buildParams []BuildParams
273 ruleParams map[blueprint.Rule]blueprint.RuleParams
274 variables map[string]string
Yu Liu4297ad92024-08-27 19:50:13 +0000275
276 // moduleInfoJSON can be filled out by GenerateAndroidBuildActions to write a JSON file that will
277 // be included in the final module-info.json produced by Make.
278 moduleInfoJSON *ModuleInfoJSON
Yu Liu9a993132024-08-27 23:21:06 +0000279
280 // containersInfo stores the information about the containers and the information of the
281 // apexes the module belongs to.
282 containersInfo ContainersInfo
283
284 // Merged Aconfig files for all transitive deps.
285 aconfigFilePaths Paths
286
287 // complianceMetadataInfo is for different module types to dump metadata.
288 // See android.ModuleContext interface.
289 complianceMetadataInfo *ComplianceMetadataInfo
Colin Cross69452e12023-11-15 11:20:53 -0800290}
291
Cole Faust02987bd2024-03-21 17:58:43 -0700292var _ ModuleContext = &moduleContext{}
293
Colin Cross69452e12023-11-15 11:20:53 -0800294func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
295 return pctx, BuildParams{
296 Rule: ErrorRule,
297 Description: params.Description,
298 Output: params.Output,
299 Outputs: params.Outputs,
300 ImplicitOutput: params.ImplicitOutput,
301 ImplicitOutputs: params.ImplicitOutputs,
302 Args: map[string]string{
303 "error": err.Error(),
304 },
305 }
306}
307
308func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
309 m.Build(pctx, BuildParams(params))
310}
311
Colin Cross69452e12023-11-15 11:20:53 -0800312// Convert build parameters from their concrete Android types into their string representations,
313// and combine the singular and plural fields of the same type (e.g. Output and Outputs).
314func convertBuildParams(params BuildParams) blueprint.BuildParams {
315 bparams := blueprint.BuildParams{
316 Rule: params.Rule,
317 Description: params.Description,
318 Deps: params.Deps,
319 Outputs: params.Outputs.Strings(),
320 ImplicitOutputs: params.ImplicitOutputs.Strings(),
Colin Cross69452e12023-11-15 11:20:53 -0800321 Inputs: params.Inputs.Strings(),
322 Implicits: params.Implicits.Strings(),
323 OrderOnly: params.OrderOnly.Strings(),
324 Validations: params.Validations.Strings(),
325 Args: params.Args,
326 Optional: !params.Default,
327 }
328
329 if params.Depfile != nil {
330 bparams.Depfile = params.Depfile.String()
331 }
332 if params.Output != nil {
333 bparams.Outputs = append(bparams.Outputs, params.Output.String())
334 }
Colin Cross69452e12023-11-15 11:20:53 -0800335 if params.ImplicitOutput != nil {
336 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
337 }
338 if params.Input != nil {
339 bparams.Inputs = append(bparams.Inputs, params.Input.String())
340 }
341 if params.Implicit != nil {
342 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
343 }
344 if params.Validation != nil {
345 bparams.Validations = append(bparams.Validations, params.Validation.String())
346 }
347
348 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
349 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
Colin Cross69452e12023-11-15 11:20:53 -0800350 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
351 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
352 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
353 bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
354 bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
355
356 return bparams
357}
358
359func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
360 if m.config.captureBuild {
361 m.variables[name] = value
362 }
363
364 m.bp.Variable(pctx.PackageContext, name, value)
365}
366
367func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
368 argNames ...string) blueprint.Rule {
369
370 if m.config.UseRemoteBuild() {
371 if params.Pool == nil {
372 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
373 // jobs to the local parallelism value
374 params.Pool = localPool
375 } else if params.Pool == remotePool {
376 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
377 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
378 // parallelism.
379 params.Pool = nil
380 }
381 }
382
383 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
384
385 if m.config.captureBuild {
386 m.ruleParams[rule] = params
387 }
388
389 return rule
390}
391
392func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
393 if params.Description != "" {
394 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
395 }
396
397 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
398 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
399 m.ModuleName(), strings.Join(missingDeps, ", ")))
400 }
401
402 if m.config.captureBuild {
403 m.buildParams = append(m.buildParams, params)
404 }
405
406 bparams := convertBuildParams(params)
Colin Cross69452e12023-11-15 11:20:53 -0800407 m.bp.Build(pctx.PackageContext, bparams)
408}
409
410func (m *moduleContext) Phony(name string, deps ...Path) {
Yu Liu54513622024-08-19 20:00:32 +0000411 m.phonies[name] = append(m.phonies[name], deps...)
Colin Cross69452e12023-11-15 11:20:53 -0800412}
413
414func (m *moduleContext) GetMissingDependencies() []string {
415 var missingDeps []string
416 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
417 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
418 missingDeps = FirstUniqueStrings(missingDeps)
419 return missingDeps
420}
421
422func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
423 module, _ := m.getDirectDepInternal(name, tag)
424 return module
425}
426
427func (m *moduleContext) ModuleSubDir() string {
428 return m.bp.ModuleSubDir()
429}
430
Colin Cross69452e12023-11-15 11:20:53 -0800431func (m *moduleContext) InstallInData() bool {
432 return m.module.InstallInData()
433}
434
435func (m *moduleContext) InstallInTestcases() bool {
436 return m.module.InstallInTestcases()
437}
438
439func (m *moduleContext) InstallInSanitizerDir() bool {
440 return m.module.InstallInSanitizerDir()
441}
442
443func (m *moduleContext) InstallInRamdisk() bool {
444 return m.module.InstallInRamdisk()
445}
446
447func (m *moduleContext) InstallInVendorRamdisk() bool {
448 return m.module.InstallInVendorRamdisk()
449}
450
451func (m *moduleContext) InstallInDebugRamdisk() bool {
452 return m.module.InstallInDebugRamdisk()
453}
454
455func (m *moduleContext) InstallInRecovery() bool {
456 return m.module.InstallInRecovery()
457}
458
459func (m *moduleContext) InstallInRoot() bool {
460 return m.module.InstallInRoot()
461}
462
463func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
464 return m.module.InstallForceOS()
465}
466
Colin Crossea30d852023-11-29 16:00:16 -0800467func (m *moduleContext) InstallInOdm() bool {
468 return m.module.InstallInOdm()
469}
470
471func (m *moduleContext) InstallInProduct() bool {
472 return m.module.InstallInProduct()
473}
474
Colin Cross69452e12023-11-15 11:20:53 -0800475func (m *moduleContext) InstallInVendor() bool {
476 return m.module.InstallInVendor()
477}
478
479func (m *moduleContext) skipInstall() bool {
480 if m.module.base().commonProperties.SkipInstall {
481 return true
482 }
483
484 if m.module.base().commonProperties.HideFromMake {
485 return true
486 }
487
488 // We'll need a solution for choosing which of modules with the same name in different
489 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
490 // list of namespaces to install in a Soong-only build.
491 if !m.module.base().commonProperties.NamespaceExportedToMake {
492 return true
493 }
494
495 return false
496}
497
Jiyong Park3f627e62024-05-01 16:14:38 +0900498// Tells whether this module is installed to the full install path (ex:
499// out/target/product/<name>/<partition>) or not. If this returns false, the install build rule is
500// not created and this module can only be installed to packaging modules like android_filesystem.
501func (m *moduleContext) requiresFullInstall() bool {
502 if m.skipInstall() {
503 return false
504 }
505
506 if proptools.Bool(m.module.base().commonProperties.No_full_install) {
507 return false
508 }
509
510 return true
511}
512
Colin Cross69452e12023-11-15 11:20:53 -0800513func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
Colin Cross09ad3a62023-11-15 12:29:33 -0800514 deps ...InstallPath) InstallPath {
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800515 return m.installFile(installPath, name, srcPath, deps, false, true, nil)
Colin Cross69452e12023-11-15 11:20:53 -0800516}
517
518func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
Colin Cross09ad3a62023-11-15 12:29:33 -0800519 deps ...InstallPath) InstallPath {
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800520 return m.installFile(installPath, name, srcPath, deps, true, true, nil)
Colin Cross69452e12023-11-15 11:20:53 -0800521}
522
523func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path,
Colin Cross09ad3a62023-11-15 12:29:33 -0800524 extraZip Path, deps ...InstallPath) InstallPath {
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800525 return m.installFile(installPath, name, srcPath, deps, false, true, &extraFilesZip{
Colin Cross69452e12023-11-15 11:20:53 -0800526 zip: extraZip,
527 dir: installPath,
528 })
529}
530
531func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec {
532 fullInstallPath := installPath.Join(m, name)
533 return m.packageFile(fullInstallPath, srcPath, false)
534}
535
Justin Yun74f3f302024-05-07 14:32:14 +0900536func (m *moduleContext) getAconfigPaths() *Paths {
Yu Liu9a993132024-08-27 23:21:06 +0000537 return &m.aconfigFilePaths
538}
539
540func (m *moduleContext) setAconfigPaths(paths Paths) {
541 m.aconfigFilePaths = paths
Justin Yun74f3f302024-05-07 14:32:14 +0900542}
543
Colin Cross69452e12023-11-15 11:20:53 -0800544func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
545 licenseFiles := m.Module().EffectiveLicenseFiles()
546 spec := PackagingSpec{
547 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
548 srcPath: srcPath,
549 symlinkTarget: "",
550 executable: executable,
551 effectiveLicenseFiles: &licenseFiles,
552 partition: fullInstallPath.partition,
Jiyong Park4152b192024-04-30 21:24:21 +0900553 skipInstall: m.skipInstall(),
Justin Yun74f3f302024-05-07 14:32:14 +0900554 aconfigPaths: m.getAconfigPaths(),
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900555 archType: m.target.Arch.ArchType,
Colin Cross69452e12023-11-15 11:20:53 -0800556 }
557 m.packagingSpecs = append(m.packagingSpecs, spec)
558 return spec
559}
560
Colin Cross09ad3a62023-11-15 12:29:33 -0800561func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []InstallPath,
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800562 executable bool, hooks bool, extraZip *extraFilesZip) InstallPath {
Colin Cross69452e12023-11-15 11:20:53 -0800563
564 fullInstallPath := installPath.Join(m, name)
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800565 if hooks {
566 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
567 }
Colin Cross69452e12023-11-15 11:20:53 -0800568
Jiyong Park3f627e62024-05-01 16:14:38 +0900569 if m.requiresFullInstall() {
Yu Liubad1eef2024-08-21 22:37:35 +0000570 deps = append(deps, InstallPaths(m.TransitiveInstallFiles.ToList())...)
Yu Liu82a6d142024-08-27 19:02:29 +0000571 deps = append(deps, m.installedInitRcPaths...)
572 deps = append(deps, m.installedVintfFragmentsPaths...)
Colin Cross69452e12023-11-15 11:20:53 -0800573
574 var implicitDeps, orderOnlyDeps Paths
575
576 if m.Host() {
577 // Installed host modules might be used during the build, depend directly on their
578 // dependencies so their timestamp is updated whenever their dependency is updated
Colin Cross09ad3a62023-11-15 12:29:33 -0800579 implicitDeps = InstallPaths(deps).Paths()
Colin Cross69452e12023-11-15 11:20:53 -0800580 } else {
Colin Cross09ad3a62023-11-15 12:29:33 -0800581 orderOnlyDeps = InstallPaths(deps).Paths()
Colin Cross69452e12023-11-15 11:20:53 -0800582 }
583
584 if m.Config().KatiEnabled() {
585 // When creating the install rule in Soong but embedding in Make, write the rule to a
586 // makefile instead of directly to the ninja file so that main.mk can add the
587 // dependencies from the `required` property that are hard to resolve in Soong.
588 m.katiInstalls = append(m.katiInstalls, katiInstall{
589 from: srcPath,
590 to: fullInstallPath,
591 implicitDeps: implicitDeps,
592 orderOnlyDeps: orderOnlyDeps,
593 executable: executable,
594 extraFiles: extraZip,
595 })
596 } else {
597 rule := Cp
598 if executable {
599 rule = CpExecutable
600 }
601
602 extraCmds := ""
603 if extraZip != nil {
604 extraCmds += fmt.Sprintf(" && ( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} )",
605 extraZip.dir.String(), extraZip.zip.String())
606 extraCmds += " || ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )"
607 implicitDeps = append(implicitDeps, extraZip.zip)
608 }
609
610 m.Build(pctx, BuildParams{
611 Rule: rule,
612 Description: "install " + fullInstallPath.Base(),
613 Output: fullInstallPath,
614 Input: srcPath,
615 Implicits: implicitDeps,
616 OrderOnly: orderOnlyDeps,
617 Default: !m.Config().KatiEnabled(),
618 Args: map[string]string{
619 "extraCmds": extraCmds,
620 },
621 })
622 }
623
624 m.installFiles = append(m.installFiles, fullInstallPath)
625 }
626
627 m.packageFile(fullInstallPath, srcPath, executable)
628
629 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
630
631 return fullInstallPath
632}
633
634func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
635 fullInstallPath := installPath.Join(m, name)
636 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
637
638 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
639 if err != nil {
640 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
641 }
Jiyong Park3f627e62024-05-01 16:14:38 +0900642 if m.requiresFullInstall() {
Colin Cross69452e12023-11-15 11:20:53 -0800643
644 if m.Config().KatiEnabled() {
645 // When creating the symlink rule in Soong but embedding in Make, write the rule to a
646 // makefile instead of directly to the ninja file so that main.mk can add the
647 // dependencies from the `required` property that are hard to resolve in Soong.
648 m.katiSymlinks = append(m.katiSymlinks, katiInstall{
649 from: srcPath,
650 to: fullInstallPath,
651 })
652 } else {
653 // The symlink doesn't need updating when the target is modified, but we sometimes
654 // have a dependency on a symlink to a binary instead of to the binary directly, and
655 // the mtime of the symlink must be updated when the binary is modified, so use a
656 // normal dependency here instead of an order-only dependency.
657 m.Build(pctx, BuildParams{
658 Rule: Symlink,
659 Description: "install symlink " + fullInstallPath.Base(),
660 Output: fullInstallPath,
661 Input: srcPath,
662 Default: !m.Config().KatiEnabled(),
663 Args: map[string]string{
664 "fromPath": relPath,
665 },
666 })
667 }
668
669 m.installFiles = append(m.installFiles, fullInstallPath)
670 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
671 }
672
673 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
674 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
675 srcPath: nil,
676 symlinkTarget: relPath,
677 executable: false,
678 partition: fullInstallPath.partition,
Jiyong Park4152b192024-04-30 21:24:21 +0900679 skipInstall: m.skipInstall(),
Justin Yun74f3f302024-05-07 14:32:14 +0900680 aconfigPaths: m.getAconfigPaths(),
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900681 archType: m.target.Arch.ArchType,
Colin Cross69452e12023-11-15 11:20:53 -0800682 })
683
684 return fullInstallPath
685}
686
687// installPath/name -> absPath where absPath might be a path that is available only at runtime
688// (e.g. /apex/...)
689func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
690 fullInstallPath := installPath.Join(m, name)
691 m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
692
Jiyong Park3f627e62024-05-01 16:14:38 +0900693 if m.requiresFullInstall() {
Colin Cross69452e12023-11-15 11:20:53 -0800694 if m.Config().KatiEnabled() {
695 // When creating the symlink rule in Soong but embedding in Make, write the rule to a
696 // makefile instead of directly to the ninja file so that main.mk can add the
697 // dependencies from the `required` property that are hard to resolve in Soong.
698 m.katiSymlinks = append(m.katiSymlinks, katiInstall{
699 absFrom: absPath,
700 to: fullInstallPath,
701 })
702 } else {
703 m.Build(pctx, BuildParams{
704 Rule: Symlink,
705 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
706 Output: fullInstallPath,
707 Default: !m.Config().KatiEnabled(),
708 Args: map[string]string{
709 "fromPath": absPath,
710 },
711 })
712 }
713
714 m.installFiles = append(m.installFiles, fullInstallPath)
715 }
716
717 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
718 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
719 srcPath: nil,
720 symlinkTarget: absPath,
721 executable: false,
722 partition: fullInstallPath.partition,
Jiyong Park4152b192024-04-30 21:24:21 +0900723 skipInstall: m.skipInstall(),
Justin Yun74f3f302024-05-07 14:32:14 +0900724 aconfigPaths: m.getAconfigPaths(),
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900725 archType: m.target.Arch.ArchType,
Colin Cross69452e12023-11-15 11:20:53 -0800726 })
727
728 return fullInstallPath
729}
730
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800731func (m *moduleContext) InstallTestData(installPath InstallPath, data []DataPath) InstallPaths {
732 m.testData = append(m.testData, data...)
733
734 ret := make(InstallPaths, 0, len(data))
735 for _, d := range data {
736 relPath := d.ToRelativeInstallPath()
737 installed := m.installFile(installPath, relPath, d.SrcPath, nil, false, false, nil)
738 ret = append(ret, installed)
739 }
740
741 return ret
742}
743
Colin Cross69452e12023-11-15 11:20:53 -0800744func (m *moduleContext) CheckbuildFile(srcPath Path) {
745 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
746}
747
748func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
749 return m.bp
750}
751
752func (m *moduleContext) LicenseMetadataFile() Path {
Yu Liuec810542024-08-26 18:09:15 +0000753 return m.licenseMetadataFile
Colin Cross69452e12023-11-15 11:20:53 -0800754}
755
Colin Crossd6fd0132023-11-06 13:54:06 -0800756func (m *moduleContext) ModuleInfoJSON() *ModuleInfoJSON {
Yu Liu4297ad92024-08-27 19:50:13 +0000757 if moduleInfoJSON := m.moduleInfoJSON; moduleInfoJSON != nil {
Colin Crossd6fd0132023-11-06 13:54:06 -0800758 return moduleInfoJSON
759 }
760 moduleInfoJSON := &ModuleInfoJSON{}
Yu Liu4297ad92024-08-27 19:50:13 +0000761 m.moduleInfoJSON = moduleInfoJSON
Colin Crossd6fd0132023-11-06 13:54:06 -0800762 return moduleInfoJSON
763}
764
mrziwange6c85812024-05-22 14:36:09 -0700765func (m *moduleContext) SetOutputFiles(outputFiles Paths, tag string) {
766 if tag == "" {
Yu Liu876b7ce2024-08-21 18:20:13 +0000767 if len(m.outputFiles.DefaultOutputFiles) > 0 {
mrziwange6c85812024-05-22 14:36:09 -0700768 m.ModuleErrorf("Module %s default OutputFiles cannot be overwritten", m.ModuleName())
769 }
Yu Liu876b7ce2024-08-21 18:20:13 +0000770 m.outputFiles.DefaultOutputFiles = outputFiles
mrziwange6c85812024-05-22 14:36:09 -0700771 } else {
Yu Liu876b7ce2024-08-21 18:20:13 +0000772 if m.outputFiles.TaggedOutputFiles == nil {
773 m.outputFiles.TaggedOutputFiles = make(map[string]Paths)
mrziwang57768d72024-06-06 11:31:51 -0700774 }
Yu Liu876b7ce2024-08-21 18:20:13 +0000775 if _, exists := m.outputFiles.TaggedOutputFiles[tag]; exists {
mrziwange6c85812024-05-22 14:36:09 -0700776 m.ModuleErrorf("Module %s OutputFiles at tag %s cannot be overwritten", m.ModuleName(), tag)
777 } else {
Yu Liu876b7ce2024-08-21 18:20:13 +0000778 m.outputFiles.TaggedOutputFiles[tag] = outputFiles
mrziwange6c85812024-05-22 14:36:09 -0700779 }
780 }
781}
782
Yu Liu876b7ce2024-08-21 18:20:13 +0000783func (m *moduleContext) GetOutputFiles() OutputFilesInfo {
784 return m.outputFiles
785}
786
Yu Liubad1eef2024-08-21 22:37:35 +0000787func (m *moduleContext) SetLicenseInstallMap(installMap []string) {
788 m.licenseInstallMap = append(m.licenseInstallMap, installMap...)
789}
790
Wei Lia1aa2972024-06-21 13:08:51 -0700791func (m *moduleContext) ComplianceMetadataInfo() *ComplianceMetadataInfo {
Yu Liu9a993132024-08-27 23:21:06 +0000792 if m.complianceMetadataInfo == nil {
793 m.complianceMetadataInfo = NewComplianceMetadataInfo()
Wei Lia1aa2972024-06-21 13:08:51 -0700794 }
Yu Liu9a993132024-08-27 23:21:06 +0000795 return m.complianceMetadataInfo
Wei Lia1aa2972024-06-21 13:08:51 -0700796}
797
Colin Cross69452e12023-11-15 11:20:53 -0800798// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
799// be tagged with `android:"path" to support automatic source module dependency resolution.
800//
801// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
802func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
803 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
804}
805
806// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
807// be tagged with `android:"path" to support automatic source module dependency resolution.
808//
809// Deprecated: use PathForModuleSrc instead.
810func (m *moduleContext) ExpandSource(srcFile, _ string) Path {
811 return PathForModuleSrc(m, srcFile)
812}
813
814// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
815// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
816// dependency resolution.
817func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) OptionalPath {
818 if srcFile != nil {
819 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
820 }
821 return OptionalPath{}
822}
823
Cole Faust43ddd082024-06-17 12:32:40 -0700824func (m *moduleContext) RequiredModuleNames(ctx ConfigAndErrorContext) []string {
825 return m.module.RequiredModuleNames(ctx)
Colin Cross69452e12023-11-15 11:20:53 -0800826}
827
828func (m *moduleContext) HostRequiredModuleNames() []string {
829 return m.module.HostRequiredModuleNames()
830}
831
832func (m *moduleContext) TargetRequiredModuleNames() []string {
833 return m.module.TargetRequiredModuleNames()
834}
Yu Liu9a993132024-08-27 23:21:06 +0000835
836func (m *moduleContext) getContainersInfo() ContainersInfo {
837 return m.containersInfo
838}
839
840func (m *moduleContext) setContainersInfo(info ContainersInfo) {
841 m.containersInfo = info
842}