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