Skip to content

Commit 585c898

Browse files
committed
Do not run run-make tests in the test source directory
1 parent 468310e commit 585c898

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/tools/compiletest/src/runtest.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::errors::{self, Error, ErrorKind};
1515
use crate::header::TestProps;
1616
use crate::json;
1717
use crate::read2::{read2_abbreviated, Truncated};
18-
use crate::util::{add_dylib_path, dylib_env_var, logv, PathBufExt};
18+
use crate::util::{add_dylib_path, copy_dir_all, dylib_env_var, logv, PathBufExt};
1919
use crate::ColorConfig;
2020
use colored::Colorize;
2121
use miropt_test_tools::{files_for_miropt_test, MiroptTest, MiroptTestFile};
@@ -3458,6 +3458,21 @@ impl<'test> TestCx<'test> {
34583458
let rmake_out_dir = base_dir.join("rmake_out");
34593459
create_dir_all(&rmake_out_dir).unwrap();
34603460

3461+
// Copy all input files (apart from rmake.rs) to the temporary directory,
3462+
// so that the input directory structure from `tests/run-make/<test>` is mirrored
3463+
// to the `rmake_out` directory.
3464+
for path in walkdir::WalkDir::new(&self.testpaths.file).min_depth(1) {
3465+
let path = path.unwrap().path().to_path_buf();
3466+
if path.file_name().map(|s| s != OsStr::new("rmake.rs")).unwrap_or(false) {
3467+
let target = rmake_out_dir.join(path.strip_prefix(&self.testpaths.file).unwrap());
3468+
if path.is_dir() {
3469+
copy_dir_all(&path, target).unwrap();
3470+
} else {
3471+
fs::copy(&path, target).unwrap();
3472+
}
3473+
}
3474+
}
3475+
34613476
// HACK: assume stageN-target, we only want stageN.
34623477
let stage = self.config.stage_id.split('-').next().unwrap();
34633478

@@ -3559,7 +3574,7 @@ impl<'test> TestCx<'test> {
35593574
let target_rpath_env_path = env::join_paths(target_rpath_env_path).unwrap();
35603575

35613576
let mut cmd = Command::new(&recipe_bin);
3562-
cmd.current_dir(&self.testpaths.file)
3577+
cmd.current_dir(&rmake_out_dir)
35633578
.stdout(Stdio::piped())
35643579
.stderr(Stdio::piped())
35653580
.env("LD_LIB_PATH_ENVVAR", dylib_env_var())

src/tools/compiletest/src/util.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::common::Config;
22
use std::env;
33
use std::ffi::OsStr;
4-
use std::path::PathBuf;
4+
use std::path::{Path, PathBuf};
55
use std::process::Command;
66

77
use tracing::*;
@@ -76,3 +76,17 @@ pub fn add_dylib_path(cmd: &mut Command, paths: impl Iterator<Item = impl Into<P
7676
let new_paths = paths.map(Into::into).chain(old_paths.into_iter().flatten());
7777
cmd.env(dylib_env_var(), env::join_paths(new_paths).unwrap());
7878
}
79+
80+
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
81+
std::fs::create_dir_all(&dst)?;
82+
for entry in std::fs::read_dir(src)? {
83+
let entry = entry?;
84+
let ty = entry.file_type()?;
85+
if ty.is_dir() {
86+
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
87+
} else {
88+
std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
89+
}
90+
}
91+
Ok(())
92+
}

0 commit comments

Comments
 (0)