Skip to content

Commit 8603e30

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

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

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

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

257257
/// Returns the host `deps` directory path.
258-
pub fn host_deps(&self) -> &Path {
259-
self.host.deps()
258+
pub fn host_deps(&self, unit: &Unit) -> PathBuf {
259+
let dir = self.pkg_dir(unit);
260+
self.host.deps(&dir)
260261
}
261262

262263
/// Returns the directories where Rust crate dependencies are found for the
263264
/// specified unit.
264-
pub fn deps_dir(&self, unit: &Unit) -> &Path {
265-
self.layout(unit.kind).deps()
265+
pub fn deps_dir(&self, unit: &Unit) -> PathBuf {
266+
let dir = self.pkg_dir(unit);
267+
self.layout(unit.kind).deps(&dir)
266268
}
267269

268270
/// Directory where the fingerprint for the given unit should go.
269271
pub fn fingerprint_dir(&self, unit: &Unit) -> PathBuf {
270272
let dir = self.pkg_dir(unit);
271-
self.layout(unit.kind).fingerprint().join(dir)
273+
self.layout(unit.kind).fingerprint(&dir)
274+
}
275+
276+
/// Directory where incremental output for the given unit should go.
277+
pub fn incremental_dir(&self, unit: &Unit) -> &Path {
278+
self.layout(unit.kind).incremental()
272279
}
273280

274281
/// Returns the path for a file in the fingerprint directory.
@@ -303,7 +310,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
303310
assert!(!unit.mode.is_run_custom_build());
304311
assert!(self.metas.contains_key(unit));
305312
let dir = self.pkg_dir(unit);
306-
self.layout(CompileKind::Host).build().join(dir)
313+
self.layout(CompileKind::Host).build_script(&dir)
307314
}
308315

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
403403
.insert(kind, layout.dest().to_path_buf());
404404
self.compilation
405405
.deps_output
406-
.insert(kind, layout.deps().to_path_buf());
406+
.insert(kind, layout.legacy_deps().to_path_buf());
407407
}
408408
Ok(())
409409
}

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, _pkg_dir: &str) -> PathBuf {
236+
self.deps.clone()
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.fingerprint.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: 3 additions & 7 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 {
@@ -1679,7 +1675,7 @@ fn build_deps_args(
16791675
if !unit.kind.is_host() {
16801676
cmd.arg("-L").arg(&{
16811677
let mut deps = OsString::from("dependency=");
1682-
deps.push(build_runner.files().host_deps());
1678+
deps.push(build_runner.files().host_deps(&unit));
16831679
deps
16841680
});
16851681
}

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)