Skip to content

Commit

Permalink
Merge #44
Browse files Browse the repository at this point in the history
44: Support trybuild r=taiki-e a=taiki-e

Fixes #32

~~The following patch is needed until dtolnay/trybuild#121 is merged:~~ 

UPDATE: dtolnay/trybuild#121 merged and released in trybuild 1.0.44.


Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e authored Aug 7, 2021
2 parents 03190cd + 472da1c commit b42adf7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rustc-demangle = "0.1.19"
serde = { version = "1.0.103", features = ["derive"] }
serde_json = "1"
shell-escape = "0.1.5"
toml = "0.5.2"
tracing = { version = "0.1.21", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.2.16", default-features = false, features = ["ansi", "env-filter"] }
walkdir = "2"
Expand Down
11 changes: 11 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(test, allow(dead_code))]

pub(crate) use std::fs::ReadDir;
use std::{io, path::Path};

use anyhow::{Context as _, Result};
Expand Down Expand Up @@ -81,3 +82,13 @@ pub(crate) fn read_to_string(path: impl AsRef<Path>) -> Result<String> {
trace!(track_caller: ?res, ?path, "read_to_string");
res.with_context(|| format!("failed to read from file `{}`", path.display()))
}

/// Returns an iterator over the entries within a directory.
/// This is a wrapper for [`std::fs::read_dir`].
#[track_caller]
pub(crate) fn read_dir(path: impl AsRef<Path>) -> Result<ReadDir> {
let path = path.as_ref();
let res = std::fs::read_dir(path);
trace!(track_caller: ?res, ?path, "read_dir");
res.with_context(|| format!("failed to read directory `{}`", path.display()))
}
50 changes: 50 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::{
};

use anyhow::Result;
use regex::Regex;
use serde::Deserialize;
use tracing::warn;
use walkdir::WalkDir;
Expand Down Expand Up @@ -167,6 +168,43 @@ fn object_files(cx: &Context) -> Result<Vec<OsString>> {
}
}
}

// trybuild
let trybuild_dir = &cx.metadata.target_directory.join("tests");
let mut trybuild_target = trybuild_dir.join("target");
if let Some(target) = &cx.target {
trybuild_target.push(target);
}
trybuild_target.push("debug");
if trybuild_target.is_dir() {
let mut trybuild_projects = vec![];
for entry in fs::read_dir(trybuild_dir)?.filter_map(Result::ok) {
let manifest_path = entry.path().join("Cargo.toml");
if !manifest_path.is_file() {
continue;
}
let manifest: Manifest = toml::from_str(&fs::read_to_string(manifest_path)?)?;
trybuild_projects.push(manifest.package.name);
}
if !trybuild_projects.is_empty() {
let re =
Regex::new(&format!("^({})-[0-9A-Fa-f]+$", trybuild_projects.join("|"))).unwrap();
for entry in WalkDir::new(trybuild_target).into_iter().filter_map(Result::ok) {
let path = entry.path();
if let Some(path) = path.file_name().unwrap().to_str() {
if re.is_match(path) {
// Excludes dummy binaries generated by trybuild.
// https://github.com/dtolnay/trybuild/blob/54ddc67c9e2f236d44ac6640a2327e178ff6ae68/src/run.rs#L228-L231
continue;
}
}
if is_executable::is_executable(path) {
files.push(path.to_owned().into_os_string());
}
}
}
}

// This sort is necessary to make the result of `llvm-cov show` match between macos and linux.
files.sort_unstable();
trace!(object_files = ?files);
Expand Down Expand Up @@ -338,6 +376,18 @@ struct Profile {
test: bool,
}

// Cargo manifest
// https://doc.rust-lang.org/cargo/reference/manifest.html
#[derive(Debug, Deserialize)]
struct Manifest {
package: Package,
}

#[derive(Debug, Deserialize)]
struct Package {
name: String,
}

fn append_args(cx: &Context, cmd: &mut ProcessBuilder) {
if cx.no_fail_fast {
cmd.arg("--no-fail-fast");
Expand Down

0 comments on commit b42adf7

Please sign in to comment.