blob: 789219353445d121af435614eb24109cf6c37d30 [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)
Steven Morelanda7227fd2019-03-08 10:16:19 -0800510
511 commonJavaProperties := javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700512 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()},
Colin Crossa5050552018-03-29 10:30:03 -0700516
517 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
518 // to build framework, which is used to build system_current. Use core_current
519 // plus hwbinder.stubs, which together form a subset of system_current that does
520 // not depend on framework.
521 Sdk_version: proptools.StringPtr("core_current"),
522 Libs: []string{"hwbinder.stubs"},
Steven Morelanda7227fd2019-03-08 10:16:19 -0800523 }
524
525 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
526 Name: proptools.StringPtr(name.javaName()),
527 Static_libs: javaDependencies,
528 }, &i.inheritCommonProperties, &commonJavaProperties)
529 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
530 Name: proptools.StringPtr(name.javaSharedName()),
531 Libs: javaDependencies,
532 }, &i.inheritCommonProperties, &commonJavaProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700533 }
534
535 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700536 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
537 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
538 }, &hidlGenProperties{
539 Language: "java-constants",
540 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800541 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700542 Interfaces: i.properties.Interfaces,
543 Inputs: i.properties.Srcs,
544 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Moreland650bc512018-12-06 11:53:09 -0800545 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700546 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700547 Name: proptools.StringPtr(name.javaConstantsName()),
548 Defaults: []string{"hidl-java-module-defaults"},
549 No_framework_libs: proptools.BoolPtr(true),
550 Srcs: []string{":" + name.javaConstantsSourcesName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800551 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700552 }
553
Steven Moreland744eb322018-07-25 16:31:08 -0700554 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
555 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
556 }, &hidlGenProperties{
557 Language: "c++-adapter-sources",
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), ".cpp"),
Steven Moreland650bc512018-12-06 11:53:09 -0800563 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700564 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
565 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
566 }, &hidlGenProperties{
567 Language: "c++-adapter-headers",
568 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800569 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700570 Interfaces: i.properties.Interfaces,
571 Inputs: i.properties.Srcs,
572 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Moreland650bc512018-12-06 11:53:09 -0800573 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700574
575 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
576 Name: proptools.StringPtr(name.adapterHelperName()),
577 Vendor_available: proptools.BoolPtr(true),
578 Defaults: []string{"hidl-module-defaults"},
579 Generated_sources: []string{name.adapterHelperSourcesName()},
580 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800581 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800582 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800583 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700584 "libhidlbase",
585 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800586 "libhwbinder",
587 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700588 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800589 },
590 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700591 "libhidladapter",
592 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800593 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700594 "libhidlbase",
595 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800596 },
597 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700598 "libhidladapter",
599 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
600 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800601 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800602 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700603 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
604 Name: proptools.StringPtr(name.adapterSourcesName()),
605 }, &hidlGenProperties{
606 Language: "c++-adapter-main",
607 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800608 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700609 Interfaces: i.properties.Interfaces,
610 Inputs: i.properties.Srcs,
611 Outputs: []string{"main.cpp"},
Steven Moreland650bc512018-12-06 11:53:09 -0800612 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700613 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
614 Name: proptools.StringPtr(name.adapterName()),
615 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800616 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800617 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800618 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700619 "libhidlbase",
620 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800621 "libhwbinder",
622 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700623 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800624 },
625 Static_libs: concat([]string{
626 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700627 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800628 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
629 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800630 }, &i.inheritCommonProperties)
Steven Morelandeaba9232019-01-16 17:55:05 -0800631
632 if shouldGenerateVts {
633 vtsSpecs := concat(wrap(name.dir(), interfaces, ".vts"), wrap(name.dir(), types, ".vts"))
634
635 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
636 Name: proptools.StringPtr(name.vtsSpecName()),
637 }, &hidlGenProperties{
638 Language: "vts",
639 FqName: name.string(),
640 Root: i.properties.Root,
641 Interfaces: i.properties.Interfaces,
642 Inputs: i.properties.Srcs,
643 Outputs: vtsSpecs,
644 }, &i.inheritCommonProperties)
645
646 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
647 Name: proptools.StringPtr(name.vtsDriverSourcesName()),
648 }, &vtscProperties{
649 Mode: "DRIVER",
650 Type: "SOURCE",
651 SpecName: name.vtsSpecName(),
652 Outputs: wrap("", vtsSpecs, ".cpp"),
653 PackagePath: name.dir(),
654 }, &i.inheritCommonProperties)
655 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
656 Name: proptools.StringPtr(name.vtsDriverHeadersName()),
657 }, &vtscProperties{
658 Mode: "DRIVER",
659 Type: "HEADER",
660 SpecName: name.vtsSpecName(),
661 Outputs: wrap("", vtsSpecs, ".h"),
662 PackagePath: name.dir(),
663 }, &i.inheritCommonProperties)
664 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
665 Name: proptools.StringPtr(name.vtsDriverName()),
666 Defaults: []string{"VtsHalDriverDefaults"},
667 Generated_sources: []string{name.vtsDriverSourcesName()},
668 Generated_headers: []string{name.vtsDriverHeadersName()},
669 Export_generated_headers: []string{name.vtsDriverHeadersName()},
670 Shared_libs: wrap("", cppDependencies, "-vts.driver"),
671 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.driver"),
672 Static_libs: concat(cppDependencies, libraryIfExists),
673
674 // TODO(b/126244142)
675 Cflags: []string{"-Wno-unused-variable"},
676 }, &i.inheritCommonProperties)
677
678 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
679 Name: proptools.StringPtr(name.vtsProfilerSourcesName()),
680 }, &vtscProperties{
681 Mode: "PROFILER",
682 Type: "SOURCE",
683 SpecName: name.vtsSpecName(),
684 Outputs: wrap("", vtsSpecs, ".cpp"),
685 PackagePath: name.dir(),
686 }, &i.inheritCommonProperties)
687 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
688 Name: proptools.StringPtr(name.vtsProfilerHeadersName()),
689 }, &vtscProperties{
690 Mode: "PROFILER",
691 Type: "HEADER",
692 SpecName: name.vtsSpecName(),
693 Outputs: wrap("", vtsSpecs, ".h"),
694 PackagePath: name.dir(),
695 }, &i.inheritCommonProperties)
696 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
697 Name: proptools.StringPtr(name.vtsProfilerName()),
698 Defaults: []string{"VtsHalProfilerDefaults"},
699 Generated_sources: []string{name.vtsProfilerSourcesName()},
700 Generated_headers: []string{name.vtsProfilerHeadersName()},
701 Export_generated_headers: []string{name.vtsProfilerHeadersName()},
702 Shared_libs: wrap("", cppDependencies, "-vts.profiler"),
703 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.profiler"),
704 Static_libs: concat(cppDependencies, libraryIfExists),
705
706 // TODO(b/126244142)
707 Cflags: []string{"-Wno-unused-variable"},
708 }, &i.inheritCommonProperties)
709 }
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700710}
711
712func (h *hidlInterface) Name() string {
713 return h.ModuleBase.Name() + hidlInterfaceSuffix
714}
715func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700716 visited := false
717 ctx.VisitDirectDeps(func(dep android.Module) {
718 if visited {
719 panic("internal error, multiple dependencies found but only one added")
720 }
721 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800722 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700723 })
724 if !visited {
725 panic("internal error, no dependencies found but dependency added")
726 }
727
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700728}
729func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700730 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700731}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700732
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700733func hidlInterfaceFactory() android.Module {
734 i := &hidlInterface{}
735 i.AddProperties(&i.properties)
Steven Moreland650bc512018-12-06 11:53:09 -0800736 i.AddProperties(&i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700737 android.InitAndroidModule(i)
738 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
739
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700740 return i
741}
742
Colin Crossf5536c32018-06-26 23:29:10 -0700743var doubleLoadablePackageNames = []string{
Jooyung Han407469c2019-01-18 18:16:21 +0900744 "android.hardware.cas@1.0",
745 "android.hardware.cas.native@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900746 "android.hardware.configstore@",
Jooyung Han407469c2019-01-18 18:16:21 +0900747 "android.hardware.drm@1.0",
748 "android.hardware.drm@1.1",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900749 "android.hardware.graphics.allocator@",
750 "android.hardware.graphics.bufferqueue@",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900751 "android.hardware.media@",
Jooyung Han407469c2019-01-18 18:16:21 +0900752 "android.hardware.media.omx@",
753 "android.hardware.memtrack@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900754 "android.hardware.neuralnetworks@",
755 "android.hidl.allocator@",
756 "android.hidl.token@",
Jooyung Han407469c2019-01-18 18:16:21 +0900757 "android.system.suspend@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900758}
759
760func isDoubleLoadable(name string) bool {
761 for _, pkgname := range doubleLoadablePackageNames {
762 if strings.HasPrefix(name, pkgname) {
763 return true
764 }
765 }
766 return false
767}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700768
769// packages in libhidltransport
770var coreDependencyPackageNames = []string{
771 "android.hidl.base@",
772 "android.hidl.manager@",
773}
774
775func isCorePackage(name string) bool {
776 for _, pkgname := range coreDependencyPackageNames {
777 if strings.HasPrefix(name, pkgname) {
778 return true
779 }
780 }
781 return false
782}
Steven Morelandeaba9232019-01-16 17:55:05 -0800783
784// TODO(b/126383715): centralize this logic/support filtering in core VTS build
785var coreVtsSpecs = []string{
786 "android.frameworks.",
787 "android.hardware.",
788 "android.hidl.",
789 "android.system.",
790}
791
792func isVtsSpecPackage(name string) bool {
793 for _, pkgname := range coreVtsSpecs {
794 if strings.HasPrefix(name, pkgname) {
795 return true
796 }
797 }
798 return false
799}
800
801var vtsListKey = android.NewOnceKey("vtsList")
802
803func vtsList(config android.Config) *android.Paths {
804 return config.Once(vtsListKey, func() interface{} {
805 return &android.Paths{}
806 }).(*android.Paths)
807}
808
809var vtsListMutex sync.Mutex
810
811func makeVarsProvider(ctx android.MakeVarsContext) {
812 vtsList := vtsList(ctx.Config()).Strings()
813 sort.Strings(vtsList)
814
815 ctx.Strict("VTS_SPEC_FILE_LIST", strings.Join(vtsList, " "))
816}