blob: a8d3d4e2cc92574d887cf2dd7aca1a4b0dc12e75 [file] [log] [blame]
Spandan Dasc32e0462024-11-05 17:55:39 +00001// 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 (
Cole Faust996b5222024-11-06 10:32:06 -080018 "github.com/google/blueprint"
Spandan Dasc32e0462024-11-05 17:55:39 +000019 "github.com/google/blueprint/proptools"
20)
21
Cole Faust996b5222024-11-06 10:32:06 -080022var (
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 Dasc32e0462024-11-05 17:55:39 +000035type 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 }
Cole Faust996b5222024-11-06 10:32:06 -080058 androidInfoTxtName := proptools.StringDefault(p.properties.Stem, ctx.ModuleName()+".txt")
59 androidInfoTxt := PathForModuleOut(ctx, androidInfoTxtName)
Spandan Dasc32e0462024-11-05 17:55:39 +000060 androidInfoProp := androidInfoTxt.ReplaceExtension(ctx, "prop")
61
Spandan Dasc32e0462024-11-05 17:55:39 +000062 if boardInfoFiles := PathsForModuleSrc(ctx, p.properties.Board_info_files); len(boardInfoFiles) > 0 {
Cole Faust996b5222024-11-06 10:32:06 -080063 ctx.Build(pctx, BuildParams{
64 Rule: mergeAndRemoveComments,
65 Inputs: boardInfoFiles,
66 Output: androidInfoTxt,
67 })
Spandan Dasc32e0462024-11-05 17:55:39 +000068 } else if bootloaderBoardName := proptools.String(p.properties.Bootloader_board_name); bootloaderBoardName != "" {
Cole Faust996b5222024-11-06 10:32:06 -080069 WriteFileRule(ctx, androidInfoTxt, "board="+bootloaderBoardName)
Spandan Dasc32e0462024-11-05 17:55:39 +000070 } else {
Cole Faust996b5222024-11-06 10:32:06 -080071 WriteFileRule(ctx, androidInfoTxt, "")
Spandan Dasc32e0462024-11-05 17:55:39 +000072 }
73
Spandan Dasc32e0462024-11-05 17:55:39 +000074 // Create android_info.prop
Cole Faust996b5222024-11-06 10:32:06 -080075 ctx.Build(pctx, BuildParams{
76 Rule: androidInfoTxtToProp,
77 Input: androidInfoTxt,
78 Output: androidInfoProp,
79 })
Spandan Dasc32e0462024-11-05 17:55:39 +000080
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}