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) { |
Colin Cross | 323dc60 | 2020-09-18 14:25:31 -0700 | [diff] [blame] | 25 | t.Parallel() |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 26 | bp := ` |
| 27 | java_library { |
| 28 | name: "device_module", |
| 29 | srcs: ["a.java"], |
| 30 | java_resources: ["java-res/a/a"], |
| 31 | } |
| 32 | |
| 33 | java_import { |
| 34 | name: "device_import_module", |
| 35 | jars: ["a.jar"], |
| 36 | } |
| 37 | |
| 38 | java_device_for_host { |
| 39 | name: "device_for_host_module", |
| 40 | libs: [ |
| 41 | "device_module", |
| 42 | "device_import_module", |
| 43 | ], |
| 44 | } |
| 45 | |
| 46 | java_library_host { |
| 47 | name: "host_module", |
| 48 | srcs: ["b.java"], |
| 49 | java_resources: ["java-res/b/b"], |
| 50 | static_libs: ["device_for_host_module"], |
| 51 | } |
| 52 | ` |
| 53 | |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 54 | ctx, config := testJava(t, bp) |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 55 | |
| 56 | deviceModule := ctx.ModuleForTests("device_module", "android_common") |
| 57 | deviceTurbineCombined := deviceModule.Output("turbine-combined/device_module.jar") |
| 58 | deviceJavac := deviceModule.Output("javac/device_module.jar") |
| 59 | deviceRes := deviceModule.Output("res/device_module.jar") |
| 60 | |
| 61 | deviceImportModule := ctx.ModuleForTests("device_import_module", "android_common") |
| 62 | deviceImportCombined := deviceImportModule.Output("combined/device_import_module.jar") |
| 63 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 64 | hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String()) |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 65 | hostJavac := hostModule.Output("javac/host_module.jar") |
| 66 | hostRes := hostModule.Output("res/host_module.jar") |
| 67 | combined := hostModule.Output("combined/host_module.jar") |
| 68 | resCombined := hostModule.Output("res-combined/host_module.jar") |
| 69 | |
| 70 | // check classpath of host module with dependency on device_for_host_module |
| 71 | expectedClasspath := "-classpath " + strings.Join(android.Paths{ |
| 72 | deviceTurbineCombined.Output, |
| 73 | deviceImportCombined.Output, |
| 74 | }.Strings(), ":") |
| 75 | |
| 76 | if hostJavac.Args["classpath"] != expectedClasspath { |
| 77 | t.Errorf("expected host_module javac classpath:\n%s\ngot:\n%s", |
| 78 | expectedClasspath, hostJavac.Args["classpath"]) |
| 79 | } |
| 80 | |
| 81 | // check host module merged with static dependency implementation jars from device_for_host module |
| 82 | expectedInputs := android.Paths{ |
| 83 | hostJavac.Output, |
| 84 | deviceJavac.Output, |
| 85 | deviceImportCombined.Output, |
| 86 | } |
| 87 | |
| 88 | if !reflect.DeepEqual(combined.Inputs, expectedInputs) { |
| 89 | t.Errorf("expected host_module combined inputs:\n%q\ngot:\n%q", |
| 90 | expectedInputs, combined.Inputs) |
| 91 | } |
| 92 | |
| 93 | // check host module merged with static dependency resource jars from device_for_host module |
| 94 | expectedInputs = android.Paths{ |
| 95 | hostRes.Output, |
| 96 | deviceRes.Output, |
| 97 | } |
| 98 | |
| 99 | if !reflect.DeepEqual(resCombined.Inputs, expectedInputs) { |
| 100 | t.Errorf("expected host_module res combined inputs:\n%q\ngot:\n%q", |
| 101 | expectedInputs, resCombined.Inputs) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func TestHostForDevice(t *testing.T) { |
Colin Cross | 323dc60 | 2020-09-18 14:25:31 -0700 | [diff] [blame] | 106 | t.Parallel() |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 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", |
Paul Duffin | 5c2f963 | 2019-06-12 14:21:31 +0100 | [diff] [blame] | 129 | sdk_version: "core_platform", |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 130 | srcs: ["b.java"], |
| 131 | java_resources: ["java-res/b/b"], |
| 132 | static_libs: ["host_for_device_module"], |
| 133 | } |
| 134 | ` |
| 135 | |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 136 | ctx, config := testJava(t, bp) |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 137 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 138 | hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String()) |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 139 | hostJavac := hostModule.Output("javac/host_module.jar") |
| 140 | hostRes := hostModule.Output("res/host_module.jar") |
| 141 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 142 | hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOSCommonTarget.String()) |
Colin Cross | 3d7c982 | 2019-03-01 13:46:24 -0800 | [diff] [blame] | 143 | hostImportCombined := hostImportModule.Output("combined/host_import_module.jar") |
| 144 | |
| 145 | deviceModule := ctx.ModuleForTests("device_module", "android_common") |
| 146 | deviceJavac := deviceModule.Output("javac/device_module.jar") |
| 147 | deviceRes := deviceModule.Output("res/device_module.jar") |
| 148 | combined := deviceModule.Output("combined/device_module.jar") |
| 149 | resCombined := deviceModule.Output("res-combined/device_module.jar") |
| 150 | |
| 151 | // check classpath of device module with dependency on host_for_device_module |
| 152 | expectedClasspath := "-classpath " + strings.Join(android.Paths{ |
| 153 | hostJavac.Output, |
| 154 | hostImportCombined.Output, |
| 155 | }.Strings(), ":") |
| 156 | |
| 157 | if deviceJavac.Args["classpath"] != expectedClasspath { |
| 158 | t.Errorf("expected device_module javac classpath:\n%s\ngot:\n%s", |
| 159 | expectedClasspath, deviceJavac.Args["classpath"]) |
| 160 | } |
| 161 | |
| 162 | // check device module merged with static dependency implementation jars from host_for_device module |
| 163 | expectedInputs := android.Paths{ |
| 164 | deviceJavac.Output, |
| 165 | hostJavac.Output, |
| 166 | hostImportCombined.Output, |
| 167 | } |
| 168 | |
| 169 | if !reflect.DeepEqual(combined.Inputs, expectedInputs) { |
| 170 | t.Errorf("expected device_module combined inputs:\n%q\ngot:\n%q", |
| 171 | expectedInputs, combined.Inputs) |
| 172 | } |
| 173 | |
| 174 | // check device module merged with static dependency resource jars from host_for_device module |
| 175 | expectedInputs = android.Paths{ |
| 176 | deviceRes.Output, |
| 177 | hostRes.Output, |
| 178 | } |
| 179 | |
| 180 | if !reflect.DeepEqual(resCombined.Inputs, expectedInputs) { |
| 181 | t.Errorf("expected device_module res combined inputs:\n%q\ngot:\n%q", |
| 182 | expectedInputs, resCombined.Inputs) |
| 183 | } |
| 184 | } |