1// 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 buildProp != nil { 87 if buildPropPath := PathForModuleSrc(ctx, proptools.String(buildProp)); buildPropPath != nil { 88 buildProps = append(buildProps, buildPropPath) 89 } 90 } 91 } 92 return buildProps 93} 94 95func (r *recoveryBuildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) { 96 if !r.InstallInRecovery() { 97 ctx.ModuleErrorf("recovery_build_prop module must set `recovery` property to true") 98 } 99 r.outputFilePath = PathForModuleOut(ctx, ctx.ModuleName(), "prop.default") 100 101 // Replicates the logic in https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2733;drc=0585bb1bcf4c89065adaf709f48acc8b869fd3ce 102 rule := NewRuleBuilder(pctx, ctx) 103 rule.Command().Text("rm").FlagWithOutput("-f ", r.outputFilePath) 104 rule.Command().Text("cat"). 105 Inputs(r.getBuildProps(ctx)). 106 Text(">>"). 107 Output(r.outputFilePath) 108 r.appendRecoveryUIProperties(ctx, rule) 109 110 rule.Build(ctx.ModuleName(), "generating recovery prop.default") 111 r.installPath = PathForModuleInstall(ctx) 112 ctx.InstallFile(r.installPath, "prop.default", r.outputFilePath) 113} 114