Significantly improve prebuilt download error messages (#57)

* Significantly improve prebuilt download error messages

* Remove github API call

* Ignore clippy issue
This commit is contained in:
Ashley Hauck 2021-05-28 12:03:21 +02:00 committed by GitHub
parent 8b39e7a105
commit fea270b0c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 65 deletions

View file

@ -199,82 +199,53 @@ mod mac {
} }
pub(crate) fn download_prebuilt_molten<P: AsRef<Path>>(target_dir: &P) { pub(crate) fn download_prebuilt_molten<P: AsRef<Path>>(target_dir: &P) {
use std::process::{Command, Stdio}; use std::process::Command;
std::fs::create_dir_all(&target_dir).expect("Couldn't create directory"); std::fs::create_dir_all(&target_dir).expect("Couldn't create directory");
let previous_path = std::env::current_dir().expect("Couldn't get current directory"); let download_url = format!(
"https://github.com/EmbarkStudios/ash-molten/releases/download/MoltenVK-{}/MoltenVK.xcframework.zip",
get_artifact_tag().replace("#", "%23")
);
let download_path = target_dir.as_ref().join("MoltenVK.xcframework.zip");
std::env::set_current_dir(&target_dir).expect("Couldn't change current directory"); let curl_status = Command::new("curl")
.args(&["--location", "--silent", &download_url, "-o"])
let curl = Command::new("curl") .arg(&download_path)
.arg("-s")
.arg(format!(
"https://api.github.com/repos/EmbarkStudios/ash-molten/releases/tags/MoltenVK-{}",
get_artifact_tag().replace("#", "%23")
))
.stdout(Stdio::piped())
.spawn() .spawn()
.expect("Couldn't launch curl"); .expect("Couldn't launch curl")
.wait()
.expect("failed to wait on curl");
let curl_out = curl.stdout.expect("Failed to open curl stdout"); assert!(curl_status.success());
let grep = Command::new("grep") let unzip_status = Command::new("unzip")
.arg("browser_download_url.*zip") .arg("-o")
.stdin(Stdio::from(curl_out)) .arg(&download_path)
.stdout(Stdio::piped()) .arg("-x")
.arg("__MACOSX/*")
.arg("-d")
.arg(target_dir.as_ref())
.spawn() .spawn()
.expect("Couldn't launch grep"); .expect("Couldn't launch unzip")
.wait()
.expect("failed to wait on unzip");
let grep_out = grep.stdout.expect("Failed to open grep stdout"); if !unzip_status.success() {
let bytes = std::fs::read(download_path)
let cut = Command::new("cut") .expect("unzip failed, and further, could not open output zip file");
.args(&["-d", ":", "-f", "2,3"]) match std::str::from_utf8(&bytes) {
.stdin(Stdio::from(grep_out)) Ok(string) => {
.stdout(Stdio::piped()) panic!(
.spawn() "Could not unzip MoltenVK.xcframework.zip. File was utf8, perhaps an error?\n{}",
.expect("Couldn't launch cut"); string
);
let cut_out = cut.stdout.expect("Failed to open grep stdout"); }
Err(_) => {
let tr = Command::new("tr") panic!("Could not unzip MoltenVK.xcframework.zip");
.args(&["-d", "\""]) }
.stdin(Stdio::from(cut_out))
.stdout(Stdio::piped())
.spawn()
.expect("Couldn't launch tr");
let tr_out = tr.stdout.expect("Failed to open grep stdout");
let output = Command::new("xargs")
.args(&["-n", "1", "curl", "-LO", "--silent"])
.stdin(Stdio::from(tr_out))
.stdout(Stdio::piped())
.spawn()
.expect("Couldn't launch xargs")
.wait_with_output()
.expect("failed to wait on xargs");
assert!(output.status.success());
for path in std::fs::read_dir(&target_dir).expect("Couldn't read dir") {
let path = path.unwrap().path();
if let Some("zip") = path.extension().and_then(std::ffi::OsStr::to_str) {
let status = Command::new("unzip")
.arg("-o")
.arg(path.to_owned())
.arg("-x")
.arg("__MACOSX/*")
.spawn()
.expect("Couldn't launch unzip")
.wait()
.expect("failed to wait on unzip");
assert!(status.success());
} }
} }
std::env::set_current_dir(&previous_path).expect("Couldn't change current directory");
} }
} }

View file

@ -14,6 +14,7 @@ pub enum Arch {
#[serde(from = "String")] #[serde(from = "String")]
pub enum Platform { pub enum Platform {
MacOS, MacOS,
#[allow(clippy::upper_case_acronyms)]
IOS, IOS,
TvOS, TvOS,
WatchOS, WatchOS,