blob: 0139a990aa6a3ee2f2172354ca16b9bddf8beb17 [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
Steven Moreland9f7c2972019-03-01 09:56:20 -0800269 // Whether to generate VTS-related testing libraries.
270 Gen_vts *bool
271
Steven Moreland744eb322018-07-25 16:31:08 -0700272 // example: -randroid.hardware:hardware/interfaces
273 Full_root_option string `blueprint:"mutated"`
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700274}
275
Steven Moreland650bc512018-12-06 11:53:09 -0800276// TODO(b/119771576): These properties are shared by all Android modules, and we are specifically
277// calling these out to be copied to every create module. However, if a new property is added, it
278// could break things because this code has no way to know about that.
279type manuallyInheritCommonProperties struct {
280 Enabled *bool
281 Compile_multilib *string
282 Target struct {
283 Host struct {
284 Compile_multilib *string
285 }
286 Android struct {
287 Compile_multilib *string
288 }
289 }
290 Proprietary *bool
291 Owner *string
292 Vendor *bool
293 Soc_specific *bool
294 Device_specific *bool
295 Product_specific *bool
296 Product_services_specific *bool
297 Recovery *bool
298 Init_rc []string
299 Vintf_fragments []string
300 Required []string
301 Notice *string
302 Dist struct {
303 Targets []string
304 Dest *string
305 Dir *string
306 Suffix *string
307 }
308}
309
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700310type hidlInterface struct {
311 android.ModuleBase
312
Steven Moreland650bc512018-12-06 11:53:09 -0800313 properties hidlInterfaceProperties
314 inheritCommonProperties manuallyInheritCommonProperties
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700315}
316
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700317func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) {
318 var interfaces []string
319 var types []string // hidl-gen only supports types.hal, but don't assume that here
320
321 hasError := false
322
323 for _, v := range srcs {
324 if !strings.HasSuffix(v, ".hal") {
325 mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v)
326 hasError = true
327 continue
328 }
329
330 name := strings.TrimSuffix(v, ".hal")
331
332 if strings.HasPrefix(name, "I") {
333 baseName := strings.TrimPrefix(name, "I")
334 interfaces = append(interfaces, baseName)
335 } else {
336 types = append(types, name)
337 }
338 }
339
340 return interfaces, types, !hasError
341}
342
343func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) {
344 var dependencies []string
345 var javaDependencies []string
346
347 hasError := false
348
349 for _, v := range interfaces {
350 name, err := parseFqName(v)
351 if err != nil {
352 mctx.PropertyErrorf("interfaces", err.Error())
353 hasError = true
354 continue
355 }
356 dependencies = append(dependencies, name.string())
357 javaDependencies = append(javaDependencies, name.javaName())
358 }
359
360 return dependencies, javaDependencies, !hasError
361}
362
Steven Moreland744eb322018-07-25 16:31:08 -0700363func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700364 var ret []string
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700365
366 for _, i := range dependencies {
Steven Morelandb49d3a72018-07-25 16:40:03 -0700367 if !isCorePackage(i) {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700368 ret = append(ret, i)
369 }
370 }
371
Steven Moreland744eb322018-07-25 16:31:08 -0700372 return ret
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700373}
374
375func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) {
376 name, err := parseFqName(i.ModuleBase.Name())
377 if err != nil {
378 mctx.PropertyErrorf("name", err.Error())
379 }
380
381 if !name.inPackage(i.properties.Root) {
Steven Moreland744eb322018-07-25 16:31:08 -0700382 mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".")
383 }
384 if lookupPackageRoot(i.properties.Root) == nil {
385 mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+
386 `root '%s' needed for module '%s'. Either this is a mispelling of the package `+
387 `root, or a new hidl_package_root module needs to be added. For example, you can `+
388 `fix this error by adding the following to <some path>/Android.bp:
389
390hidl_package_root {
391name: "%s",
392path: "<some path>",
393}
394
395This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`,
396 i.properties.Root, name, i.properties.Root, i.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700397 }
398
399 interfaces, types, _ := processSources(mctx, i.properties.Srcs)
400
401 if len(interfaces) == 0 && len(types) == 0 {
402 mctx.PropertyErrorf("srcs", "No sources provided.")
403 }
404
405 dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces)
Steven Moreland744eb322018-07-25 16:31:08 -0700406 cppDependencies := removeCoreDependencies(mctx, dependencies)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700407
408 if mctx.Failed() {
409 return
410 }
411
Steven Morelandb49d3a72018-07-25 16:40:03 -0700412 shouldGenerateLibrary := !isCorePackage(name.string())
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700413 // explicitly true if not specified to give early warning to devs
Steven Moreland9f7c2972019-03-01 09:56:20 -0800414 shouldGenerateJava := proptools.BoolDefault(i.properties.Gen_java, true)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700415 shouldGenerateJavaConstants := i.properties.Gen_java_constants
Steven Moreland9f7c2972019-03-01 09:56:20 -0800416 shouldGenerateVts := shouldGenerateLibrary && proptools.BoolDefault(i.properties.Gen_vts, true)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700417
418 var libraryIfExists []string
419 if shouldGenerateLibrary {
420 libraryIfExists = []string{name.string()}
421 }
422
423 // TODO(b/69002743): remove filegroups
Pirama Arumuga Nainarf43bb1e2018-04-18 11:34:56 -0700424 mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{
Steven Moreland650bc512018-12-06 11:53:09 -0800425 Name: proptools.StringPtr(name.fileGroupName()),
426 Srcs: i.properties.Srcs,
427 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700428
Steven Moreland744eb322018-07-25 16:31:08 -0700429 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
430 Name: proptools.StringPtr(name.sourcesName()),
431 }, &hidlGenProperties{
432 Language: "c++-sources",
433 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800434 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700435 Interfaces: i.properties.Interfaces,
436 Inputs: i.properties.Srcs,
437 Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")),
Steven Moreland650bc512018-12-06 11:53:09 -0800438 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700439 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
440 Name: proptools.StringPtr(name.headersName()),
441 }, &hidlGenProperties{
442 Language: "c++-headers",
443 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800444 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700445 Interfaces: i.properties.Interfaces,
446 Inputs: i.properties.Srcs,
447 Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700448 wrap(name.dir()+"Bs", interfaces, ".h"),
449 wrap(name.dir()+"BnHw", interfaces, ".h"),
450 wrap(name.dir()+"BpHw", interfaces, ".h"),
451 wrap(name.dir()+"IHw", interfaces, ".h"),
452 wrap(name.dir(), types, ".h"),
453 wrap(name.dir()+"hw", types, ".h")),
Steven Moreland650bc512018-12-06 11:53:09 -0800454 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700455
456 if shouldGenerateLibrary {
457 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
Jerry Zhangf2a93962018-05-30 17:16:05 -0700458 Name: proptools.StringPtr(name.string()),
Jerry Zhangf2a93962018-05-30 17:16:05 -0700459 Recovery_available: proptools.BoolPtr(true),
460 Vendor_available: proptools.BoolPtr(true),
461 Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())),
462 Defaults: []string{"hidl-module-defaults"},
463 Generated_sources: []string{name.sourcesName()},
464 Generated_headers: []string{name.headersName()},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700465 Shared_libs: concat(cppDependencies, []string{
466 "libhidlbase",
467 "libhidltransport",
468 "libhwbinder",
469 "liblog",
470 "libutils",
471 "libcutils",
472 }),
473 Export_shared_lib_headers: concat(cppDependencies, []string{
474 "libhidlbase",
475 "libhidltransport",
476 "libhwbinder",
477 "libutils",
478 }),
479 Export_generated_headers: []string{name.headersName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800480 }, &i.properties.VndkProperties, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700481 }
482
483 if shouldGenerateJava {
Steven Moreland744eb322018-07-25 16:31:08 -0700484 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
485 Name: proptools.StringPtr(name.javaSourcesName()),
486 }, &hidlGenProperties{
487 Language: "java",
488 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800489 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700490 Interfaces: i.properties.Interfaces,
491 Inputs: i.properties.Srcs,
492 Outputs: concat(wrap(name.sanitizedDir()+"I", interfaces, ".java"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700493 wrap(name.sanitizedDir(), i.properties.Types, ".java")),
Steven Moreland650bc512018-12-06 11:53:09 -0800494 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700495 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700496 Name: proptools.StringPtr(name.javaName()),
497 Defaults: []string{"hidl-java-module-defaults"},
498 No_framework_libs: proptools.BoolPtr(true),
Colin Crossf5536c32018-06-26 23:29:10 -0700499 Installable: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700500 Srcs: []string{":" + name.javaSourcesName()},
Steven Morelandfcfbeaf2018-01-29 19:34:52 -0800501 Static_libs: javaDependencies,
Colin Crossa5050552018-03-29 10:30:03 -0700502
503 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
504 // to build framework, which is used to build system_current. Use core_current
505 // plus hwbinder.stubs, which together form a subset of system_current that does
506 // not depend on framework.
507 Sdk_version: proptools.StringPtr("core_current"),
508 Libs: []string{"hwbinder.stubs"},
Steven Moreland650bc512018-12-06 11:53:09 -0800509 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700510 }
511
512 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700513 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
514 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
515 }, &hidlGenProperties{
516 Language: "java-constants",
517 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800518 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700519 Interfaces: i.properties.Interfaces,
520 Inputs: i.properties.Srcs,
521 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Moreland650bc512018-12-06 11:53:09 -0800522 }, &i.inheritCommonProperties)
Colin Crossf5536c32018-06-26 23:29:10 -0700523 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700524 Name: proptools.StringPtr(name.javaConstantsName()),
525 Defaults: []string{"hidl-java-module-defaults"},
526 No_framework_libs: proptools.BoolPtr(true),
527 Srcs: []string{":" + name.javaConstantsSourcesName()},
Steven Moreland650bc512018-12-06 11:53:09 -0800528 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700529 }
530
Steven Moreland744eb322018-07-25 16:31:08 -0700531 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
532 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
533 }, &hidlGenProperties{
534 Language: "c++-adapter-sources",
535 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800536 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700537 Interfaces: i.properties.Interfaces,
538 Inputs: i.properties.Srcs,
539 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"),
Steven Moreland650bc512018-12-06 11:53:09 -0800540 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700541 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
542 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
543 }, &hidlGenProperties{
544 Language: "c++-adapter-headers",
545 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800546 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700547 Interfaces: i.properties.Interfaces,
548 Inputs: i.properties.Srcs,
549 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Moreland650bc512018-12-06 11:53:09 -0800550 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700551
552 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
553 Name: proptools.StringPtr(name.adapterHelperName()),
554 Vendor_available: proptools.BoolPtr(true),
555 Defaults: []string{"hidl-module-defaults"},
556 Generated_sources: []string{name.adapterHelperSourcesName()},
557 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800558 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800559 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800560 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700561 "libhidlbase",
562 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800563 "libhwbinder",
564 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700565 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800566 },
567 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700568 "libhidladapter",
569 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800570 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700571 "libhidlbase",
572 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800573 },
574 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700575 "libhidladapter",
576 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
577 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800578 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800579 }, &i.inheritCommonProperties)
Steven Moreland744eb322018-07-25 16:31:08 -0700580 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
581 Name: proptools.StringPtr(name.adapterSourcesName()),
582 }, &hidlGenProperties{
583 Language: "c++-adapter-main",
584 FqName: name.string(),
Steven Morelandd9fd1952018-11-08 18:14:37 -0800585 Root: i.properties.Root,
Steven Moreland744eb322018-07-25 16:31:08 -0700586 Interfaces: i.properties.Interfaces,
587 Inputs: i.properties.Srcs,
588 Outputs: []string{"main.cpp"},
Steven Moreland650bc512018-12-06 11:53:09 -0800589 }, &i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700590 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
591 Name: proptools.StringPtr(name.adapterName()),
592 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800593 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800594 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800595 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700596 "libhidlbase",
597 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800598 "libhwbinder",
599 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700600 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800601 },
602 Static_libs: concat([]string{
603 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700604 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800605 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
606 Group_static_libs: proptools.BoolPtr(true),
Steven Moreland650bc512018-12-06 11:53:09 -0800607 }, &i.inheritCommonProperties)
Steven Morelandeaba9232019-01-16 17:55:05 -0800608
609 if shouldGenerateVts {
610 vtsSpecs := concat(wrap(name.dir(), interfaces, ".vts"), wrap(name.dir(), types, ".vts"))
611
612 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
613 Name: proptools.StringPtr(name.vtsSpecName()),
614 }, &hidlGenProperties{
615 Language: "vts",
616 FqName: name.string(),
617 Root: i.properties.Root,
618 Interfaces: i.properties.Interfaces,
619 Inputs: i.properties.Srcs,
620 Outputs: vtsSpecs,
621 }, &i.inheritCommonProperties)
622
623 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
624 Name: proptools.StringPtr(name.vtsDriverSourcesName()),
625 }, &vtscProperties{
626 Mode: "DRIVER",
627 Type: "SOURCE",
628 SpecName: name.vtsSpecName(),
629 Outputs: wrap("", vtsSpecs, ".cpp"),
630 PackagePath: name.dir(),
631 }, &i.inheritCommonProperties)
632 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
633 Name: proptools.StringPtr(name.vtsDriverHeadersName()),
634 }, &vtscProperties{
635 Mode: "DRIVER",
636 Type: "HEADER",
637 SpecName: name.vtsSpecName(),
638 Outputs: wrap("", vtsSpecs, ".h"),
639 PackagePath: name.dir(),
640 }, &i.inheritCommonProperties)
641 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
642 Name: proptools.StringPtr(name.vtsDriverName()),
643 Defaults: []string{"VtsHalDriverDefaults"},
644 Generated_sources: []string{name.vtsDriverSourcesName()},
645 Generated_headers: []string{name.vtsDriverHeadersName()},
646 Export_generated_headers: []string{name.vtsDriverHeadersName()},
647 Shared_libs: wrap("", cppDependencies, "-vts.driver"),
648 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.driver"),
649 Static_libs: concat(cppDependencies, libraryIfExists),
650
651 // TODO(b/126244142)
652 Cflags: []string{"-Wno-unused-variable"},
653 }, &i.inheritCommonProperties)
654
655 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
656 Name: proptools.StringPtr(name.vtsProfilerSourcesName()),
657 }, &vtscProperties{
658 Mode: "PROFILER",
659 Type: "SOURCE",
660 SpecName: name.vtsSpecName(),
661 Outputs: wrap("", vtsSpecs, ".cpp"),
662 PackagePath: name.dir(),
663 }, &i.inheritCommonProperties)
664 mctx.CreateModule(android.ModuleFactoryAdaptor(vtscFactory), &nameProperties{
665 Name: proptools.StringPtr(name.vtsProfilerHeadersName()),
666 }, &vtscProperties{
667 Mode: "PROFILER",
668 Type: "HEADER",
669 SpecName: name.vtsSpecName(),
670 Outputs: wrap("", vtsSpecs, ".h"),
671 PackagePath: name.dir(),
672 }, &i.inheritCommonProperties)
673 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
674 Name: proptools.StringPtr(name.vtsProfilerName()),
675 Defaults: []string{"VtsHalProfilerDefaults"},
676 Generated_sources: []string{name.vtsProfilerSourcesName()},
677 Generated_headers: []string{name.vtsProfilerHeadersName()},
678 Export_generated_headers: []string{name.vtsProfilerHeadersName()},
679 Shared_libs: wrap("", cppDependencies, "-vts.profiler"),
680 Export_shared_lib_headers: wrap("", cppDependencies, "-vts.profiler"),
681 Static_libs: concat(cppDependencies, libraryIfExists),
682
683 // TODO(b/126244142)
684 Cflags: []string{"-Wno-unused-variable"},
685 }, &i.inheritCommonProperties)
686 }
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700687}
688
689func (h *hidlInterface) Name() string {
690 return h.ModuleBase.Name() + hidlInterfaceSuffix
691}
692func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700693 visited := false
694 ctx.VisitDirectDeps(func(dep android.Module) {
695 if visited {
696 panic("internal error, multiple dependencies found but only one added")
697 }
698 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800699 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700700 })
701 if !visited {
702 panic("internal error, no dependencies found but dependency added")
703 }
704
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700705}
706func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700707 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700708}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700709
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700710func hidlInterfaceFactory() android.Module {
711 i := &hidlInterface{}
712 i.AddProperties(&i.properties)
Steven Moreland650bc512018-12-06 11:53:09 -0800713 i.AddProperties(&i.inheritCommonProperties)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700714 android.InitAndroidModule(i)
715 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
716
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700717 return i
718}
719
Colin Crossf5536c32018-06-26 23:29:10 -0700720var doubleLoadablePackageNames = []string{
Jooyung Han407469c2019-01-18 18:16:21 +0900721 "android.hardware.cas@1.0",
722 "android.hardware.cas.native@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900723 "android.hardware.configstore@",
Jooyung Han407469c2019-01-18 18:16:21 +0900724 "android.hardware.drm@1.0",
725 "android.hardware.drm@1.1",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900726 "android.hardware.graphics.allocator@",
727 "android.hardware.graphics.bufferqueue@",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900728 "android.hardware.media@",
Jooyung Han407469c2019-01-18 18:16:21 +0900729 "android.hardware.media.omx@",
730 "android.hardware.memtrack@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900731 "android.hardware.neuralnetworks@",
732 "android.hidl.allocator@",
733 "android.hidl.token@",
Jooyung Han407469c2019-01-18 18:16:21 +0900734 "android.system.suspend@1.0",
Jiyong Parkd26759f2018-04-09 12:22:18 +0900735}
736
737func isDoubleLoadable(name string) bool {
738 for _, pkgname := range doubleLoadablePackageNames {
739 if strings.HasPrefix(name, pkgname) {
740 return true
741 }
742 }
743 return false
744}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700745
746// packages in libhidltransport
747var coreDependencyPackageNames = []string{
748 "android.hidl.base@",
749 "android.hidl.manager@",
750}
751
752func isCorePackage(name string) bool {
753 for _, pkgname := range coreDependencyPackageNames {
754 if strings.HasPrefix(name, pkgname) {
755 return true
756 }
757 }
758 return false
759}
Steven Morelandeaba9232019-01-16 17:55:05 -0800760
761// TODO(b/126383715): centralize this logic/support filtering in core VTS build
762var coreVtsSpecs = []string{
763 "android.frameworks.",
764 "android.hardware.",
765 "android.hidl.",
766 "android.system.",
767}
768
769func isVtsSpecPackage(name string) bool {
770 for _, pkgname := range coreVtsSpecs {
771 if strings.HasPrefix(name, pkgname) {
772 return true
773 }
774 }
775 return false
776}
777
778var vtsListKey = android.NewOnceKey("vtsList")
779
780func vtsList(config android.Config) *android.Paths {
781 return config.Once(vtsListKey, func() interface{} {
782 return &android.Paths{}
783 }).(*android.Paths)
784}
785
786var vtsListMutex sync.Mutex
787
788func makeVarsProvider(ctx android.MakeVarsContext) {
789 vtsList := vtsList(ctx.Config()).Strings()
790 sort.Strings(vtsList)
791
792 ctx.Strict("VTS_SPEC_FILE_LIST", strings.Join(vtsList, " "))
793}