blob: 5b67d9aa2481248097351a5b3fd1fbaf4f889918 [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 Morelandeaba9232019-01-16 17:55:05 -080037 hidl = pctx.HostBinToolVariable("hidl", "hidl-gen")
38 vtsc = pctx.HostBinToolVariable("vtsc", "vtsc")
39
Steven Moreland744eb322018-07-25 16:31:08 -070040 hidlRule = pctx.StaticRule("hidlRule", blueprint.RuleParams{
41 Depfile: "${depfile}",
42 Deps: blueprint.DepsGCC,
Steven Morelandbc98bdb2018-10-31 14:47:07 -070043 Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${depfile} -o ${genDir} -L ${language} ${roots} ${fqName}",
Steven Moreland744eb322018-07-25 16:31:08 -070044 CommandDeps: []string{"${hidl}"},
45 Description: "HIDL ${language}: ${in} => ${out}",
46 }, "depfile", "fqName", "genDir", "language", "roots")
Steven Morelandeaba9232019-01-16 17:55:05 -080047
48 vtsRule = pctx.StaticRule("vtsRule", blueprint.RuleParams{
49 Command: "rm -rf ${genDir} && ${vtsc} -m${mode} -t${type} ${inputDir}/${packagePath} ${genDir}/${packagePath}",
50 CommandDeps: []string{"${vtsc}"},
51 Description: "VTS ${mode} ${type}: ${in} => ${out}",
52 }, "mode", "type", "inputDir", "genDir", "packagePath")
Steven Morelandd56e5bb2017-07-18 22:04:16 -070053)
54
55func init() {
56 android.RegisterModuleType("hidl_interface", hidlInterfaceFactory)
Steven Morelandeaba9232019-01-16 17:55:05 -080057 android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
Steven Morelandd56e5bb2017-07-18 22:04:16 -070058}
59
Steven Moreland744eb322018-07-25 16:31:08 -070060type hidlGenProperties struct {
61 Language string
62 FqName string
Steven Morelandd9fd1952018-11-08 18:14:37 -080063 Root string
Steven Moreland744eb322018-07-25 16:31:08 -070064 Interfaces []string
65 Inputs []string
66 Outputs []string
67}
68
69type hidlGenRule struct {
70 android.ModuleBase
71
72 properties hidlGenProperties
73
74 genOutputDir android.Path
75 genInputs android.Paths
76 genOutputs android.WritablePaths
77}
78
79var _ android.SourceFileProducer = (*hidlGenRule)(nil)
80var _ genrule.SourceFileGenerator = (*hidlGenRule)(nil)
81
82func (g *hidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
83 g.genOutputDir = android.PathForModuleGen(ctx)
84
85 for _, input := range g.properties.Inputs {
86 g.genInputs = append(g.genInputs, android.PathForModuleSrc(ctx, input))
87 }
88
89 for _, output := range g.properties.Outputs {
90 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
91 }
92
Steven Morelandeaba9232019-01-16 17:55:05 -080093 if g.properties.Language == "vts" && isVtsSpecPackage(ctx.ModuleName()) {
94 vtsList := vtsList(ctx.AConfig())
95 vtsListMutex.Lock()
96 *vtsList = append(*vtsList, g.genOutputs.Paths()...)
97 vtsListMutex.Unlock()
98 }
99
Steven Moreland744eb322018-07-25 16:31:08 -0700100 var fullRootOptions []string
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800101 var currentPath android.OptionalPath
Steven Moreland744eb322018-07-25 16:31:08 -0700102 ctx.VisitDirectDeps(func(dep android.Module) {
Steven Morelandd9fd1952018-11-08 18:14:37 -0800103 switch t := dep.(type) {
104 case *hidlInterface:
105 fullRootOptions = append(fullRootOptions, t.properties.Full_root_option)
106 case *hidlPackageRoot:
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800107 if currentPath.Valid() {
108 panic(fmt.Sprintf("Expecting only one path, but found %v %v", currentPath, t.getCurrentPath()))
109 }
110
111 currentPath = t.getCurrentPath()
Steven Morelandd9fd1952018-11-08 18:14:37 -0800112 default:
113 panic(fmt.Sprintf("Unrecognized hidlGenProperties dependency: %T", t))
114 }
Steven Moreland744eb322018-07-25 16:31:08 -0700115 })
116
117 fullRootOptions = android.FirstUniqueStrings(fullRootOptions)
118
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800119 inputs := g.genInputs
Jooyung Han407469c2019-01-18 18:16:21 +0900120 if currentPath.Valid() {
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800121 inputs = append(inputs, currentPath.Path())
122 }
123
Steven Moreland744eb322018-07-25 16:31:08 -0700124 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
125 Rule: hidlRule,
Steven Moreland9ae68ab2019-01-16 14:04:08 -0800126 Inputs: inputs,
Steven Moreland744eb322018-07-25 16:31:08 -0700127 Output: g.genOutputs[0],
128 ImplicitOutputs: g.genOutputs[1:],
129 Args: map[string]string{
130 "depfile": g.genOutputs[0].String() + ".d",
131 "genDir": g.genOutputDir.String(),
132 "fqName": g.properties.FqName,
133 "language": g.properties.Language,
134 "roots": strings.Join(fullRootOptions, " "),
135 },
136 })
137}
138
139func (g *hidlGenRule) GeneratedSourceFiles() android.Paths {
140 return g.genOutputs.Paths()
141}
142
143func (g *hidlGenRule) Srcs() android.Paths {
144 return g.genOutputs.Paths()
145}
146
147func (g *hidlGenRule) GeneratedDeps() android.Paths {
148 return g.genOutputs.Paths()
149}
150
151func (g *hidlGenRule) GeneratedHeaderDirs() android.Paths {
152 return android.Paths{g.genOutputDir}
153}
154
155func (g *hidlGenRule) DepsMutator(ctx android.BottomUpMutatorContext) {
156 ctx.AddDependency(ctx.Module(), nil, g.properties.FqName+hidlInterfaceSuffix)
157 ctx.AddDependency(ctx.Module(), nil, wrap("", g.properties.Interfaces, hidlInterfaceSuffix)...)
Steven Morelandd9fd1952018-11-08 18:14:37 -0800158 ctx.AddDependency(ctx.Module(), nil, g.properties.Root)
Steven Moreland744eb322018-07-25 16:31:08 -0700159}
160
161func hidlGenFactory() android.Module {
162 g := &hidlGenRule{}
163 g.AddProperties(&g.properties)
164 android.InitAndroidModule(g)
165 return g
166}
167
Steven Morelandeaba9232019-01-16 17:55:05 -0800168type vtscProperties struct {
169 Mode string
170 Type string
171 SpecName string // e.g. foo-vts.spec
172 Outputs []string
173 PackagePath string // e.g. android/hardware/foo/1.0/
174}
175
176type vtscRule struct {
177 android.ModuleBase
178
179 properties vtscProperties
180
181 genOutputDir android.Path
182 genInputDir android.Path
183 genInputs android.Paths
184 genOutputs android.WritablePaths
185}
186
187var _ android.SourceFileProducer = (*vtscRule)(nil)
188var _ genrule.SourceFileGenerator = (*vtscRule)(nil)
189
190func (g *vtscRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
191 g.genOutputDir = android.PathForModuleGen(ctx)
192
193 ctx.VisitDirectDeps(func(dep android.Module) {
194 if specs, ok := dep.(*hidlGenRule); ok {
195 g.genInputDir = specs.genOutputDir
196 g.genInputs = specs.genOutputs.Paths()
197 }
198 })
199
200 for _, output := range g.properties.Outputs {
201 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
202 }
203
204 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
205 Rule: vtsRule,
206 Inputs: g.genInputs,
207 Outputs: g.genOutputs,
208 Args: map[string]string{
209 "mode": g.properties.Mode,
210 "type": g.properties.Type,
211 "inputDir": g.genInputDir.String(),
212 "genDir": g.genOutputDir.String(),
213 "packagePath": g.properties.PackagePath,
214 },
215 })
216}
217
218func (g *vtscRule) GeneratedSourceFiles() android.Paths {
219 return g.genOutputs.Paths()
220}
221
222func (g *vtscRule) Srcs() android.Paths {
223 return g.genOutputs.Paths()
224}
225
226func (g *vtscRule) GeneratedDeps() android.Paths {
227 return g.genOutputs.Paths()
228}
229
230func (g *vtscRule) GeneratedHeaderDirs() android.Paths {
231 return android.Paths{g.genOutputDir}
232}
233
234func (g *vtscRule) DepsMutator(ctx android.BottomUpMutatorContext) {
235 ctx.AddDependency(ctx.Module(), nil, g.properties.SpecName)
236}
237
238func vtscFactory() android.Module {
239 g := &vtscRule{}
240 g.AddProperties(&g.properties)
241 android.InitAndroidModule(g)
242 return g
243}
244
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700245type hidlInterfaceProperties struct {
246 // Vndk properties for interface library only.
247 cc.VndkProperties
248
249 // List of .hal files which compose this interface.
250 Srcs []string
251
252 // List of hal interface packages that this library depends on.
253 Interfaces []string
254
255 // Package root for this package, must be a prefix of name
256 Root string
257
258 // List of non-TypeDef types declared in types.hal.
259 Types []string
260
261 // Whether to generate the Java library stubs.
262 // Default: true
263 Gen_java *bool
264
265 // Whether to generate a Java library containing constants
266 // expressed by @export annotations in the hal files.
267 Gen_java_constants bool
Steven Moreland744eb322018-07-25 16:31:08 -0700268
269 // example: -randroid.hardware:hardware/interfaces
270 Full_root_option string `blueprint:"mutated"`
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700271}
272
Steven Moreland650bc512018-12-06 11:53:09 -0800273// TODO(b/119771576): These properties are shared by all Android modules, and we are specifically
274// calling these out to be copied to every create module. However, if a new property is added, it
275// could break things because this code has no way to know about that.
276type manuallyInheritCommonProperties struct {
277 Enabled *bool
278 Compile_multilib *string
279 Target struct {
280 Host struct {
281 Compile_multilib *string
282 }
283 Android struct {
284 Compile_multilib *string
285 }
286 }
287 Proprietary *bool
288 Owner *string
289 Vendor *bool
290 Soc_specific *bool
291 Device_specific *bool
292 Product_specific *bool
293 Product_services_specific *bool
294 Recovery *bool
295 Init_rc []string
296 Vintf_fragments []string
297 Required []string
298 Notice *string
299 Dist struct {
300 Targets []string
301 Dest *string
302 Dir *string
303 Suffix *string
304 }
305}
306
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700307type hidlInterface struct {
308 android.ModuleBase
309
Steven Moreland650bc512018-12-06 11:53:09 -0800310 properties hidlInterfaceProperties
311 inheritCommonProperties manuallyInheritCommonProperties
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700312}
313
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700314func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) {
315 var interfaces []string
316 var types []string // hidl-gen only supports types.hal, but don't assume that here
317
318 hasError := false
319
320 for _, v := range srcs {
321 if !strings.HasSuffix(v, ".hal") {
322 mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v)
323 hasError = true
324 continue
325 }
326
327 name := strings.TrimSuffix(v, ".hal")
328
329 if strings.HasPrefix(name, "I") {
330 baseName := strings.TrimPrefix(name, "I")
331 interfaces = append(interfaces, baseName)
332 } else {
333 types = append(types, name)
334 }
335 }
336
337 return interfaces, types, !hasError
338}
339
340func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) {
341 var dependencies []string
342 var javaDependencies []string
343
344 hasError := false
345
346 for _, v := range interfaces {
347 name, err := parseFqName(v)
348 if err != nil {
349 mctx.PropertyErrorf("interfaces", err.Error())
350 hasError = true
351 continue
352 }
353 dependencies = append(dependencies, name.string())
354 javaDependencies = append(javaDependencies, name.javaName())
355 }
356
357 return dependencies, javaDependencies, !hasError
358}
359
Steven Moreland744eb322018-07-25 16:31:08 -0700360func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700361 var ret []string
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700362
363 for _, i := range dependencies {
Steven Morelandb49d3a72018-07-25 16:40:03 -0700364 if !isCorePackage(i) {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700365 ret = append(ret, i)
366 }
367 }
368
Steven Moreland744eb322018-07-25 16:31:08 -0700369 return ret
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700370}
371
372func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) {
373 name, err := parseFqName(i.ModuleBase.Name())
374 if err != nil {
375 mctx.PropertyErrorf("name", err.Error())
376 }
377
378 if !name.inPackage(i.properties.Root) {
Steven Moreland744eb322018-07-25 16:31:08 -0700379 mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".")
380 }
381 if lookupPackageRoot(i.properties.Root) == nil {
382 mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+
383 `root '%s' needed for module '%s'. Either this is a mispelling of the package `+
384 `root, or a new hidl_package_root module needs to be added. For example, you can `+
385 `fix this error by adding the following to <some path>/Android.bp:
386
387hidl_package_root {
388name: "%s",
389path: "<some path>",
390}
391
392This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`,
393 i.properties.Root, name, i.properties.Root, i.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700394 }
395
396 interfaces, types, _ := processSources(mctx, i.properties.Srcs)
397
398 if len(interfaces) == 0 && len(types) == 0 {
399 mctx.PropertyErrorf("srcs", "No sources provided.")
400 }
401
402 dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces)
Steven Moreland744eb322018-07-25 16:31:08 -0700403 cppDependencies := removeCoreDependencies(mctx, dependencies)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700404
405 if mctx.Failed() {
406 return
407 }
408
Steven Morelandb49d3a72018-07-25 16:40:03 -0700409 shouldGenerateLibrary := !isCorePackage(name.string())
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700410 // explicitly true if not specified to give early warning to devs
411 shouldGenerateJava := i.properties.Gen_java == nil || *i.properties.Gen_java
412 shouldGenerateJavaConstants := i.properties.Gen_java_constants
Steven Morelandeaba9232019-01-16 17:55:05 -0800413 shouldGenerateVts := shouldGenerateLibrary
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700414
415 var libraryIfExists []string
416 if shouldGenerateLibrary {
417 libraryIfExists = []string{name.string()}
418 }
419
420 // TODO(b/69002743): remove filegroups
Pirama Arumuga Nainarf43bb1e2018-04-18 11:34:56 -0700421 mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{
Steven Moreland650bc512018-12-06 11:53:09 -0800422 Name: proptools.StringPtr(name.fileGroupName()),
423 Srcs: i.properties.Srcs,
424 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700425
Steven Moreland744eb322018-07-25 16:31:08 -0700426 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
427 Name: proptools.StringPtr(name.sourcesName()),
428 }, &hidlGenProperties{
429 Language: "c++-sources",
430 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800431 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700432 Interfaces: i.properties.Interfaces,
433 Inputs: i.properties.Srcs,
434 Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")),
Steven Moreland650bc512018-12-06 11:53:09 -0800435 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700436 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
437 Name: proptools.StringPtr(name.headersName()),
438 }, &hidlGenProperties{
439 Language: "c++-headers",
440 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800441 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700442 Interfaces: i.properties.Interfaces,
443 Inputs: i.properties.Srcs,
444 Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700445 wrap(name.dir()+"Bs", interfaces, ".h"),
446 wrap(name.dir()+"BnHw", interfaces, ".h"),
447 wrap(name.dir()+"BpHw", interfaces, ".h"),
448 wrap(name.dir()+"IHw", interfaces, ".h"),
449 wrap(name.dir(), types, ".h"),
450 wrap(name.dir()+"hw", types, ".h")),
Steven Moreland650bc512018-12-06 11:53:09 -0800451 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700452
453 if shouldGenerateLibrary {
454 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
Jerry Zhangf2a93962018-05-30 17:16:05 -0700455 Name: proptools.StringPtr(name.string()),
Jerry Zhangf2a93962018-05-30 17:16:05 -0700456 Recovery_available: proptools.BoolPtr(true),
457 Vendor_available: proptools.BoolPtr(true),
458 Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())),
459 Defaults: []string{"hidl-module-defaults"},
460 Generated_sources: []string{name.sourcesName()},
461 Generated_headers: []string{name.headersName()},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700462 Shared_libs: concat(cppDependencies, []string{
463 "libhidlbase",
464 "libhidltransport",
465 "libhwbinder",
466 "liblog",
467 "libutils",
468 "libcutils",
469 }),
470 Export_shared_lib_headers: concat(cppDependencies, []string{
471 "libhidlbase",
472 "libhidltransport",
473 "libhwbinder",
474 "libutils",
475 }),
476 Export_generated_headers: []string{name.headersName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800477 }, &i.properties.VndkProperties, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700478 }
479
480 if shouldGenerateJava {
Steven Moreland744eb322018-07-25 16:31:08 -0700481 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
482 Name: proptools.StringPtr(name.javaSourcesName()),
483 }, &hidlGenProperties{
484 Language: "java",
485 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800486 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700487 Interfaces: i.properties.Interfaces,
488 Inputs: i.properties.Srcs,
489 Outputs: concat(wrap(name.sanitizedDir()+"I", interfaces, ".java"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700490 wrap(name.sanitizedDir(), i.properties.Types, ".java")),
Steven Moreland650bc512018-12-06 11:53:09 -0800491 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700492 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700493 Name: proptools.StringPtr(name.javaName()),
494 Defaults: []string{"hidl-java-module-defaults"},
495 No_framework_libs: proptools.BoolPtr(true),
Colin Crossf5536c32018-06-26 23:29:10 -0700496 Installable: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700497 Srcs: []string{":" + name.javaSourcesName()},
Steven Morelandfcfbeaf2018-01-29 19:34:52 -0800498 Static_libs: javaDependencies,
Colin Crossa5050552018-03-29 10:30:03 -0700499
500 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
501 // to build framework, which is used to build system_current. Use core_current
502 // plus hwbinder.stubs, which together form a subset of system_current that does
503 // not depend on framework.
504 Sdk_version: proptools.StringPtr("core_current"),
505 Libs: []string{"hwbinder.stubs"},
Steven Moreland650bc512018-12-06 11:53:09 -0800506 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700507 }
508
509 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700510 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
511 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
512 }, &hidlGenProperties{
513 Language: "java-constants",
514 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800515 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700516 Interfaces: i.properties.Interfaces,
517 Inputs: i.properties.Srcs,
518 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Moreland650bc512018-12-06 11:53:09 -0800519 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700520 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700521 Name: proptools.StringPtr(name.javaConstantsName()),
522 Defaults: []string{"hidl-java-module-defaults"},
523 No_framework_libs: proptools.BoolPtr(true),
524 Srcs: []string{":" + name.javaConstantsSourcesName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800525 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700526 }
527
Steven Moreland744eb322018-07-25 16:31:08 -0700528 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
529 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
530 }, &hidlGenProperties{
531 Language: "c++-adapter-sources",
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: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"),
Steven Moreland650bc512018-12-06 11:53:09 -0800537 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700538 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
539 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
540 }, &hidlGenProperties{
541 Language: "c++-adapter-headers",
542 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800543 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700544 Interfaces: i.properties.Interfaces,
545 Inputs: i.properties.Srcs,
546 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Moreland650bc512018-12-06 11:53:09 -0800547 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700548
549 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
550 Name: proptools.StringPtr(name.adapterHelperName()),
551 Vendor_available: proptools.BoolPtr(true),
552 Defaults: []string{"hidl-module-defaults"},
553 Generated_sources: []string{name.adapterHelperSourcesName()},
554 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800555 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800556 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800557 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700558 "libhidlbase",
559 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800560 "libhwbinder",
561 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700562 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800563 },
564 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700565 "libhidladapter",
566 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800567 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700568 "libhidlbase",
569 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800570 },
571 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700572 "libhidladapter",
573 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
574 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800575 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800576 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700577 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
578 Name: proptools.StringPtr(name.adapterSourcesName()),
579 }, &hidlGenProperties{
580 Language: "c++-adapter-main",
581 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800582 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700583 Interfaces: i.properties.Interfaces,
584 Inputs: i.properties.Srcs,
585 Outputs: []string{"main.cpp"},
Steven Moreland650bc512018-12-06 11:53:09 -0800586 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700587 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
588 Name: proptools.StringPtr(name.adapterName()),
589 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800590 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800591 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800592 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700593 "libhidlbase",
594 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800595 "libhwbinder",
596 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700597 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800598 },
599 Static_libs: concat([]string{
600 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700601 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800602 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
603 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800604 }, &i.inheritCommonProperties)
Steven Morelandeaba9232019-01-16 17:55:05 -0800605
606 if shouldGenerateVts {
607 vtsSpecs := concat(wrap(name.dir(), interfaces, ".vts"), wrap(name.dir(), types, ".vts"))
608
609 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
610 Name: proptools.StringPtr(name.vtsSpecName()),
611 }, &hidlGenProperties{
612 Language: "vts",
613 FqName: name.string(),
614 Root: i.properties.Root,
615 Interfaces: i.properties.Interfaces,
616 Inputs: i.properties.Srcs,
617 Outputs: vtsSpecs,
618 }, &i.inheritCommonProperties)
619
620 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
621 Name: proptools.StringPtr(name.vtsDriverSourcesName()),
622 }, &vtscProperties{
623 Mode: "DRIVER",
624 Type: "SOURCE",
625 SpecName: name.vtsSpecName(),
626 Outputs: wrap("", vtsSpecs, ".cpp"),
627 PackagePath: name.dir(),
628 }, &i.inheritCommonProperties)
629 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
630 Name: proptools.StringPtr(name.vtsDriverHeadersName()),
631 }, &vtscProperties{
632 Mode: "DRIVER",
633 Type: "HEADER",
634 SpecName: name.vtsSpecName(),
635 Outputs: wrap("", vtsSpecs, ".h"),
636 PackagePath: name.dir(),
637 }, &i.inheritCommonProperties)
638 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
639 Name: proptools.StringPtr(name.vtsDriverName()),
640 Defaults: []string{"VtsHalDriverDefaults"},
641 Generated_sources: []string{name.vtsDriverSourcesName()},
642 Generated_headers: []string{name.vtsDriverHeadersName()},
643 Export_generated_headers: []string{name.vtsDriverHeadersName()},
644 Shared_libs: wrap("", cppDependencies, "-vts.driver"),
645 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.driver"),
646 Static_libs: concat(cppDependencies, libraryIfExists),
647
648 // TODO(b/126244142)
649 Cflags: []string{"-Wno-unused-variable"},
650 }, &i.inheritCommonProperties)
651
652 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
653 Name: proptools.StringPtr(name.vtsProfilerSourcesName()),
654 }, &vtscProperties{
655 Mode: "PROFILER",
656 Type: "SOURCE",
657 SpecName: name.vtsSpecName(),
658 Outputs: wrap("", vtsSpecs, ".cpp"),
659 PackagePath: name.dir(),
660 }, &i.inheritCommonProperties)
661 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
662 Name: proptools.StringPtr(name.vtsProfilerHeadersName()),
663 }, &vtscProperties{
664 Mode: "PROFILER",
665 Type: "HEADER",
666 SpecName: name.vtsSpecName(),
667 Outputs: wrap("", vtsSpecs, ".h"),
668 PackagePath: name.dir(),
669 }, &i.inheritCommonProperties)
670 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
671 Name: proptools.StringPtr(name.vtsProfilerName()),
672 Defaults: []string{"VtsHalProfilerDefaults"},
673 Generated_sources: []string{name.vtsProfilerSourcesName()},
674 Generated_headers: []string{name.vtsProfilerHeadersName()},
675 Export_generated_headers: []string{name.vtsProfilerHeadersName()},
676 Shared_libs: wrap("", cppDependencies, "-vts.profiler"),
677 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.profiler"),
678 Static_libs: concat(cppDependencies, libraryIfExists),
679
680 // TODO(b/126244142)
681 Cflags: []string{"-Wno-unused-variable"},
682 }, &i.inheritCommonProperties)
683 }
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700684}
685
686func (h *hidlInterface) Name() string {
687 return h.ModuleBase.Name() + hidlInterfaceSuffix
688}
689func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700690 visited := false
691 ctx.VisitDirectDeps(func(dep android.Module) {
692 if visited {
693 panic("internal error, multiple dependencies found but only one added")
694 }
695 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800696 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700697 })
698 if !visited {
699 panic("internal error, no dependencies found but dependency added")
700 }
701
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700702}
703func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700704 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700705}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700706
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700707func hidlInterfaceFactory() android.Module {
708 i := &hidlInterface{}
709 i.AddProperties(&i.properties)
Steven Moreland650bc512018-12-06 11:53:09 -0800710 i.AddProperties(&i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700711 android.InitAndroidModule(i)
712 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
713
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700714 return i
715}
716
Colin Crossf5536c32018-06-26 23:29:10 -0700717var doubleLoadablePackageNames = []string{
Jooyung Han407469c2019-01-18 18:16:21 +0900718 "android.hardware.cas@1.0",
719 "android.hardware.cas.native@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900720 "android.hardware.configstore@",
Jooyung Han407469c2019-01-18 18:16:21 +0900721 "android.hardware.drm@1.0",
722 "android.hardware.drm@1.1",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900723 "android.hardware.graphics.allocator@",
724 "android.hardware.graphics.bufferqueue@",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900725 "android.hardware.media@",
Jooyung Han407469c2019-01-18 18:16:21 +0900726 "android.hardware.media.omx@",
727 "android.hardware.memtrack@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900728 "android.hardware.neuralnetworks@",
729 "android.hidl.allocator@",
730 "android.hidl.token@",
Jooyung Han407469c2019-01-18 18:16:21 +0900731 "android.system.suspend@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900732}
733
734func isDoubleLoadable(name string) bool {
735 for _, pkgname := range doubleLoadablePackageNames {
736 if strings.HasPrefix(name, pkgname) {
737 return true
738 }
739 }
740 return false
741}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700742
743// packages in libhidltransport
744var coreDependencyPackageNames = []string{
745 "android.hidl.base@",
746 "android.hidl.manager@",
747}
748
749func isCorePackage(name string) bool {
750 for _, pkgname := range coreDependencyPackageNames {
751 if strings.HasPrefix(name, pkgname) {
752 return true
753 }
754 }
755 return false
756}
Steven Morelandeaba9232019-01-16 17:55:05 -0800757
758// TODO(b/126383715): centralize this logic/support filtering in core VTS build
759var coreVtsSpecs = []string{
760 "android.frameworks.",
761 "android.hardware.",
762 "android.hidl.",
763 "android.system.",
764}
765
766func isVtsSpecPackage(name string) bool {
767 for _, pkgname := range coreVtsSpecs {
768 if strings.HasPrefix(name, pkgname) {
769 return true
770 }
771 }
772 return false
773}
774
775var vtsListKey = android.NewOnceKey("vtsList")
776
777func vtsList(config android.Config) *android.Paths {
778 return config.Once(vtsListKey, func() interface{} {
779 return &android.Paths{}
780 }).(*android.Paths)
781}
782
783var vtsListMutex sync.Mutex
784
785func makeVarsProvider(ctx android.MakeVarsContext) {
786 vtsList := vtsList(ctx.Config()).Strings()
787 sort.Strings(vtsList)
788
789 ctx.Strict("VTS_SPEC_FILE_LIST", strings.Join(vtsList, " "))
790}