Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/genrule" |
| 20 | ) |
| 21 | |
| 22 | func init() { |
Paul Duffin | b0f8507 | 2019-12-19 10:28:56 +0000 | [diff] [blame] | 23 | RegisterGenRuleBuildComponents(android.InitRegistrationContext) |
| 24 | } |
| 25 | |
| 26 | func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) { |
Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 27 | ctx.RegisterModuleType("java_genrule", GenRuleFactory) |
| 28 | ctx.RegisterModuleType("java_genrule_host", GenRuleFactoryHost) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // java_genrule is a genrule that can depend on other java_* objects. |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 32 | // |
| 33 | // By default a java_genrule has a single variant that will run against the device variant of its dependencies and |
| 34 | // produce an output that can be used as an input to a device java rule. |
| 35 | // |
Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 36 | // Specifying `host_supported: true` will produce two variants, one that uses device dependencies and one that uses |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 37 | // host dependencies. Each variant will run the command. |
| 38 | // |
| 39 | // Use a java_genrule instead of a genrule when it needs to depend on or be depended on by other java modules, unless |
| 40 | // the dependency is for a generated source file. |
| 41 | // |
| 42 | // Examples: |
| 43 | // |
| 44 | // Use a java_genrule to package generated java resources: |
| 45 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 46 | // java_genrule { |
| 47 | // name: "generated_resources", |
| 48 | // tools: [ |
| 49 | // "generator", |
| 50 | // "soong_zip", |
| 51 | // ], |
| 52 | // srcs: ["generator_inputs/**/*"], |
| 53 | // out: ["generated_android_icu4j_resources.jar"], |
| 54 | // cmd: "$(location generator) $(in) -o $(genDir) " + |
| 55 | // "&& $(location soong_zip) -o $(out) -C $(genDir)/res -D $(genDir)/res", |
| 56 | // } |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 57 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 58 | // java_library { |
| 59 | // name: "lib_with_generated_resources", |
| 60 | // srcs: ["src/**/*.java"], |
| 61 | // static_libs: ["generated_resources"], |
| 62 | // } |
Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 63 | func GenRuleFactory() android.Module { |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 64 | module := genrule.NewGenRule() |
| 65 | |
| 66 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Colin Cross | 99c3ed9 | 2021-10-08 17:47:28 -0700 | [diff] [blame] | 67 | android.InitDefaultableModule(module) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 68 | |
| 69 | return module |
| 70 | } |
Makoto Onuki | 8f9ab6a | 2018-04-13 16:34:04 -0700 | [diff] [blame] | 71 | |
| 72 | // java_genrule_host is a genrule that can depend on other java_* objects. |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 73 | // |
| 74 | // A java_genrule_host has a single variant that will run against the host variant of its dependencies and |
| 75 | // produce an output that can be used as an input to a host java rule. |
Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 76 | func GenRuleFactoryHost() android.Module { |
Makoto Onuki | 8f9ab6a | 2018-04-13 16:34:04 -0700 | [diff] [blame] | 77 | module := genrule.NewGenRule() |
| 78 | |
| 79 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
Colin Cross | 99c3ed9 | 2021-10-08 17:47:28 -0700 | [diff] [blame] | 80 | android.InitDefaultableModule(module) |
Makoto Onuki | 8f9ab6a | 2018-04-13 16:34:04 -0700 | [diff] [blame] | 81 | |
| 82 | return module |
| 83 | } |