1*333d2b36SAndroid Build Coastguard Worker// Copyright 2024 The Android Open Source Project 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Worker 15*333d2b36SAndroid Build Coastguard Workerpackage android 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Workerimport ( 18*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint" 19*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint/proptools" 20*333d2b36SAndroid Build Coastguard Worker) 21*333d2b36SAndroid Build Coastguard Worker 22*333d2b36SAndroid Build Coastguard Workervar ( 23*333d2b36SAndroid Build Coastguard Worker mergeAndRemoveComments = pctx.AndroidStaticRule("merge_and_remove_comments", 24*333d2b36SAndroid Build Coastguard Worker blueprint.RuleParams{ 25*333d2b36SAndroid Build Coastguard Worker Command: "cat $in | grep -v '#' > $out", 26*333d2b36SAndroid Build Coastguard Worker }, 27*333d2b36SAndroid Build Coastguard Worker ) 28*333d2b36SAndroid Build Coastguard Worker androidInfoTxtToProp = pctx.AndroidStaticRule("android_info_txt_to_prop", 29*333d2b36SAndroid Build Coastguard Worker blueprint.RuleParams{ 30*333d2b36SAndroid Build Coastguard Worker Command: "grep 'require version-' $in | sed -e 's/require version-/ro.build.expect./g' > $out", 31*333d2b36SAndroid Build Coastguard Worker }, 32*333d2b36SAndroid Build Coastguard Worker ) 33*333d2b36SAndroid Build Coastguard Worker) 34*333d2b36SAndroid Build Coastguard Worker 35*333d2b36SAndroid Build Coastguard Workertype androidInfoProperties struct { 36*333d2b36SAndroid Build Coastguard Worker // Name of output file. Defaults to module name 37*333d2b36SAndroid Build Coastguard Worker Stem *string 38*333d2b36SAndroid Build Coastguard Worker 39*333d2b36SAndroid Build Coastguard Worker // Paths of board-info.txt files. 40*333d2b36SAndroid Build Coastguard Worker Board_info_files []string `android:"path"` 41*333d2b36SAndroid Build Coastguard Worker 42*333d2b36SAndroid Build Coastguard Worker // Name of bootloader board. If board_info_files is empty, `board={bootloader_board_name}` will 43*333d2b36SAndroid Build Coastguard Worker // be printed to output. Ignored if board_info_files is not empty. 44*333d2b36SAndroid Build Coastguard Worker Bootloader_board_name *string 45*333d2b36SAndroid Build Coastguard Worker} 46*333d2b36SAndroid Build Coastguard Worker 47*333d2b36SAndroid Build Coastguard Workertype androidInfoModule struct { 48*333d2b36SAndroid Build Coastguard Worker ModuleBase 49*333d2b36SAndroid Build Coastguard Worker 50*333d2b36SAndroid Build Coastguard Worker properties androidInfoProperties 51*333d2b36SAndroid Build Coastguard Worker} 52*333d2b36SAndroid Build Coastguard Worker 53*333d2b36SAndroid Build Coastguard Workerfunc (p *androidInfoModule) GenerateAndroidBuildActions(ctx ModuleContext) { 54*333d2b36SAndroid Build Coastguard Worker if len(p.properties.Board_info_files) > 0 && p.properties.Bootloader_board_name != nil { 55*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("Either Board_info_files or Bootloader_board_name should be set. Please remove one of them\n") 56*333d2b36SAndroid Build Coastguard Worker return 57*333d2b36SAndroid Build Coastguard Worker } 58*333d2b36SAndroid Build Coastguard Worker androidInfoTxtName := proptools.StringDefault(p.properties.Stem, ctx.ModuleName()+".txt") 59*333d2b36SAndroid Build Coastguard Worker androidInfoTxt := PathForModuleOut(ctx, androidInfoTxtName) 60*333d2b36SAndroid Build Coastguard Worker androidInfoProp := androidInfoTxt.ReplaceExtension(ctx, "prop") 61*333d2b36SAndroid Build Coastguard Worker 62*333d2b36SAndroid Build Coastguard Worker if boardInfoFiles := PathsForModuleSrc(ctx, p.properties.Board_info_files); len(boardInfoFiles) > 0 { 63*333d2b36SAndroid Build Coastguard Worker ctx.Build(pctx, BuildParams{ 64*333d2b36SAndroid Build Coastguard Worker Rule: mergeAndRemoveComments, 65*333d2b36SAndroid Build Coastguard Worker Inputs: boardInfoFiles, 66*333d2b36SAndroid Build Coastguard Worker Output: androidInfoTxt, 67*333d2b36SAndroid Build Coastguard Worker }) 68*333d2b36SAndroid Build Coastguard Worker } else if bootloaderBoardName := proptools.String(p.properties.Bootloader_board_name); bootloaderBoardName != "" { 69*333d2b36SAndroid Build Coastguard Worker WriteFileRule(ctx, androidInfoTxt, "board="+bootloaderBoardName) 70*333d2b36SAndroid Build Coastguard Worker } else { 71*333d2b36SAndroid Build Coastguard Worker WriteFileRule(ctx, androidInfoTxt, "") 72*333d2b36SAndroid Build Coastguard Worker } 73*333d2b36SAndroid Build Coastguard Worker 74*333d2b36SAndroid Build Coastguard Worker // Create android_info.prop 75*333d2b36SAndroid Build Coastguard Worker ctx.Build(pctx, BuildParams{ 76*333d2b36SAndroid Build Coastguard Worker Rule: androidInfoTxtToProp, 77*333d2b36SAndroid Build Coastguard Worker Input: androidInfoTxt, 78*333d2b36SAndroid Build Coastguard Worker Output: androidInfoProp, 79*333d2b36SAndroid Build Coastguard Worker }) 80*333d2b36SAndroid Build Coastguard Worker 81*333d2b36SAndroid Build Coastguard Worker ctx.SetOutputFiles(Paths{androidInfoProp}, "") 82*333d2b36SAndroid Build Coastguard Worker} 83*333d2b36SAndroid Build Coastguard Worker 84*333d2b36SAndroid Build Coastguard Worker// android_info module generate a file named android-info.txt that contains various information 85*333d2b36SAndroid Build Coastguard Worker// about the device we're building for. This file is typically packaged up with everything else. 86*333d2b36SAndroid Build Coastguard Workerfunc AndroidInfoFactory() Module { 87*333d2b36SAndroid Build Coastguard Worker module := &androidInfoModule{} 88*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&module.properties) 89*333d2b36SAndroid Build Coastguard Worker InitAndroidModule(module) 90*333d2b36SAndroid Build Coastguard Worker return module 91*333d2b36SAndroid Build Coastguard Worker} 92