Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame^] | 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
| 18 | "github.com/google/blueprint/proptools" |
| 19 | ) |
| 20 | |
| 21 | type androidInfoProperties struct { |
| 22 | // Name of output file. Defaults to module name |
| 23 | Stem *string |
| 24 | |
| 25 | // Paths of board-info.txt files. |
| 26 | Board_info_files []string `android:"path"` |
| 27 | |
| 28 | // Name of bootloader board. If board_info_files is empty, `board={bootloader_board_name}` will |
| 29 | // be printed to output. Ignored if board_info_files is not empty. |
| 30 | Bootloader_board_name *string |
| 31 | } |
| 32 | |
| 33 | type androidInfoModule struct { |
| 34 | ModuleBase |
| 35 | |
| 36 | properties androidInfoProperties |
| 37 | } |
| 38 | |
| 39 | func (p *androidInfoModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 40 | if len(p.properties.Board_info_files) > 0 && p.properties.Bootloader_board_name != nil { |
| 41 | ctx.ModuleErrorf("Either Board_info_files or Bootloader_board_name should be set. Please remove one of them\n") |
| 42 | return |
| 43 | } |
| 44 | outName := proptools.StringDefault(p.properties.Stem, ctx.ModuleName()+".txt") |
| 45 | androidInfoTxt := PathForModuleOut(ctx, outName).OutputPath |
| 46 | androidInfoProp := androidInfoTxt.ReplaceExtension(ctx, "prop") |
| 47 | |
| 48 | rule := NewRuleBuilder(pctx, ctx) |
| 49 | |
| 50 | if boardInfoFiles := PathsForModuleSrc(ctx, p.properties.Board_info_files); len(boardInfoFiles) > 0 { |
| 51 | rule.Command().Text("cat").Inputs(boardInfoFiles). |
| 52 | Text(" | grep").FlagWithArg("-v ", "'#'").FlagWithOutput("> ", androidInfoTxt) |
| 53 | } else if bootloaderBoardName := proptools.String(p.properties.Bootloader_board_name); bootloaderBoardName != "" { |
| 54 | rule.Command().Text("echo").Text("'board="+bootloaderBoardName+"'").FlagWithOutput("> ", androidInfoTxt) |
| 55 | } else { |
| 56 | rule.Command().Text("echo").Text("''").FlagWithOutput("> ", androidInfoTxt) |
| 57 | } |
| 58 | |
| 59 | rule.Build(ctx.ModuleName(), "generating android-info.prop") |
| 60 | |
| 61 | // Create android_info.prop |
| 62 | rule = NewRuleBuilder(pctx, ctx) |
| 63 | rule.Command().Text("cat").Input(androidInfoTxt). |
| 64 | Text(" | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' >").Output(androidInfoProp) |
| 65 | rule.Build(ctx.ModuleName()+"prop", "generating android-info.prop") |
| 66 | |
| 67 | ctx.SetOutputFiles(Paths{androidInfoProp}, "") |
| 68 | } |
| 69 | |
| 70 | // android_info module generate a file named android-info.txt that contains various information |
| 71 | // about the device we're building for. This file is typically packaged up with everything else. |
| 72 | func AndroidInfoFactory() Module { |
| 73 | module := &androidInfoModule{} |
| 74 | module.AddProperties(&module.properties) |
| 75 | InitAndroidModule(module) |
| 76 | return module |
| 77 | } |