blob: 91d19042133331afb5119691f1bccaf072f92a4d [file] [log] [blame]
Jihoon Kangefd04b92024-12-10 23:35:09 +00001// Copyright 2024 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 "github.com/google/blueprint/proptools"
18
19func init() {
20 RegisterModuleType("recovery_build_prop", RecoveryBuildPropModuleFactory)
21}
22
23type recoveryBuildPropProperties struct {
24 // Path to the system build.prop file
25 System_build_prop *string `android:"path"`
26
27 // Path to the vendor build.prop file
28 Vendor_build_prop *string `android:"path"`
29
30 // Path to the odm build.prop file
31 Odm_build_prop *string `android:"path"`
32
33 // Path to the product build.prop file
34 Product_build_prop *string `android:"path"`
35
36 // Path to the system_ext build.prop file
37 System_ext_build_prop *string `android:"path"`
38}
39
40type recoveryBuildPropModule struct {
41 ModuleBase
42 properties recoveryBuildPropProperties
43
44 outputFilePath ModuleOutPath
45
46 installPath InstallPath
47}
48
49func RecoveryBuildPropModuleFactory() Module {
50 module := &recoveryBuildPropModule{}
51 module.AddProperties(&module.properties)
52 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
53 return module
54}
55
56// Overrides ctx.Module().InstallInRoot().
57// recovery_build_prop module always installs in root so that the prop.default
58// file is installed in recovery/root instead of recovery/root/system
59func (r *recoveryBuildPropModule) InstallInRoot() bool {
60 return true
61}
62
63func (r *recoveryBuildPropModule) appendRecoveryUIProperties(ctx ModuleContext, rule *RuleBuilder) {
64 rule.Command().Text("echo '#' >>").Output(r.outputFilePath)
65 rule.Command().Text("echo '# RECOVERY UI BUILD PROPERTIES' >>").Output(r.outputFilePath)
66 rule.Command().Text("echo '#' >>").Output(r.outputFilePath)
67
68 for propName, val := range ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.PrivateRecoveryUiProperties {
69 if len(val) > 0 {
70 rule.Command().
71 Textf("echo ro.recovery.ui.%s=%s >>", propName, val).
72 Output(r.outputFilePath)
73 }
74 }
75}
76
77func (r *recoveryBuildPropModule) getBuildProps(ctx ModuleContext) Paths {
78 var buildProps Paths
79 for _, buildProp := range []*string{
80 r.properties.System_build_prop,
81 r.properties.Vendor_build_prop,
82 r.properties.Odm_build_prop,
83 r.properties.Product_build_prop,
84 r.properties.System_ext_build_prop,
85 } {
86 if buildPropPath := PathForModuleSrc(ctx, proptools.String(buildProp)); buildPropPath != nil {
87 buildProps = append(buildProps, buildPropPath)
88 }
89 }
90 return buildProps
91}
92
93func (r *recoveryBuildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
94 if !r.InstallInRecovery() {
95 ctx.ModuleErrorf("recovery_build_prop module must set `recovery` property to true")
96 }
97 r.outputFilePath = PathForModuleOut(ctx, ctx.ModuleName(), "prop.default")
98
99 // Replicates the logic in https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2733;drc=0585bb1bcf4c89065adaf709f48acc8b869fd3ce
100 rule := NewRuleBuilder(pctx, ctx)
101 rule.Command().Text("rm").FlagWithOutput("-f ", r.outputFilePath)
102 rule.Command().Text("cat").
103 Inputs(r.getBuildProps(ctx)).
104 Text(">>").
105 Output(r.outputFilePath)
106 r.appendRecoveryUIProperties(ctx, rule)
107
108 rule.Build(ctx.ModuleName(), "generating recovery prop.default")
109 r.installPath = PathForModuleInstall(ctx)
110 ctx.InstallFile(r.installPath, "prop.default", r.outputFilePath)
111}