about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorbinarycat <binarycat@envs.net>2024-08-23 11:48:04 -0400
committerbinarycat <binarycat@envs.net>2024-08-23 11:57:23 -0400
commit69ca95bf7f5462eb7ade2de18d1f0d79b2c21cfd (patch)
treef951f9e1db28d094af0dfa0865056bfc70dc95a5 /src/bootstrap
parentd1b41f3747ecb01b717bd50918513227de36f3cb (diff)
downloadrust-69ca95bf7f5462eb7ade2de18d1f0d79b2c21cfd.tar.gz
rust-69ca95bf7f5462eb7ade2de18d1f0d79b2c21cfd.zip
use tuples for semver, not floats
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/bootstrap.py7
-rw-r--r--src/bootstrap/src/core/download.rs18
2 files changed, 16 insertions, 9 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 5ea4b4882a9..c19134b4594 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -80,7 +80,10 @@ def get(base, url, path, checksums, verbose=False):
             os.unlink(temp_path)
 
 def curl_version():
-    return float(re.match(bytes("^curl ([0-9]+\\.[0-9]+)", "utf8"), require(["curl", "-V"]))[1])
+    m = re.match(bytes("^curl ([0-9]+)\\.([0-9]+)", "utf8"), require(["curl", "-V"]))
+    if m is None:
+        return (0, 0)
+    return (int(m[1]), int(m[2]))
 
 def download(path, url, probably_big, verbose):
     for _ in range(4):
@@ -110,7 +113,7 @@ def _download(path, url, probably_big, verbose, exception):
         #   but raise `CalledProcessError` or `OSError` instead
         require(["curl", "--version"], exception=platform_is_win32())
         extra_flags = []
-        if curl_version() > 7.70:
+        if curl_version() > (7, 70):
             extra_flags = [ "--retry-all-errors" ]
         run(["curl", option] + extra_flags + [
             "-L", # Follow redirect.
diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs
index 201addaec2f..fd6f17130ee 100644
--- a/src/bootstrap/src/core/download.rs
+++ b/src/bootstrap/src/core/download.rs
@@ -21,19 +21,23 @@ fn try_run(config: &Config, cmd: &mut Command) -> Result<(), ()> {
     config.try_run(cmd)
 }
 
-fn extract_curl_version(out: &[u8]) -> f32 {
+fn extract_curl_version(out: &[u8]) -> (u16, u16) {
     let out = &out[5..];
-    let Some(i) = out.iter().position(|&x| x == b' ') else { return 0.0 };
+    let Some(i) = out.iter().position(|&x| x == b' ') else { return (0, 0) };
     let out = &out[..i];
-    let Some(k) = out.iter().rev().position(|&x| x == b'.') else { return 0.0 };
+    let Some(k) = out.iter().rev().position(|&x| x == b'.') else { return (0, 0) };
     let out = &out[..out.len() - k - 1];
-    std::str::from_utf8(out).unwrap().parse().unwrap_or(0.0)
+    let Ok(s) = std::str::from_utf8(out) else { return (0, 0) };
+    let parts = s.split('.').collect::<Vec<_>>();
+    let [s_major, s_minor] = &parts[..] else { return (0, 0) };
+    let (Ok(major), Ok(minor)) = (s_major.parse(), s_minor.parse()) else { return (0, 0) };
+    (major, minor)
 }
 
-fn curl_version() -> f32 {
+fn curl_version() -> (u16, u16) {
     let mut curl = Command::new("curl");
     curl.arg("-V");
-    let Ok(out) = curl.output() else { return 0.0 };
+    let Ok(out) = curl.output() else { return (0, 0) };
     let out = out.stdout;
     extract_curl_version(&out)
 }
@@ -249,7 +253,7 @@ impl Config {
             curl.arg("--progress-bar");
         }
         // --retry-all-errors was added in 7.71.0, don't use it if curl is old.
-        if curl_version() > 7.70 {
+        if curl_version() > (7, 70) {
             curl.arg("--retry-all-errors");
         }
         curl.arg(url);