Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rustwide"
version = "0.21.0"
edition = "2018"
edition = "2024"
build = "build.rs"

documentation = "https://docs.rs/rustwide"
Expand Down
2 changes: 1 addition & 1 deletion examples/docs-builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustwide::cmd::SandboxImage;
use rustwide::{cmd::SandboxBuilder, Crate, Toolchain, WorkspaceBuilder};
use rustwide::{Crate, Toolchain, WorkspaceBuilder, cmd::SandboxBuilder};
use std::error::Error;
use std::path::Path;

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use tokio::{
runtime::Runtime,
time,
};
use tokio_stream::{wrappers::LinesStream, StreamExt};
use tokio_stream::{StreamExt, wrappers::LinesStream};

lazy_static::lazy_static! {
// TODO: Migrate to asynchronous code and remove runtime
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/sandbox.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cmd::{Command, CommandError, ProcessLinesActions, ProcessOutput};
use crate::Workspace;
use crate::cmd::{Command, CommandError, ProcessLinesActions, ProcessOutput};
use log::{error, info};
use serde::Deserialize;
use std::error::Error;
Expand Down
10 changes: 5 additions & 5 deletions src/crates/git.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::CrateTrait;
use crate::Workspace;
use crate::cmd::{Command, ProcessLinesActions};
use crate::prepare::PrepareError;
use crate::Workspace;
use anyhow::Context as _;
use log::{info, warn};
use std::path::{Path, PathBuf};
Expand All @@ -23,10 +23,10 @@ impl GitRepo {

match res {
Ok(out) => {
if let Some(shaline) = out.stdout_lines().first() {
if !shaline.is_empty() {
return Some(shaline.to_string());
}
if let Some(shaline) = out.stdout_lines().first()
&& !shaline.is_empty()
{
return Some(shaline.to_string());
}
warn!("bad output from `git rev-parse HEAD`");
}
Expand Down
12 changes: 6 additions & 6 deletions src/inside_docker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cmd::Command;
use crate::workspace::Workspace;
use base64::{engine::general_purpose::STANDARD as b64, Engine};
use base64::{Engine, engine::general_purpose::STANDARD as b64};
use getrandom::getrandom;
use log::info;

Expand Down Expand Up @@ -69,11 +69,11 @@ pub(crate) fn probe_container_id(workspace: &Workspace) -> anyhow::Result<Option
.log_output(false)
.log_command(false)
.run_capture();
if let Ok([probed]) = res.as_ref().map(|out| out.stdout_lines()) {
if *probed == probe_content {
info!("probe successful, this is container ID {id}");
return Ok(Some(id.clone()));
}
if let Ok([probed]) = res.as_ref().map(|out| out.stdout_lines())
&& *probed == probe_content
{
info!("probe successful, this is container ID {id}");
return Ok(Some(id.clone()));
}
}

Expand Down
82 changes: 43 additions & 39 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use log::{Level, LevelFilter, Log, Metadata, Record};
use std::cell::RefCell;
use std::fmt;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex, Once,
atomic::{AtomicBool, Ordering},
};
use std::thread::LocalKey;

Expand Down Expand Up @@ -174,37 +174,37 @@ impl SealedLog for LogStorage {
if inner.truncated {
return;
}
if let Some(max_lines) = self.max_lines {
if inner.records.len() >= max_lines {
inner.records.push(StoredRecord {
level: Level::Warn,
message: "too many lines in the log, truncating it".into(),
});
inner.truncated = true;
return;
}
if let Some(max_lines) = self.max_lines
&& inner.records.len() >= max_lines
{
inner.records.push(StoredRecord {
level: Level::Warn,
message: "too many lines in the log, truncating it".into(),
});
inner.truncated = true;
return;
}
let mut message = record.args().to_string();

if let Some(max_line_length) = self.max_line_length {
if message.len() > max_line_length {
let mut length = max_line_length - 3;
while !message.is_char_boundary(length) {
length -= 1;
}
message = format!("{}...", &message[..length]);
if let Some(max_line_length) = self.max_line_length
&& message.len() > max_line_length
{
let mut length = max_line_length - 3;
while !message.is_char_boundary(length) {
length -= 1;
}
message = format!("{}...", &message[..length]);
}

if let Some(max_size) = self.max_size {
if inner.size + message.len() >= max_size {
inner.records.push(StoredRecord {
level: Level::Warn,
message: "too much data in the log, truncating it".into(),
});
inner.truncated = true;
return;
}
if let Some(max_size) = self.max_size
&& inner.size + message.len() >= max_size
{
inner.records.push(StoredRecord {
level: Level::Warn,
message: "too much data in the log, truncating it".into(),
});
inner.truncated = true;
return;
}
inner.size += message.len();
inner.records.push(StoredRecord {
Expand Down Expand Up @@ -301,7 +301,7 @@ fn init_inner(logger: Option<Box<dyn Log>>) {
mod tests {
use super::{LogStorage, StoredRecord};
use crate::logging;
use log::{info, trace, warn, Level, LevelFilter};
use log::{Level, LevelFilter, info, trace, warn};

#[test]
fn test_log_storage() {
Expand Down Expand Up @@ -342,12 +342,14 @@ mod tests {

let inner = storage.inner.lock().unwrap();
assert_eq!(inner.records.len(), 1);
assert!(inner
.records
.last()
.unwrap()
.message
.contains("too much data"));
assert!(
inner
.records
.last()
.unwrap()
.message
.contains("too much data")
);
}

#[test]
Expand All @@ -364,12 +366,14 @@ mod tests {

let inner = storage.inner.lock().unwrap();
assert_eq!(inner.records.len(), 101);
assert!(inner
.records
.last()
.unwrap()
.message
.contains("too many lines"));
assert!(
inner
.records
.last()
.unwrap()
.message
.contains("too many lines")
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/native/unix.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::CurrentUser;
use crate::cmd::KillFailedError;
use nix::{
sys::signal::{kill, Signal},
sys::signal::{Signal, kill},
unistd::{Gid, Pid, Uid},
};
use std::convert::AsRef;
Expand Down
2 changes: 1 addition & 1 deletion src/native/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::anyhow;
use std::fs::File;
use std::path::Path;
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::System::Threading::{OpenProcess, TerminateProcess, PROCESS_TERMINATE};
use windows_sys::Win32::System::Threading::{OpenProcess, PROCESS_TERMINATE, TerminateProcess};

pub(crate) fn kill_process(id: u32) -> anyhow::Result<(), KillFailedError> {
let error = Err(KillFailedError { pid: id });
Expand Down
24 changes: 12 additions & 12 deletions src/prepare.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::cmd::{Command, CommandError, ProcessLinesActions};
use crate::{build::CratePatch, Crate, Toolchain, Workspace};
use crate::{Crate, Toolchain, Workspace, build::CratePatch};
use anyhow::Context as _;
use log::info;
use std::path::Path;
use toml::{
value::{Array, Table},
Value,
value::{Array, Table},
};

pub(crate) struct Prepare<'a> {
Expand Down Expand Up @@ -272,23 +272,23 @@ impl<'a> TomlTweaker<'a> {

fn remove_missing_items(&mut self, category: &str) {
let folder = &(String::from(category) + "s");
if let Some(dir) = self.dir {
if let Some(&mut Value::Array(ref mut array)) = self.table.get_mut(category) {
let dim = array.len();
*(array) = Self::test_existance(dir, array, folder);
info!("removed {} missing {}", dim - array.len(), folder);
}
if let Some(dir) = self.dir
&& let Some(&mut Value::Array(ref mut array)) = self.table.get_mut(category)
{
let dim = array.len();
*(array) = Self::test_existance(dir, array, folder);
info!("removed {} missing {}", dim - array.len(), folder);
}
}

fn remove_parent_workspaces(&mut self) {
let krate = self.krate.to_string();

// Eliminate parent workspaces
if let Some(&mut Value::Table(ref mut package)) = self.table.get_mut("package") {
if package.remove("workspace").is_some() {
info!("removed parent workspace from {krate}");
}
if let Some(&mut Value::Table(ref mut package)) = self.table.get_mut("package")
&& package.remove("workspace").is_some()
{
info!("removed parent workspace from {krate}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Tools to manage and use Rust toolchains.

use crate::Workspace;
use crate::cmd::{Binary, Command, Runnable};
use crate::tools::RUSTUP;
#[cfg(feature = "unstable-toolchain-ci")]
use crate::tools::RUSTUP_TOOLCHAIN_INSTALL_MASTER;
use crate::Workspace;
use anyhow::{anyhow, Context as _};
use anyhow::{Context as _, anyhow};
use log::info;
use std::borrow::Cow;
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cmd::{Binary, Command, Runnable};
use crate::toolchain::MAIN_TOOLCHAIN_NAME;
use crate::tools::{Tool, RUSTUP};
use crate::tools::{RUSTUP, Tool};
use crate::workspace::Workspace;
use anyhow::Context as _;
use std::env::consts::EXE_SUFFIX;
Expand Down
10 changes: 5 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ pub(crate) fn normalize_path(path: &Path) -> PathBuf {
let mut components = p.components();
let first_component = components.next().unwrap();

if let Component::Prefix(prefix) = first_component {
if let Some(mut modified_path) = strip_verbatim_from_prefix(&prefix) {
modified_path.push(components.as_path());
p = modified_path;
}
if let Component::Prefix(prefix) = first_component
&& let Some(mut modified_path) = strip_verbatim_from_prefix(&prefix)
{
modified_path.push(components.as_path());
p = modified_path;
}

if p.as_os_str().len() >= MAX_PATH_LEN {
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Toolchain;
use crate::build::BuildDirectory;
use crate::cmd::{Command, SandboxImage};
use crate::inside_docker::CurrentContainer;
use crate::Toolchain;
use anyhow::Context as _;
use log::info;
use std::fs;
Expand Down
24 changes: 15 additions & 9 deletions tests/buildtest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ fn test_hello_world() {
})?;

assert!(storage.to_string().contains("[stdout] Hello, world!\n"));
assert!(storage
.to_string()
.contains("[stdout] Hello, world again!\n"));
assert!(
storage
.to_string()
.contains("[stdout] Hello, world again!\n")
);
Ok(())
})?;
Ok(())
Expand Down Expand Up @@ -92,9 +94,11 @@ fn test_fetch_build_std() {
})?;

assert!(storage.to_string().contains("[stdout] Hello, world!\n"));
assert!(storage
.to_string()
.contains("[stdout] Hello, world again!\n"));
assert!(
storage
.to_string()
.contains("[stdout] Hello, world again!\n")
);
Ok(())
})?;
Ok(())
Expand All @@ -115,9 +119,11 @@ fn path_based_patch() {
})?;

assert!(storage.to_string().contains("[stdout] Hello, world!\n"));
assert!(storage
.to_string()
.contains("[stdout] This is coming from the patch!\n"));
assert!(
storage
.to_string()
.contains("[stdout] This is coming from the patch!\n")
);
Ok(())
})
})?;
Expand Down
4 changes: 2 additions & 2 deletions tests/buildtest/runner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rand::{distributions::Alphanumeric, Rng};
use rustwide::{cmd::SandboxBuilder, Build, BuildBuilder, Crate, Toolchain, Workspace};
use rand::{Rng, distributions::Alphanumeric};
use rustwide::{Build, BuildBuilder, Crate, Toolchain, Workspace, cmd::SandboxBuilder};
use std::path::Path;

pub(crate) fn run(crate_name: &str, f: impl FnOnce(&mut Runner) -> anyhow::Result<()>) {
Expand Down
4 changes: 2 additions & 2 deletions tests/logging_init_with.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use log::{info, LevelFilter, Log, Metadata, Record};
use log::{LevelFilter, Log, Metadata, Record, info};
use rustwide::logging::{self, LogStorage};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
atomic::{AtomicBool, Ordering},
};

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion tests/logging_not_initialized.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::{info, LevelFilter};
use log::{LevelFilter, info};
use rustwide::logging::{self, LogStorage};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use log::LevelFilter;
use rustwide::{cmd::SandboxImage, Workspace, WorkspaceBuilder};
use rustwide::{Workspace, WorkspaceBuilder, cmd::SandboxImage};
use std::path::{Path, PathBuf};

static USER_AGENT: &str = "rustwide-tests (https://github.com/rust-lang/rustwide)";
Expand Down