blob: b84225fa5c9d8777189a15051daabed1f54a40f5 [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) {
Sam Delmericocd1b80f2022-01-11 21:55:46 +000027 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//
Sam Delmericocd1b80f2022-01-11 21:55:46 +000036// Specifying `host_supported: true` will produce two variants, one that uses device dependencies and one that uses
Colin Cross1b16b0e2019-02-12 14:41:32 -080037// 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 Crossd079e0b2022-08-16 10:27:33 -070046// 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 Cross1b16b0e2019-02-12 14:41:32 -080057//
Colin Crossd079e0b2022-08-16 10:27:33 -070058// java_library {
59// name: "lib_with_generated_resources",
60// srcs: ["src/**/*.java"],
61// static_libs: ["generated_resources"],
62// }
Sam Delmericocd1b80f2022-01-11 21:55:46 +000063func GenRuleFactory() android.Module {
Colin Cross54250902017-12-05 09:28:08 -080064 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.
Sam Delmericocd1b80f2022-01-11 21:55:46 +000076func GenRuleFactoryHost() android.Module {
Makoto Onuki8f9ab6a2018-04-13 16:34:04 -070077 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}