blob: 37d753b6a2d8eac7230cf802736f7831e588086d [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
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800149 // The owner of the module
150 Owner *string
151
Justin Yune5faf7e2018-11-27 12:22:21 +0900152 // Install core variant on the /product instead of /system
153 Product_specific *bool
154
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700155 // List of .hal files which compose this interface.
156 Srcs []string
157
158 // List of hal interface packages that this library depends on.
159 Interfaces []string
160
161 // Package root for this package, must be a prefix of name
162 Root string
163
164 // List of non-TypeDef types declared in types.hal.
165 Types []string
166
167 // Whether to generate the Java library stubs.
168 // Default: true
169 Gen_java *bool
170
171 // Whether to generate a Java library containing constants
172 // expressed by @export annotations in the hal files.
173 Gen_java_constants bool
Steven Moreland744eb322018-07-25 16:31:08 -0700174
175 // example: -randroid.hardware:hardware/interfaces
176 Full_root_option string `blueprint:"mutated"`
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700177}
178
179type hidlInterface struct {
180 android.ModuleBase
181
182 properties hidlInterfaceProperties
183}
184
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700185func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) {
186 var interfaces []string
187 var types []string // hidl-gen only supports types.hal, but don't assume that here
188
189 hasError := false
190
191 for _, v := range srcs {
192 if !strings.HasSuffix(v, ".hal") {
193 mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v)
194 hasError = true
195 continue
196 }
197
198 name := strings.TrimSuffix(v, ".hal")
199
200 if strings.HasPrefix(name, "I") {
201 baseName := strings.TrimPrefix(name, "I")
202 interfaces = append(interfaces, baseName)
203 } else {
204 types = append(types, name)
205 }
206 }
207
208 return interfaces, types, !hasError
209}
210
211func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) {
212 var dependencies []string
213 var javaDependencies []string
214
215 hasError := false
216
217 for _, v := range interfaces {
218 name, err := parseFqName(v)
219 if err != nil {
220 mctx.PropertyErrorf("interfaces", err.Error())
221 hasError = true
222 continue
223 }
224 dependencies = append(dependencies, name.string())
225 javaDependencies = append(javaDependencies, name.javaName())
226 }
227
228 return dependencies, javaDependencies, !hasError
229}
230
Steven Moreland744eb322018-07-25 16:31:08 -0700231func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700232 var ret []string
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700233
234 for _, i := range dependencies {
Steven Morelandb49d3a72018-07-25 16:40:03 -0700235 if !isCorePackage(i) {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700236 ret = append(ret, i)
237 }
238 }
239
Steven Moreland744eb322018-07-25 16:31:08 -0700240 return ret
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700241}
242
243func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) {
244 name, err := parseFqName(i.ModuleBase.Name())
245 if err != nil {
246 mctx.PropertyErrorf("name", err.Error())
247 }
248
249 if !name.inPackage(i.properties.Root) {
Steven Moreland744eb322018-07-25 16:31:08 -0700250 mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".")
251 }
252 if lookupPackageRoot(i.properties.Root) == nil {
253 mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+
254 `root '%s' needed for module '%s'. Either this is a mispelling of the package `+
255 `root, or a new hidl_package_root module needs to be added. For example, you can `+
256 `fix this error by adding the following to <some path>/Android.bp:
257
258hidl_package_root {
259name: "%s",
260path: "<some path>",
261}
262
263This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`,
264 i.properties.Root, name, i.properties.Root, i.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700265 }
266
267 interfaces, types, _ := processSources(mctx, i.properties.Srcs)
268
269 if len(interfaces) == 0 && len(types) == 0 {
270 mctx.PropertyErrorf("srcs", "No sources provided.")
271 }
272
273 dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces)
Steven Moreland744eb322018-07-25 16:31:08 -0700274 cppDependencies := removeCoreDependencies(mctx, dependencies)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700275
276 if mctx.Failed() {
277 return
278 }
279
Steven Morelandb49d3a72018-07-25 16:40:03 -0700280 shouldGenerateLibrary := !isCorePackage(name.string())
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700281 // explicitly true if not specified to give early warning to devs
282 shouldGenerateJava := i.properties.Gen_java == nil || *i.properties.Gen_java
283 shouldGenerateJavaConstants := i.properties.Gen_java_constants
284
285 var libraryIfExists []string
286 if shouldGenerateLibrary {
287 libraryIfExists = []string{name.string()}
288 }
289
290 // TODO(b/69002743): remove filegroups
Pirama Arumuga Nainarf43bb1e2018-04-18 11:34:56 -0700291 mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800292 Name: proptools.StringPtr(name.fileGroupName()),
293 Owner: i.properties.Owner,
294 Srcs: i.properties.Srcs,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700295 })
296
Steven Moreland744eb322018-07-25 16:31:08 -0700297 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
298 Name: proptools.StringPtr(name.sourcesName()),
299 }, &hidlGenProperties{
300 Language: "c++-sources",
301 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800302 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700303 Interfaces: i.properties.Interfaces,
304 Inputs: i.properties.Srcs,
305 Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700306 })
Steven Moreland744eb322018-07-25 16:31:08 -0700307 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
308 Name: proptools.StringPtr(name.headersName()),
309 }, &hidlGenProperties{
310 Language: "c++-headers",
311 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800312 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700313 Interfaces: i.properties.Interfaces,
314 Inputs: i.properties.Srcs,
315 Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700316 wrap(name.dir()+"Bs", interfaces, ".h"),
317 wrap(name.dir()+"BnHw", interfaces, ".h"),
318 wrap(name.dir()+"BpHw", interfaces, ".h"),
319 wrap(name.dir()+"IHw", interfaces, ".h"),
320 wrap(name.dir(), types, ".h"),
321 wrap(name.dir()+"hw", types, ".h")),
322 })
323
324 if shouldGenerateLibrary {
325 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
Jerry Zhangf2a93962018-05-30 17:16:05 -0700326 Name: proptools.StringPtr(name.string()),
327 Owner: i.properties.Owner,
Justin Yune5faf7e2018-11-27 12:22:21 +0900328 Product_specific: i.properties.Product_specific,
Jerry Zhangf2a93962018-05-30 17:16:05 -0700329 Recovery_available: proptools.BoolPtr(true),
330 Vendor_available: proptools.BoolPtr(true),
331 Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())),
332 Defaults: []string{"hidl-module-defaults"},
333 Generated_sources: []string{name.sourcesName()},
334 Generated_headers: []string{name.headersName()},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700335 Shared_libs: concat(cppDependencies, []string{
336 "libhidlbase",
337 "libhidltransport",
338 "libhwbinder",
339 "liblog",
340 "libutils",
341 "libcutils",
342 }),
343 Export_shared_lib_headers: concat(cppDependencies, []string{
344 "libhidlbase",
345 "libhidltransport",
346 "libhwbinder",
347 "libutils",
348 }),
349 Export_generated_headers: []string{name.headersName()},
350 }, &i.properties.VndkProperties)
351 }
352
353 if shouldGenerateJava {
Steven Moreland744eb322018-07-25 16:31:08 -0700354 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
355 Name: proptools.StringPtr(name.javaSourcesName()),
356 }, &hidlGenProperties{
357 Language: "java",
358 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800359 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700360 Interfaces: i.properties.Interfaces,
361 Inputs: i.properties.Srcs,
362 Outputs: concat(wrap(name.sanitizedDir()+"I", interfaces, ".java"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700363 wrap(name.sanitizedDir(), i.properties.Types, ".java")),
364 })
Colin Crossf5536c32018-06-26 23:29:10 -0700365 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700366 Name: proptools.StringPtr(name.javaName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800367 Owner: i.properties.Owner,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700368 Defaults: []string{"hidl-java-module-defaults"},
369 No_framework_libs: proptools.BoolPtr(true),
Colin Crossf5536c32018-06-26 23:29:10 -0700370 Installable: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700371 Srcs: []string{":" + name.javaSourcesName()},
Steven Morelandfcfbeaf2018-01-29 19:34:52 -0800372 Static_libs: javaDependencies,
Colin Crossa5050552018-03-29 10:30:03 -0700373
374 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
375 // to build framework, which is used to build system_current. Use core_current
376 // plus hwbinder.stubs, which together form a subset of system_current that does
377 // not depend on framework.
378 Sdk_version: proptools.StringPtr("core_current"),
379 Libs: []string{"hwbinder.stubs"},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700380 })
381 }
382
383 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700384 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
385 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
386 }, &hidlGenProperties{
387 Language: "java-constants",
388 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800389 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700390 Interfaces: i.properties.Interfaces,
391 Inputs: i.properties.Srcs,
392 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700393 })
Colin Crossf5536c32018-06-26 23:29:10 -0700394 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700395 Name: proptools.StringPtr(name.javaConstantsName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800396 Owner: i.properties.Owner,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700397 Defaults: []string{"hidl-java-module-defaults"},
398 No_framework_libs: proptools.BoolPtr(true),
399 Srcs: []string{":" + name.javaConstantsSourcesName()},
400 })
401 }
402
Steven Moreland744eb322018-07-25 16:31:08 -0700403 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
404 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
405 }, &hidlGenProperties{
406 Language: "c++-adapter-sources",
407 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800408 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700409 Interfaces: i.properties.Interfaces,
410 Inputs: i.properties.Srcs,
411 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700412 })
Steven Moreland744eb322018-07-25 16:31:08 -0700413 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
414 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
415 }, &hidlGenProperties{
416 Language: "c++-adapter-headers",
417 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800418 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700419 Interfaces: i.properties.Interfaces,
420 Inputs: i.properties.Srcs,
421 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700422 })
423
424 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
425 Name: proptools.StringPtr(name.adapterHelperName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800426 Owner: i.properties.Owner,
Justin Yune5faf7e2018-11-27 12:22:21 +0900427 Product_specific: i.properties.Product_specific,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700428 Vendor_available: proptools.BoolPtr(true),
429 Defaults: []string{"hidl-module-defaults"},
430 Generated_sources: []string{name.adapterHelperSourcesName()},
431 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800432 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800433 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800434 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700435 "libhidlbase",
436 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800437 "libhwbinder",
438 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700439 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800440 },
441 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700442 "libhidladapter",
443 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800444 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700445 "libhidlbase",
446 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800447 },
448 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700449 "libhidladapter",
450 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
451 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800452 Group_static_libs: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700453 })
Steven Moreland744eb322018-07-25 16:31:08 -0700454 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
455 Name: proptools.StringPtr(name.adapterSourcesName()),
456 }, &hidlGenProperties{
457 Language: "c++-adapter-main",
458 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800459 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700460 Interfaces: i.properties.Interfaces,
461 Inputs: i.properties.Srcs,
462 Outputs: []string{"main.cpp"},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700463 })
464 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
465 Name: proptools.StringPtr(name.adapterName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800466 Owner: i.properties.Owner,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700467 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800468 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800469 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800470 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700471 "libhidlbase",
472 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800473 "libhwbinder",
474 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700475 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800476 },
477 Static_libs: concat([]string{
478 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700479 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800480 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
481 Group_static_libs: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700482 })
483}
484
485func (h *hidlInterface) Name() string {
486 return h.ModuleBase.Name() + hidlInterfaceSuffix
487}
488func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700489 visited := false
490 ctx.VisitDirectDeps(func(dep android.Module) {
491 if visited {
492 panic("internal error, multiple dependencies found but only one added")
493 }
494 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800495 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700496 })
497 if !visited {
498 panic("internal error, no dependencies found but dependency added")
499 }
500
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700501}
502func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700503 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700504}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700505
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700506func hidlInterfaceFactory() android.Module {
507 i := &hidlInterface{}
508 i.AddProperties(&i.properties)
509 android.InitAndroidModule(i)
510 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
511
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700512 return i
513}
514
Colin Crossf5536c32018-06-26 23:29:10 -0700515var doubleLoadablePackageNames = []string{
Jiyong Parkd26759f2018-04-09 12:22:18 +0900516 "android.hardware.configstore@",
517 "android.hardware.graphics.allocator@",
518 "android.hardware.graphics.bufferqueue@",
519 "android.hardware.media.omx@",
520 "android.hardware.media@",
521 "android.hardware.neuralnetworks@",
522 "android.hidl.allocator@",
523 "android.hidl.token@",
524}
525
526func isDoubleLoadable(name string) bool {
527 for _, pkgname := range doubleLoadablePackageNames {
528 if strings.HasPrefix(name, pkgname) {
529 return true
530 }
531 }
532 return false
533}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700534
535// packages in libhidltransport
536var coreDependencyPackageNames = []string{
537 "android.hidl.base@",
538 "android.hidl.manager@",
539}
540
541func isCorePackage(name string) bool {
542 for _, pkgname := range coreDependencyPackageNames {
543 if strings.HasPrefix(name, pkgname) {
544 return true
545 }
546 }
547 return false
548}