Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct swift package manager version #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions Sources/PackageConfig/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@ enum Package {
var spmVersionDir = latestVersion
let swiftToolsVersion = getSwiftToolsVersion()

if let swiftToolsVersion = swiftToolsVersion, versions.contains(swiftToolsVersion) {
if let swiftToolsVersion = swiftToolsVersion.map({ folderPath(minor: $0.minor, major: $0.major) }),
versions.contains(swiftToolsVersion) {
spmVersionDir = swiftToolsVersion
}

let packageDescriptionVersion = swiftToolsVersion?.replacingOccurrences(of: "_", with: ".")
let packageDescriptionVersion = swiftToolsVersion.map { "\($0.major).\($0.minor)" }
let libraryPathSPM = swiftPMDir + "/" + spmVersionDir

debugLog("Using SPM version: \(libraryPathSPM)")
return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription", "-package-description-version", packageDescriptionVersion ?? "5.2"]
}

private static func getSwiftToolsVersion() -> String? {
private static func getSwiftToolsVersion() -> PackageVersion? {
guard let contents = try? String(contentsOfFile: "Package.swift") else {
return nil
}
Expand All @@ -145,14 +146,19 @@ enum Package {
return nil
}

switch major {
case 4:
if minor < 2 {
return "4"
}
return PackageVersion(minor: minor, major: major)
}

private static func folderPath(minor: Int, major: Int) -> String {
if major == 4 && minor < 2 {
return "4"
} else {
return "4_2"
default:
return "\(major)_\(minor)"
}
}

struct PackageVersion {
let minor: Int
let major: Int
}
}