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 ( |
Cole Faust | 996b522 | 2024-11-06 10:32:06 -0800 | [diff] [blame] | 18 | "github.com/google/blueprint" |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 19 | "github.com/google/blueprint/proptools" |
| 20 | ) |
| 21 | |
Cole Faust | 996b522 | 2024-11-06 10:32:06 -0800 | [diff] [blame] | 22 | var ( |
| 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 | |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 35 | type 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 | |
| 47 | type androidInfoModule struct { |
| 48 | ModuleBase |
| 49 | |
| 50 | properties androidInfoProperties |
| 51 | } |
| 52 | |
| 53 | func (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 | } |
Cole Faust | 996b522 | 2024-11-06 10:32:06 -0800 | [diff] [blame] | 58 | androidInfoTxtName := proptools.StringDefault(p.properties.Stem, ctx.ModuleName()+".txt") |
| 59 | androidInfoTxt := PathForModuleOut(ctx, androidInfoTxtName) |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 60 | androidInfoProp := androidInfoTxt.ReplaceExtension(ctx, "prop") |
| 61 | |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 62 | if boardInfoFiles := PathsForModuleSrc(ctx, p.properties.Board_info_files); len(boardInfoFiles) > 0 { |
Cole Faust | 996b522 | 2024-11-06 10:32:06 -0800 | [diff] [blame] | 63 | ctx.Build(pctx, BuildParams{ |
| 64 | Rule: mergeAndRemoveComments, |
| 65 | Inputs: boardInfoFiles, |
| 66 | Output: androidInfoTxt, |
| 67 | }) |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 68 | } else if bootloaderBoardName := proptools.String(p.properties.Bootloader_board_name); bootloaderBoardName != "" { |
Cole Faust | 996b522 | 2024-11-06 10:32:06 -0800 | [diff] [blame] | 69 | WriteFileRule(ctx, androidInfoTxt, "board="+bootloaderBoardName) |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 70 | } else { |
Cole Faust | 996b522 | 2024-11-06 10:32:06 -0800 | [diff] [blame] | 71 | WriteFileRule(ctx, androidInfoTxt, "") |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 74 | // Create android_info.prop |
Cole Faust | 996b522 | 2024-11-06 10:32:06 -0800 | [diff] [blame] | 75 | ctx.Build(pctx, BuildParams{ |
| 76 | Rule: androidInfoTxtToProp, |
| 77 | Input: androidInfoTxt, |
| 78 | Output: androidInfoProp, |
| 79 | }) |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 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. |
| 86 | func AndroidInfoFactory() Module { |
| 87 | module := &androidInfoModule{} |
| 88 | module.AddProperties(&module.properties) |
| 89 | InitAndroidModule(module) |
| 90 | return module |
| 91 | } |