Skip to content

Commit

Permalink
Merge pull request #14 from brightdigit/feature/platforms-2019
Browse files Browse the repository at this point in the history
Feature/platforms 2019
  • Loading branch information
orta authored May 27, 2020
2 parents 321fe51 + 0177184 commit bf90dc6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Sources/PackageConfig/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ enum Package {
static private func runXCRun(tool: String) throws -> String {
let process = Process()
let pipe = Pipe()

process.launchPath = "/usr/bin/xcrun"
process.arguments = ["--find", tool]
process.standardOutput = pipe

debugLog("CMD: \(process.launchPath!) \( ["--find", tool].joined(separator: " "))")

process.launch()
process.waitUntilExit()
return String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)!
.trimmingCharacters(in: .whitespacesAndNewlines)
}

private static func findPath(tool: String) throws -> String {
let process = Process()
let pipe = Pipe()
Expand Down 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"
return "\(major)_\(minor)"
}
}
}

0 comments on commit bf90dc6

Please sign in to comment.