blob: 16743b357a1574411983cc336d08c5024ad4b733 [file] [log] [blame]
Colin Cross54250902017-12-05 09:28:08 -08001// 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
15package java
16
17import (
18 "android/soong/android"
19 "android/soong/genrule"
20)
21
22func init() {
Paul Duffinb0f85072019-12-19 10:28:56 +000023 RegisterGenRuleBuildComponents(android.InitRegistrationContext)
24}
25
26func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) {
27 ctx.RegisterModuleType("java_genrule", genRuleFactory)
28 ctx.RegisterModuleType("java_genrule_host", genRuleFactoryHost)
Colin Cross54250902017-12-05 09:28:08 -080029}
30
31// java_genrule is a genrule that can depend on other java_* objects.
Colin Cross1b16b0e2019-02-12 14:41:32 -080032//
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//
36// Specifying `host_supported: true` will produce two variants, one that uses device dependencie sand one that uses
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//
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// }
57//
58// java_library {
59// name: "lib_with_generated_resources",
60// srcs: ["src/**/*.java"],
61// static_libs: ["generated_resources"],
62// }
Colin Cross54250902017-12-05 09:28:08 -080063func genRuleFactory() android.Module {
64 module := genrule.NewGenRule()
65
66 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Colin Cross99c3ed92021-10-08 17:47:28 -070067 android.InitDefaultableModule(module)
Colin Cross54250902017-12-05 09:28:08 -080068
69 return module
70}
Makoto Onuki8f9ab6a2018-04-13 16:34:04 -070071
72// java_genrule_host is a genrule that can depend on other java_* objects.
Colin Cross1b16b0e2019-02-12 14:41:32 -080073//
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.
Makoto Onuki8f9ab6a2018-04-13 16:34:04 -070076func genRuleFactoryHost() android.Module {
77 module := genrule.NewGenRule()
78
79 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Colin Cross99c3ed92021-10-08 17:47:28 -070080 android.InitDefaultableModule(module)
Makoto Onuki8f9ab6a2018-04-13 16:34:04 -070081
82 return module
83}