Skip to content

Commit

Permalink
Merge branch 'main' into dev/fast-interp
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Oct 22, 2024
2 parents cc48cb9 + ea331ec commit a648e3f
Show file tree
Hide file tree
Showing 14 changed files with 814 additions and 18 deletions.
4 changes: 3 additions & 1 deletion crates/cli-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Minor

- Add `cargo` and `changelog` modules and features
- Handle more errors during platform discovery and `action::PlatformReboot`
- Extend `fs::write()` first parameter to set the `OpenOptions` too
- Add `error::root_cause_is()` to check the `anyhow::Error` root cause
- Add `action::PlatformLock` for locking a platform protocol
Expand All @@ -33,4 +35,4 @@

## 0.1.0

<!-- Increment to skip CHANGELOG.md test: 6 -->
<!-- Increment to skip CHANGELOG.md test: 7 -->
1 change: 1 addition & 0 deletions crates/cli-tools/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion crates/cli-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ humantime = { version = "2.1.0", default-features = false, optional = true }
indicatif = { version = "0.17.8", default-features = false, optional = true }
log = { version = "0.4.21", default-features = false }
rusb = { version = "0.9.4", default-features = false, optional = true }
semver = { version = "1.0.23", default-features = false, optional = true }
serde = { version = "1.0.202", default-features = false, features = ["derive"] }
toml = { version = "0.8.13", default-features = false, features = ["display", "parse"] }
wasefire-wire = { version = "0.1.1-git", path = "../wire", optional = true }
Expand Down Expand Up @@ -57,7 +58,7 @@ optional = true

[features]
action = [
"dep:cargo_metadata",
"cargo",
"dep:clap",
"dep:data-encoding",
"dep:humantime",
Expand All @@ -69,6 +70,8 @@ action = [
"dep:wasefire-wire",
"tokio/time",
]
cargo = ["dep:cargo_metadata"]
changelog = ["cargo", "dep:clap", "dep:semver"]

[lints]
clippy.unit-arg = "allow"
Expand Down
16 changes: 5 additions & 11 deletions crates/cli-tools/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use std::path::{Path, PathBuf};
use std::time::Duration;

use anyhow::{bail, ensure, Result};
use cargo_metadata::{Metadata, MetadataCommand};
use clap::{ValueEnum, ValueHint};
use rusb::GlobalContext;
use tokio::process::Command;
use wasefire_protocol::{self as service, applet, Connection, ConnectionExt};
use wasefire_wire::{self as wire, Yoke};

use crate::cargo::metadata;
use crate::error::root_cause_is;
use crate::{cmd, fs};

Expand Down Expand Up @@ -375,7 +375,10 @@ async fn final_call<S: service::Service>(
match connection.receive::<S>().await {
Ok(x) => proof(x)?,
Err(e) => {
if root_cause_is::<rusb::Error>(&e, |x| matches!(x, rusb::Error::NoDevice)) {
if root_cause_is::<rusb::Error>(&e, |x| {
use rusb::Error::*;
matches!(x, NoDevice | Pipe)
}) {
return Ok(());
}
if root_cause_is::<std::io::Error>(&e, |x| {
Expand Down Expand Up @@ -630,15 +633,6 @@ pub async fn optimize_wasm(applet: impl AsRef<Path>, opt_level: Option<OptLevel>
Ok(())
}

async fn metadata(dir: impl Into<PathBuf>) -> Result<Metadata> {
let dir = dir.into();
let metadata =
tokio::task::spawn_blocking(|| MetadataCommand::new().current_dir(dir).no_deps().exec())
.await??;
ensure!(metadata.packages.len() == 1, "not exactly one package");
Ok(metadata)
}

fn wasefire_feature(
package: &cargo_metadata::Package, feature: &str, cargo: &mut Command,
) -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions crates/cli-tools/src/action/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl ProtocolUsb {
let context = GlobalContext::default();
let mut matches = Vec::new();
for candidate in wasefire_protocol_usb::list(&context)? {
let mut connection = candidate.connect(timeout)?;
let info = connection.call::<service::PlatformInfo>(()).await?;
let Ok(mut connection) = candidate.connect(timeout) else { continue };
let Ok(info) = connection.call::<service::PlatformInfo>(()).await else { continue };
if !self.matches(connection.device(), &info) {
continue;
}
Expand Down
27 changes: 27 additions & 0 deletions crates/cli-tools/src/cargo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::path::PathBuf;

use anyhow::{ensure, Result};
use cargo_metadata::{Metadata, MetadataCommand};

pub async fn metadata(dir: impl Into<PathBuf>) -> Result<Metadata> {
let dir = dir.into();
let metadata =
tokio::task::spawn_blocking(|| MetadataCommand::new().current_dir(dir).no_deps().exec())
.await??;
ensure!(metadata.packages.len() == 1, "not exactly one package");
Ok(metadata)
}
Loading

0 comments on commit a648e3f

Please sign in to comment.