Skip to content

Commit 3ab2520

Browse files
committed
contrib: Fixup verify-binaries OS platform parsing
Parse platform strings with "-" or '.' correctly such as "linux-gnu" or "x86_64-linux-gnu.tar.gz" to download the matching files or file. String partition() is used to tolerate more dashes. Update `VERSION_EXAMPLE` with a new string parsed correctly now. Fix "-aarch64" interpreted as a release candidate due to sub-string "rc", causing all downloads to fail. Now "rc" must immediately follow first "-" to indicate an [-rc] string. Local variables `version_rc`, `version_os` renamed to `rc`, `platform`. If "-rcN" is specified, `platform` is reassigned to remove the '-rcN'. Changes are useful to only download one bitcoin core binary on slow connections. Making `verify.py pub` more intuitive, robust, and versatile. Closes #30145 When user types a platform string not found in any filename lets help and say the platform closest to what they typed in a `f"No files matched the platform specified. Did you mean: {closest_match}"` log. Improves UX when unaware how we name our files. Uses the difflib Python built-in which was already imported elsewhere. Update test.py to test single file verification verify-binaries/verify.py can accept an entire filename filter for its "-platform" parameter now so let us test that it succeeds and downloads and verifies only one file. `verify.py pub 22.0-x86_64-linux-gnu.tar.gz` should get and verify only the requested binary. It is placed before the existing <version> wide verification as it is a faster test and possibly easier to break. Update doc with examples now possible after bugfix Add example to show release candidates now work with "-platform" strings containing "-" and string provided can be from the middle of filename: `./contrib/verify-binaries/verify.py --json pub 23.0-rc5-linux-gnu` Change example 5 to not match example 3. New examples to show platform can now be provided specifically enough to download only a single binary down to its file extension: `./contrib/verify-binaries/verify.py pub 25.2-x86_64-linux` `./contrib/verify-binaries/verify.py pub 24.1-rc1-darwin` `./contrib/verify-binaries/verify.py pub 27.0-win64-setup.exe` This is the most common use if not verifying all files so users see it as the first example for "only download the binaries for a certain architecture and/or platform". Downloading one file is intuitively what most will think this meant and this change delivers on that expectation. Co-authored-by: stickies-v
1 parent 0388dd7 commit 3ab2520

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

contrib/verify-binaries/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,23 @@ Get JSON output and don't prompt for user input (no auto key import):
5050

5151
```sh
5252
./contrib/verify-binaries/verify.py --json pub 22.0-x86
53+
./contrib/verify-binaries/verify.py --json pub 23.0-rc5-linux-gnu
5354
```
5455

5556
Rely only on local GPG state and manually specified keys, while requiring a
5657
threshold of at least 10 trusted signatures:
5758
```sh
5859
./contrib/verify-binaries/verify.py \
5960
--trusted-keys 74E2DEF5D77260B98BC19438099BAD163C70FBFA,9D3CC86A72F8494342EA5FD10A41BDC3F4FAFF1C \
60-
--min-good-sigs 10 pub 22.0-x86
61+
--min-good-sigs 10 pub 22.0-linux
6162
```
6263

63-
If you only want to download the binaries for a certain platform, add the corresponding suffix, e.g.:
64+
If you only want to download the binaries for a certain architecture and/or platform, add the corresponding suffix, e.g.:
6465

6566
```sh
66-
./contrib/verify-binaries/verify.py pub 24.0.1-darwin
67-
./contrib/verify-binaries/verify.py pub 23.1-rc1-win64
67+
./contrib/verify-binaries/verify.py pub 25.2-x86_64-linux
68+
./contrib/verify-binaries/verify.py pub 24.1-rc1-darwin
69+
./contrib/verify-binaries/verify.py pub 27.0-win64-setup.exe
6870
```
6971

7072
If you do not want to keep the downloaded binaries, specify the cleanup option.

contrib/verify-binaries/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ def main():
1212
expect_code(run_verify("", "pub", '0.32.awefa.12f9h'), 11, "Malformed version should fail")
1313
expect_code(run_verify('--min-good-sigs 20', "pub", "22.0"), 9, "--min-good-sigs 20 should fail")
1414

15+
print("- testing verification (22.0-x86_64-linux-gnu.tar.gz)", flush=True)
16+
_220_x86_64_linux_gnu = run_verify("--json", "pub", "22.0-x86_64-linux-gnu.tar.gz")
17+
try:
18+
result = json.loads(_220_x86_64_linux_gnu.stdout.decode())
19+
except Exception:
20+
print("failed on 22.0-x86_64-linux-gnu.tar.gz --json:")
21+
print_process_failure(_220_x86_64_linux_gnu)
22+
raise
23+
24+
expect_code(_220_x86_64_linux_gnu, 0, "22.0-x86_64-linux-gnu.tar.gz should succeed")
25+
v = result['verified_binaries']
26+
assert result['good_trusted_sigs']
27+
assert len(v) == 1
28+
assert v['bitcoin-22.0-x86_64-linux-gnu.tar.gz'] == '59ebd25dd82a51638b7a6bb914586201e67db67b919b2a1ff08925a7936d1b16'
29+
1530
print("- testing verification (22.0)", flush=True)
1631
_220 = run_verify("--json", "pub", "22.0")
1732
try:

contrib/verify-binaries/verify.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,17 @@ def bool_from_env(key, default=False) -> bool:
9797

9898

9999
VERSION_FORMAT = "<major>.<minor>[.<patch>][-rc[0-9]][-platform]"
100-
VERSION_EXAMPLE = "22.0-x86_64 or 23.1-rc1-darwin"
100+
VERSION_EXAMPLE = "22.0 or 23.1-rc1-darwin.dmg or 27.0-x86_64-linux-gnu"
101101

102102
def parse_version_string(version_str):
103-
parts = version_str.split('-')
104-
version_base = parts[0]
105-
version_rc = ""
106-
version_os = ""
107-
if len(parts) == 2: # "<version>-rcN" or "version-platform"
108-
if "rc" in parts[1]:
109-
version_rc = parts[1]
110-
else:
111-
version_os = parts[1]
112-
elif len(parts) == 3: # "<version>-rcN-platform"
113-
version_rc = parts[1]
114-
version_os = parts[2]
103+
# "<version>[-rcN][-platform]"
104+
version_base, _, platform = version_str.partition('-')
105+
rc = ""
106+
if platform.startswith("rc"): # "<version>-rcN[-platform]"
107+
rc, _, platform = platform.partition('-')
108+
# else "<version>" or "<version>-platform"
115109

116-
return version_base, version_rc, version_os
110+
return version_base, rc, platform
117111

118112

119113
def download_with_wget(remote_file, local_file):
@@ -514,7 +508,9 @@ def cleanup():
514508
# Extract hashes and filenames
515509
hashes_to_verify = parse_sums_file(SUMS_FILENAME, [os_filter])
516510
if not hashes_to_verify:
517-
log.error("no files matched the platform specified")
511+
available_versions = ["-".join(line[1].split("-")[2:]) for line in parse_sums_file(SUMS_FILENAME, [])]
512+
closest_match = difflib.get_close_matches(os_filter, available_versions, cutoff=0, n=1)[0]
513+
log.error(f"No files matched the platform specified. Did you mean: {closest_match}")
518514
return ReturnCode.NO_BINARIES_MATCH
519515

520516
# remove binaries that are known not to be hosted by bitcoincore.org

0 commit comments

Comments
 (0)