blob: 179642fa654e76757275d376f405a5d11fe5a3cc [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 Morelandeaba9232019-01-16 17:55:05 -080019 "sort"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070020 "strings"
Steven Morelandeaba9232019-01-16 17:55:05 -080021 "sync"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070022
Steven Moreland744eb322018-07-25 16:31:08 -070023 "github.com/google/blueprint"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070024 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/genrule"
29 "android/soong/java"
30)
31
32var (
33 hidlInterfaceSuffix = "_interface"
Steven Moreland744eb322018-07-25 16:31:08 -070034
35 pctx = android.NewPackageContext("android/hidl")
36
Steven Morelandfeaee3b2019-03-01 12:44:36 -080037 hidl = pctx.HostBinToolVariable("hidl", "hidl-gen")
38 vtsc = pctx.HostBinToolVariable("vtsc", "vtsc")
39 soong_zip = pctx.HostBinToolVariable("soong_zip", "soong_zip")
Steven Morelandeaba9232019-01-16 17:55:05 -080040
Steven Moreland744eb322018-07-25 16:31:08 -070041 hidlRule = pctx.StaticRule("hidlRule", blueprint.RuleParams{
42 Depfile: "${depfile}",
43 Deps: blueprint.DepsGCC,
Steven Morelandbc98bdb2018-10-31 14:47:07 -070044 Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${depfile} -o ${genDir} -L ${language} ${roots} ${fqName}",
Steven Moreland744eb322018-07-25 16:31:08 -070045 CommandDeps: []string{"${hidl}"},
46 Description: "HIDL ${language}: ${in} => ${out}",
47 }, "depfile", "fqName", "genDir", "language", "roots")
Steven Morelandeaba9232019-01-16 17:55:05 -080048
Steven Morelandfeaee3b2019-03-01 12:44:36 -080049 hidlSrcJarRule = pctx.StaticRule("hidlSrcJarRule", blueprint.RuleParams{
50 Depfile: "${depfile}",
51 Deps: blueprint.DepsGCC,
52 Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${depfile} -o ${genDir}/srcs -L ${language} ${roots} ${fqName} && ${soong_zip} -o ${genDir}/srcs.srcjar -D ${genDir}/srcs",
53 CommandDeps: []string{"${hidl}", "${soong_zip}"},
54 Description: "HIDL ${language}: ${in} => srcs.srcjar",
55 }, "depfile", "fqName", "genDir", "language", "roots")
56
Steven Morelandeaba9232019-01-16 17:55:05 -080057 vtsRule = pctx.StaticRule("vtsRule", blueprint.RuleParams{
58 Command: "rm -rf ${genDir} && ${vtsc} -m${mode} -t${type} ${inputDir}/${packagePath} ${genDir}/${packagePath}",
59 CommandDeps: []string{"${vtsc}"},
60 Description: "VTS ${mode} ${type}: ${in} => ${out}",
61 }, "mode", "type", "inputDir", "genDir", "packagePath")
Steven Morelandd56e5bb2017-07-18 22:04:16 -070062)
63
64func init() {
65 android.RegisterModuleType("hidl_interface", hidlInterfaceFactory)
Steven Morelandeaba9232019-01-16 17:55:05 -080066 android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
Steven Morelandd56e5bb2017-07-18 22:04:16 -070067}
68
Steven Moreland744eb322018-07-25 16:31:08 -070069type hidlGenProperties struct {
70 Language string
71 FqName string
Steven Morelandd9fd1952018-11-08 18:14:37 -080072 Root string
Steven Moreland744eb322018-07-25 16:31:08 -070073 Interfaces []string
74 Inputs []string
75 Outputs []string
76}
77
78type hidlGenRule struct {
79 android.ModuleBase
80
81 properties hidlGenProperties
82
83 genOutputDir android.Path
84 genInputs android.Paths
85 genOutputs android.WritablePaths
86}
87
88var _ android.SourceFileProducer = (*hidlGenRule)(nil)
89var _ genrule.SourceFileGenerator = (*hidlGenRule)(nil)
90
91func (g *hidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
92 g.genOutputDir = android.PathForModuleGen(ctx)
93
94 for _, input := range g.properties.Inputs {
95 g.genInputs = append(g.genInputs, android.PathForModuleSrc(ctx, input))
96 }
97
98 for _, output := range g.properties.Outputs {
99 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
100 }
101
Steven Morelandeaba9232019-01-16 17:55:05 -0800102 if g.properties.Language == "vts" && isVtsSpecPackage(ctx.ModuleName()) {
103 vtsList := vtsList(ctx.AConfig())
104 vtsListMutex.Lock()
105 *vtsList = append(*vtsList, g.genOutputs.Paths()...)
106 vtsListMutex.Unlock()
107 }
108
Steven Moreland744eb322018-07-25 16:31:08 -0700109 var fullRootOptions []string
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800110 var currentPath android.OptionalPath
Steven Moreland744eb322018-07-25 16:31:08 -0700111 ctx.VisitDirectDeps(func(dep android.Module) {
Steven Morelandd9fd1952018-11-08 18:14:37 -0800112 switch t := dep.(type) {
113 case *hidlInterface:
114 fullRootOptions = append(fullRootOptions, t.properties.Full_root_option)
115 case *hidlPackageRoot:
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800116 if currentPath.Valid() {
117 panic(fmt.Sprintf("Expecting only one path, but found %v %v", currentPath, t.getCurrentPath()))
118 }
119
120 currentPath = t.getCurrentPath()
Steven Morelandd9fd1952018-11-08 18:14:37 -0800121 default:
122 panic(fmt.Sprintf("Unrecognized hidlGenProperties dependency: %T", t))
123 }
Steven Moreland744eb322018-07-25 16:31:08 -0700124 })
125
126 fullRootOptions = android.FirstUniqueStrings(fullRootOptions)
127
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800128 inputs := g.genInputs
Jooyung Han407469c2019-01-18 18:16:21 +0900129 if currentPath.Valid() {
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800130 inputs = append(inputs, currentPath.Path())
131 }
132
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800133 rule := hidlRule
134 if g.properties.Language == "java" {
135 rule = hidlSrcJarRule
136 }
137
Steven Moreland744eb322018-07-25 16:31:08 -0700138 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800139 Rule: rule,
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800140 Inputs: inputs,
Steven Moreland744eb322018-07-25 16:31:08 -0700141 Output: g.genOutputs[0],
142 ImplicitOutputs: g.genOutputs[1:],
143 Args: map[string]string{
144 "depfile": g.genOutputs[0].String() + ".d",
145 "genDir": g.genOutputDir.String(),
146 "fqName": g.properties.FqName,
147 "language": g.properties.Language,
148 "roots": strings.Join(fullRootOptions, " "),
149 },
150 })
151}
152
153func (g *hidlGenRule) GeneratedSourceFiles() android.Paths {
154 return g.genOutputs.Paths()
155}
156
157func (g *hidlGenRule) Srcs() android.Paths {
158 return g.genOutputs.Paths()
159}
160
161func (g *hidlGenRule) GeneratedDeps() android.Paths {
162 return g.genOutputs.Paths()
163}
164
165func (g *hidlGenRule) GeneratedHeaderDirs() android.Paths {
166 return android.Paths{g.genOutputDir}
167}
168
169func (g *hidlGenRule) DepsMutator(ctx android.BottomUpMutatorContext) {
170 ctx.AddDependency(ctx.Module(), nil, g.properties.FqName+hidlInterfaceSuffix)
171 ctx.AddDependency(ctx.Module(), nil, wrap("", g.properties.Interfaces, hidlInterfaceSuffix)...)
Steven Morelandd9fd1952018-11-08 18:14:37 -0800172 ctx.AddDependency(ctx.Module(), nil, g.properties.Root)
Steven Moreland744eb322018-07-25 16:31:08 -0700173}
174
175func hidlGenFactory() android.Module {
176 g := &hidlGenRule{}
177 g.AddProperties(&g.properties)
178 android.InitAndroidModule(g)
179 return g
180}
181
Steven Morelandeaba9232019-01-16 17:55:05 -0800182type vtscProperties struct {
183 Mode string
184 Type string
185 SpecName string // e.g. foo-vts.spec
186 Outputs []string
187 PackagePath string // e.g. android/hardware/foo/1.0/
188}
189
190type vtscRule struct {
191 android.ModuleBase
192
193 properties vtscProperties
194
195 genOutputDir android.Path
196 genInputDir android.Path
197 genInputs android.Paths
198 genOutputs android.WritablePaths
199}
200
201var _ android.SourceFileProducer = (*vtscRule)(nil)
202var _ genrule.SourceFileGenerator = (*vtscRule)(nil)
203
204func (g *vtscRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
205 g.genOutputDir = android.PathForModuleGen(ctx)
206
207 ctx.VisitDirectDeps(func(dep android.Module) {
208 if specs, ok := dep.(*hidlGenRule); ok {
209 g.genInputDir = specs.genOutputDir
210 g.genInputs = specs.genOutputs.Paths()
211 }
212 })
213
214 for _, output := range g.properties.Outputs {
215 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
216 }
217
218 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
219 Rule: vtsRule,
220 Inputs: g.genInputs,
221 Outputs: g.genOutputs,
222 Args: map[string]string{
223 "mode": g.properties.Mode,
224 "type": g.properties.Type,
225 "inputDir": g.genInputDir.String(),
226 "genDir": g.genOutputDir.String(),
227 "packagePath": g.properties.PackagePath,
228 },
229 })
230}
231
232func (g *vtscRule) GeneratedSourceFiles() android.Paths {
233 return g.genOutputs.Paths()
234}
235
236func (g *vtscRule) Srcs() android.Paths {
237 return g.genOutputs.Paths()
238}
239
240func (g *vtscRule) GeneratedDeps() android.Paths {
241 return g.genOutputs.Paths()
242}
243
244func (g *vtscRule) GeneratedHeaderDirs() android.Paths {
245 return android.Paths{g.genOutputDir}
246}
247
248func (g *vtscRule) DepsMutator(ctx android.BottomUpMutatorContext) {
249 ctx.AddDependency(ctx.Module(), nil, g.properties.SpecName)
250}
251
252func vtscFactory() android.Module {
253 g := &vtscRule{}
254 g.AddProperties(&g.properties)
255 android.InitAndroidModule(g)
256 return g
257}
258
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700259type hidlInterfaceProperties struct {
260 // Vndk properties for interface library only.
261 cc.VndkProperties
262
263 // List of .hal files which compose this interface.
264 Srcs []string
265
266 // List of hal interface packages that this library depends on.
267 Interfaces []string
268
269 // Package root for this package, must be a prefix of name
270 Root string
271
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800272 // Unused/deprecated: List of non-TypeDef types declared in types.hal.
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700273 Types []string
274
275 // Whether to generate the Java library stubs.
276 // Default: true
277 Gen_java *bool
278
279 // Whether to generate a Java library containing constants
280 // expressed by @export annotations in the hal files.
281 Gen_java_constants bool
Steven Moreland744eb322018-07-25 16:31:08 -0700282
Steven Moreland9f7c2972019-03-01 09:56:20 -0800283 // Whether to generate VTS-related testing libraries.
284 Gen_vts *bool
285
Steven Moreland744eb322018-07-25 16:31:08 -0700286 // example: -randroid.hardware:hardware/interfaces
287 Full_root_option string `blueprint:"mutated"`
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700288}
289
Steven Moreland650bc512018-12-06 11:53:09 -0800290// TODO(b/119771576): These properties are shared by all Android modules, and we are specifically
291// calling these out to be copied to every create module. However, if a new property is added, it
292// could break things because this code has no way to know about that.
293type manuallyInheritCommonProperties struct {
294 Enabled *bool
295 Compile_multilib *string
296 Target struct {
297 Host struct {
298 Compile_multilib *string
299 }
300 Android struct {
301 Compile_multilib *string
302 }
303 }
304 Proprietary *bool
305 Owner *string
306 Vendor *bool
307 Soc_specific *bool
308 Device_specific *bool
309 Product_specific *bool
310 Product_services_specific *bool
311 Recovery *bool
312 Init_rc []string
313 Vintf_fragments []string
314 Required []string
315 Notice *string
316 Dist struct {
317 Targets []string
318 Dest *string
319 Dir *string
320 Suffix *string
321 }
322}
323
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700324type hidlInterface struct {
325 android.ModuleBase
326
Steven Moreland650bc512018-12-06 11:53:09 -0800327 properties hidlInterfaceProperties
328 inheritCommonProperties manuallyInheritCommonProperties
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700329}
330
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700331func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) {
332 var interfaces []string
333 var types []string // hidl-gen only supports types.hal, but don't assume that here
334
335 hasError := false
336
337 for _, v := range srcs {
338 if !strings.HasSuffix(v, ".hal") {
339 mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v)
340 hasError = true
341 continue
342 }
343
344 name := strings.TrimSuffix(v, ".hal")
345
346 if strings.HasPrefix(name, "I") {
347 baseName := strings.TrimPrefix(name, "I")
348 interfaces = append(interfaces, baseName)
349 } else {
350 types = append(types, name)
351 }
352 }
353
354 return interfaces, types, !hasError
355}
356
357func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) {
358 var dependencies []string
359 var javaDependencies []string
360
361 hasError := false
362
363 for _, v := range interfaces {
364 name, err := parseFqName(v)
365 if err != nil {
366 mctx.PropertyErrorf("interfaces", err.Error())
367 hasError = true
368 continue
369 }
370 dependencies = append(dependencies, name.string())
371 javaDependencies = append(javaDependencies, name.javaName())
372 }
373
374 return dependencies, javaDependencies, !hasError
375}
376
Steven Moreland744eb322018-07-25 16:31:08 -0700377func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700378 var ret []string
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700379
380 for _, i := range dependencies {
Steven Morelandb49d3a72018-07-25 16:40:03 -0700381 if !isCorePackage(i) {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700382 ret = append(ret, i)
383 }
384 }
385
Steven Moreland744eb322018-07-25 16:31:08 -0700386 return ret
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700387}
388
389func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) {
390 name, err := parseFqName(i.ModuleBase.Name())
391 if err != nil {
392 mctx.PropertyErrorf("name", err.Error())
393 }
394
395 if !name.inPackage(i.properties.Root) {
Steven Moreland744eb322018-07-25 16:31:08 -0700396 mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".")
397 }
398 if lookupPackageRoot(i.properties.Root) == nil {
399 mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+
400 `root '%s' needed for module '%s'. Either this is a mispelling of the package `+
401 `root, or a new hidl_package_root module needs to be added. For example, you can `+
402 `fix this error by adding the following to <some path>/Android.bp:
403
404hidl_package_root {
405name: "%s",
406path: "<some path>",
407}
408
409This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`,
410 i.properties.Root, name, i.properties.Root, i.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700411 }
412
413 interfaces, types, _ := processSources(mctx, i.properties.Srcs)
414
415 if len(interfaces) == 0 && len(types) == 0 {
416 mctx.PropertyErrorf("srcs", "No sources provided.")
417 }
418
419 dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces)
Steven Moreland744eb322018-07-25 16:31:08 -0700420 cppDependencies := removeCoreDependencies(mctx, dependencies)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700421
422 if mctx.Failed() {
423 return
424 }
425
Steven Morelandb49d3a72018-07-25 16:40:03 -0700426 shouldGenerateLibrary := !isCorePackage(name.string())
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700427 // explicitly true if not specified to give early warning to devs
Steven Moreland9f7c2972019-03-01 09:56:20 -0800428 shouldGenerateJava := proptools.BoolDefault(i.properties.Gen_java, true)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700429 shouldGenerateJavaConstants := i.properties.Gen_java_constants
Steven Moreland9f7c2972019-03-01 09:56:20 -0800430 shouldGenerateVts := shouldGenerateLibrary && proptools.BoolDefault(i.properties.Gen_vts, true)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700431
432 var libraryIfExists []string
433 if shouldGenerateLibrary {
434 libraryIfExists = []string{name.string()}
435 }
436
437 // TODO(b/69002743): remove filegroups
Pirama Arumuga Nainarf43bb1e2018-04-18 11:34:56 -0700438 mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{
Steven Moreland650bc512018-12-06 11:53:09 -0800439 Name: proptools.StringPtr(name.fileGroupName()),
440 Srcs: i.properties.Srcs,
441 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700442
Steven Moreland744eb322018-07-25 16:31:08 -0700443 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
444 Name: proptools.StringPtr(name.sourcesName()),
445 }, &hidlGenProperties{
446 Language: "c++-sources",
447 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800448 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700449 Interfaces: i.properties.Interfaces,
450 Inputs: i.properties.Srcs,
451 Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")),
Steven Moreland650bc512018-12-06 11:53:09 -0800452 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700453 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
454 Name: proptools.StringPtr(name.headersName()),
455 }, &hidlGenProperties{
456 Language: "c++-headers",
457 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800458 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700459 Interfaces: i.properties.Interfaces,
460 Inputs: i.properties.Srcs,
461 Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700462 wrap(name.dir()+"Bs", interfaces, ".h"),
463 wrap(name.dir()+"BnHw", interfaces, ".h"),
464 wrap(name.dir()+"BpHw", interfaces, ".h"),
465 wrap(name.dir()+"IHw", interfaces, ".h"),
466 wrap(name.dir(), types, ".h"),
467 wrap(name.dir()+"hw", types, ".h")),
Steven Moreland650bc512018-12-06 11:53:09 -0800468 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700469
470 if shouldGenerateLibrary {
471 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
Jerry Zhangf2a93962018-05-30 17:16:05 -0700472 Name: proptools.StringPtr(name.string()),
Jerry Zhangf2a93962018-05-30 17:16:05 -0700473 Recovery_available: proptools.BoolPtr(true),
474 Vendor_available: proptools.BoolPtr(true),
475 Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())),
476 Defaults: []string{"hidl-module-defaults"},
477 Generated_sources: []string{name.sourcesName()},
478 Generated_headers: []string{name.headersName()},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700479 Shared_libs: concat(cppDependencies, []string{
480 "libhidlbase",
481 "libhidltransport",
482 "libhwbinder",
483 "liblog",
484 "libutils",
485 "libcutils",
486 }),
487 Export_shared_lib_headers: concat(cppDependencies, []string{
488 "libhidlbase",
489 "libhidltransport",
490 "libhwbinder",
491 "libutils",
492 }),
493 Export_generated_headers: []string{name.headersName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800494 }, &i.properties.VndkProperties, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700495 }
496
497 if shouldGenerateJava {
Steven Moreland744eb322018-07-25 16:31:08 -0700498 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
499 Name: proptools.StringPtr(name.javaSourcesName()),
500 }, &hidlGenProperties{
501 Language: "java",
502 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800503 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700504 Interfaces: i.properties.Interfaces,
505 Inputs: i.properties.Srcs,
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800506 Outputs: []string{"srcs.srcjar"},
Steven Moreland650bc512018-12-06 11:53:09 -0800507 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700508 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700509 Name: proptools.StringPtr(name.javaName()),
510 Defaults: []string{"hidl-java-module-defaults"},
511 No_framework_libs: proptools.BoolPtr(true),
Colin Crossf5536c32018-06-26 23:29:10 -0700512 Installable: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700513 Srcs: []string{":" + name.javaSourcesName()},
Steven Morelandfcfbeaf2018-01-29 19:34:52 -0800514 Static_libs: javaDependencies,
Colin Crossa5050552018-03-29 10:30:03 -0700515
516 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
517 // to build framework, which is used to build system_current. Use core_current
518 // plus hwbinder.stubs, which together form a subset of system_current that does
519 // not depend on framework.
520 Sdk_version: proptools.StringPtr("core_current"),
521 Libs: []string{"hwbinder.stubs"},
Steven Moreland650bc512018-12-06 11:53:09 -0800522 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700523 }
524
525 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700526 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
527 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
528 }, &hidlGenProperties{
529 Language: "java-constants",
530 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800531 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700532 Interfaces: i.properties.Interfaces,
533 Inputs: i.properties.Srcs,
534 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Moreland650bc512018-12-06 11:53:09 -0800535 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700536 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700537 Name: proptools.StringPtr(name.javaConstantsName()),
538 Defaults: []string{"hidl-java-module-defaults"},
539 No_framework_libs: proptools.BoolPtr(true),
540 Srcs: []string{":" + name.javaConstantsSourcesName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800541 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700542 }
543
Steven Moreland744eb322018-07-25 16:31:08 -0700544 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
545 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
546 }, &hidlGenProperties{
547 Language: "c++-adapter-sources",
548 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800549 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700550 Interfaces: i.properties.Interfaces,
551 Inputs: i.properties.Srcs,
552 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"),
Steven Moreland650bc512018-12-06 11:53:09 -0800553 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700554 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
555 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
556 }, &hidlGenProperties{
557 Language: "c++-adapter-headers",
558 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800559 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700560 Interfaces: i.properties.Interfaces,
561 Inputs: i.properties.Srcs,
562 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Moreland650bc512018-12-06 11:53:09 -0800563 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700564
565 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
566 Name: proptools.StringPtr(name.adapterHelperName()),
567 Vendor_available: proptools.BoolPtr(true),
568 Defaults: []string{"hidl-module-defaults"},
569 Generated_sources: []string{name.adapterHelperSourcesName()},
570 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800571 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800572 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800573 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700574 "libhidlbase",
575 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800576 "libhwbinder",
577 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700578 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800579 },
580 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700581 "libhidladapter",
582 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800583 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700584 "libhidlbase",
585 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800586 },
587 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700588 "libhidladapter",
589 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
590 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800591 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800592 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700593 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
594 Name: proptools.StringPtr(name.adapterSourcesName()),
595 }, &hidlGenProperties{
596 Language: "c++-adapter-main",
597 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800598 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700599 Interfaces: i.properties.Interfaces,
600 Inputs: i.properties.Srcs,
601 Outputs: []string{"main.cpp"},
Steven Moreland650bc512018-12-06 11:53:09 -0800602 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700603 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
604 Name: proptools.StringPtr(name.adapterName()),
605 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800606 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800607 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800608 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700609 "libhidlbase",
610 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800611 "libhwbinder",
612 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700613 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800614 },
615 Static_libs: concat([]string{
616 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700617 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800618 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
619 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800620 }, &i.inheritCommonProperties)
Steven Morelandeaba9232019-01-16 17:55:05 -0800621
622 if shouldGenerateVts {
623 vtsSpecs := concat(wrap(name.dir(), interfaces, ".vts"), wrap(name.dir(), types, ".vts"))
624
625 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
626 Name: proptools.StringPtr(name.vtsSpecName()),
627 }, &hidlGenProperties{
628 Language: "vts",
629 FqName: name.string(),
630 Root: i.properties.Root,
631 Interfaces: i.properties.Interfaces,
632 Inputs: i.properties.Srcs,
633 Outputs: vtsSpecs,
634 }, &i.inheritCommonProperties)
635
636 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
637 Name: proptools.StringPtr(name.vtsDriverSourcesName()),
638 }, &vtscProperties{
639 Mode: "DRIVER",
640 Type: "SOURCE",
641 SpecName: name.vtsSpecName(),
642 Outputs: wrap("", vtsSpecs, ".cpp"),
643 PackagePath: name.dir(),
644 }, &i.inheritCommonProperties)
645 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
646 Name: proptools.StringPtr(name.vtsDriverHeadersName()),
647 }, &vtscProperties{
648 Mode: "DRIVER",
649 Type: "HEADER",
650 SpecName: name.vtsSpecName(),
651 Outputs: wrap("", vtsSpecs, ".h"),
652 PackagePath: name.dir(),
653 }, &i.inheritCommonProperties)
654 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
655 Name: proptools.StringPtr(name.vtsDriverName()),
656 Defaults: []string{"VtsHalDriverDefaults"},
657 Generated_sources: []string{name.vtsDriverSourcesName()},
658 Generated_headers: []string{name.vtsDriverHeadersName()},
659 Export_generated_headers: []string{name.vtsDriverHeadersName()},
660 Shared_libs: wrap("", cppDependencies, "-vts.driver"),
661 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.driver"),
662 Static_libs: concat(cppDependencies, libraryIfExists),
663
664 // TODO(b/126244142)
665 Cflags: []string{"-Wno-unused-variable"},
666 }, &i.inheritCommonProperties)
667
668 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
669 Name: proptools.StringPtr(name.vtsProfilerSourcesName()),
670 }, &vtscProperties{
671 Mode: "PROFILER",
672 Type: "SOURCE",
673 SpecName: name.vtsSpecName(),
674 Outputs: wrap("", vtsSpecs, ".cpp"),
675 PackagePath: name.dir(),
676 }, &i.inheritCommonProperties)
677 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
678 Name: proptools.StringPtr(name.vtsProfilerHeadersName()),
679 }, &vtscProperties{
680 Mode: "PROFILER",
681 Type: "HEADER",
682 SpecName: name.vtsSpecName(),
683 Outputs: wrap("", vtsSpecs, ".h"),
684 PackagePath: name.dir(),
685 }, &i.inheritCommonProperties)
686 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
687 Name: proptools.StringPtr(name.vtsProfilerName()),
688 Defaults: []string{"VtsHalProfilerDefaults"},
689 Generated_sources: []string{name.vtsProfilerSourcesName()},
690 Generated_headers: []string{name.vtsProfilerHeadersName()},
691 Export_generated_headers: []string{name.vtsProfilerHeadersName()},
692 Shared_libs: wrap("", cppDependencies, "-vts.profiler"),
693 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.profiler"),
694 Static_libs: concat(cppDependencies, libraryIfExists),
695
696 // TODO(b/126244142)
697 Cflags: []string{"-Wno-unused-variable"},
698 }, &i.inheritCommonProperties)
699 }
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700700}
701
702func (h *hidlInterface) Name() string {
703 return h.ModuleBase.Name() + hidlInterfaceSuffix
704}
705func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700706 visited := false
707 ctx.VisitDirectDeps(func(dep android.Module) {
708 if visited {
709 panic("internal error, multiple dependencies found but only one added")
710 }
711 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800712 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700713 })
714 if !visited {
715 panic("internal error, no dependencies found but dependency added")
716 }
717
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700718}
719func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700720 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700721}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700722
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700723func hidlInterfaceFactory() android.Module {
724 i := &hidlInterface{}
725 i.AddProperties(&i.properties)
Steven Moreland650bc512018-12-06 11:53:09 -0800726 i.AddProperties(&i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700727 android.InitAndroidModule(i)
728 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
729
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700730 return i
731}
732
Colin Crossf5536c32018-06-26 23:29:10 -0700733var doubleLoadablePackageNames = []string{
Jooyung Han407469c2019-01-18 18:16:21 +0900734 "android.hardware.cas@1.0",
735 "android.hardware.cas.native@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900736 "android.hardware.configstore@",
Jooyung Han407469c2019-01-18 18:16:21 +0900737 "android.hardware.drm@1.0",
738 "android.hardware.drm@1.1",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900739 "android.hardware.graphics.allocator@",
740 "android.hardware.graphics.bufferqueue@",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900741 "android.hardware.media@",
Jooyung Han407469c2019-01-18 18:16:21 +0900742 "android.hardware.media.omx@",
743 "android.hardware.memtrack@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900744 "android.hardware.neuralnetworks@",
745 "android.hidl.allocator@",
746 "android.hidl.token@",
Jooyung Han407469c2019-01-18 18:16:21 +0900747 "android.system.suspend@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900748}
749
750func isDoubleLoadable(name string) bool {
751 for _, pkgname := range doubleLoadablePackageNames {
752 if strings.HasPrefix(name, pkgname) {
753 return true
754 }
755 }
756 return false
757}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700758
759// packages in libhidltransport
760var coreDependencyPackageNames = []string{
761 "android.hidl.base@",
762 "android.hidl.manager@",
763}
764
765func isCorePackage(name string) bool {
766 for _, pkgname := range coreDependencyPackageNames {
767 if strings.HasPrefix(name, pkgname) {
768 return true
769 }
770 }
771 return false
772}
Steven Morelandeaba9232019-01-16 17:55:05 -0800773
774// TODO(b/126383715): centralize this logic/support filtering in core VTS build
775var coreVtsSpecs = []string{
776 "android.frameworks.",
777 "android.hardware.",
778 "android.hidl.",
779 "android.system.",
780}
781
782func isVtsSpecPackage(name string) bool {
783 for _, pkgname := range coreVtsSpecs {
784 if strings.HasPrefix(name, pkgname) {
785 return true
786 }
787 }
788 return false
789}
790
791var vtsListKey = android.NewOnceKey("vtsList")
792
793func vtsList(config android.Config) *android.Paths {
794 return config.Once(vtsListKey, func() interface{} {
795 return &android.Paths{}
796 }).(*android.Paths)
797}
798
799var vtsListMutex sync.Mutex
800
801func makeVarsProvider(ctx android.MakeVarsContext) {
802 vtsList := vtsList(ctx.Config()).Strings()
803 sort.Strings(vtsList)
804
805 ctx.Strict("VTS_SPEC_FILE_LIST", strings.Join(vtsList, " "))
806}