blob: cd5f0964475f16f551518a52e3b5dd3e2e3fc470 [file] [log] [blame]
Bill Yang42816dc2024-10-07 10:02:31 +00001// Copyright 2024 Google Inc. All rights reserved.
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 "fmt"
19 "strings"
20
21 "github.com/google/blueprint/proptools"
22)
23
24const (
25 deviceCmType = "device_cm"
26 systemManifestType = "system_manifest"
27 productManifestType = "product_manifest"
28 systemExtManifestType = "system_ext_manifest"
29
30 defaultDcm = "system/libhidl/vintfdata/device_compatibility_matrix.default.xml"
31 defaultSystemManifest = "system/libhidl/vintfdata/manifest.xml"
32 defaultSystemExtManifest = "system/libhidl/vintfdata/system_ext_manifest.default.xml"
33)
34
35type vintfDataProperties struct {
36 // Optional name for the installed file. If unspecified it will be manifest.xml by default.
37 Filename *string
38
39 // Type of the vintf data type, the allowed type are device_compatibility_matrix, system_manifest,
40 // product_manifest, and system_ext_manifest.
41 Type *string
42}
43
44type vintfDataRule struct {
45 ModuleBase
46
47 properties vintfDataProperties
48
49 installDirPath InstallPath
50 outputFilePath OutputPath
51 noAction bool
52}
53
54func init() {
55 registerVintfDataComponents(InitRegistrationContext)
56}
57
58func registerVintfDataComponents(ctx RegistrationContext) {
59 ctx.RegisterModuleType("vintf_data", vintfDataFactory)
60}
61
62// vintf_fragment module processes vintf fragment file and installs under etc/vintf/manifest.
63func vintfDataFactory() Module {
64 m := &vintfDataRule{}
65 m.AddProperties(
66 &m.properties,
67 )
68 InitAndroidArchModule(m, DeviceSupported, MultilibFirst)
69
70 return m
71}
72
73func (m *vintfDataRule) GenerateAndroidBuildActions(ctx ModuleContext) {
74 builder := NewRuleBuilder(pctx, ctx)
75 gensrc := PathForModuleOut(ctx, "manifest.xml")
76 assembleVintfEnvs := []string{}
77 inputPaths := make(Paths, 0)
78
79 switch proptools.String(m.properties.Type) {
80 case deviceCmType:
81 assembleVintfEnvs = append(assembleVintfEnvs, fmt.Sprintf("BOARD_SYSTEMSDK_VERSIONS=\"%s\"", strings.Join(ctx.DeviceConfig().SystemSdkVersions(), " ")))
82
83 deviceMatrixs := PathsForSource(ctx, ctx.Config().DeviceMatrixFile())
84 if len(deviceMatrixs) > 0 {
85 inputPaths = append(inputPaths, deviceMatrixs...)
86 } else {
87 inputPaths = append(inputPaths, PathForSource(ctx, defaultDcm))
88 }
89 case systemManifestType:
90 assembleVintfEnvs = append(assembleVintfEnvs, fmt.Sprintf("PLATFORM_SYSTEMSDK_VERSIONS=\"%s\"", strings.Join(ctx.DeviceConfig().PlatformSystemSdkVersions(), " ")))
91
92 inputPaths = append(inputPaths, PathForSource(ctx, defaultSystemManifest))
93 systemManifestFiles := PathsForSource(ctx, ctx.Config().SystemManifestFile())
94 if len(systemManifestFiles) > 0 {
95 inputPaths = append(inputPaths, systemManifestFiles...)
96 }
97 case productManifestType:
98 productManifestFiles := PathsForSource(ctx, ctx.Config().ProductManifestFiles())
99 // Only need to generate the manifest if PRODUCT_MANIFEST_FILES not defined.
100 if len(productManifestFiles) == 0 {
101 m.noAction = true
102 return
103 }
104
105 inputPaths = append(inputPaths, productManifestFiles...)
106 case systemExtManifestType:
107 assembleVintfEnvs = append(assembleVintfEnvs, fmt.Sprintf("PROVIDED_VNDK_VERSIONS=\"%s\"", strings.Join(ctx.DeviceConfig().ExtraVndkVersions(), " ")))
108
109 inputPaths = append(inputPaths, PathForSource(ctx, defaultSystemExtManifest))
110 systemExtManifestFiles := PathsForSource(ctx, ctx.Config().SystemExtManifestFiles())
111 if len(systemExtManifestFiles) > 0 {
112 inputPaths = append(inputPaths, systemExtManifestFiles...)
113 }
114 default:
115 panic(fmt.Errorf("For %s: The attribute 'type' value only allowed device_cm, system_manifest, product_manifest, system_ext_manifest!", ctx.Module().Name()))
116 }
117
118 // Process vintf fragment source file with assemble_vintf tool
119 builder.Command().
120 Flags(assembleVintfEnvs).
121 BuiltTool("assemble_vintf").
122 FlagWithArg("-i ", strings.Join(inputPaths.Strings(), ":")).
123 FlagWithOutput("-o ", gensrc)
124
125 builder.Build("assemble_vintf", "Process vintf data "+gensrc.String())
126
127 m.installDirPath = PathForModuleInstall(ctx, "etc", "vintf")
128 m.outputFilePath = gensrc.OutputPath
129
130 installFileName := "manifest.xml"
131 if filename := proptools.String(m.properties.Filename); filename != "" {
132 installFileName = filename
133 }
134
135 ctx.InstallFile(m.installDirPath, installFileName, gensrc)
136}
137
138// Make this module visible to AndroidMK so it can be referenced from modules defined from Android.mk files
139func (m *vintfDataRule) AndroidMkEntries() []AndroidMkEntries {
140 if m.noAction {
141 return []AndroidMkEntries{}
142 }
143
144 return []AndroidMkEntries{{
145 Class: "ETC",
146 OutputFile: OptionalPathForPath(m.outputFilePath),
147 }}
148}