genrule.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2017 Google Inc. All rights reserved.
  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. package java
  15. import (
  16. "android/soong/android"
  17. "android/soong/genrule"
  18. )
  19. func init() {
  20. RegisterGenRuleBuildComponents(android.InitRegistrationContext)
  21. }
  22. func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) {
  23. ctx.RegisterModuleType("java_genrule", GenRuleFactory)
  24. ctx.RegisterModuleType("java_genrule_host", GenRuleFactoryHost)
  25. }
  26. // java_genrule is a genrule that can depend on other java_* objects.
  27. //
  28. // By default a java_genrule has a single variant that will run against the device variant of its dependencies and
  29. // produce an output that can be used as an input to a device java rule.
  30. //
  31. // Specifying `host_supported: true` will produce two variants, one that uses device dependencies and one that uses
  32. // host dependencies. Each variant will run the command.
  33. //
  34. // Use a java_genrule instead of a genrule when it needs to depend on or be depended on by other java modules, unless
  35. // the dependency is for a generated source file.
  36. //
  37. // Examples:
  38. //
  39. // Use a java_genrule to package generated java resources:
  40. //
  41. // java_genrule {
  42. // name: "generated_resources",
  43. // tools: [
  44. // "generator",
  45. // "soong_zip",
  46. // ],
  47. // srcs: ["generator_inputs/**/*"],
  48. // out: ["generated_android_icu4j_resources.jar"],
  49. // cmd: "$(location generator) $(in) -o $(genDir) " +
  50. // "&& $(location soong_zip) -o $(out) -C $(genDir)/res -D $(genDir)/res",
  51. // }
  52. //
  53. // java_library {
  54. // name: "lib_with_generated_resources",
  55. // srcs: ["src/**/*.java"],
  56. // static_libs: ["generated_resources"],
  57. // }
  58. func GenRuleFactory() android.Module {
  59. module := genrule.NewGenRule()
  60. android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
  61. android.InitDefaultableModule(module)
  62. android.InitBazelModule(module)
  63. return module
  64. }
  65. // java_genrule_host is a genrule that can depend on other java_* objects.
  66. //
  67. // A java_genrule_host has a single variant that will run against the host variant of its dependencies and
  68. // produce an output that can be used as an input to a host java rule.
  69. func GenRuleFactoryHost() android.Module {
  70. module := genrule.NewGenRule()
  71. android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
  72. android.InitDefaultableModule(module)
  73. android.InitBazelModule(module)
  74. return module
  75. }