Skip to content

Commit 019479e

Browse files
committed
refactor(layout): Created dedicated layout helper fns for build-dir inner directories
1 parent 0b81b44 commit 019479e

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

src/cargo/core/compiler/build_runner/compilation_files.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,25 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
255255
}
256256

257257
/// Returns the host `deps` directory path.
258-
pub fn host_deps(&self) -> &Path {
258+
pub fn host_deps(&self) -> PathBuf {
259259
self.host.deps()
260260
}
261261

262262
/// Returns the directories where Rust crate dependencies are found for the
263263
/// specified unit.
264-
pub fn deps_dir(&self, unit: &Unit) -> &Path {
264+
pub fn deps_dir(&self, unit: &Unit) -> PathBuf {
265265
self.layout(unit.kind).deps()
266266
}
267267

268268
/// Directory where the fingerprint for the given unit should go.
269269
pub fn fingerprint_dir(&self, unit: &Unit) -> PathBuf {
270270
let dir = self.pkg_dir(unit);
271-
self.layout(unit.kind).fingerprint().join(dir)
271+
self.layout(unit.kind).fingerprint(&dir)
272+
}
273+
274+
/// Directory where incremental output for the given unit should go.
275+
pub fn incremental_dir(&self, unit: &Unit) -> &Path {
276+
self.layout(unit.kind).incremental()
272277
}
273278

274279
/// Returns the path for a file in the fingerprint directory.
@@ -303,7 +308,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
303308
assert!(!unit.mode.is_run_custom_build());
304309
assert!(self.metas.contains_key(unit));
305310
let dir = self.pkg_dir(unit);
306-
self.layout(CompileKind::Host).build().join(dir)
311+
self.layout(CompileKind::Host).build_script(&dir)
307312
}
308313

309314
/// Returns the directory for compiled artifacts files.

src/cargo/core/compiler/layout.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ impl Layout {
232232
&self.dest
233233
}
234234
/// Fetch the deps path.
235-
pub fn deps(&self) -> &Path {
235+
pub fn deps(&self) -> PathBuf {
236+
self.legacy_deps().to_path_buf()
237+
}
238+
/// Fetch the deps path. (old layout)
239+
pub fn legacy_deps(&self) -> &Path {
236240
&self.deps
237241
}
238242
/// Fetch the examples path.
@@ -256,13 +260,25 @@ impl Layout {
256260
&self.incremental
257261
}
258262
/// Fetch the fingerprint path.
259-
pub fn fingerprint(&self) -> &Path {
263+
pub fn fingerprint(&self, pkg_dir: &str) -> PathBuf {
264+
self.legacy_fingerprint().to_path_buf().join(pkg_dir)
265+
}
266+
/// Fetch the fingerprint path. (old layout)
267+
pub fn legacy_fingerprint(&self) -> &Path {
260268
&self.fingerprint
261269
}
262-
/// Fetch the build script path.
270+
/// Fetch the build path.
263271
pub fn build(&self) -> &Path {
264272
&self.build
265273
}
274+
/// Fetch the build script path.
275+
pub fn build_script(&self, pkg_dir: &str) -> PathBuf {
276+
self.build().join(pkg_dir)
277+
}
278+
/// Fetch the build script execution path.
279+
pub fn build_script_execution(&self, pkg_dir: &str) -> PathBuf {
280+
self.build().join(pkg_dir)
281+
}
266282
/// Fetch the artifact path.
267283
pub fn artifact(&self) -> &Path {
268284
&self.artifact

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,12 +1353,8 @@ fn build_base_args(
13531353
.map(|s| s.as_ref()),
13541354
);
13551355
if incremental {
1356-
let dir = build_runner
1357-
.files()
1358-
.layout(unit.kind)
1359-
.incremental()
1360-
.as_os_str();
1361-
opt(cmd, "-C", "incremental=", Some(dir));
1356+
let dir = build_runner.files().incremental_dir(&unit);
1357+
opt(cmd, "-C", "incremental=", Some(dir.as_os_str()));
13621358
}
13631359

13641360
let pkg_hint_mostly_unused = match hints.mostly_unused {

src/cargo/ops/cargo_clean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn clean_specs(
200200

201201
// Clean fingerprints.
202202
for (_, layout) in &layouts_with_host {
203-
let dir = escape_glob_path(layout.fingerprint())?;
203+
let dir = escape_glob_path(layout.legacy_fingerprint())?;
204204
clean_ctx
205205
.rm_rf_package_glob_containing_hash(&pkg.name(), &Path::new(&dir).join(&pkg_dir))?;
206206
}
@@ -236,8 +236,8 @@ fn clean_specs(
236236
(layout.build_examples(), Some(layout.examples()))
237237
}
238238
// Tests/benchmarks are never uplifted.
239-
TargetKind::Test | TargetKind::Bench => (layout.deps(), None),
240-
_ => (layout.deps(), Some(layout.dest())),
239+
TargetKind::Test | TargetKind::Bench => (layout.legacy_deps(), None),
240+
_ => (layout.legacy_deps(), Some(layout.dest())),
241241
};
242242
let mut dir_glob_str = escape_glob_path(dir)?;
243243
let dir_glob = Path::new(&dir_glob_str);

0 commit comments

Comments
 (0)