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