mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
Merge branch 'master' into feat_sharedmemory
This commit is contained in:
@@ -645,17 +645,20 @@ impl Run {
|
||||
}
|
||||
}
|
||||
|
||||
fn start_spinner(msg: String) -> Option<spinner::SpinnerHandle> {
|
||||
fn start_spinner(msg: String) -> Option<spinoff::Spinner> {
|
||||
if !isatty::stdout_isatty() {
|
||||
return None;
|
||||
}
|
||||
Some(
|
||||
spinner::SpinnerBuilder::new(msg)
|
||||
.spinner(vec![
|
||||
"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷", " ", "⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈",
|
||||
])
|
||||
.start(),
|
||||
)
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use colored::control;
|
||||
let _ = control::set_virtual_terminal(true);
|
||||
}
|
||||
Some(spinoff::Spinner::new(
|
||||
spinoff::Spinners::Dots,
|
||||
msg,
|
||||
spinoff::Color::White,
|
||||
))
|
||||
}
|
||||
|
||||
/// Before looking up a command from the registry, try to see if we have
|
||||
@@ -706,8 +709,7 @@ pub(crate) fn try_autoinstall_package(
|
||||
force_install,
|
||||
);
|
||||
if let Some(sp) = sp.take() {
|
||||
sp.close();
|
||||
print!("\r");
|
||||
sp.clear();
|
||||
}
|
||||
let _ = std::io::stdout().flush();
|
||||
let (_, package_dir) = match result {
|
||||
@@ -765,8 +767,8 @@ fn try_lookup_command(sv: &mut SplitVersion) -> Result<PackageDownloadInfo, anyh
|
||||
|
||||
for registry in wasmer_registry::get_all_available_registries().unwrap_or_default() {
|
||||
let result = wasmer_registry::query_command_from_registry(®istry, &sv.package);
|
||||
if sp.is_some() {
|
||||
print!("\r");
|
||||
if let Some(s) = sp.take() {
|
||||
s.clear();
|
||||
}
|
||||
let _ = std::io::stdout().flush();
|
||||
let command = sv.package.clone();
|
||||
@@ -779,8 +781,7 @@ fn try_lookup_command(sv: &mut SplitVersion) -> Result<PackageDownloadInfo, anyh
|
||||
}
|
||||
|
||||
if let Some(sp) = sp.take() {
|
||||
sp.close();
|
||||
print!("\r");
|
||||
sp.clear();
|
||||
}
|
||||
let _ = std::io::stdout().flush();
|
||||
Err(anyhow::anyhow!("command {sv} not found"))
|
||||
@@ -828,11 +829,6 @@ pub(crate) fn try_run_package_or_file(
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let debug_msgs_allowed = isatty::stdout_isatty();
|
||||
|
||||
if let Ok(url) = url::Url::parse(&format!("{}", r.path.display())) {
|
||||
let result = try_run_url(&url, args, r, debug);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check "r.path" is a file or a package / command name
|
||||
if r.path.exists() {
|
||||
if r.path.is_dir() && r.path.join("wapm.toml").exists() {
|
||||
@@ -848,6 +844,18 @@ pub(crate) fn try_run_package_or_file(
|
||||
return r.execute();
|
||||
}
|
||||
|
||||
// c:// might be parsed as a URL on Windows
|
||||
let url_string = format!("{}", r.path.display());
|
||||
if let Ok(url) = url::Url::parse(&url_string) {
|
||||
if url.scheme() == "http" || url.scheme() == "https" {
|
||||
match try_run_url(&url, args, r, debug) {
|
||||
Err(ExecuteLocalPackageError::BeforeExec(_)) => {}
|
||||
Err(ExecuteLocalPackageError::DuringExec(e)) => return Err(e),
|
||||
Ok(o) => return Ok(o),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let package = format!("{}", r.path.display());
|
||||
|
||||
let mut is_fake_sv = false;
|
||||
@@ -915,9 +923,15 @@ pub(crate) fn try_run_package_or_file(
|
||||
try_autoinstall_package(args, &sv, package_download_info, r.force_install)
|
||||
}
|
||||
|
||||
fn try_run_url(url: &Url, _args: &[String], r: &Run, _debug: bool) -> Result<(), anyhow::Error> {
|
||||
let checksum = wasmer_registry::get_remote_webc_checksum(url)
|
||||
.map_err(|e| anyhow::anyhow!("error fetching {url}: {e}"))?;
|
||||
fn try_run_url(
|
||||
url: &Url,
|
||||
_args: &[String],
|
||||
r: &Run,
|
||||
_debug: bool,
|
||||
) -> Result<(), ExecuteLocalPackageError> {
|
||||
let checksum = wasmer_registry::get_remote_webc_checksum(url).map_err(|e| {
|
||||
ExecuteLocalPackageError::BeforeExec(anyhow::anyhow!("error fetching {url}: {e}"))
|
||||
})?;
|
||||
|
||||
let packages = wasmer_registry::get_all_installed_webc_packages();
|
||||
|
||||
@@ -926,20 +940,23 @@ fn try_run_url(url: &Url, _args: &[String], r: &Run, _debug: bool) -> Result<(),
|
||||
|
||||
let result = wasmer_registry::install_webc_package(url, &checksum);
|
||||
|
||||
result.map_err(|e| anyhow::anyhow!("error fetching {url}: {e}"))?;
|
||||
result.map_err(|e| {
|
||||
ExecuteLocalPackageError::BeforeExec(anyhow::anyhow!("error fetching {url}: {e}"))
|
||||
})?;
|
||||
|
||||
if let Some(sp) = sp {
|
||||
sp.close();
|
||||
sp.clear();
|
||||
}
|
||||
}
|
||||
|
||||
let webc_dir = wasmer_registry::get_webc_dir();
|
||||
|
||||
let webc_install_path = webc_dir
|
||||
.context("Error installing package: no webc dir")?
|
||||
.context("Error installing package: no webc dir")
|
||||
.map_err(ExecuteLocalPackageError::BeforeExec)?
|
||||
.join(checksum);
|
||||
|
||||
let mut r = r.clone();
|
||||
r.path = webc_install_path;
|
||||
r.execute()
|
||||
r.execute().map_err(ExecuteLocalPackageError::DuringExec)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user