Skip to content

Commit

Permalink
Allow to pass a full path for run-make tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 23, 2024
1 parent 49649bf commit baf948d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
31 changes: 13 additions & 18 deletions src/tools/compiletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,24 @@ fn collect_tests_from_dir(
}

if config.mode == Mode::RunMake {
if dir.join("Makefile").exists() && dir.join("rmake.rs").exists() {
let makefile_path = dir.join("Makefile");
let rmake_path = dir.join("rmake.rs");
if makefile_path.exists() && rmake_path.exists() {
return Err(io::Error::other(
"run-make tests cannot have both `Makefile` and `rmake.rs`",
));
}

if dir.join("Makefile").exists() || dir.join("rmake.rs").exists() {
if rmake_path.exists() {
let paths = TestPaths {
file: dir.to_path_buf(),
file: rmake_path,
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
};
tests.extend(make_test(config, cache, &paths, inputs, poisoned));
return Ok(());
} else if makefile_path.exists() {
let paths = TestPaths {
file: makefile_path,
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
};
tests.extend(make_test(config, cache, &paths, inputs, poisoned));
Expand Down Expand Up @@ -750,21 +759,7 @@ fn make_test(
inputs: &Stamp,
poisoned: &mut bool,
) -> Vec<test::TestDescAndFn> {
let test_path = if config.mode == Mode::RunMake {
if testpaths.file.join("rmake.rs").exists() && testpaths.file.join("Makefile").exists() {
panic!("run-make tests cannot have both `rmake.rs` and `Makefile`");
}

if testpaths.file.join("rmake.rs").exists() {
// Parse directives in rmake.rs.
testpaths.file.join("rmake.rs")
} else {
// Parse directives in the Makefile.
testpaths.file.join("Makefile")
}
} else {
PathBuf::from(&testpaths.file)
};
let test_path = PathBuf::from(&testpaths.file);
let early_props = EarlyProps::from_file(&config, &test_path);

// Incremental tests are special, they inherently cannot be run in parallel.
Expand Down
22 changes: 10 additions & 12 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn run(config: Arc<Config>, testpaths: &TestPaths, revision: Option<&str>) {
// We're going to be dumping a lot of info. Start on a new line.
print!("\n\n");
}
debug!("running {:?}", testpaths.file.display());
eprintln!("running {:?}", testpaths.file.display());
let mut props = TestProps::from_file(&testpaths.file, revision, &config);

// For non-incremental (i.e. regular UI) tests, the incremental directory
Expand Down Expand Up @@ -3253,13 +3253,10 @@ impl<'test> TestCx<'test> {
}

fn run_rmake_test(&self) {
let test_dir = &self.testpaths.file;
if test_dir.join("rmake.rs").exists() {
self.run_rmake_v2_test();
} else if test_dir.join("Makefile").exists() {
self.run_rmake_legacy_test();
} else {
self.fatal("failed to find either `rmake.rs` or `Makefile`")
match &self.testpaths.file.iter().last() {
Some(s) if *s == OsStr::new("rmake.rs") => self.run_rmake_v2_test(),
Some(s) if *s == OsStr::new("Makefile") => self.run_rmake_legacy_test(),
_ => self.fatal("failed to find either `rmake.rs` or `Makefile`"),
}
}

Expand Down Expand Up @@ -3287,7 +3284,7 @@ impl<'test> TestCx<'test> {
};

let mut cmd = Command::new(make);
cmd.current_dir(&self.testpaths.file)
cmd.current_dir(&self.testpaths.file.parent().unwrap())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.env("TARGET", &self.config.target)
Expand Down Expand Up @@ -3487,10 +3484,11 @@ impl<'test> TestCx<'test> {
// Copy all input files (apart from rmake.rs) to the temporary directory,
// so that the input directory structure from `tests/run-make/<test>` is mirrored
// to the `rmake_out` directory.
for path in walkdir::WalkDir::new(&self.testpaths.file).min_depth(1) {
let parent = self.testpaths.file.parent().unwrap();
for path in walkdir::WalkDir::new(&parent).min_depth(1) {
let path = path.unwrap().path().to_path_buf();
if path.file_name().is_some_and(|s| s != "rmake.rs") {
let target = rmake_out_dir.join(path.strip_prefix(&self.testpaths.file).unwrap());
let target = rmake_out_dir.join(path.strip_prefix(&parent).unwrap());
if path.is_dir() {
copy_dir_all(&path, target).unwrap();
} else {
Expand Down Expand Up @@ -3588,7 +3586,7 @@ impl<'test> TestCx<'test> {
.arg("--extern")
.arg(format!("run_make_support={}", &support_lib_path.to_string_lossy()))
.arg("--edition=2021")
.arg(&self.testpaths.file.join("rmake.rs"))
.arg(&self.testpaths.file)
// Provide necessary library search paths for rustc.
.env(dylib_env_var(), &env::join_paths(host_dylib_search_paths).unwrap());

Expand Down

0 comments on commit baf948d

Please sign in to comment.