Skip to content

Commit 1231679

Browse files
committed
Move SwiftTarget convenience initializer to declaration and change to public access level
1 parent aa3f08b commit 1231679

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

Sources/PackageGraph/ResolvedProduct.swift

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,3 @@ extension ResolvedProduct: CustomStringConvertible {
7777
return "<ResolvedProduct: \(name)>"
7878
}
7979
}
80-
81-
fileprivate extension SwiftTarget {
82-
/// Create an executable Swift target from linux main test manifest file.
83-
convenience init(linuxMain: AbsolutePath, name: String, dependencies: [Target.Dependency]) {
84-
// Look for the first swift test target and use the same swift version
85-
// for linux main target. This will need to change if we move to a model
86-
// where we allow per target swift language version build settings.
87-
let swiftTestTarget = dependencies.first {
88-
guard case .target(let target as SwiftTarget, _) = $0 else { return false }
89-
return target.type == .test
90-
}.flatMap { $0.target as? SwiftTarget }
91-
92-
// FIXME: This is not very correct but doesn't matter much in practice.
93-
// We need to select the latest Swift language version that can
94-
// satisfy the current tools version but there is not a good way to
95-
// do that currently.
96-
let sources = Sources(paths: [linuxMain], root: linuxMain.parentDirectory)
97-
98-
let platforms: [SupportedPlatform] = swiftTestTarget?.platforms ?? []
99-
100-
let swiftVersion = swiftTestTarget?.swiftVersion ?? SwiftLanguageVersion(string: String(ToolsVersion.currentToolsVersion.major)) ?? .v4
101-
102-
self.init(
103-
name: name,
104-
defaultLocalization: nil,
105-
platforms: platforms,
106-
sources: sources,
107-
dependencies: dependencies,
108-
swiftVersion: swiftVersion,
109-
buildSettings: .init()
110-
)
111-
}
112-
}

Sources/PackageModel/Target.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,37 @@ public final class SwiftTarget: Target {
247247
)
248248
}
249249

250+
/// Create an executable Swift target from linux main test manifest file.
251+
public convenience init(linuxMain: AbsolutePath, name: String, dependencies: [Target.Dependency]) {
252+
// Look for the first swift test target and use the same swift version
253+
// for linux main target. This will need to change if we move to a model
254+
// where we allow per target swift language version build settings.
255+
let swiftTestTarget = dependencies.first {
256+
guard case .target(let target as SwiftTarget, _) = $0 else { return false }
257+
return target.type == .test
258+
}.flatMap { $0.target as? SwiftTarget }
259+
260+
// FIXME: This is not very correct but doesn't matter much in practice.
261+
// We need to select the latest Swift language version that can
262+
// satisfy the current tools version but there is not a good way to
263+
// do that currently.
264+
let sources = Sources(paths: [linuxMain], root: linuxMain.parentDirectory)
265+
266+
let platforms: [SupportedPlatform] = swiftTestTarget?.platforms ?? []
267+
268+
let swiftVersion = swiftTestTarget?.swiftVersion ?? SwiftLanguageVersion(string: String(ToolsVersion.currentToolsVersion.major)) ?? .v4
269+
270+
self.init(
271+
name: name,
272+
defaultLocalization: nil,
273+
platforms: platforms,
274+
sources: sources,
275+
dependencies: dependencies,
276+
swiftVersion: swiftVersion,
277+
buildSettings: .init()
278+
)
279+
}
280+
250281
private enum CodingKeys: String, CodingKey {
251282
case swiftVersion
252283
}

0 commit comments

Comments
 (0)