Fix xtask wasm-bindgen install (#4944)

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
Lucas Kent 2024-01-03 09:12:22 +11:00 committed by GitHub
parent d7db4e5ef0
commit a0c2b25829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 10 deletions

View File

@ -2,16 +2,28 @@ use anyhow::Context;
use pico_args::Arguments;
use crate::util::check_all_programs;
use crate::util::{check_all_programs, Program};
pub(crate) fn run_wasm(mut args: Arguments) -> Result<(), anyhow::Error> {
let no_serve = args.contains("--no-serve");
let release = args.contains("--release");
let programs_needed: &[_] = if no_serve {
&["wasm-bindgen"]
&[Program {
crate_name: "wasm-bindgen-cli",
binary_name: "wasm-bindgen",
}]
} else {
&["wasm-bindgen", "simple-http-server"]
&[
Program {
crate_name: "wasm-bindgen-cli",
binary_name: "wasm-bindgen",
},
Program {
crate_name: "simple-http-server",
binary_name: "simple-http-server",
},
]
};
check_all_programs(programs_needed)?;

View File

@ -1,21 +1,30 @@
use std::{io, process::Command};
pub(crate) fn check_all_programs(programs: &[&str]) -> anyhow::Result<()> {
pub(crate) struct Program {
pub binary_name: &'static str,
pub crate_name: &'static str,
}
pub(crate) fn check_all_programs(programs: &[Program]) -> anyhow::Result<()> {
let mut failed = Vec::new();
for &program in programs {
let mut cmd = Command::new(program);
for Program {
binary_name,
crate_name,
} in programs
{
let mut cmd = Command::new(binary_name);
cmd.arg("--help");
let output = cmd.output();
match output {
Ok(_output) => {
log::info!("Checking for {program} in PATH: ✅");
log::info!("Checking for {binary_name} in PATH: ✅");
}
Err(e) if matches!(e.kind(), io::ErrorKind::NotFound) => {
log::error!("Checking for {program} in PATH: ❌");
failed.push(program);
log::error!("Checking for {binary_name} in PATH: ❌");
failed.push(*crate_name);
}
Err(e) => {
log::error!("Checking for {program} in PATH: ❌");
log::error!("Checking for {binary_name} in PATH: ❌");
panic!("Unknown IO error: {:?}", e);
}
}