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() { 23 android.RegisterModuleType("java_genrule", genRuleFactory) 24 android.RegisterModuleType("java_genrule_host", genRuleFactoryHost) 25 } 26 27 // java_genrule is a genrule that can depend on other java_* objects. 28 // 29 // By default a java_genrule has a single variant that will run against the device variant of its dependencies and 30 // produce an output that can be used as an input to a device java rule. 31 // 32 // Specifying `host_supported: true` will produce two variants, one that uses device dependencie sand one that uses 33 // host dependencies. Each variant will run the command. 34 // 35 // Use a java_genrule instead of a genrule when it needs to depend on or be depended on by other java modules, unless 36 // the dependency is for a generated source file. 37 // 38 // Examples: 39 // 40 // Use a java_genrule to package generated java resources: 41 // 42 // java_genrule { 43 // name: "generated_resources", 44 // tools: [ 45 // "generator", 46 // "soong_zip", 47 // ], 48 // srcs: ["generator_inputs/**/*"], 49 // out: ["generated_android_icu4j_resources.jar"], 50 // cmd: "$(location generator) $(in) -o $(genDir) " + 51 // "&& $(location soong_zip) -o $(out) -C $(genDir)/res -D $(genDir)/res", 52 // } 53 // 54 // java_library { 55 // name: "lib_with_generated_resources", 56 // srcs: ["src/**/*.java"], 57 // static_libs: ["generated_resources"], 58 // } 59 func genRuleFactory() android.Module { 60 module := genrule.NewGenRule() 61 62 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) 63 64 return module 65 } 66 67 // java_genrule_host is a genrule that can depend on other java_* objects. 68 // 69 // A java_genrule_host has a single variant that will run against the host variant of its dependencies and 70 // produce an output that can be used as an input to a host java rule. 71 func genRuleFactoryHost() android.Module { 72 module := genrule.NewGenRule() 73 74 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) 75 76 return module 77 } 78