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) {
use std::process::{Command, Stdio};
use std::process::Command;
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 = Command::new("curl")
.arg("-s")
.arg(format!(
"https://api.github.com/repos/EmbarkStudios/ash-molten/releases/tags/MoltenVK-{}",
get_artifact_tag().replace("#", "%23")
))
.stdout(Stdio::piped())
let curl_status = Command::new("curl")
.args(&["--location", "--silent", &download_url, "-o"])
.arg(&download_path)
.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")
.arg("browser_download_url.*zip")
.stdin(Stdio::from(curl_out))
.stdout(Stdio::piped())
let unzip_status = Command::new("unzip")
.arg("-o")
.arg(&download_path)
.arg("-x")
.arg("__MACOSX/*")
.arg("-d")
.arg(target_dir.as_ref())
.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");
let cut = Command::new("cut")
.args(&["-d", ":", "-f", "2,3"])
.stdin(Stdio::from(grep_out))
.stdout(Stdio::piped())
.spawn()
.expect("Couldn't launch cut");
let cut_out = cut.stdout.expect("Failed to open grep stdout");
let tr = Command::new("tr")
.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());
if !unzip_status.success() {
let bytes = std::fs::read(download_path)
.expect("unzip failed, and further, could not open output zip file");
match std::str::from_utf8(&bytes) {
Ok(string) => {
panic!(
"Could not unzip MoltenVK.xcframework.zip. File was utf8, perhaps an error?\n{}",
string
);
}
Err(_) => {
panic!("Could not unzip MoltenVK.xcframework.zip");
}
}
}
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")]
pub enum Platform {
MacOS,
#[allow(clippy::upper_case_acronyms)]
IOS,
TvOS,
WatchOS,