@@ -1056,8 +1056,7 @@ class PluginInvocationTests: XCTestCase {
1056
1056
}
1057
1057
}
1058
1058
1059
-
1060
- func testParseArtifactNotSupportedOnTargetPlatform( ) throws {
1059
+ func checkParseArtifactsPlatformCompatibility( artifactSupportedTriples: [ Triple ] , hostTriple: Triple , pluginResultChecker: ( [ ResolvedTarget : [ BuildToolPluginInvocationResult ] ] ) throws -> ( ) ) throws {
1061
1060
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
1062
1061
try XCTSkipIf ( !UserToolchain. default. supportsSwiftConcurrency ( ) , " skipping because test environment doesn't support concurrency " )
1063
1062
@@ -1119,7 +1118,12 @@ class PluginInvocationTests: XCTestCase {
1119
1118
}
1120
1119
"""
1121
1120
try localFileSystem. writeFileContents ( myPluginTargetDir. appending ( component: " plugin.swift " ) , string: content)
1122
- let tripleString = " x86_64-apple-macos15 "
1121
+ let artifactVariants = artifactSupportedTriples. map {
1122
+ """
1123
+ { " path " : " LocalBinaryTool.sh " , " supportedTriples " : [ " \( $0. tripleString) " ] }
1124
+ """
1125
+ }
1126
+
1123
1127
try localFileSystem. writeFileContents ( packageDir. appending ( components: " Binaries " , " LocalBinaryTool.artifactbundle " , " info.json " ) ) {
1124
1128
$0 <<< """
1125
1129
{ " schemaVersion " : " 1.0 " ,
@@ -1128,9 +1132,7 @@ class PluginInvocationTests: XCTestCase {
1128
1132
" type " : " executable " ,
1129
1133
" version " : " 1.2.3 " ,
1130
1134
" variants " : [
1131
- { " path " : " LocalBinaryTool.sh " ,
1132
- " supportedTriples " : [ " \( tripleString) " ]
1133
- },
1135
+ \( artifactVariants. joined ( separator: " , " ) )
1134
1136
]
1135
1137
}
1136
1138
}
@@ -1166,12 +1168,16 @@ class PluginInvocationTests: XCTestCase {
1166
1168
XCTAssertEqual ( buildToolPlugin. name, " Foo " )
1167
1169
XCTAssertEqual ( buildToolPlugin. capability, . buildTool)
1168
1170
1171
+ // Construct a toolchain with a made-up host/target triple
1172
+ let destination = try Destination . default
1173
+ let toolchain = try UserToolchain ( destination: Destination ( hostTriple: hostTriple, targetTriple: hostTriple, sdkRootDir: destination. sdkRootDir, toolchainBinDir: destination. toolchainBinDir) )
1174
+
1169
1175
// Create a plugin script runner for the duration of the test.
1170
1176
let pluginCacheDir = tmpPath. appending ( component: " plugin-cache " )
1171
1177
let pluginScriptRunner = DefaultPluginScriptRunner (
1172
1178
fileSystem: localFileSystem,
1173
1179
cacheDir: pluginCacheDir,
1174
- toolchain: try UserToolchain . default
1180
+ toolchain: toolchain
1175
1181
)
1176
1182
1177
1183
// Invoke build tool plugin
@@ -1186,13 +1192,50 @@ class PluginInvocationTests: XCTestCase {
1186
1192
observabilityScope: observability. topScope,
1187
1193
fileSystem: localFileSystem
1188
1194
)
1189
- var checked = false
1195
+ try pluginResultChecker ( result)
1196
+ }
1197
+ }
1198
+
1199
+ func testParseArtifactNotSupportedOnTargetPlatform( ) throws {
1200
+ let hostTriple = try UserToolchain . default. triple
1201
+ let artifactSupportedTriples = try [ Triple ( " riscv64-apple-windows-android " ) ]
1202
+
1203
+ var checked = false
1204
+ try checkParseArtifactsPlatformCompatibility ( artifactSupportedTriples: artifactSupportedTriples, hostTriple: hostTriple) { result in
1190
1205
if let pluginResult = result. first,
1191
1206
let diag = pluginResult. value. first? . diagnostics,
1192
1207
diag. description == " [[error]: Tool ‘LocalBinaryTool’ is not supported on the target platform] " {
1193
1208
checked = true
1194
1209
}
1195
- XCTAssertTrue ( checked)
1210
+ }
1211
+ XCTAssertTrue ( checked)
1212
+ }
1213
+
1214
+ func testParseArtifactsDoesNotCheckPlatformVersion( ) throws {
1215
+ let hostTriple = try UserToolchain . default. triple
1216
+ let artifactSupportedTriples = try [ Triple ( " \( hostTriple. withoutVersion ( ) . tripleString) 20.0 " ) ]
1217
+
1218
+ try checkParseArtifactsPlatformCompatibility ( artifactSupportedTriples: artifactSupportedTriples, hostTriple: hostTriple) { result in
1219
+ result. forEach {
1220
+ $0. value. forEach {
1221
+ XCTAssertTrue ( $0. succeeded, " plugin unexpectedly failed " )
1222
+ XCTAssertEqual ( $0. diagnostics. map { $0. message } , [ ] , " plugin produced unexpected diagnostics " )
1223
+ }
1224
+ }
1225
+ }
1226
+ }
1227
+
1228
+ func testParseArtifactsConsidersAllSupportedTriples( ) throws {
1229
+ let hostTriple = try UserToolchain . default. triple
1230
+ let artifactSupportedTriples = [ hostTriple, try Triple ( " riscv64-apple-windows-android " ) ]
1231
+
1232
+ try checkParseArtifactsPlatformCompatibility ( artifactSupportedTriples: artifactSupportedTriples, hostTriple: hostTriple) { result in
1233
+ result. forEach {
1234
+ $0. value. forEach {
1235
+ XCTAssertTrue ( $0. succeeded, " plugin unexpectedly failed " )
1236
+ XCTAssertEqual ( $0. diagnostics. map { $0. message } , [ ] , " plugin produced unexpected diagnostics " )
1237
+ }
1238
+ }
1196
1239
}
1197
1240
}
1198
1241
}
0 commit comments