| Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 1 | // Copyright 2019 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 | "reflect" | 
|  | 20 | "strings" | 
|  | 21 | "testing" | 
|  | 22 | ) | 
|  | 23 |  | 
|  | 24 | func TestDeviceForHost(t *testing.T) { | 
|  | 25 | bp := ` | 
|  | 26 | java_library { | 
|  | 27 | name: "device_module", | 
|  | 28 | srcs: ["a.java"], | 
|  | 29 | java_resources: ["java-res/a/a"], | 
|  | 30 | } | 
|  | 31 |  | 
|  | 32 | java_import { | 
|  | 33 | name: "device_import_module", | 
|  | 34 | jars: ["a.jar"], | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | java_device_for_host { | 
|  | 38 | name: "device_for_host_module", | 
|  | 39 | libs: [ | 
|  | 40 | "device_module", | 
|  | 41 | "device_import_module", | 
|  | 42 | ], | 
|  | 43 | } | 
|  | 44 |  | 
|  | 45 | java_library_host { | 
|  | 46 | name: "host_module", | 
|  | 47 | srcs: ["b.java"], | 
|  | 48 | java_resources: ["java-res/b/b"], | 
|  | 49 | static_libs: ["device_for_host_module"], | 
|  | 50 | } | 
|  | 51 | ` | 
|  | 52 |  | 
|  | 53 | config := testConfig(nil) | 
|  | 54 | ctx := testContext(config, bp, nil) | 
|  | 55 | run(t, ctx, config) | 
|  | 56 |  | 
|  | 57 | deviceModule := ctx.ModuleForTests("device_module", "android_common") | 
|  | 58 | deviceTurbineCombined := deviceModule.Output("turbine-combined/device_module.jar") | 
|  | 59 | deviceJavac := deviceModule.Output("javac/device_module.jar") | 
|  | 60 | deviceRes := deviceModule.Output("res/device_module.jar") | 
|  | 61 |  | 
|  | 62 | deviceImportModule := ctx.ModuleForTests("device_import_module", "android_common") | 
|  | 63 | deviceImportCombined := deviceImportModule.Output("combined/device_import_module.jar") | 
|  | 64 |  | 
|  | 65 | hostModule := ctx.ModuleForTests("host_module", config.BuildOsCommonVariant) | 
|  | 66 | hostJavac := hostModule.Output("javac/host_module.jar") | 
|  | 67 | hostRes := hostModule.Output("res/host_module.jar") | 
|  | 68 | combined := hostModule.Output("combined/host_module.jar") | 
|  | 69 | resCombined := hostModule.Output("res-combined/host_module.jar") | 
|  | 70 |  | 
|  | 71 | // check classpath of host module with dependency on device_for_host_module | 
|  | 72 | expectedClasspath := "-classpath " + strings.Join(android.Paths{ | 
|  | 73 | deviceTurbineCombined.Output, | 
|  | 74 | deviceImportCombined.Output, | 
|  | 75 | }.Strings(), ":") | 
|  | 76 |  | 
|  | 77 | if hostJavac.Args["classpath"] != expectedClasspath { | 
|  | 78 | t.Errorf("expected host_module javac classpath:\n%s\ngot:\n%s", | 
|  | 79 | expectedClasspath, hostJavac.Args["classpath"]) | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | // check host module merged with static dependency implementation jars from device_for_host module | 
|  | 83 | expectedInputs := android.Paths{ | 
|  | 84 | hostJavac.Output, | 
|  | 85 | deviceJavac.Output, | 
|  | 86 | deviceImportCombined.Output, | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | if !reflect.DeepEqual(combined.Inputs, expectedInputs) { | 
|  | 90 | t.Errorf("expected host_module combined inputs:\n%q\ngot:\n%q", | 
|  | 91 | expectedInputs, combined.Inputs) | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | // check host module merged with static dependency resource jars from device_for_host module | 
|  | 95 | expectedInputs = android.Paths{ | 
|  | 96 | hostRes.Output, | 
|  | 97 | deviceRes.Output, | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | if !reflect.DeepEqual(resCombined.Inputs, expectedInputs) { | 
|  | 101 | t.Errorf("expected host_module res combined inputs:\n%q\ngot:\n%q", | 
|  | 102 | expectedInputs, resCombined.Inputs) | 
|  | 103 | } | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | func TestHostForDevice(t *testing.T) { | 
|  | 107 | bp := ` | 
|  | 108 | java_library_host { | 
|  | 109 | name: "host_module", | 
|  | 110 | srcs: ["a.java"], | 
|  | 111 | java_resources: ["java-res/a/a"], | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | java_import_host { | 
|  | 115 | name: "host_import_module", | 
|  | 116 | jars: ["a.jar"], | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | java_host_for_device { | 
|  | 120 | name: "host_for_device_module", | 
|  | 121 | libs: [ | 
|  | 122 | "host_module", | 
|  | 123 | "host_import_module", | 
|  | 124 | ], | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | java_library { | 
|  | 128 | name: "device_module", | 
|  | 129 | no_framework_libs: true, | 
|  | 130 | srcs: ["b.java"], | 
|  | 131 | java_resources: ["java-res/b/b"], | 
|  | 132 | static_libs: ["host_for_device_module"], | 
|  | 133 | } | 
|  | 134 | ` | 
|  | 135 |  | 
|  | 136 | config := testConfig(nil) | 
|  | 137 | ctx := testContext(config, bp, nil) | 
|  | 138 | run(t, ctx, config) | 
|  | 139 |  | 
|  | 140 | hostModule := ctx.ModuleForTests("host_module", config.BuildOsCommonVariant) | 
|  | 141 | hostJavac := hostModule.Output("javac/host_module.jar") | 
|  | 142 | hostRes := hostModule.Output("res/host_module.jar") | 
|  | 143 |  | 
|  | 144 | hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOsCommonVariant) | 
|  | 145 | hostImportCombined := hostImportModule.Output("combined/host_import_module.jar") | 
|  | 146 |  | 
|  | 147 | deviceModule := ctx.ModuleForTests("device_module", "android_common") | 
|  | 148 | deviceJavac := deviceModule.Output("javac/device_module.jar") | 
|  | 149 | deviceRes := deviceModule.Output("res/device_module.jar") | 
|  | 150 | combined := deviceModule.Output("combined/device_module.jar") | 
|  | 151 | resCombined := deviceModule.Output("res-combined/device_module.jar") | 
|  | 152 |  | 
|  | 153 | // check classpath of device module with dependency on host_for_device_module | 
|  | 154 | expectedClasspath := "-classpath " + strings.Join(android.Paths{ | 
|  | 155 | hostJavac.Output, | 
|  | 156 | hostImportCombined.Output, | 
|  | 157 | }.Strings(), ":") | 
|  | 158 |  | 
|  | 159 | if deviceJavac.Args["classpath"] != expectedClasspath { | 
|  | 160 | t.Errorf("expected device_module javac classpath:\n%s\ngot:\n%s", | 
|  | 161 | expectedClasspath, deviceJavac.Args["classpath"]) | 
|  | 162 | } | 
|  | 163 |  | 
|  | 164 | // check device module merged with static dependency implementation jars from host_for_device module | 
|  | 165 | expectedInputs := android.Paths{ | 
|  | 166 | deviceJavac.Output, | 
|  | 167 | hostJavac.Output, | 
|  | 168 | hostImportCombined.Output, | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | if !reflect.DeepEqual(combined.Inputs, expectedInputs) { | 
|  | 172 | t.Errorf("expected device_module combined inputs:\n%q\ngot:\n%q", | 
|  | 173 | expectedInputs, combined.Inputs) | 
|  | 174 | } | 
|  | 175 |  | 
|  | 176 | // check device module merged with static dependency resource jars from host_for_device module | 
|  | 177 | expectedInputs = android.Paths{ | 
|  | 178 | deviceRes.Output, | 
|  | 179 | hostRes.Output, | 
|  | 180 | } | 
|  | 181 |  | 
|  | 182 | if !reflect.DeepEqual(resCombined.Inputs, expectedInputs) { | 
|  | 183 | t.Errorf("expected device_module res combined inputs:\n%q\ngot:\n%q", | 
|  | 184 | expectedInputs, resCombined.Inputs) | 
|  | 185 | } | 
|  | 186 | } |