blob: bd99cfa4c0f78f9bd9fd2a02a23a0c69c7465c23 [file] [log] [blame]
Steven Morelandd56e5bb2017-07-18 22:04:16 -07001// Copyright (C) 2017 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 hidl
16
17import (
Steven Morelandd9fd1952018-11-08 18:14:37 -080018 "fmt"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070019 "strings"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070020
Steven Moreland744eb322018-07-25 16:31:08 -070021 "github.com/google/blueprint"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070022 "github.com/google/blueprint/proptools"
23
24 "android/soong/android"
25 "android/soong/cc"
26 "android/soong/genrule"
27 "android/soong/java"
28)
29
30var (
31 hidlInterfaceSuffix = "_interface"
Steven Moreland744eb322018-07-25 16:31:08 -070032
33 pctx = android.NewPackageContext("android/hidl")
34
35 hidl = pctx.HostBinToolVariable("hidl", "hidl-gen")
36 hidlRule = pctx.StaticRule("hidlRule", blueprint.RuleParams{
37 Depfile: "${depfile}",
38 Deps: blueprint.DepsGCC,
Steven Morelandbc98bdb2018-10-31 14:47:07 -070039 Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${depfile} -o ${genDir} -L ${language} ${roots} ${fqName}",
Steven Moreland744eb322018-07-25 16:31:08 -070040 CommandDeps: []string{"${hidl}"},
41 Description: "HIDL ${language}: ${in} => ${out}",
42 }, "depfile", "fqName", "genDir", "language", "roots")
Steven Morelandd56e5bb2017-07-18 22:04:16 -070043)
44
45func init() {
46 android.RegisterModuleType("hidl_interface", hidlInterfaceFactory)
47}
48
Steven Moreland744eb322018-07-25 16:31:08 -070049type hidlGenProperties struct {
50 Language string
51 FqName string
Steven Morelandd9fd1952018-11-08 18:14:37 -080052 Root string
Steven Moreland744eb322018-07-25 16:31:08 -070053 Interfaces []string
54 Inputs []string
55 Outputs []string
56}
57
58type hidlGenRule struct {
59 android.ModuleBase
60
61 properties hidlGenProperties
62
63 genOutputDir android.Path
64 genInputs android.Paths
65 genOutputs android.WritablePaths
66}
67
68var _ android.SourceFileProducer = (*hidlGenRule)(nil)
69var _ genrule.SourceFileGenerator = (*hidlGenRule)(nil)
70
71func (g *hidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
72 g.genOutputDir = android.PathForModuleGen(ctx)
73
74 for _, input := range g.properties.Inputs {
75 g.genInputs = append(g.genInputs, android.PathForModuleSrc(ctx, input))
76 }
77
78 for _, output := range g.properties.Outputs {
79 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
80 }
81
82 var fullRootOptions []string
Steven Morelandd9fd1952018-11-08 18:14:37 -080083 var currentPaths android.Paths
Steven Moreland744eb322018-07-25 16:31:08 -070084 ctx.VisitDirectDeps(func(dep android.Module) {
Steven Morelandd9fd1952018-11-08 18:14:37 -080085 switch t := dep.(type) {
86 case *hidlInterface:
87 fullRootOptions = append(fullRootOptions, t.properties.Full_root_option)
88 case *hidlPackageRoot:
89 currentPaths = append(currentPaths, t.getCurrentPaths()...)
90 default:
91 panic(fmt.Sprintf("Unrecognized hidlGenProperties dependency: %T", t))
92 }
Steven Moreland744eb322018-07-25 16:31:08 -070093 })
94
Steven Morelandd9fd1952018-11-08 18:14:37 -080095 if len(currentPaths) > 1 {
96 panic(fmt.Sprintf("Expecting one or zero current paths, but found: %v", currentPaths))
97 }
98
Steven Moreland744eb322018-07-25 16:31:08 -070099 fullRootOptions = android.FirstUniqueStrings(fullRootOptions)
100
101 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
102 Rule: hidlRule,
Steven Morelandd9fd1952018-11-08 18:14:37 -0800103 Inputs: append(g.genInputs, currentPaths...),
Steven Moreland744eb322018-07-25 16:31:08 -0700104 Output: g.genOutputs[0],
105 ImplicitOutputs: g.genOutputs[1:],
106 Args: map[string]string{
107 "depfile": g.genOutputs[0].String() + ".d",
108 "genDir": g.genOutputDir.String(),
109 "fqName": g.properties.FqName,
110 "language": g.properties.Language,
111 "roots": strings.Join(fullRootOptions, " "),
112 },
113 })
114}
115
116func (g *hidlGenRule) GeneratedSourceFiles() android.Paths {
117 return g.genOutputs.Paths()
118}
119
120func (g *hidlGenRule) Srcs() android.Paths {
121 return g.genOutputs.Paths()
122}
123
124func (g *hidlGenRule) GeneratedDeps() android.Paths {
125 return g.genOutputs.Paths()
126}
127
128func (g *hidlGenRule) GeneratedHeaderDirs() android.Paths {
129 return android.Paths{g.genOutputDir}
130}
131
132func (g *hidlGenRule) DepsMutator(ctx android.BottomUpMutatorContext) {
133 ctx.AddDependency(ctx.Module(), nil, g.properties.FqName+hidlInterfaceSuffix)
134 ctx.AddDependency(ctx.Module(), nil, wrap("", g.properties.Interfaces, hidlInterfaceSuffix)...)
Steven Morelandd9fd1952018-11-08 18:14:37 -0800135 ctx.AddDependency(ctx.Module(), nil, g.properties.Root)
Steven Moreland744eb322018-07-25 16:31:08 -0700136}
137
138func hidlGenFactory() android.Module {
139 g := &hidlGenRule{}
140 g.AddProperties(&g.properties)
141 android.InitAndroidModule(g)
142 return g
143}
144
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700145type hidlInterfaceProperties struct {
146 // Vndk properties for interface library only.
147 cc.VndkProperties
148
149 // List of .hal files which compose this interface.
150 Srcs []string
151
152 // List of hal interface packages that this library depends on.
153 Interfaces []string
154
155 // Package root for this package, must be a prefix of name
156 Root string
157
158 // List of non-TypeDef types declared in types.hal.
159 Types []string
160
161 // Whether to generate the Java library stubs.
162 // Default: true
163 Gen_java *bool
164
165 // Whether to generate a Java library containing constants
166 // expressed by @export annotations in the hal files.
167 Gen_java_constants bool
Steven Moreland744eb322018-07-25 16:31:08 -0700168
169 // example: -randroid.hardware:hardware/interfaces
170 Full_root_option string `blueprint:"mutated"`
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700171}
172
Steven Moreland650bc512018-12-06 11:53:09 -0800173// TODO(b/119771576): These properties are shared by all Android modules, and we are specifically
174// calling these out to be copied to every create module. However, if a new property is added, it
175// could break things because this code has no way to know about that.
176type manuallyInheritCommonProperties struct {
177 Enabled *bool
178 Compile_multilib *string
179 Target struct {
180 Host struct {
181 Compile_multilib *string
182 }
183 Android struct {
184 Compile_multilib *string
185 }
186 }
187 Proprietary *bool
188 Owner *string
189 Vendor *bool
190 Soc_specific *bool
191 Device_specific *bool
192 Product_specific *bool
193 Product_services_specific *bool
194 Recovery *bool
195 Init_rc []string
196 Vintf_fragments []string
197 Required []string
198 Notice *string
199 Dist struct {
200 Targets []string
201 Dest *string
202 Dir *string
203 Suffix *string
204 }
205}
206
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700207type hidlInterface struct {
208 android.ModuleBase
209
Steven Moreland650bc512018-12-06 11:53:09 -0800210 properties hidlInterfaceProperties
211 inheritCommonProperties manuallyInheritCommonProperties
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700212}
213
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700214func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) {
215 var interfaces []string
216 var types []string // hidl-gen only supports types.hal, but don't assume that here
217
218 hasError := false
219
220 for _, v := range srcs {
221 if !strings.HasSuffix(v, ".hal") {
222 mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v)
223 hasError = true
224 continue
225 }
226
227 name := strings.TrimSuffix(v, ".hal")
228
229 if strings.HasPrefix(name, "I") {
230 baseName := strings.TrimPrefix(name, "I")
231 interfaces = append(interfaces, baseName)
232 } else {
233 types = append(types, name)
234 }
235 }
236
237 return interfaces, types, !hasError
238}
239
240func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) {
241 var dependencies []string
242 var javaDependencies []string
243
244 hasError := false
245
246 for _, v := range interfaces {
247 name, err := parseFqName(v)
248 if err != nil {
249 mctx.PropertyErrorf("interfaces", err.Error())
250 hasError = true
251 continue
252 }
253 dependencies = append(dependencies, name.string())
254 javaDependencies = append(javaDependencies, name.javaName())
255 }
256
257 return dependencies, javaDependencies, !hasError
258}
259
Steven Moreland744eb322018-07-25 16:31:08 -0700260func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700261 var ret []string
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700262
263 for _, i := range dependencies {
Steven Morelandb49d3a72018-07-25 16:40:03 -0700264 if !isCorePackage(i) {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700265 ret = append(ret, i)
266 }
267 }
268
Steven Moreland744eb322018-07-25 16:31:08 -0700269 return ret
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700270}
271
272func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) {
273 name, err := parseFqName(i.ModuleBase.Name())
274 if err != nil {
275 mctx.PropertyErrorf("name", err.Error())
276 }
277
278 if !name.inPackage(i.properties.Root) {
Steven Moreland744eb322018-07-25 16:31:08 -0700279 mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".")
280 }
281 if lookupPackageRoot(i.properties.Root) == nil {
282 mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+
283 `root '%s' needed for module '%s'. Either this is a mispelling of the package `+
284 `root, or a new hidl_package_root module needs to be added. For example, you can `+
285 `fix this error by adding the following to <some path>/Android.bp:
286
287hidl_package_root {
288name: "%s",
289path: "<some path>",
290}
291
292This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`,
293 i.properties.Root, name, i.properties.Root, i.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700294 }
295
296 interfaces, types, _ := processSources(mctx, i.properties.Srcs)
297
298 if len(interfaces) == 0 && len(types) == 0 {
299 mctx.PropertyErrorf("srcs", "No sources provided.")
300 }
301
302 dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces)
Steven Moreland744eb322018-07-25 16:31:08 -0700303 cppDependencies := removeCoreDependencies(mctx, dependencies)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700304
305 if mctx.Failed() {
306 return
307 }
308
Steven Morelandb49d3a72018-07-25 16:40:03 -0700309 shouldGenerateLibrary := !isCorePackage(name.string())
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700310 // explicitly true if not specified to give early warning to devs
311 shouldGenerateJava := i.properties.Gen_java == nil || *i.properties.Gen_java
312 shouldGenerateJavaConstants := i.properties.Gen_java_constants
313
314 var libraryIfExists []string
315 if shouldGenerateLibrary {
316 libraryIfExists = []string{name.string()}
317 }
318
319 // TODO(b/69002743): remove filegroups
Pirama Arumuga Nainarf43bb1e2018-04-18 11:34:56 -0700320 mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{
Steven Moreland650bc512018-12-06 11:53:09 -0800321 Name: proptools.StringPtr(name.fileGroupName()),
322 Srcs: i.properties.Srcs,
323 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700324
Steven Moreland744eb322018-07-25 16:31:08 -0700325 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
326 Name: proptools.StringPtr(name.sourcesName()),
327 }, &hidlGenProperties{
328 Language: "c++-sources",
329 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800330 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700331 Interfaces: i.properties.Interfaces,
332 Inputs: i.properties.Srcs,
333 Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")),
Steven Moreland650bc512018-12-06 11:53:09 -0800334 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700335 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
336 Name: proptools.StringPtr(name.headersName()),
337 }, &hidlGenProperties{
338 Language: "c++-headers",
339 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800340 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700341 Interfaces: i.properties.Interfaces,
342 Inputs: i.properties.Srcs,
343 Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700344 wrap(name.dir()+"Bs", interfaces, ".h"),
345 wrap(name.dir()+"BnHw", interfaces, ".h"),
346 wrap(name.dir()+"BpHw", interfaces, ".h"),
347 wrap(name.dir()+"IHw", interfaces, ".h"),
348 wrap(name.dir(), types, ".h"),
349 wrap(name.dir()+"hw", types, ".h")),
Steven Moreland650bc512018-12-06 11:53:09 -0800350 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700351
352 if shouldGenerateLibrary {
353 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
Jerry Zhangf2a93962018-05-30 17:16:05 -0700354 Name: proptools.StringPtr(name.string()),
Jerry Zhangf2a93962018-05-30 17:16:05 -0700355 Recovery_available: proptools.BoolPtr(true),
356 Vendor_available: proptools.BoolPtr(true),
357 Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())),
358 Defaults: []string{"hidl-module-defaults"},
359 Generated_sources: []string{name.sourcesName()},
360 Generated_headers: []string{name.headersName()},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700361 Shared_libs: concat(cppDependencies, []string{
362 "libhidlbase",
363 "libhidltransport",
364 "libhwbinder",
365 "liblog",
366 "libutils",
367 "libcutils",
368 }),
369 Export_shared_lib_headers: concat(cppDependencies, []string{
370 "libhidlbase",
371 "libhidltransport",
372 "libhwbinder",
373 "libutils",
374 }),
375 Export_generated_headers: []string{name.headersName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800376 }, &i.properties.VndkProperties, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700377 }
378
379 if shouldGenerateJava {
Steven Moreland744eb322018-07-25 16:31:08 -0700380 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
381 Name: proptools.StringPtr(name.javaSourcesName()),
382 }, &hidlGenProperties{
383 Language: "java",
384 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800385 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700386 Interfaces: i.properties.Interfaces,
387 Inputs: i.properties.Srcs,
388 Outputs: concat(wrap(name.sanitizedDir()+"I", interfaces, ".java"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700389 wrap(name.sanitizedDir(), i.properties.Types, ".java")),
Steven Moreland650bc512018-12-06 11:53:09 -0800390 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700391 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700392 Name: proptools.StringPtr(name.javaName()),
393 Defaults: []string{"hidl-java-module-defaults"},
394 No_framework_libs: proptools.BoolPtr(true),
Colin Crossf5536c32018-06-26 23:29:10 -0700395 Installable: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700396 Srcs: []string{":" + name.javaSourcesName()},
Steven Morelandfcfbeaf2018-01-29 19:34:52 -0800397 Static_libs: javaDependencies,
Colin Crossa5050552018-03-29 10:30:03 -0700398
399 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
400 // to build framework, which is used to build system_current. Use core_current
401 // plus hwbinder.stubs, which together form a subset of system_current that does
402 // not depend on framework.
403 Sdk_version: proptools.StringPtr("core_current"),
404 Libs: []string{"hwbinder.stubs"},
Steven Moreland650bc512018-12-06 11:53:09 -0800405 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700406 }
407
408 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700409 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
410 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
411 }, &hidlGenProperties{
412 Language: "java-constants",
413 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800414 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700415 Interfaces: i.properties.Interfaces,
416 Inputs: i.properties.Srcs,
417 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Moreland650bc512018-12-06 11:53:09 -0800418 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700419 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700420 Name: proptools.StringPtr(name.javaConstantsName()),
421 Defaults: []string{"hidl-java-module-defaults"},
422 No_framework_libs: proptools.BoolPtr(true),
423 Srcs: []string{":" + name.javaConstantsSourcesName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800424 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700425 }
426
Steven Moreland744eb322018-07-25 16:31:08 -0700427 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
428 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
429 }, &hidlGenProperties{
430 Language: "c++-adapter-sources",
431 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800432 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700433 Interfaces: i.properties.Interfaces,
434 Inputs: i.properties.Srcs,
435 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"),
Steven Moreland650bc512018-12-06 11:53:09 -0800436 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700437 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
438 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
439 }, &hidlGenProperties{
440 Language: "c++-adapter-headers",
441 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800442 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700443 Interfaces: i.properties.Interfaces,
444 Inputs: i.properties.Srcs,
445 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Moreland650bc512018-12-06 11:53:09 -0800446 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700447
448 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
449 Name: proptools.StringPtr(name.adapterHelperName()),
450 Vendor_available: proptools.BoolPtr(true),
451 Defaults: []string{"hidl-module-defaults"},
452 Generated_sources: []string{name.adapterHelperSourcesName()},
453 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800454 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800455 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800456 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700457 "libhidlbase",
458 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800459 "libhwbinder",
460 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700461 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800462 },
463 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700464 "libhidladapter",
465 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800466 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700467 "libhidlbase",
468 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800469 },
470 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700471 "libhidladapter",
472 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
473 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800474 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800475 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700476 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
477 Name: proptools.StringPtr(name.adapterSourcesName()),
478 }, &hidlGenProperties{
479 Language: "c++-adapter-main",
480 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800481 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700482 Interfaces: i.properties.Interfaces,
483 Inputs: i.properties.Srcs,
484 Outputs: []string{"main.cpp"},
Steven Moreland650bc512018-12-06 11:53:09 -0800485 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700486 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
487 Name: proptools.StringPtr(name.adapterName()),
488 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800489 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800490 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800491 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700492 "libhidlbase",
493 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800494 "libhwbinder",
495 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700496 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800497 },
498 Static_libs: concat([]string{
499 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700500 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800501 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
502 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800503 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700504}
505
506func (h *hidlInterface) Name() string {
507 return h.ModuleBase.Name() + hidlInterfaceSuffix
508}
509func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700510 visited := false
511 ctx.VisitDirectDeps(func(dep android.Module) {
512 if visited {
513 panic("internal error, multiple dependencies found but only one added")
514 }
515 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800516 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700517 })
518 if !visited {
519 panic("internal error, no dependencies found but dependency added")
520 }
521
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700522}
523func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700524 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700525}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700526
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700527func hidlInterfaceFactory() android.Module {
528 i := &hidlInterface{}
529 i.AddProperties(&i.properties)
Steven Moreland650bc512018-12-06 11:53:09 -0800530 i.AddProperties(&i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700531 android.InitAndroidModule(i)
532 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
533
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700534 return i
535}
536
Colin Crossf5536c32018-06-26 23:29:10 -0700537var doubleLoadablePackageNames = []string{
Jiyong Parkd26759f2018-04-09 12:22:18 +0900538 "android.hardware.configstore@",
539 "android.hardware.graphics.allocator@",
540 "android.hardware.graphics.bufferqueue@",
541 "android.hardware.media.omx@",
542 "android.hardware.media@",
543 "android.hardware.neuralnetworks@",
544 "android.hidl.allocator@",
545 "android.hidl.token@",
546}
547
548func isDoubleLoadable(name string) bool {
549 for _, pkgname := range doubleLoadablePackageNames {
550 if strings.HasPrefix(name, pkgname) {
551 return true
552 }
553 }
554 return false
555}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700556
557// packages in libhidltransport
558var coreDependencyPackageNames = []string{
559 "android.hidl.base@",
560 "android.hidl.manager@",
561}
562
563func isCorePackage(name string) bool {
564 for _, pkgname := range coreDependencyPackageNames {
565 if strings.HasPrefix(name, pkgname) {
566 return true
567 }
568 }
569 return false
570}