mirror of
https://github.com/italicsjenga/ash-molten.git
synced 2024-12-23 21:31:30 +11:00
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:
parent
8b39e7a105
commit
fea270b0c9
|
@ -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",
|
||||||
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")
|
get_artifact_tag().replace("#", "%23")
|
||||||
))
|
);
|
||||||
.stdout(Stdio::piped())
|
let download_path = target_dir.as_ref().join("MoltenVK.xcframework.zip");
|
||||||
|
|
||||||
|
let curl_status = Command::new("curl")
|
||||||
|
.args(&["--location", "--silent", &download_url, "-o"])
|
||||||
|
.arg(&download_path)
|
||||||
.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")
|
|
||||||
.stdin(Stdio::from(curl_out))
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.expect("Couldn't launch grep");
|
|
||||||
|
|
||||||
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("-o")
|
||||||
.arg(path.to_owned())
|
.arg(&download_path)
|
||||||
.arg("-x")
|
.arg("-x")
|
||||||
.arg("__MACOSX/*")
|
.arg("__MACOSX/*")
|
||||||
|
.arg("-d")
|
||||||
|
.arg(target_dir.as_ref())
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("Couldn't launch unzip")
|
.expect("Couldn't launch unzip")
|
||||||
.wait()
|
.wait()
|
||||||
.expect("failed to wait on unzip");
|
.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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue