Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package hidl |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 19 | |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 21 | "github.com/google/blueprint/proptools" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | "android/soong/cc" |
| 25 | "android/soong/genrule" |
| 26 | "android/soong/java" |
| 27 | ) |
| 28 | |
| 29 | var ( |
| 30 | hidlInterfaceSuffix = "_interface" |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 31 | |
| 32 | pctx = android.NewPackageContext("android/hidl") |
| 33 | |
| 34 | hidl = pctx.HostBinToolVariable("hidl", "hidl-gen") |
| 35 | hidlRule = pctx.StaticRule("hidlRule", blueprint.RuleParams{ |
| 36 | Depfile: "${depfile}", |
| 37 | Deps: blueprint.DepsGCC, |
Steven Moreland | bc98bdb | 2018-10-31 14:47:07 -0700 | [diff] [blame] | 38 | Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${depfile} -o ${genDir} -L ${language} ${roots} ${fqName}", |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 39 | CommandDeps: []string{"${hidl}"}, |
| 40 | Description: "HIDL ${language}: ${in} => ${out}", |
| 41 | }, "depfile", "fqName", "genDir", "language", "roots") |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 42 | ) |
| 43 | |
| 44 | func init() { |
| 45 | android.RegisterModuleType("hidl_interface", hidlInterfaceFactory) |
| 46 | } |
| 47 | |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 48 | type hidlGenProperties struct { |
| 49 | Language string |
| 50 | FqName string |
| 51 | Interfaces []string |
| 52 | Inputs []string |
| 53 | Outputs []string |
| 54 | } |
| 55 | |
| 56 | type hidlGenRule struct { |
| 57 | android.ModuleBase |
| 58 | |
| 59 | properties hidlGenProperties |
| 60 | |
| 61 | genOutputDir android.Path |
| 62 | genInputs android.Paths |
| 63 | genOutputs android.WritablePaths |
| 64 | } |
| 65 | |
| 66 | var _ android.SourceFileProducer = (*hidlGenRule)(nil) |
| 67 | var _ genrule.SourceFileGenerator = (*hidlGenRule)(nil) |
| 68 | |
| 69 | func (g *hidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 70 | g.genOutputDir = android.PathForModuleGen(ctx) |
| 71 | |
| 72 | for _, input := range g.properties.Inputs { |
| 73 | g.genInputs = append(g.genInputs, android.PathForModuleSrc(ctx, input)) |
| 74 | } |
| 75 | |
| 76 | for _, output := range g.properties.Outputs { |
| 77 | g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output)) |
| 78 | } |
| 79 | |
| 80 | var fullRootOptions []string |
| 81 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 82 | fullRootOptions = append(fullRootOptions, dep.(*hidlInterface).properties.Full_root_option) |
| 83 | }) |
| 84 | |
| 85 | fullRootOptions = android.FirstUniqueStrings(fullRootOptions) |
| 86 | |
| 87 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
| 88 | Rule: hidlRule, |
| 89 | Inputs: g.genInputs, |
| 90 | Output: g.genOutputs[0], |
| 91 | ImplicitOutputs: g.genOutputs[1:], |
| 92 | Args: map[string]string{ |
| 93 | "depfile": g.genOutputs[0].String() + ".d", |
| 94 | "genDir": g.genOutputDir.String(), |
| 95 | "fqName": g.properties.FqName, |
| 96 | "language": g.properties.Language, |
| 97 | "roots": strings.Join(fullRootOptions, " "), |
| 98 | }, |
| 99 | }) |
| 100 | } |
| 101 | |
| 102 | func (g *hidlGenRule) GeneratedSourceFiles() android.Paths { |
| 103 | return g.genOutputs.Paths() |
| 104 | } |
| 105 | |
| 106 | func (g *hidlGenRule) Srcs() android.Paths { |
| 107 | return g.genOutputs.Paths() |
| 108 | } |
| 109 | |
| 110 | func (g *hidlGenRule) GeneratedDeps() android.Paths { |
| 111 | return g.genOutputs.Paths() |
| 112 | } |
| 113 | |
| 114 | func (g *hidlGenRule) GeneratedHeaderDirs() android.Paths { |
| 115 | return android.Paths{g.genOutputDir} |
| 116 | } |
| 117 | |
| 118 | func (g *hidlGenRule) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 119 | ctx.AddDependency(ctx.Module(), nil, g.properties.FqName+hidlInterfaceSuffix) |
| 120 | ctx.AddDependency(ctx.Module(), nil, wrap("", g.properties.Interfaces, hidlInterfaceSuffix)...) |
| 121 | } |
| 122 | |
| 123 | func hidlGenFactory() android.Module { |
| 124 | g := &hidlGenRule{} |
| 125 | g.AddProperties(&g.properties) |
| 126 | android.InitAndroidModule(g) |
| 127 | return g |
| 128 | } |
| 129 | |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 130 | type hidlInterfaceProperties struct { |
| 131 | // Vndk properties for interface library only. |
| 132 | cc.VndkProperties |
| 133 | |
Steven Moreland | 89a9ebb | 2017-12-04 10:18:00 -0800 | [diff] [blame] | 134 | // The owner of the module |
| 135 | Owner *string |
| 136 | |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 137 | // List of .hal files which compose this interface. |
| 138 | Srcs []string |
| 139 | |
| 140 | // List of hal interface packages that this library depends on. |
| 141 | Interfaces []string |
| 142 | |
| 143 | // Package root for this package, must be a prefix of name |
| 144 | Root string |
| 145 | |
| 146 | // List of non-TypeDef types declared in types.hal. |
| 147 | Types []string |
| 148 | |
| 149 | // Whether to generate the Java library stubs. |
| 150 | // Default: true |
| 151 | Gen_java *bool |
| 152 | |
| 153 | // Whether to generate a Java library containing constants |
| 154 | // expressed by @export annotations in the hal files. |
| 155 | Gen_java_constants bool |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 156 | |
| 157 | // example: -randroid.hardware:hardware/interfaces |
| 158 | Full_root_option string `blueprint:"mutated"` |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | type hidlInterface struct { |
| 162 | android.ModuleBase |
| 163 | |
| 164 | properties hidlInterfaceProperties |
| 165 | } |
| 166 | |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 167 | func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) { |
| 168 | var interfaces []string |
| 169 | var types []string // hidl-gen only supports types.hal, but don't assume that here |
| 170 | |
| 171 | hasError := false |
| 172 | |
| 173 | for _, v := range srcs { |
| 174 | if !strings.HasSuffix(v, ".hal") { |
| 175 | mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v) |
| 176 | hasError = true |
| 177 | continue |
| 178 | } |
| 179 | |
| 180 | name := strings.TrimSuffix(v, ".hal") |
| 181 | |
| 182 | if strings.HasPrefix(name, "I") { |
| 183 | baseName := strings.TrimPrefix(name, "I") |
| 184 | interfaces = append(interfaces, baseName) |
| 185 | } else { |
| 186 | types = append(types, name) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return interfaces, types, !hasError |
| 191 | } |
| 192 | |
| 193 | func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) { |
| 194 | var dependencies []string |
| 195 | var javaDependencies []string |
| 196 | |
| 197 | hasError := false |
| 198 | |
| 199 | for _, v := range interfaces { |
| 200 | name, err := parseFqName(v) |
| 201 | if err != nil { |
| 202 | mctx.PropertyErrorf("interfaces", err.Error()) |
| 203 | hasError = true |
| 204 | continue |
| 205 | } |
| 206 | dependencies = append(dependencies, name.string()) |
| 207 | javaDependencies = append(javaDependencies, name.javaName()) |
| 208 | } |
| 209 | |
| 210 | return dependencies, javaDependencies, !hasError |
| 211 | } |
| 212 | |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 213 | func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string { |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 214 | var ret []string |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 215 | |
| 216 | for _, i := range dependencies { |
Steven Moreland | b49d3a7 | 2018-07-25 16:40:03 -0700 | [diff] [blame] | 217 | if !isCorePackage(i) { |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 218 | ret = append(ret, i) |
| 219 | } |
| 220 | } |
| 221 | |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 222 | return ret |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) { |
| 226 | name, err := parseFqName(i.ModuleBase.Name()) |
| 227 | if err != nil { |
| 228 | mctx.PropertyErrorf("name", err.Error()) |
| 229 | } |
| 230 | |
| 231 | if !name.inPackage(i.properties.Root) { |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 232 | mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".") |
| 233 | } |
| 234 | if lookupPackageRoot(i.properties.Root) == nil { |
| 235 | mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+ |
| 236 | `root '%s' needed for module '%s'. Either this is a mispelling of the package `+ |
| 237 | `root, or a new hidl_package_root module needs to be added. For example, you can `+ |
| 238 | `fix this error by adding the following to <some path>/Android.bp: |
| 239 | |
| 240 | hidl_package_root { |
| 241 | name: "%s", |
| 242 | path: "<some path>", |
| 243 | } |
| 244 | |
| 245 | This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`, |
| 246 | i.properties.Root, name, i.properties.Root, i.properties.Root) |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | interfaces, types, _ := processSources(mctx, i.properties.Srcs) |
| 250 | |
| 251 | if len(interfaces) == 0 && len(types) == 0 { |
| 252 | mctx.PropertyErrorf("srcs", "No sources provided.") |
| 253 | } |
| 254 | |
| 255 | dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces) |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 256 | cppDependencies := removeCoreDependencies(mctx, dependencies) |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 257 | |
| 258 | if mctx.Failed() { |
| 259 | return |
| 260 | } |
| 261 | |
Steven Moreland | b49d3a7 | 2018-07-25 16:40:03 -0700 | [diff] [blame] | 262 | shouldGenerateLibrary := !isCorePackage(name.string()) |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 263 | // explicitly true if not specified to give early warning to devs |
| 264 | shouldGenerateJava := i.properties.Gen_java == nil || *i.properties.Gen_java |
| 265 | shouldGenerateJavaConstants := i.properties.Gen_java_constants |
| 266 | |
| 267 | var libraryIfExists []string |
| 268 | if shouldGenerateLibrary { |
| 269 | libraryIfExists = []string{name.string()} |
| 270 | } |
| 271 | |
| 272 | // TODO(b/69002743): remove filegroups |
Pirama Arumuga Nainar | f43bb1e | 2018-04-18 11:34:56 -0700 | [diff] [blame] | 273 | mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{ |
Steven Moreland | 89a9ebb | 2017-12-04 10:18:00 -0800 | [diff] [blame] | 274 | Name: proptools.StringPtr(name.fileGroupName()), |
| 275 | Owner: i.properties.Owner, |
| 276 | Srcs: i.properties.Srcs, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 277 | }) |
| 278 | |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 279 | mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{ |
| 280 | Name: proptools.StringPtr(name.sourcesName()), |
| 281 | }, &hidlGenProperties{ |
| 282 | Language: "c++-sources", |
| 283 | FqName: name.string(), |
| 284 | Interfaces: i.properties.Interfaces, |
| 285 | Inputs: i.properties.Srcs, |
| 286 | Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 287 | }) |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 288 | mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{ |
| 289 | Name: proptools.StringPtr(name.headersName()), |
| 290 | }, &hidlGenProperties{ |
| 291 | Language: "c++-headers", |
| 292 | FqName: name.string(), |
| 293 | Interfaces: i.properties.Interfaces, |
| 294 | Inputs: i.properties.Srcs, |
| 295 | Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 296 | wrap(name.dir()+"Bs", interfaces, ".h"), |
| 297 | wrap(name.dir()+"BnHw", interfaces, ".h"), |
| 298 | wrap(name.dir()+"BpHw", interfaces, ".h"), |
| 299 | wrap(name.dir()+"IHw", interfaces, ".h"), |
| 300 | wrap(name.dir(), types, ".h"), |
| 301 | wrap(name.dir()+"hw", types, ".h")), |
| 302 | }) |
| 303 | |
| 304 | if shouldGenerateLibrary { |
| 305 | mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{ |
Jerry Zhang | f2a9396 | 2018-05-30 17:16:05 -0700 | [diff] [blame] | 306 | Name: proptools.StringPtr(name.string()), |
| 307 | Owner: i.properties.Owner, |
| 308 | Recovery_available: proptools.BoolPtr(true), |
| 309 | Vendor_available: proptools.BoolPtr(true), |
| 310 | Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())), |
| 311 | Defaults: []string{"hidl-module-defaults"}, |
| 312 | Generated_sources: []string{name.sourcesName()}, |
| 313 | Generated_headers: []string{name.headersName()}, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 314 | Shared_libs: concat(cppDependencies, []string{ |
| 315 | "libhidlbase", |
| 316 | "libhidltransport", |
| 317 | "libhwbinder", |
| 318 | "liblog", |
| 319 | "libutils", |
| 320 | "libcutils", |
| 321 | }), |
| 322 | Export_shared_lib_headers: concat(cppDependencies, []string{ |
| 323 | "libhidlbase", |
| 324 | "libhidltransport", |
| 325 | "libhwbinder", |
| 326 | "libutils", |
| 327 | }), |
| 328 | Export_generated_headers: []string{name.headersName()}, |
| 329 | }, &i.properties.VndkProperties) |
| 330 | } |
| 331 | |
| 332 | if shouldGenerateJava { |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 333 | mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{ |
| 334 | Name: proptools.StringPtr(name.javaSourcesName()), |
| 335 | }, &hidlGenProperties{ |
| 336 | Language: "java", |
| 337 | FqName: name.string(), |
| 338 | Interfaces: i.properties.Interfaces, |
| 339 | Inputs: i.properties.Srcs, |
| 340 | Outputs: concat(wrap(name.sanitizedDir()+"I", interfaces, ".java"), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 341 | wrap(name.sanitizedDir(), i.properties.Types, ".java")), |
| 342 | }) |
Colin Cross | f5536c3 | 2018-06-26 23:29:10 -0700 | [diff] [blame] | 343 | mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{ |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 344 | Name: proptools.StringPtr(name.javaName()), |
Steven Moreland | 89a9ebb | 2017-12-04 10:18:00 -0800 | [diff] [blame] | 345 | Owner: i.properties.Owner, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 346 | Defaults: []string{"hidl-java-module-defaults"}, |
| 347 | No_framework_libs: proptools.BoolPtr(true), |
Colin Cross | f5536c3 | 2018-06-26 23:29:10 -0700 | [diff] [blame] | 348 | Installable: proptools.BoolPtr(true), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 349 | Srcs: []string{":" + name.javaSourcesName()}, |
Steven Moreland | fcfbeaf | 2018-01-29 19:34:52 -0800 | [diff] [blame] | 350 | Static_libs: javaDependencies, |
Colin Cross | a505055 | 2018-03-29 10:30:03 -0700 | [diff] [blame] | 351 | |
| 352 | // This should ideally be system_current, but android.hidl.base-V1.0-java is used |
| 353 | // to build framework, which is used to build system_current. Use core_current |
| 354 | // plus hwbinder.stubs, which together form a subset of system_current that does |
| 355 | // not depend on framework. |
| 356 | Sdk_version: proptools.StringPtr("core_current"), |
| 357 | Libs: []string{"hwbinder.stubs"}, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 358 | }) |
| 359 | } |
| 360 | |
| 361 | if shouldGenerateJavaConstants { |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 362 | mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{ |
| 363 | Name: proptools.StringPtr(name.javaConstantsSourcesName()), |
| 364 | }, &hidlGenProperties{ |
| 365 | Language: "java-constants", |
| 366 | FqName: name.string(), |
| 367 | Interfaces: i.properties.Interfaces, |
| 368 | Inputs: i.properties.Srcs, |
| 369 | Outputs: []string{name.sanitizedDir() + "Constants.java"}, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 370 | }) |
Colin Cross | f5536c3 | 2018-06-26 23:29:10 -0700 | [diff] [blame] | 371 | mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{ |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 372 | Name: proptools.StringPtr(name.javaConstantsName()), |
Steven Moreland | 89a9ebb | 2017-12-04 10:18:00 -0800 | [diff] [blame] | 373 | Owner: i.properties.Owner, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 374 | Defaults: []string{"hidl-java-module-defaults"}, |
| 375 | No_framework_libs: proptools.BoolPtr(true), |
| 376 | Srcs: []string{":" + name.javaConstantsSourcesName()}, |
| 377 | }) |
| 378 | } |
| 379 | |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 380 | mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{ |
| 381 | Name: proptools.StringPtr(name.adapterHelperSourcesName()), |
| 382 | }, &hidlGenProperties{ |
| 383 | Language: "c++-adapter-sources", |
| 384 | FqName: name.string(), |
| 385 | Interfaces: i.properties.Interfaces, |
| 386 | Inputs: i.properties.Srcs, |
| 387 | Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 388 | }) |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 389 | mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{ |
| 390 | Name: proptools.StringPtr(name.adapterHelperHeadersName()), |
| 391 | }, &hidlGenProperties{ |
| 392 | Language: "c++-adapter-headers", |
| 393 | FqName: name.string(), |
| 394 | Interfaces: i.properties.Interfaces, |
| 395 | Inputs: i.properties.Srcs, |
| 396 | Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 397 | }) |
| 398 | |
| 399 | mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{ |
| 400 | Name: proptools.StringPtr(name.adapterHelperName()), |
Steven Moreland | 89a9ebb | 2017-12-04 10:18:00 -0800 | [diff] [blame] | 401 | Owner: i.properties.Owner, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 402 | Vendor_available: proptools.BoolPtr(true), |
| 403 | Defaults: []string{"hidl-module-defaults"}, |
| 404 | Generated_sources: []string{name.adapterHelperSourcesName()}, |
| 405 | Generated_headers: []string{name.adapterHelperHeadersName()}, |
Steven Moreland | 10d1ec4 | 2017-11-29 13:56:28 -0800 | [diff] [blame] | 406 | Shared_libs: []string{ |
Steven Moreland | d90bdaa | 2018-01-03 11:12:43 -0800 | [diff] [blame] | 407 | "libbase", |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 408 | "libcutils", |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 409 | "libhidlbase", |
| 410 | "libhidltransport", |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 411 | "libhwbinder", |
| 412 | "liblog", |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 413 | "libutils", |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 414 | }, |
| 415 | Static_libs: concat([]string{ |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 416 | "libhidladapter", |
| 417 | }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists), |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 418 | Export_shared_lib_headers: []string{ |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 419 | "libhidlbase", |
| 420 | "libhidltransport", |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 421 | }, |
| 422 | Export_static_lib_headers: concat([]string{ |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 423 | "libhidladapter", |
| 424 | }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists), |
| 425 | Export_generated_headers: []string{name.adapterHelperHeadersName()}, |
Steven Moreland | 10d1ec4 | 2017-11-29 13:56:28 -0800 | [diff] [blame] | 426 | Group_static_libs: proptools.BoolPtr(true), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 427 | }) |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 428 | mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{ |
| 429 | Name: proptools.StringPtr(name.adapterSourcesName()), |
| 430 | }, &hidlGenProperties{ |
| 431 | Language: "c++-adapter-main", |
| 432 | FqName: name.string(), |
| 433 | Interfaces: i.properties.Interfaces, |
| 434 | Inputs: i.properties.Srcs, |
| 435 | Outputs: []string{"main.cpp"}, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 436 | }) |
| 437 | mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{ |
| 438 | Name: proptools.StringPtr(name.adapterName()), |
Steven Moreland | 89a9ebb | 2017-12-04 10:18:00 -0800 | [diff] [blame] | 439 | Owner: i.properties.Owner, |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 440 | Generated_sources: []string{name.adapterSourcesName()}, |
Steven Moreland | 10d1ec4 | 2017-11-29 13:56:28 -0800 | [diff] [blame] | 441 | Shared_libs: []string{ |
Steven Moreland | d90bdaa | 2018-01-03 11:12:43 -0800 | [diff] [blame] | 442 | "libbase", |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 443 | "libcutils", |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 444 | "libhidlbase", |
| 445 | "libhidltransport", |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 446 | "libhwbinder", |
| 447 | "liblog", |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 448 | "libutils", |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 449 | }, |
| 450 | Static_libs: concat([]string{ |
| 451 | "libhidladapter", |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 452 | name.adapterHelperName(), |
Steven Moreland | ffa2528 | 2017-11-13 14:23:25 -0800 | [diff] [blame] | 453 | }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists), |
| 454 | Group_static_libs: proptools.BoolPtr(true), |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 455 | }) |
| 456 | } |
| 457 | |
| 458 | func (h *hidlInterface) Name() string { |
| 459 | return h.ModuleBase.Name() + hidlInterfaceSuffix |
| 460 | } |
| 461 | func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 462 | visited := false |
| 463 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 464 | if visited { |
| 465 | panic("internal error, multiple dependencies found but only one added") |
| 466 | } |
| 467 | visited = true |
Steven Moreland | 136abb8 | 2018-11-08 17:27:42 -0800 | [diff] [blame^] | 468 | h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot() |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 469 | }) |
| 470 | if !visited { |
| 471 | panic("internal error, no dependencies found but dependency added") |
| 472 | } |
| 473 | |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 474 | } |
| 475 | func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) { |
Steven Moreland | 744eb32 | 2018-07-25 16:31:08 -0700 | [diff] [blame] | 476 | ctx.AddDependency(ctx.Module(), nil, h.properties.Root) |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 477 | } |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 478 | |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 479 | func hidlInterfaceFactory() android.Module { |
| 480 | i := &hidlInterface{} |
| 481 | i.AddProperties(&i.properties) |
| 482 | android.InitAndroidModule(i) |
| 483 | android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) }) |
| 484 | |
Steven Moreland | d56e5bb | 2017-07-18 22:04:16 -0700 | [diff] [blame] | 485 | return i |
| 486 | } |
| 487 | |
Colin Cross | f5536c3 | 2018-06-26 23:29:10 -0700 | [diff] [blame] | 488 | var doubleLoadablePackageNames = []string{ |
Jiyong Park | d26759f | 2018-04-09 12:22:18 +0900 | [diff] [blame] | 489 | "android.hardware.configstore@", |
| 490 | "android.hardware.graphics.allocator@", |
| 491 | "android.hardware.graphics.bufferqueue@", |
| 492 | "android.hardware.media.omx@", |
| 493 | "android.hardware.media@", |
| 494 | "android.hardware.neuralnetworks@", |
| 495 | "android.hidl.allocator@", |
| 496 | "android.hidl.token@", |
| 497 | } |
| 498 | |
| 499 | func isDoubleLoadable(name string) bool { |
| 500 | for _, pkgname := range doubleLoadablePackageNames { |
| 501 | if strings.HasPrefix(name, pkgname) { |
| 502 | return true |
| 503 | } |
| 504 | } |
| 505 | return false |
| 506 | } |
Steven Moreland | b49d3a7 | 2018-07-25 16:40:03 -0700 | [diff] [blame] | 507 | |
| 508 | // packages in libhidltransport |
| 509 | var coreDependencyPackageNames = []string{ |
| 510 | "android.hidl.base@", |
| 511 | "android.hidl.manager@", |
| 512 | } |
| 513 | |
| 514 | func isCorePackage(name string) bool { |
| 515 | for _, pkgname := range coreDependencyPackageNames { |
| 516 | if strings.HasPrefix(name, pkgname) { |
| 517 | return true |
| 518 | } |
| 519 | } |
| 520 | return false |
| 521 | } |