1// Copyright 2024 The Android Open Source Project 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 "github.com/google/blueprint" 19 "github.com/google/blueprint/proptools" 20) 21 22var ( 23 mergeAndRemoveComments = pctx.AndroidStaticRule("merge_and_remove_comments", 24 blueprint.RuleParams{ 25 Command: "cat $in | grep -v '#' > $out", 26 }, 27 ) 28 androidInfoTxtToProp = pctx.AndroidStaticRule("android_info_txt_to_prop", 29 blueprint.RuleParams{ 30 Command: "grep 'require version-' $in | sed -e 's/require version-/ro.build.expect./g' > $out", 31 }, 32 ) 33) 34 35type androidInfoProperties struct { 36 // Name of output file. Defaults to module name 37 Stem *string 38 39 // Paths of board-info.txt files. 40 Board_info_files []string `android:"path"` 41 42 // Name of bootloader board. If board_info_files is empty, `board={bootloader_board_name}` will 43 // be printed to output. Ignored if board_info_files is not empty. 44 Bootloader_board_name *string 45} 46 47type androidInfoModule struct { 48 ModuleBase 49 50 properties androidInfoProperties 51} 52 53func (p *androidInfoModule) GenerateAndroidBuildActions(ctx ModuleContext) { 54 if len(p.properties.Board_info_files) > 0 && p.properties.Bootloader_board_name != nil { 55 ctx.ModuleErrorf("Either Board_info_files or Bootloader_board_name should be set. Please remove one of them\n") 56 return 57 } 58 androidInfoTxtName := proptools.StringDefault(p.properties.Stem, ctx.ModuleName()+".txt") 59 androidInfoTxt := PathForModuleOut(ctx, androidInfoTxtName) 60 androidInfoProp := androidInfoTxt.ReplaceExtension(ctx, "prop") 61 62 if boardInfoFiles := PathsForModuleSrc(ctx, p.properties.Board_info_files); len(boardInfoFiles) > 0 { 63 ctx.Build(pctx, BuildParams{ 64 Rule: mergeAndRemoveComments, 65 Inputs: boardInfoFiles, 66 Output: androidInfoTxt, 67 }) 68 } else if bootloaderBoardName := proptools.String(p.properties.Bootloader_board_name); bootloaderBoardName != "" { 69 WriteFileRule(ctx, androidInfoTxt, "board="+bootloaderBoardName) 70 } else { 71 WriteFileRule(ctx, androidInfoTxt, "") 72 } 73 74 // Create android_info.prop 75 ctx.Build(pctx, BuildParams{ 76 Rule: androidInfoTxtToProp, 77 Input: androidInfoTxt, 78 Output: androidInfoProp, 79 }) 80 81 ctx.SetOutputFiles(Paths{androidInfoProp}, "") 82} 83 84// android_info module generate a file named android-info.txt that contains various information 85// about the device we're building for. This file is typically packaged up with everything else. 86func AndroidInfoFactory() Module { 87 module := &androidInfoModule{} 88 module.AddProperties(&module.properties) 89 InitAndroidModule(module) 90 return module 91} 92