Skip to content

Commit

Permalink
added support for swift 5.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed May 25, 2020
1 parent 9c32a8d commit f121052
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Sources/PackageConfig/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ enum Package {
spmVersionDir = swiftToolsVersion
}

let packageDescriptionVersion = swiftToolsVersion?.replacingOccurrences(of: "_", with: ".")
let libraryPathSPM = swiftPMDir + "/" + spmVersionDir

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

private static func getSwiftToolsVersion() -> String? {
Expand All @@ -136,7 +137,7 @@ enum Package {
}

let range = NSRange(location: 0, length: contents.count)
guard let regex = try? NSRegularExpression(pattern: "^// swift-tools-version:(?:(\\d)\\.(\\d)(?:\\.\\d)?)$"),
guard let regex = try? NSRegularExpression(pattern: "^// swift-tools-version:(?:(\\d)\\.(\\d)(?:\\.\\d)?)"),
let match = regex.firstMatch(in: contents, options: [], range: range),
let majorRange = Range(match.range(at: 1), in: contents), let major = Int(contents[majorRange]),
let minorRange = Range(match.range(at: 2), in: contents), let minor = Int(contents[minorRange])
Expand All @@ -151,7 +152,7 @@ enum Package {
}
return "4_2"
default:
return "5_1"
return "\(major)_\(minor)"
}
}
}

0 comments on commit f121052

Please sign in to comment.