Skip to content
Closed
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
37 changes: 37 additions & 0 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,43 @@ fn cargo_target_dir(project: &Project) -> impl Iterator<Item = (&'static str, Pa
))
}

// Check if this Cargo contains https://github.com/rust-lang/cargo/pull/10383
pub fn supports_keep_going(project: &Project) -> Result<bool> {
let scratch_dir = env!("OUT_DIR");
let dir = path!(scratch_dir / "keepgoing");
fs::create_dir_all(&dir)?;

let manifest_path = path!(dir / "Cargo.toml");
let cargo_toml = "\
[package]\n\
name = \"trybuild_keep_going\"\n\
version = \"0.0.0\"\n\
[[bin]]\n\
name = \"trybuild_keep_going\"\n\
path = \"main.rs\"\n\
[workspace]\n\
";
crate::fs::write_if_needed(&manifest_path, cargo_toml)?;

let main_rs_path = path!(dir / "main.rs");
crate::fs::write_if_needed(main_rs_path, "fn main() {}\n")?;

let status = raw_cargo()
.envs(cargo_target_dir(project))
.envs(rustflags::envs())
.arg("-Zunstable-options")
.arg("check")
.args(target())
.arg("--manifest-path")
.arg(manifest_path)
.arg("--keep-going")
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()?;

Ok(status.success())
}

pub fn build_dependencies(project: &Project) -> Result<()> {
let workspace_cargo_lock = path!(project.workspace / "Cargo.lock");
if workspace_cargo_lock.exists() {
Expand Down
18 changes: 18 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::fs;
use std::io::Result;
use std::path::Path;

pub fn write_if_needed<P, C>(path: P, contents: C) -> Result<()>
where
P: AsRef<Path>,
C: AsRef<[u8]>,
{
let path = path.as_ref();
let contents = contents.as_ref();
if let Ok(existing_contents) = fs::read(path) {
if existing_contents == contents {
return Ok(());
}
}
fs::write(path, contents)
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ mod env;
mod error;
mod features;
mod flock;
mod fs;
mod manifest;
mod message;
mod normalize;
Expand Down
11 changes: 9 additions & 2 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub struct Project {
pub workspace: Directory,
pub path_dependencies: Vec<PathDependency>,
manifest: Manifest,
#[allow(dead_code)]
keep_going: bool,
}

#[derive(Debug)]
Expand Down Expand Up @@ -137,7 +139,7 @@ impl Runner {
enabled_features.retain(|feature| manifest.features.contains_key(feature));
}

Ok(Project {
let mut project = Project {
dir: project_dir,
source_dir,
target_dir,
Expand All @@ -149,7 +151,12 @@ impl Runner {
workspace,
path_dependencies,
manifest,
})
keep_going: false,
};

project.keep_going = cargo::supports_keep_going(&project).unwrap_or(false);

Ok(project)
}

fn write(&self, project: &Project) -> Result<()> {
Expand Down