@@ -195,6 +195,11 @@ public final class ClangTargetBuildDescription {
195
195
public var clangTarget : ClangTarget {
196
196
return target. underlyingTarget as! ClangTarget
197
197
}
198
+
199
+ /// The tools version of the package that declared the target. This can
200
+ /// can be used to conditionalize semantically significant changes in how
201
+ /// a target is built.
202
+ public let toolsVersion : ToolsVersion
198
203
199
204
/// The build parameters.
200
205
let buildParameters : BuildParameters
@@ -249,11 +254,12 @@ public final class ClangTargetBuildDescription {
249
254
}
250
255
251
256
/// Create a new target description with target and build parameters.
252
- init ( target: ResolvedTarget , buildParameters: BuildParameters , fileSystem: FileSystem = localFileSystem, diagnostics: DiagnosticsEngine ) throws {
257
+ init ( target: ResolvedTarget , toolsVersion : ToolsVersion , buildParameters: BuildParameters , fileSystem: FileSystem = localFileSystem, diagnostics: DiagnosticsEngine ) throws {
253
258
assert ( target. underlyingTarget is ClangTarget , " underlying target type mismatch \( target) " )
254
259
self . fileSystem = fileSystem
255
260
self . diagnostics = diagnostics
256
261
self . target = target
262
+ self . toolsVersion = toolsVersion
257
263
self . buildParameters = buildParameters
258
264
self . tempsPath = buildParameters. buildPath. appending ( component: target. c99name + " .build " )
259
265
self . derivedSources = Sources ( paths: [ ] , root: tempsPath. appending ( component: " DerivedSources " ) )
@@ -472,6 +478,11 @@ public final class SwiftTargetBuildDescription {
472
478
/// The target described by this target.
473
479
public let target : ResolvedTarget
474
480
481
+ /// The tools version of the package that declared the target. This can
482
+ /// can be used to conditionalize semantically significant changes in how
483
+ /// a target is built.
484
+ public let toolsVersion : ToolsVersion
485
+
475
486
/// The build parameters.
476
487
let buildParameters : BuildParameters
477
488
@@ -547,6 +558,7 @@ public final class SwiftTargetBuildDescription {
547
558
/// Create a new target description with target and build parameters.
548
559
init (
549
560
target: ResolvedTarget ,
561
+ toolsVersion: ToolsVersion ,
550
562
buildParameters: BuildParameters ,
551
563
pluginInvocationResults: [ PluginInvocationResult ] = [ ] ,
552
564
isTestTarget: Bool ? = nil ,
@@ -555,6 +567,7 @@ public final class SwiftTargetBuildDescription {
555
567
) throws {
556
568
assert ( target. underlyingTarget is SwiftTarget , " underlying target type mismatch \( target) " )
557
569
self . target = target
570
+ self . toolsVersion = toolsVersion
558
571
self . buildParameters = buildParameters
559
572
// Unless mentioned explicitly, use the target type to determine if this is a test target.
560
573
self . isTestTarget = isTestTarget ?? ( target. type == . test)
@@ -1003,6 +1016,11 @@ public final class ProductBuildDescription {
1003
1016
/// The reference to the product.
1004
1017
public let product : ResolvedProduct
1005
1018
1019
+ /// The tools version of the package that declared the product. This can
1020
+ /// can be used to conditionalize semantically significant changes in how
1021
+ /// a target is built.
1022
+ public let toolsVersion : ToolsVersion
1023
+
1006
1024
/// The build parameters.
1007
1025
let buildParameters : BuildParameters
1008
1026
@@ -1052,9 +1070,10 @@ public final class ProductBuildDescription {
1052
1070
let diagnostics : DiagnosticsEngine
1053
1071
1054
1072
/// Create a build description for a product.
1055
- init ( product: ResolvedProduct , buildParameters: BuildParameters , fs: FileSystem , diagnostics: DiagnosticsEngine ) {
1073
+ init ( product: ResolvedProduct , toolsVersion : ToolsVersion , buildParameters: BuildParameters , fs: FileSystem , diagnostics: DiagnosticsEngine ) {
1056
1074
assert ( product. type != . library( . automatic) , " Automatic type libraries should not be described. " )
1057
1075
self . product = product
1076
+ self . toolsVersion = toolsVersion
1058
1077
self . buildParameters = buildParameters
1059
1078
self . fs = fs
1060
1079
self . diagnostics = diagnostics
@@ -1308,9 +1327,11 @@ public class BuildPlan {
1308
1327
// if test manifest exists, prefer that over test detection,
1309
1328
// this is designed as an escape hatch when test discovery is not appropriate
1310
1329
// and for backwards compatibility for projects that have existing test manifests (LinuxMain.swift)
1330
+ let toolsVersion = graph. package ( for: testProduct) ? . manifest. toolsVersion ?? . vNext
1311
1331
if let testManifestTarget = testProduct. testManifestTarget, !generate {
1312
1332
let desc = try SwiftTargetBuildDescription (
1313
1333
target: testManifestTarget,
1334
+ toolsVersion: toolsVersion,
1314
1335
buildParameters: buildParameters,
1315
1336
isTestTarget: true
1316
1337
)
@@ -1342,6 +1363,7 @@ public class BuildPlan {
1342
1363
1343
1364
let target = try SwiftTargetBuildDescription (
1344
1365
target: testManifestTarget,
1366
+ toolsVersion: toolsVersion,
1345
1367
buildParameters: buildParameters,
1346
1368
isTestTarget: true ,
1347
1369
testDiscoveryTarget: true
@@ -1382,17 +1404,23 @@ public class BuildPlan {
1382
1404
}
1383
1405
}
1384
1406
}
1407
+
1408
+ // Determine the appropriate tools version to use for the target.
1409
+ // This can affect what flags to pass and other semantics.
1410
+ let toolsVersion = graph. package ( for: target) ? . manifest. toolsVersion ?? . vNext
1385
1411
1386
1412
switch target. underlyingTarget {
1387
1413
case is SwiftTarget :
1388
1414
targetMap [ target] = try . swift( SwiftTargetBuildDescription (
1389
1415
target: target,
1416
+ toolsVersion: toolsVersion,
1390
1417
buildParameters: buildParameters,
1391
1418
pluginInvocationResults: pluginInvocationResults [ target] ?? [ ] ,
1392
1419
fs: fileSystem) )
1393
1420
case is ClangTarget :
1394
1421
targetMap [ target] = try . clang( ClangTargetBuildDescription (
1395
1422
target: target,
1423
+ toolsVersion: toolsVersion,
1396
1424
buildParameters: buildParameters,
1397
1425
fileSystem: fileSystem,
1398
1426
diagnostics: diagnostics) )
@@ -1426,8 +1454,14 @@ public class BuildPlan {
1426
1454
// Create product description for each product we have in the package graph except
1427
1455
// for automatic libraries and plugins, because they don't produce any output.
1428
1456
for product in graph. allProducts where product. type != . library( . automatic) && product. type != . plugin {
1457
+
1458
+ // Determine the appropriate tools version to use for the product.
1459
+ // This can affect what flags to pass and other semantics.
1460
+ let toolsVersion = graph. package ( for: product) ? . manifest. toolsVersion ?? . vNext
1429
1461
productMap [ product] = ProductBuildDescription (
1430
- product: product, buildParameters: buildParameters,
1462
+ product: product,
1463
+ toolsVersion: toolsVersion,
1464
+ buildParameters: buildParameters,
1431
1465
fs: fileSystem,
1432
1466
diagnostics: diagnostics
1433
1467
)
0 commit comments