blob: 0154a61040a383248ace0f99dc972141043c9aef [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{
Sasha Smundakca658942019-03-04 18:28:56 -080050 Depfile: "${depfile}",
51 Deps: blueprint.DepsGCC,
52 Command: "rm -rf ${genDir} && " +
53 "${hidl} -R -p . -d ${depfile} -o ${genDir}/srcs -L ${language} ${roots} ${fqName} && " +
54 "${soong_zip} -o ${genDir}/srcs.srcjar -C ${genDir}/srcs -D ${genDir}/srcs",
Steven Morelandfeaee3b2019-03-01 12:44:36 -080055 CommandDeps: []string{"${hidl}", "${soong_zip}"},
56 Description: "HIDL ${language}: ${in} => srcs.srcjar",
57 }, "depfile", "fqName", "genDir", "language", "roots")
58
Steven Morelandeaba9232019-01-16 17:55:05 -080059 vtsRule = pctx.StaticRule("vtsRule", blueprint.RuleParams{
60 Command: "rm -rf ${genDir} && ${vtsc} -m${mode} -t${type} ${inputDir}/${packagePath} ${genDir}/${packagePath}",
61 CommandDeps: []string{"${vtsc}"},
62 Description: "VTS ${mode} ${type}: ${in} => ${out}",
63 }, "mode", "type", "inputDir", "genDir", "packagePath")
Steven Morelandd56e5bb2017-07-18 22:04:16 -070064)
65
66func init() {
67 android.RegisterModuleType("hidl_interface", hidlInterfaceFactory)
Steven Morelandeaba9232019-01-16 17:55:05 -080068 android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
Steven Morelandd56e5bb2017-07-18 22:04:16 -070069}
70
Steven Moreland744eb322018-07-25 16:31:08 -070071type hidlGenProperties struct {
72 Language string
73 FqName string
Steven Morelandd9fd1952018-11-08 18:14:37 -080074 Root string
Steven Moreland744eb322018-07-25 16:31:08 -070075 Interfaces []string
76 Inputs []string
77 Outputs []string
78}
79
80type hidlGenRule struct {
81 android.ModuleBase
82
83 properties hidlGenProperties
84
85 genOutputDir android.Path
86 genInputs android.Paths
87 genOutputs android.WritablePaths
88}
89
90var _ android.SourceFileProducer = (*hidlGenRule)(nil)
91var _ genrule.SourceFileGenerator = (*hidlGenRule)(nil)
92
93func (g *hidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
94 g.genOutputDir = android.PathForModuleGen(ctx)
95
96 for _, input := range g.properties.Inputs {
97 g.genInputs = append(g.genInputs, android.PathForModuleSrc(ctx, input))
98 }
99
100 for _, output := range g.properties.Outputs {
101 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
102 }
103
Steven Morelandeaba9232019-01-16 17:55:05 -0800104 if g.properties.Language == "vts" && isVtsSpecPackage(ctx.ModuleName()) {
105 vtsList := vtsList(ctx.AConfig())
106 vtsListMutex.Lock()
107 *vtsList = append(*vtsList, g.genOutputs.Paths()...)
108 vtsListMutex.Unlock()
109 }
110
Steven Moreland744eb322018-07-25 16:31:08 -0700111 var fullRootOptions []string
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800112 var currentPath android.OptionalPath
Steven Moreland744eb322018-07-25 16:31:08 -0700113 ctx.VisitDirectDeps(func(dep android.Module) {
Steven Morelandd9fd1952018-11-08 18:14:37 -0800114 switch t := dep.(type) {
115 case *hidlInterface:
116 fullRootOptions = append(fullRootOptions, t.properties.Full_root_option)
117 case *hidlPackageRoot:
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800118 if currentPath.Valid() {
119 panic(fmt.Sprintf("Expecting only one path, but found %v %v", currentPath, t.getCurrentPath()))
120 }
121
122 currentPath = t.getCurrentPath()
Steven Morelandd9fd1952018-11-08 18:14:37 -0800123 default:
124 panic(fmt.Sprintf("Unrecognized hidlGenProperties dependency: %T", t))
125 }
Steven Moreland744eb322018-07-25 16:31:08 -0700126 })
127
128 fullRootOptions = android.FirstUniqueStrings(fullRootOptions)
129
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800130 inputs := g.genInputs
Jooyung Han407469c2019-01-18 18:16:21 +0900131 if currentPath.Valid() {
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800132 inputs = append(inputs, currentPath.Path())
133 }
134
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800135 rule := hidlRule
136 if g.properties.Language == "java" {
137 rule = hidlSrcJarRule
138 }
139
Steven Moreland744eb322018-07-25 16:31:08 -0700140 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800141 Rule: rule,
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800142 Inputs: inputs,
Steven Moreland744eb322018-07-25 16:31:08 -0700143 Output: g.genOutputs[0],
144 ImplicitOutputs: g.genOutputs[1:],
145 Args: map[string]string{
146 "depfile": g.genOutputs[0].String() + ".d",
147 "genDir": g.genOutputDir.String(),
148 "fqName": g.properties.FqName,
149 "language": g.properties.Language,
150 "roots": strings.Join(fullRootOptions, " "),
151 },
152 })
153}
154
155func (g *hidlGenRule) GeneratedSourceFiles() android.Paths {
156 return g.genOutputs.Paths()
157}
158
159func (g *hidlGenRule) Srcs() android.Paths {
160 return g.genOutputs.Paths()
161}
162
163func (g *hidlGenRule) GeneratedDeps() android.Paths {
164 return g.genOutputs.Paths()
165}
166
167func (g *hidlGenRule) GeneratedHeaderDirs() android.Paths {
168 return android.Paths{g.genOutputDir}
169}
170
171func (g *hidlGenRule) DepsMutator(ctx android.BottomUpMutatorContext) {
172 ctx.AddDependency(ctx.Module(), nil, g.properties.FqName+hidlInterfaceSuffix)
173 ctx.AddDependency(ctx.Module(), nil, wrap("", g.properties.Interfaces, hidlInterfaceSuffix)...)
Steven Morelandd9fd1952018-11-08 18:14:37 -0800174 ctx.AddDependency(ctx.Module(), nil, g.properties.Root)
Steven Moreland744eb322018-07-25 16:31:08 -0700175}
176
177func hidlGenFactory() android.Module {
178 g := &hidlGenRule{}
179 g.AddProperties(&g.properties)
180 android.InitAndroidModule(g)
181 return g
182}
183
Steven Morelandeaba9232019-01-16 17:55:05 -0800184type vtscProperties struct {
185 Mode string
186 Type string
187 SpecName string // e.g. foo-vts.spec
188 Outputs []string
189 PackagePath string // e.g. android/hardware/foo/1.0/
190}
191
192type vtscRule struct {
193 android.ModuleBase
194
195 properties vtscProperties
196
197 genOutputDir android.Path
198 genInputDir android.Path
199 genInputs android.Paths
200 genOutputs android.WritablePaths
201}
202
203var _ android.SourceFileProducer = (*vtscRule)(nil)
204var _ genrule.SourceFileGenerator = (*vtscRule)(nil)
205
206func (g *vtscRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
207 g.genOutputDir = android.PathForModuleGen(ctx)
208
209 ctx.VisitDirectDeps(func(dep android.Module) {
210 if specs, ok := dep.(*hidlGenRule); ok {
211 g.genInputDir = specs.genOutputDir
212 g.genInputs = specs.genOutputs.Paths()
213 }
214 })
215
216 for _, output := range g.properties.Outputs {
217 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
218 }
219
220 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
221 Rule: vtsRule,
222 Inputs: g.genInputs,
223 Outputs: g.genOutputs,
224 Args: map[string]string{
225 "mode": g.properties.Mode,
226 "type": g.properties.Type,
227 "inputDir": g.genInputDir.String(),
228 "genDir": g.genOutputDir.String(),
229 "packagePath": g.properties.PackagePath,
230 },
231 })
232}
233
234func (g *vtscRule) GeneratedSourceFiles() android.Paths {
235 return g.genOutputs.Paths()
236}
237
238func (g *vtscRule) Srcs() android.Paths {
239 return g.genOutputs.Paths()
240}
241
242func (g *vtscRule) GeneratedDeps() android.Paths {
243 return g.genOutputs.Paths()
244}
245
246func (g *vtscRule) GeneratedHeaderDirs() android.Paths {
247 return android.Paths{g.genOutputDir}
248}
249
250func (g *vtscRule) DepsMutator(ctx android.BottomUpMutatorContext) {
251 ctx.AddDependency(ctx.Module(), nil, g.properties.SpecName)
252}
253
254func vtscFactory() android.Module {
255 g := &vtscRule{}
256 g.AddProperties(&g.properties)
257 android.InitAndroidModule(g)
258 return g
259}
260
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700261type hidlInterfaceProperties struct {
262 // Vndk properties for interface library only.
263 cc.VndkProperties
264
265 // List of .hal files which compose this interface.
266 Srcs []string
267
268 // List of hal interface packages that this library depends on.
269 Interfaces []string
270
271 // Package root for this package, must be a prefix of name
272 Root string
273
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800274 // Unused/deprecated: List of non-TypeDef types declared in types.hal.
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700275 Types []string
276
277 // Whether to generate the Java library stubs.
278 // Default: true
279 Gen_java *bool
280
281 // Whether to generate a Java library containing constants
282 // expressed by @export annotations in the hal files.
283 Gen_java_constants bool
Steven Moreland744eb322018-07-25 16:31:08 -0700284
Steven Moreland9f7c2972019-03-01 09:56:20 -0800285 // Whether to generate VTS-related testing libraries.
286 Gen_vts *bool
287
Steven Moreland744eb322018-07-25 16:31:08 -0700288 // example: -randroid.hardware:hardware/interfaces
289 Full_root_option string `blueprint:"mutated"`
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700290}
291
Steven Moreland650bc512018-12-06 11:53:09 -0800292// TODO(b/119771576): These properties are shared by all Android modules, and we are specifically
293// calling these out to be copied to every create module. However, if a new property is added, it
294// could break things because this code has no way to know about that.
295type manuallyInheritCommonProperties struct {
296 Enabled *bool
297 Compile_multilib *string
298 Target struct {
299 Host struct {
300 Compile_multilib *string
301 }
302 Android struct {
303 Compile_multilib *string
304 }
305 }
306 Proprietary *bool
307 Owner *string
308 Vendor *bool
309 Soc_specific *bool
310 Device_specific *bool
311 Product_specific *bool
312 Product_services_specific *bool
313 Recovery *bool
314 Init_rc []string
315 Vintf_fragments []string
316 Required []string
317 Notice *string
318 Dist struct {
319 Targets []string
320 Dest *string
321 Dir *string
322 Suffix *string
323 }
324}
325
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700326type hidlInterface struct {
327 android.ModuleBase
328
Steven Moreland650bc512018-12-06 11:53:09 -0800329 properties hidlInterfaceProperties
330 inheritCommonProperties manuallyInheritCommonProperties
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700331}
332
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700333func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) {
334 var interfaces []string
335 var types []string // hidl-gen only supports types.hal, but don't assume that here
336
337 hasError := false
338
339 for _, v := range srcs {
340 if !strings.HasSuffix(v, ".hal") {
341 mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v)
342 hasError = true
343 continue
344 }
345
346 name := strings.TrimSuffix(v, ".hal")
347
348 if strings.HasPrefix(name, "I") {
349 baseName := strings.TrimPrefix(name, "I")
350 interfaces = append(interfaces, baseName)
351 } else {
352 types = append(types, name)
353 }
354 }
355
356 return interfaces, types, !hasError
357}
358
359func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) {
360 var dependencies []string
361 var javaDependencies []string
362
363 hasError := false
364
365 for _, v := range interfaces {
366 name, err := parseFqName(v)
367 if err != nil {
368 mctx.PropertyErrorf("interfaces", err.Error())
369 hasError = true
370 continue
371 }
372 dependencies = append(dependencies, name.string())
373 javaDependencies = append(javaDependencies, name.javaName())
374 }
375
376 return dependencies, javaDependencies, !hasError
377}
378
Steven Moreland744eb322018-07-25 16:31:08 -0700379func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700380 var ret []string
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700381
382 for _, i := range dependencies {
Steven Morelandb49d3a72018-07-25 16:40:03 -0700383 if !isCorePackage(i) {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700384 ret = append(ret, i)
385 }
386 }
387
Steven Moreland744eb322018-07-25 16:31:08 -0700388 return ret
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700389}
390
391func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) {
392 name, err := parseFqName(i.ModuleBase.Name())
393 if err != nil {
394 mctx.PropertyErrorf("name", err.Error())
395 }
396
397 if !name.inPackage(i.properties.Root) {
Steven Moreland744eb322018-07-25 16:31:08 -0700398 mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".")
399 }
400 if lookupPackageRoot(i.properties.Root) == nil {
401 mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+
402 `root '%s' needed for module '%s'. Either this is a mispelling of the package `+
403 `root, or a new hidl_package_root module needs to be added. For example, you can `+
404 `fix this error by adding the following to <some path>/Android.bp:
405
406hidl_package_root {
407name: "%s",
408path: "<some path>",
409}
410
411This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`,
412 i.properties.Root, name, i.properties.Root, i.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700413 }
414
415 interfaces, types, _ := processSources(mctx, i.properties.Srcs)
416
417 if len(interfaces) == 0 && len(types) == 0 {
418 mctx.PropertyErrorf("srcs", "No sources provided.")
419 }
420
421 dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces)
Steven Moreland744eb322018-07-25 16:31:08 -0700422 cppDependencies := removeCoreDependencies(mctx, dependencies)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700423
424 if mctx.Failed() {
425 return
426 }
427
Steven Morelandb49d3a72018-07-25 16:40:03 -0700428 shouldGenerateLibrary := !isCorePackage(name.string())
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700429 // explicitly true if not specified to give early warning to devs
Steven Moreland9f7c2972019-03-01 09:56:20 -0800430 shouldGenerateJava := proptools.BoolDefault(i.properties.Gen_java, true)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700431 shouldGenerateJavaConstants := i.properties.Gen_java_constants
Steven Moreland9f7c2972019-03-01 09:56:20 -0800432 shouldGenerateVts := shouldGenerateLibrary && proptools.BoolDefault(i.properties.Gen_vts, true)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700433
434 var libraryIfExists []string
435 if shouldGenerateLibrary {
436 libraryIfExists = []string{name.string()}
437 }
438
439 // TODO(b/69002743): remove filegroups
Pirama Arumuga Nainarf43bb1e2018-04-18 11:34:56 -0700440 mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{
Steven Moreland650bc512018-12-06 11:53:09 -0800441 Name: proptools.StringPtr(name.fileGroupName()),
442 Srcs: i.properties.Srcs,
443 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700444
Steven Moreland744eb322018-07-25 16:31:08 -0700445 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
446 Name: proptools.StringPtr(name.sourcesName()),
447 }, &hidlGenProperties{
448 Language: "c++-sources",
449 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800450 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700451 Interfaces: i.properties.Interfaces,
452 Inputs: i.properties.Srcs,
453 Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")),
Steven Moreland650bc512018-12-06 11:53:09 -0800454 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700455 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
456 Name: proptools.StringPtr(name.headersName()),
457 }, &hidlGenProperties{
458 Language: "c++-headers",
459 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800460 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700461 Interfaces: i.properties.Interfaces,
462 Inputs: i.properties.Srcs,
463 Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700464 wrap(name.dir()+"Bs", interfaces, ".h"),
465 wrap(name.dir()+"BnHw", interfaces, ".h"),
466 wrap(name.dir()+"BpHw", interfaces, ".h"),
467 wrap(name.dir()+"IHw", interfaces, ".h"),
468 wrap(name.dir(), types, ".h"),
469 wrap(name.dir()+"hw", types, ".h")),
Steven Moreland650bc512018-12-06 11:53:09 -0800470 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700471
472 if shouldGenerateLibrary {
473 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
Jerry Zhangf2a93962018-05-30 17:16:05 -0700474 Name: proptools.StringPtr(name.string()),
Jerry Zhangf2a93962018-05-30 17:16:05 -0700475 Recovery_available: proptools.BoolPtr(true),
476 Vendor_available: proptools.BoolPtr(true),
477 Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())),
478 Defaults: []string{"hidl-module-defaults"},
479 Generated_sources: []string{name.sourcesName()},
480 Generated_headers: []string{name.headersName()},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700481 Shared_libs: concat(cppDependencies, []string{
482 "libhidlbase",
483 "libhidltransport",
484 "libhwbinder",
485 "liblog",
486 "libutils",
487 "libcutils",
488 }),
489 Export_shared_lib_headers: concat(cppDependencies, []string{
490 "libhidlbase",
491 "libhidltransport",
492 "libhwbinder",
493 "libutils",
494 }),
495 Export_generated_headers: []string{name.headersName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800496 }, &i.properties.VndkProperties, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700497 }
498
499 if shouldGenerateJava {
Steven Moreland744eb322018-07-25 16:31:08 -0700500 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
501 Name: proptools.StringPtr(name.javaSourcesName()),
502 }, &hidlGenProperties{
503 Language: "java",
504 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800505 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700506 Interfaces: i.properties.Interfaces,
507 Inputs: i.properties.Srcs,
Steven Morelandfeaee3b2019-03-01 12:44:36 -0800508 Outputs: []string{"srcs.srcjar"},
Steven Moreland650bc512018-12-06 11:53:09 -0800509 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700510 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700511 Name: proptools.StringPtr(name.javaName()),
512 Defaults: []string{"hidl-java-module-defaults"},
513 No_framework_libs: proptools.BoolPtr(true),
Colin Crossf5536c32018-06-26 23:29:10 -0700514 Installable: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700515 Srcs: []string{":" + name.javaSourcesName()},
Steven Morelandfcfbeaf2018-01-29 19:34:52 -0800516 Static_libs: javaDependencies,
Colin Crossa5050552018-03-29 10:30:03 -0700517
518 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
519 // to build framework, which is used to build system_current. Use core_current
520 // plus hwbinder.stubs, which together form a subset of system_current that does
521 // not depend on framework.
522 Sdk_version: proptools.StringPtr("core_current"),
523 Libs: []string{"hwbinder.stubs"},
Steven Moreland650bc512018-12-06 11:53:09 -0800524 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700525 }
526
527 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700528 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
529 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
530 }, &hidlGenProperties{
531 Language: "java-constants",
532 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800533 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700534 Interfaces: i.properties.Interfaces,
535 Inputs: i.properties.Srcs,
536 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Moreland650bc512018-12-06 11:53:09 -0800537 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700538 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700539 Name: proptools.StringPtr(name.javaConstantsName()),
540 Defaults: []string{"hidl-java-module-defaults"},
541 No_framework_libs: proptools.BoolPtr(true),
542 Srcs: []string{":" + name.javaConstantsSourcesName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800543 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700544 }
545
Steven Moreland744eb322018-07-25 16:31:08 -0700546 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
547 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
548 }, &hidlGenProperties{
549 Language: "c++-adapter-sources",
550 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800551 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700552 Interfaces: i.properties.Interfaces,
553 Inputs: i.properties.Srcs,
554 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"),
Steven Moreland650bc512018-12-06 11:53:09 -0800555 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700556 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
557 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
558 }, &hidlGenProperties{
559 Language: "c++-adapter-headers",
560 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800561 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700562 Interfaces: i.properties.Interfaces,
563 Inputs: i.properties.Srcs,
564 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Moreland650bc512018-12-06 11:53:09 -0800565 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700566
567 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
568 Name: proptools.StringPtr(name.adapterHelperName()),
569 Vendor_available: proptools.BoolPtr(true),
570 Defaults: []string{"hidl-module-defaults"},
571 Generated_sources: []string{name.adapterHelperSourcesName()},
572 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800573 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800574 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800575 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700576 "libhidlbase",
577 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800578 "libhwbinder",
579 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700580 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800581 },
582 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700583 "libhidladapter",
584 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800585 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700586 "libhidlbase",
587 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800588 },
589 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700590 "libhidladapter",
591 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
592 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800593 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800594 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700595 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
596 Name: proptools.StringPtr(name.adapterSourcesName()),
597 }, &hidlGenProperties{
598 Language: "c++-adapter-main",
599 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800600 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700601 Interfaces: i.properties.Interfaces,
602 Inputs: i.properties.Srcs,
603 Outputs: []string{"main.cpp"},
Steven Moreland650bc512018-12-06 11:53:09 -0800604 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700605 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
606 Name: proptools.StringPtr(name.adapterName()),
607 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800608 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800609 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800610 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700611 "libhidlbase",
612 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800613 "libhwbinder",
614 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700615 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800616 },
617 Static_libs: concat([]string{
618 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700619 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800620 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
621 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800622 }, &i.inheritCommonProperties)
Steven Morelandeaba9232019-01-16 17:55:05 -0800623
624 if shouldGenerateVts {
625 vtsSpecs := concat(wrap(name.dir(), interfaces, ".vts"), wrap(name.dir(), types, ".vts"))
626
627 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
628 Name: proptools.StringPtr(name.vtsSpecName()),
629 }, &hidlGenProperties{
630 Language: "vts",
631 FqName: name.string(),
632 Root: i.properties.Root,
633 Interfaces: i.properties.Interfaces,
634 Inputs: i.properties.Srcs,
635 Outputs: vtsSpecs,
636 }, &i.inheritCommonProperties)
637
638 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
639 Name: proptools.StringPtr(name.vtsDriverSourcesName()),
640 }, &vtscProperties{
641 Mode: "DRIVER",
642 Type: "SOURCE",
643 SpecName: name.vtsSpecName(),
644 Outputs: wrap("", vtsSpecs, ".cpp"),
645 PackagePath: name.dir(),
646 }, &i.inheritCommonProperties)
647 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
648 Name: proptools.StringPtr(name.vtsDriverHeadersName()),
649 }, &vtscProperties{
650 Mode: "DRIVER",
651 Type: "HEADER",
652 SpecName: name.vtsSpecName(),
653 Outputs: wrap("", vtsSpecs, ".h"),
654 PackagePath: name.dir(),
655 }, &i.inheritCommonProperties)
656 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
657 Name: proptools.StringPtr(name.vtsDriverName()),
658 Defaults: []string{"VtsHalDriverDefaults"},
659 Generated_sources: []string{name.vtsDriverSourcesName()},
660 Generated_headers: []string{name.vtsDriverHeadersName()},
661 Export_generated_headers: []string{name.vtsDriverHeadersName()},
662 Shared_libs: wrap("", cppDependencies, "-vts.driver"),
663 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.driver"),
664 Static_libs: concat(cppDependencies, libraryIfExists),
665
666 // TODO(b/126244142)
667 Cflags: []string{"-Wno-unused-variable"},
668 }, &i.inheritCommonProperties)
669
670 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
671 Name: proptools.StringPtr(name.vtsProfilerSourcesName()),
672 }, &vtscProperties{
673 Mode: "PROFILER",
674 Type: "SOURCE",
675 SpecName: name.vtsSpecName(),
676 Outputs: wrap("", vtsSpecs, ".cpp"),
677 PackagePath: name.dir(),
678 }, &i.inheritCommonProperties)
679 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
680 Name: proptools.StringPtr(name.vtsProfilerHeadersName()),
681 }, &vtscProperties{
682 Mode: "PROFILER",
683 Type: "HEADER",
684 SpecName: name.vtsSpecName(),
685 Outputs: wrap("", vtsSpecs, ".h"),
686 PackagePath: name.dir(),
687 }, &i.inheritCommonProperties)
688 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
689 Name: proptools.StringPtr(name.vtsProfilerName()),
690 Defaults: []string{"VtsHalProfilerDefaults"},
691 Generated_sources: []string{name.vtsProfilerSourcesName()},
692 Generated_headers: []string{name.vtsProfilerHeadersName()},
693 Export_generated_headers: []string{name.vtsProfilerHeadersName()},
694 Shared_libs: wrap("", cppDependencies, "-vts.profiler"),
695 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.profiler"),
696 Static_libs: concat(cppDependencies, libraryIfExists),
697
698 // TODO(b/126244142)
699 Cflags: []string{"-Wno-unused-variable"},
700 }, &i.inheritCommonProperties)
701 }
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700702}
703
704func (h *hidlInterface) Name() string {
705 return h.ModuleBase.Name() + hidlInterfaceSuffix
706}
707func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700708 visited := false
709 ctx.VisitDirectDeps(func(dep android.Module) {
710 if visited {
711 panic("internal error, multiple dependencies found but only one added")
712 }
713 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800714 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700715 })
716 if !visited {
717 panic("internal error, no dependencies found but dependency added")
718 }
719
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700720}
721func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700722 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700723}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700724
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700725func hidlInterfaceFactory() android.Module {
726 i := &hidlInterface{}
727 i.AddProperties(&i.properties)
Steven Moreland650bc512018-12-06 11:53:09 -0800728 i.AddProperties(&i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700729 android.InitAndroidModule(i)
730 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
731
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700732 return i
733}
734
Colin Crossf5536c32018-06-26 23:29:10 -0700735var doubleLoadablePackageNames = []string{
Jooyung Han407469c2019-01-18 18:16:21 +0900736 "android.hardware.cas@1.0",
737 "android.hardware.cas.native@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900738 "android.hardware.configstore@",
Jooyung Han407469c2019-01-18 18:16:21 +0900739 "android.hardware.drm@1.0",
740 "android.hardware.drm@1.1",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900741 "android.hardware.graphics.allocator@",
742 "android.hardware.graphics.bufferqueue@",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900743 "android.hardware.media@",
Jooyung Han407469c2019-01-18 18:16:21 +0900744 "android.hardware.media.omx@",
745 "android.hardware.memtrack@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900746 "android.hardware.neuralnetworks@",
747 "android.hidl.allocator@",
748 "android.hidl.token@",
Jooyung Han407469c2019-01-18 18:16:21 +0900749 "android.system.suspend@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900750}
751
752func isDoubleLoadable(name string) bool {
753 for _, pkgname := range doubleLoadablePackageNames {
754 if strings.HasPrefix(name, pkgname) {
755 return true
756 }
757 }
758 return false
759}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700760
761// packages in libhidltransport
762var coreDependencyPackageNames = []string{
763 "android.hidl.base@",
764 "android.hidl.manager@",
765}
766
767func isCorePackage(name string) bool {
768 for _, pkgname := range coreDependencyPackageNames {
769 if strings.HasPrefix(name, pkgname) {
770 return true
771 }
772 }
773 return false
774}
Steven Morelandeaba9232019-01-16 17:55:05 -0800775
776// TODO(b/126383715): centralize this logic/support filtering in core VTS build
777var coreVtsSpecs = []string{
778 "android.frameworks.",
779 "android.hardware.",
780 "android.hidl.",
781 "android.system.",
782}
783
784func isVtsSpecPackage(name string) bool {
785 for _, pkgname := range coreVtsSpecs {
786 if strings.HasPrefix(name, pkgname) {
787 return true
788 }
789 }
790 return false
791}
792
793var vtsListKey = android.NewOnceKey("vtsList")
794
795func vtsList(config android.Config) *android.Paths {
796 return config.Once(vtsListKey, func() interface{} {
797 return &android.Paths{}
798 }).(*android.Paths)
799}
800
801var vtsListMutex sync.Mutex
802
803func makeVarsProvider(ctx android.MakeVarsContext) {
804 vtsList := vtsList(ctx.Config()).Strings()
805 sort.Strings(vtsList)
806
807 ctx.Strict("VTS_SPEC_FILE_LIST", strings.Join(vtsList, " "))
808}