Skip to content

Commit 13e2d72

Browse files
committed
Auto merge of #125827 - jieyouxu:rmake-separate-tmp-dir, r=onur-ozkan
compiletest: split rmake.rs executable from scratch directory When implementing support for rmake.rs, I copied over the `$TMPDIR` directory logic from the legacy Makefile setup. In doing so, I also compiled recipe `rmake.rs` into executables which unfortunately are placed into `$TMPDIR` as well. This causes a problem on Windows (as observed in PRs like #125752 (comment)) where: - The `rmake.exe` executable is placed in `$TMPDIR`. - We run the `rmake.exe` as a process. - The process uses `rmake.exe` inside `$TMPDIR`. - Windows prevents the .exe file from being deleted when the process is still alive. - The recipe test code tries to `remove_dir_all($TMPDIR)`, which fails with access denied because `rmake.exe` is still being used. We fix this by separating the recipe executable and the output artifacts directory: ``` base_dir/ rmake.exe rmake_out/ ``` We construct a base directory, unique to each run-make test, under which we place rmake.exe alongside a `rmake_out/` directory. This `rmake_out/` directory is what is passed to rmake.rs tests as `$TMPDIR`, so now `remove_dir_all($TMPDIR)` has a chance to succeed because it no longer contains `rmake.exe`. This wasn't a problem for Makefile tests because there's no exe file under `$TMPDIR` whose process is still running when `rm -rf $TMPDIR` is called. try-job: x86_64-msvc
2 parents a83cf56 + 4562245 commit 13e2d72

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/tools/compiletest/src/runtest.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -3431,11 +3431,23 @@ impl<'test> TestCx<'test> {
34313431
let build_root = self.config.build_base.parent().unwrap().parent().unwrap();
34323432
let build_root = cwd.join(&build_root);
34333433

3434-
let tmpdir = cwd.join(self.output_base_name());
3435-
if tmpdir.exists() {
3436-
self.aggressive_rm_rf(&tmpdir).unwrap();
3434+
// We construct the following directory tree for each rmake.rs test:
3435+
// ```
3436+
// base_dir/
3437+
// rmake.exe
3438+
// scratch/
3439+
// ```
3440+
// having the executable separate from the scratch directory allows the recipes to
3441+
// `remove_dir_all(scratch)` without running into permission denied issues because
3442+
// the executable is not under the `scratch/` directory.
3443+
//
3444+
// This setup diverges from legacy Makefile run-make tests.
3445+
let base_dir = cwd.join(self.output_base_name());
3446+
if base_dir.exists() {
3447+
self.aggressive_rm_rf(&base_dir).unwrap();
34373448
}
3438-
create_dir_all(&tmpdir).unwrap();
3449+
let rmake_out_dir = base_dir.join("rmake_out");
3450+
create_dir_all(&rmake_out_dir).unwrap();
34393451

34403452
// HACK: assume stageN-target, we only want stageN.
34413453
let stage = self.config.stage_id.split('-').next().unwrap();
@@ -3452,8 +3464,11 @@ impl<'test> TestCx<'test> {
34523464
stage_std_path.push("lib");
34533465

34543466
// Then, we need to build the recipe `rmake.rs` and link in the support library.
3455-
let recipe_bin =
3456-
tmpdir.join(if self.config.target.contains("windows") { "rmake.exe" } else { "rmake" });
3467+
let recipe_bin = base_dir.join(if self.config.target.contains("windows") {
3468+
"rmake.exe"
3469+
} else {
3470+
"rmake"
3471+
});
34573472

34583473
let mut support_lib_deps = PathBuf::new();
34593474
support_lib_deps.push(&build_root);
@@ -3494,7 +3509,7 @@ impl<'test> TestCx<'test> {
34943509
.env("S", &src_root)
34953510
.env("RUST_BUILD_STAGE", &self.config.stage_id)
34963511
.env("RUSTC", cwd.join(&self.config.rustc_path))
3497-
.env("TMPDIR", &tmpdir)
3512+
.env("TMPDIR", &rmake_out_dir)
34983513
.env("LD_LIB_PATH_ENVVAR", dylib_env_var())
34993514
.env(dylib_env_var(), &host_dylib_env_paths)
35003515
.env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path))
@@ -3530,7 +3545,7 @@ impl<'test> TestCx<'test> {
35303545
let dylib_env_paths = env::join_paths(dylib_env_paths).unwrap();
35313546

35323547
let mut target_rpath_env_path = Vec::new();
3533-
target_rpath_env_path.push(&tmpdir);
3548+
target_rpath_env_path.push(&rmake_out_dir);
35343549
target_rpath_env_path.extend(&orig_dylib_env_paths);
35353550
let target_rpath_env_path = env::join_paths(target_rpath_env_path).unwrap();
35363551

@@ -3546,7 +3561,7 @@ impl<'test> TestCx<'test> {
35463561
.env("S", &src_root)
35473562
.env("RUST_BUILD_STAGE", &self.config.stage_id)
35483563
.env("RUSTC", cwd.join(&self.config.rustc_path))
3549-
.env("TMPDIR", &tmpdir)
3564+
.env("TMPDIR", &rmake_out_dir)
35503565
.env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path))
35513566
.env("TARGET_RPATH_DIR", cwd.join(&self.config.run_lib_path))
35523567
.env("LLVM_COMPONENTS", &self.config.llvm_components)

0 commit comments

Comments
 (0)