Skip to content

Commit 3d2c342

Browse files
committed
[hermes] Isolate shadow crate from other artifacts
Previously, we stored the shadow crate in `target/hermes_shadow_<hash>`. Now we store it in `target/hermes/<hash>/shadow`. This allows us to store other build artifacts in `target/hermes/<hash>` but outside of `/shadow` to avoid polluting the shadow copy. gherrit-pr-id: G7f8abd90b628d02a6fdc01985535eef50509312e
1 parent 578c25f commit 3d2c342

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

tools/hermes/src/resolve.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ impl TryFrom<&TargetKind> for HermesTargetKind {
102102
pub struct Roots {
103103
pub workspace: PathBuf,
104104
pub cargo_target_dir: PathBuf,
105-
pub shadow_root: PathBuf,
105+
// E.g., `target/hermes/<hash>`.
106+
hermes_run_root: PathBuf,
106107
pub roots: Vec<(PackageName, HermesTargetKind, PathBuf)>,
107108
}
108109

110+
impl Roots {
111+
pub fn shadow_root(&self) -> PathBuf {
112+
self.hermes_run_root.join("shadow")
113+
}
114+
}
115+
109116
/// Resolves all verification roots.
110117
///
111118
/// Each entry represents a distinct compilation artifact to be verified.
@@ -129,7 +136,7 @@ pub fn resolve_roots(args: &Args) -> Result<Roots> {
129136
let mut roots = Roots {
130137
workspace: metadata.workspace_root.as_std_path().to_owned(),
131138
cargo_target_dir: metadata.target_directory.as_std_path().to_owned(),
132-
shadow_root: resolve_shadow_path(&metadata),
139+
hermes_run_root: resolve_run_root(&metadata),
133140
roots: Vec::new(),
134141
};
135142

@@ -155,15 +162,16 @@ pub fn resolve_roots(args: &Args) -> Result<Roots> {
155162
Ok(roots)
156163
}
157164

158-
fn resolve_shadow_path(metadata: &Metadata) -> PathBuf {
159-
log::trace!("resolve_shadow_path");
165+
fn resolve_run_root(metadata: &Metadata) -> PathBuf {
166+
log::trace!("resolve_run_root");
160167
log::debug!("workspace_root: {:?}", metadata.workspace_root.as_std_path());
161168
// NOTE: Automatically handles `CARGO_TARGET_DIR` env var.
162169
let target_dir = metadata.target_directory.as_std_path();
170+
let hermes_global = target_dir.join("hermes");
163171

164172
// Used by integration tests to ensure deterministic shadow dir names.
165173
if let Ok(name) = std::env::var("HERMES_TEST_SHADOW_NAME") {
166-
return target_dir.join(name);
174+
return hermes_global.join(name);
167175
}
168176

169177
// Hash the path to the workspace root to avoid collisions between different
@@ -175,7 +183,7 @@ fn resolve_shadow_path(metadata: &Metadata) -> PathBuf {
175183
hasher.finish()
176184
};
177185

178-
target_dir.join(format!("hermes_shadow_{workspace_root_hash}"))
186+
hermes_global.join(format!("{workspace_root_hash:x}"))
179187
}
180188

181189
/// Resolves which packages to process based on workspace flags and CWD.

tools/hermes/src/shadow.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ use crate::{parse, resolve::Roots, transform};
1818
/// 2. Creates symlinks for the remaining skeleton.
1919
pub fn build_shadow_crate(roots: &Roots) -> Result<()> {
2020
log::trace!("build_shadow_crate({:?})", roots);
21-
if roots.shadow_root.exists() {
22-
fs::remove_dir_all(&roots.shadow_root).context("Failed to clear shadow root")?;
21+
let shadow_root = roots.shadow_root();
22+
if shadow_root.exists() {
23+
fs::remove_dir_all(&shadow_root).context("Failed to clear shadow root")?;
2324
}
24-
fs::create_dir_all(&roots.shadow_root).context("Failed to create shadow root")?;
25+
fs::create_dir_all(&shadow_root).context("Failed to create shadow root")?;
2526

2627
let visited_paths = DashSet::new();
2728
let (err_tx, err_rx) = std::sync::mpsc::channel();
@@ -62,12 +63,7 @@ pub fn build_shadow_crate(roots: &Roots) -> Result<()> {
6263

6364
let skip_paths: HashSet<PathBuf> = visited_paths.into_iter().collect();
6465

65-
create_symlink_skeleton(
66-
&roots.workspace,
67-
&roots.shadow_root,
68-
&roots.cargo_target_dir,
69-
&skip_paths,
70-
)?;
66+
create_symlink_skeleton(&roots.workspace, &shadow_root, &roots.cargo_target_dir, &skip_paths)?;
7167

7268
Ok(())
7369
}
@@ -99,7 +95,7 @@ fn process_file_recursive<'a>(
9995
return;
10096
}
10197
};
102-
let dest_path = config.shadow_root.join(relative_path);
98+
let dest_path = config.shadow_root().join(relative_path);
10399

104100
let result = (|| -> Result<Vec<PathBuf>> {
105101
if let Some(parent) = dest_path.parent() {

tools/hermes/tests/integration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn run_integration_test(path: &Path) -> datatest_stable::Result<()> {
2020
let mut cmd = assert_cmd::cargo_bin_cmd!("hermes");
2121
cmd.env("CARGO_TARGET_DIR", sandbox_root.join("target"))
2222
.env_remove("RUSTFLAGS")
23-
.env("HERMES_TEST_SHADOW_NAME", "hermes_shadow");
23+
.env("HERMES_TEST_SHADOW_NAME", "hermes_test_target");
2424

2525
// Tests can specify the cwd to invoke from.
2626
let cwd_file = test_case_root.join("cwd.txt");
@@ -64,7 +64,7 @@ fn run_integration_test(path: &Path) -> datatest_stable::Result<()> {
6464
}
6565

6666
// Tests can specify the expected shadow crate content.
67-
let actual_shadow = sandbox_root.join("target/hermes_shadow");
67+
let actual_shadow = sandbox_root.join("target/hermes/hermes_test_target/shadow");
6868
let expected_shadow = test_case_root.join("expected");
6969

7070
if expected_shadow.exists() {

0 commit comments

Comments
 (0)