1*333d2b36SAndroid Build Coastguard Worker// Copyright 2017 Google Inc. All rights reserved. 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Worker 15*333d2b36SAndroid Build Coastguard Workerpackage java 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Workerimport ( 18*333d2b36SAndroid Build Coastguard Worker "android/soong/android" 19*333d2b36SAndroid Build Coastguard Worker "android/soong/genrule" 20*333d2b36SAndroid Build Coastguard Worker) 21*333d2b36SAndroid Build Coastguard Worker 22*333d2b36SAndroid Build Coastguard Workerfunc init() { 23*333d2b36SAndroid Build Coastguard Worker RegisterGenRuleBuildComponents(android.InitRegistrationContext) 24*333d2b36SAndroid Build Coastguard Worker} 25*333d2b36SAndroid Build Coastguard Worker 26*333d2b36SAndroid Build Coastguard Workerfunc RegisterGenRuleBuildComponents(ctx android.RegistrationContext) { 27*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("java_genrule", GenRuleFactory) 28*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("java_genrule_host", GenRuleFactoryHost) 29*333d2b36SAndroid Build Coastguard Worker} 30*333d2b36SAndroid Build Coastguard Worker 31*333d2b36SAndroid Build Coastguard Worker// java_genrule is a genrule that can depend on other java_* objects. 32*333d2b36SAndroid Build Coastguard Worker// 33*333d2b36SAndroid Build Coastguard Worker// By default a java_genrule has a single variant that will run against the device variant of its dependencies and 34*333d2b36SAndroid Build Coastguard Worker// produce an output that can be used as an input to a device java rule. 35*333d2b36SAndroid Build Coastguard Worker// 36*333d2b36SAndroid Build Coastguard Worker// Specifying `host_supported: true` will produce two variants, one that uses device dependencies and one that uses 37*333d2b36SAndroid Build Coastguard Worker// host dependencies. Each variant will run the command. 38*333d2b36SAndroid Build Coastguard Worker// 39*333d2b36SAndroid Build Coastguard Worker// Use a java_genrule instead of a genrule when it needs to depend on or be depended on by other java modules, unless 40*333d2b36SAndroid Build Coastguard Worker// the dependency is for a generated source file. 41*333d2b36SAndroid Build Coastguard Worker// 42*333d2b36SAndroid Build Coastguard Worker// Examples: 43*333d2b36SAndroid Build Coastguard Worker// 44*333d2b36SAndroid Build Coastguard Worker// Use a java_genrule to package generated java resources: 45*333d2b36SAndroid Build Coastguard Worker// 46*333d2b36SAndroid Build Coastguard Worker// java_genrule { 47*333d2b36SAndroid Build Coastguard Worker// name: "generated_resources", 48*333d2b36SAndroid Build Coastguard Worker// tools: [ 49*333d2b36SAndroid Build Coastguard Worker// "generator", 50*333d2b36SAndroid Build Coastguard Worker// "soong_zip", 51*333d2b36SAndroid Build Coastguard Worker// ], 52*333d2b36SAndroid Build Coastguard Worker// srcs: ["generator_inputs/**/*"], 53*333d2b36SAndroid Build Coastguard Worker// out: ["generated_android_icu4j_resources.jar"], 54*333d2b36SAndroid Build Coastguard Worker// cmd: "$(location generator) $(in) -o $(genDir) " + 55*333d2b36SAndroid Build Coastguard Worker// "&& $(location soong_zip) -o $(out) -C $(genDir)/res -D $(genDir)/res", 56*333d2b36SAndroid Build Coastguard Worker// } 57*333d2b36SAndroid Build Coastguard Worker// 58*333d2b36SAndroid Build Coastguard Worker// java_library { 59*333d2b36SAndroid Build Coastguard Worker// name: "lib_with_generated_resources", 60*333d2b36SAndroid Build Coastguard Worker// srcs: ["src/**/*.java"], 61*333d2b36SAndroid Build Coastguard Worker// static_libs: ["generated_resources"], 62*333d2b36SAndroid Build Coastguard Worker// } 63*333d2b36SAndroid Build Coastguard Workerfunc GenRuleFactory() android.Module { 64*333d2b36SAndroid Build Coastguard Worker module := genrule.NewGenRule() 65*333d2b36SAndroid Build Coastguard Worker 66*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) 67*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 68*333d2b36SAndroid Build Coastguard Worker 69*333d2b36SAndroid Build Coastguard Worker return module 70*333d2b36SAndroid Build Coastguard Worker} 71*333d2b36SAndroid Build Coastguard Worker 72*333d2b36SAndroid Build Coastguard Worker// java_genrule_host is a genrule that can depend on other java_* objects. 73*333d2b36SAndroid Build Coastguard Worker// 74*333d2b36SAndroid Build Coastguard Worker// A java_genrule_host has a single variant that will run against the host variant of its dependencies and 75*333d2b36SAndroid Build Coastguard Worker// produce an output that can be used as an input to a host java rule. 76*333d2b36SAndroid Build Coastguard Workerfunc GenRuleFactoryHost() android.Module { 77*333d2b36SAndroid Build Coastguard Worker module := genrule.NewGenRule() 78*333d2b36SAndroid Build Coastguard Worker 79*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) 80*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 81*333d2b36SAndroid Build Coastguard Worker 82*333d2b36SAndroid Build Coastguard Worker return module 83*333d2b36SAndroid Build Coastguard Worker} 84