Skip to content

[swift-snapshot-tool] Make computing the branch name part of the download url more flexible so it works for release branches. #83180

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

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func downloadToolchainAndRunTest(
let fileType = platform.fileType
let toolchainType = platform.toolchainType

let realBranch = branch != .development ? "swift-\(branch)-branch" : branch.rawValue
let realBranch = branch.urlBranchName
let toolchainDir = "\(workspace)/\(tag.name)-\(platform)"
let downloadPath = URL(fileURLWithPath: "\(workspace)/\(tag.name)-\(platform).\(fileType)")
if !fileExists(toolchainDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@ struct Tag: Decodable {
ref.dropFirst(10)
}

func dateString(_ branch: Branch) -> Substring {
// FIXME: If we ever actually use interesting a-b builds, we should capture this information
// would be better to do it sooner than later.
return name.dropFirst("swift-".count + branch.rawValue.count + "-SNAPSHOT-".count).dropLast(2)
}

func date(branch: Branch) -> Date {
// TODO: I think that d might be a class... if so, we really want to memoize
// this.
let d = DateFormatter()
d.dateFormat = "yyyy-MM-dd"
return d.date(from: String(dateString(branch)))!
// TODO: Change top use swift regexp
let pattern = "swift-.*DEVELOPMENT-SNAPSHOT-(\\d+-\\d+-\\d+)"
do {
let regex = try NSRegularExpression(pattern: pattern, options: .caseInsensitive)
guard let match = regex.firstMatch(in: String(name),
options: [],
range: NSRange(location: 0, length: name.utf16.count)) else {
fatalError("Failed to find match!")
}
let str = String((name as NSString).substring(with: match.range(at: 1)))
return d.date(from: str)!
} catch let error as NSError {
fatalError("Error creating NSRegularExpression: \(error)")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ enum Platform: String, EnumerableFlag {
case .osx:
return "pkg"
case .ubuntu1404,
.ubuntu1604,
.ubuntu1804:
.ubuntu1604,
.ubuntu1804:
return "tar.gz"
}
}
Expand All @@ -34,8 +34,8 @@ enum Platform: String, EnumerableFlag {
case .osx:
return "xcode"
case .ubuntu1404,
.ubuntu1604,
.ubuntu1804:
.ubuntu1604,
.ubuntu1804:
return self.rawValue
}
}
Expand All @@ -50,9 +50,18 @@ enum Branch: String, EnumerableFlag {
var tagPrefix: String {
switch self {
case .development:
"swift-\(rawValue.uppercased())"
"swift-\(rawValue.uppercased())"
default:
"swift-\(rawValue.uppercased())-DEVELOPMENT"
"swift-\(rawValue.uppercased())-DEVELOPMENT"
}
}

var urlBranchName: String {
switch self {
case .development:
return self.rawValue
default:
return "swift-\(self.rawValue)-branch"
}
}
}