Skip to content

Commit 71a2d87

Browse files
authored
Merge pull request #81034 from gottesmm/swift-snapshot-fixes-2
[swift-snapshot-tool] A few small fixes
2 parents f0831f3 + 1e7eb3e commit 71a2d87

File tree

6 files changed

+95
-33
lines changed

6 files changed

+95
-33
lines changed

utils/swift_snapshot_tool/README.md

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Used to list and bisect nightly snapshots off of swift.org.
99

1010
```
1111
# xcrun swift run swift_snapshot_tool list
12-
[INFO] Starting to download snapshot information from github.
13-
[INFO] Finished downloading snapshot information from github.
12+
[INFO] Starting to download snapshot information from github.
13+
[INFO] Finished downloading snapshot information from github.
1414
0 swift-DEVELOPMENT-SNAPSHOT-2024-09-06-a
1515
1 swift-DEVELOPMENT-SNAPSHOT-2024-09-05-a
1616
2 swift-DEVELOPMENT-SNAPSHOT-2024-09-04-a
@@ -23,11 +23,46 @@ value is at. This allows for one to get a sense of the range of time in between
2323
two bisect numbers since one can look at the range in between them and how time
2424
varies.
2525

26+
## Run
27+
28+
```
29+
xcrun swift run swift_snapshot_tool run --script $SCRIPT_NAME \
30+
--date YYYY-MM-DD [--invert] [--workspace $DIR_TO_DOWNLOAD_TOOLCHAINS]
31+
```
32+
33+
run success is defined by `$SCRIPT_NAME` returning 0 as an exit code. All other
34+
exit codes are considered a failure.
35+
36+
This command is meant to help one figure out where to start bisecting.
37+
38+
Options:
39+
40+
- workspace: This is the place where we will download toolchains to. Defaults to
41+
`/tmp/swift_snapshot_tool_workspace_v1`. We suggest that you use an external
42+
hard drive or a specified place so that one does not have to redownload
43+
toolchains in between system restarts.
44+
45+
- script: This is the script that should be run. We pass in the environment
46+
variables `SWIFT_EXEC`, `SWIFT_FRONTEND`, and `SWIFT_LIBRARY_PATH` to the
47+
script. If the script returns a zero exit code then the run is considered a
48+
succeess. If the script returns a non-zero exit code, then the run is
49+
considered a failure.
50+
51+
- date: A date in the form YYYY-MM-DD. If a snapshot at date does not exist, we
52+
choose the first snapshot before that date.
53+
54+
- invert: This causes test.sh's result to be inverted. This allows one to bisect
55+
backwards from a good state to a bad state. This is useful to determine when
56+
an error was fixed.
57+
58+
- branch: This controls the specific branch of snapshots that are downloaded. By
59+
default uses development. Also supports the options 5.0 and 6.0.
60+
2661
## Bisect
2762

2863
```
29-
xcrun swift run swift_snapshot_tool bisect --script $SCRIPT_NAME --workspace $DIR_TO_DOWNLOAD_TOOLCHAINS \
30-
--good-tag $OLDER_TAG_NAME_THAT_PASSES --bad-tag $NEWER_TAG_NAME_THAT_FAILS
64+
xcrun swift run swift_snapshot_tool bisect --script $SCRIPT_NAME --old-date YYYY_MM_DD \
65+
[--new-date YYYY_MM_DD] [--workspace $DIR_TO_DOWNLOAD_TOOLCHAINS]
3166
```
3267

3368
bisect success is defined by `$SCRIPT_NAME` returning 0 as an exit code. All
@@ -36,18 +71,23 @@ other exit codes are considered a failure.
3671
Options:
3772

3873
- workspace: This is the place where we will download toolchains to. Defaults to
39-
`/tmp/swift_snapshot_tool_workspace_v1`
74+
`/tmp/swift_snapshot_tool_workspace_v1`. We suggest that you use an external
75+
hard drive or a specified place so that one does not have to redownload
76+
toolchains in between system restarts.
4077

4178
- script: This is the script that should be run. We pass in the environment
42-
variables `SWIFT_EXEC` and `SWIFT_FRONTEND` to the subscript. If the script
43-
returns a zero exit code then the run is considered a succeess. If the script
44-
returns a non-zero exit code, then the run is considered a failure.
45-
46-
- good_tag: This is the older tag and is assumed to succeed by returning a zero
47-
exit code.
48-
49-
- bad_tag: This is the newer tag and is assumed to fail by returning a non-zero
50-
exit code.
79+
variables `SWIFT_EXEC`, `SWIFT_FRONTEND`, `SWIFT_LIBRARY_PATH` to the
80+
script. If the script returns a zero exit code then the run is considered a
81+
succeess. If the script returns a non-zero exit code, then the run is
82+
considered a failure.
83+
84+
- old-date: Date in the form of YYYY-MM-DD. This is assumed to succeed by
85+
returning a zero exit code. If a snapshot does not exist at this date, the
86+
tool will choose the first snapshot before the date.
87+
88+
- new-date: Date in the form of YYYY-MM-DD. This is assumed to fail by returning
89+
a non-zero exit code. If a snapshot does not exist at this date, the tool will
90+
choose the first snapshot before the date.
5191

5292
- invert: This causes test.sh's result to be inverted. This allows one to bisect
5393
backwards from a good state to a bad state. This is useful to determine when

utils/swift_snapshot_tool/Sources/swift_snapshot_tool/bisect_toolchains.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ struct BisectToolchains: AsyncParsableCommand {
1717
static let configuration = CommandConfiguration(
1818
commandName: "bisect",
1919
discussion: """
20-
Bisects on exit status of attached script. Passes in name of swift as the
21-
environment variables \(environmentVariables).
20+
Bisects on swift snapshots downloaded from swift.org via an exit status of
21+
a script. Script is passed paths into the downloaded snapshot via
22+
environment variables and is expected to compile and or run swift programs
23+
using the snapshot artifacts.
2224
""")
2325

2426
@Flag var platform: Platform = .osx
@@ -34,13 +36,16 @@ struct BisectToolchains: AsyncParsableCommand {
3436

3537
@Option(
3638
help: """
37-
The script that should be run. It runs a specific swift compilation and
38-
optionally program using the passed in environment variables
39-
\(environmentVariables)
39+
The script that should be run. It should run a specific swift compilation and
40+
or program. Paths into the snapshots are passed in via the environment variables \(environmentVariables).
4041
""")
4142
var script: String
4243

43-
@Option(help: "Oldest Date. Expected to Pass. We use the first snapshot produced before the given date")
44+
@Option(help:
45+
"""
46+
Expected to Pass. We use the first snapshot produced before the
47+
given date if a snapshot at this specific date does not exist
48+
""")
4449
var oldDate: String
4550

4651
var oldDateAsDate: Date {
@@ -54,9 +59,10 @@ struct BisectToolchains: AsyncParsableCommand {
5459
}
5560

5661
@Option(help: """
57-
Newest Date. Expected to fail. If not set, use newest snapshot. We use the
58-
first snapshot after new date
59-
""")
62+
Expected to fail. If not set, defaults to use newest snapshot. If a
63+
date is specified and a snapshot does not exist for that date, the
64+
first snapshot before the specified date is used.
65+
""")
6066
var newDate: String?
6167

6268
var newDateAsDate: Date? {

utils/swift_snapshot_tool/Sources/swift_snapshot_tool/get_tags.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,10 @@ func getTagsFromSwiftRepo(branch: Branch, dryRun: Bool = false) async throws ->
7777
let allTags = try! decoder.decode([Tag].self, from: await data)
7878
log("[INFO] Finished downloading snapshot information from github.")
7979

80-
let snapshotTagPrefix = "swift-\(branch.rawValue.uppercased())"
81-
8280
// Then filter the tags to just include the specific snapshot branch
8381
// prefix. Add the branch to an aggregate BranchTag.
8482
var filteredTags: [BranchTag] = allTags.filter {
85-
$0.name.starts(with: snapshotTagPrefix)
83+
$0.name.starts(with: branch.tagPrefix)
8684
}.map {
8785
BranchTag(tag: $0, branch: branch)
8886
}

utils/swift_snapshot_tool/Sources/swift_snapshot_tool/github_repository.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ enum Platform: String, EnumerableFlag {
4343

4444
enum Branch: String, EnumerableFlag {
4545
case development
46-
case release50 = "5.0"
47-
case release60 = "6.0"
46+
case release_5_0 = "5.0"
47+
case release_6_0 = "6.0"
48+
case release_6_2 = "6.2"
49+
50+
var tagPrefix: String {
51+
switch self {
52+
case .development:
53+
"swift-\(rawValue.uppercased())"
54+
default:
55+
"swift-\(rawValue.uppercased())-DEVELOPMENT"
56+
}
57+
}
4858
}

utils/swift_snapshot_tool/Sources/swift_snapshot_tool/list_snapshots.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import ArgumentParser
1414

1515
struct ListSnapshots: AsyncParsableCommand {
1616
static let configuration = CommandConfiguration(
17-
commandName: "list")
17+
commandName: "list",
18+
discussion: """
19+
Downloads the current list of available snapshots from swift.org and
20+
outputs the snapshots to stdout. Useful to see what snapshots are
21+
available.
22+
""")
1823

1924
@Flag var platform: Platform = .osx
2025

utils/swift_snapshot_tool/Sources/swift_snapshot_tool/run_toolchain.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ struct RunToolchains: AsyncParsableCommand {
1717
static let configuration = CommandConfiguration(
1818
commandName: "run",
1919
discussion: """
20-
Run a toolchain like bisect would. Passed the environment variables:
21-
\(environmentVariables)
20+
Run and determine success/failure of a script against a specified snapshot
21+
like the bisect command would. Used to determine the start/end bisect
22+
dates to pass to the bisect command. The script is passed paths into the
23+
downloaded snapshot via environment variables and is expected to compile
24+
and or run swift programs using the snapshot artifacts.
2225
""")
2326

2427
@Flag var platform: Platform = .osx
@@ -34,8 +37,8 @@ struct RunToolchains: AsyncParsableCommand {
3437

3538
@Option(
3639
help: """
37-
The script that should be run. The environment variable
38-
SWIFT_EXEC is used by the script to know where swift-frontend is
40+
The script that should be run. It should run a specific swift compilation and
41+
or program. Paths into the snapshots are passed in via the environment variables \(environmentVariables).
3942
""")
4043
var script: String
4144

0 commit comments

Comments
 (0)