• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15package java
16
17import (
18	"android/soong/android"
19	"android/soong/genrule"
20)
21
22func init() {
23	RegisterGenRuleBuildComponents(android.InitRegistrationContext)
24}
25
26func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) {
27	ctx.RegisterModuleType("java_genrule", genRuleFactory)
28	ctx.RegisterModuleType("java_genrule_host", genRuleFactoryHost)
29}
30
31// java_genrule is a genrule that can depend on other java_* objects.
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//
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//     }
63func genRuleFactory() android.Module {
64	module := genrule.NewGenRule()
65
66	android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
67
68	return module
69}
70
71// java_genrule_host is a genrule that can depend on other java_* objects.
72//
73// A java_genrule_host has a single variant that will run against the host variant of its dependencies and
74// produce an output that can be used as an input to a host java rule.
75func genRuleFactoryHost() android.Module {
76	module := genrule.NewGenRule()
77
78	android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
79
80	return module
81}
82