From d87341a7ce0faece4eccee191dc5c4e49c549212 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Sun, 31 May 2020 13:36:56 -0500 Subject: [PATCH] Fallback to curl if download_file.py fails (#373) --- build.rs | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/build.rs b/build.rs index c0900a51..31a8425a 100644 --- a/build.rs +++ b/build.rs @@ -187,6 +187,39 @@ fn static_lib_url() -> (String, String) { } } +fn download_file(url: String, filename: PathBuf) { + // Try downloading with python first. Python is a V8 build dependency, + // so this saves us from adding a Rust HTTP client dependency. + println!("Downloading {}", url); + let status = Command::new("python") + .arg("./tools/download_file.py") + .arg("--url") + .arg(&url) + .arg("--filename") + .arg(&filename) + .status(); + + // Python is only a required dependency for `V8_FROM_SOURCE` builds. + // If python is not available, try falling back to curl. + let status = match status { + Ok(status) if status.success() => status, + _ => { + println!("Python downloader failed, trying with curl."); + Command::new("curl") + .arg("-L") + .arg("-s") + .arg("-o") + .arg(&filename) + .arg(&url) + .status() + .unwrap() + } + }; + + assert!(status.success()); + assert!(filename.exists()); +} + fn download_static_lib_binaries() { let (url, static_lib_name) = static_lib_url(); println!("static lib URL: {}", url); @@ -216,19 +249,7 @@ fn download_static_lib_binaries() { println!("static lib already exists {}", filename.display()); println!("To re-download this file, it must be manually deleted."); } else { - // Using python to do the HTTP download because it's already a dependency - // and so we don't have to add a Rust HTTP client dependency. - println!("Downloading {}", url); - let status = Command::new("python") - .arg("./tools/download_file.py") - .arg("--url") - .arg(url) - .arg("--filename") - .arg(&filename) - .status() - .unwrap(); - assert!(status.success()); - assert!(filename.exists()); + download_file(url, filename); } }