Skip to content

Commit 45fa34e

Browse files
committed
refactor: Moved logic to enable new layout to dedicated function
1 parent 9e691e7 commit 45fa34e

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use tracing::debug;
1111

1212
use super::{BuildContext, BuildRunner, CompileKind, FileFlavor, Layout};
1313
use crate::core::compiler::{CompileMode, CompileTarget, CrateType, FileType, Unit};
14+
use crate::core::features::is_new_build_dir_layout_enabled;
1415
use crate::core::{Target, TargetKind, Workspace};
1516
use crate::util::{self, CargoResult, OnceExt, StableHasher};
1617

@@ -239,7 +240,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
239240
/// Note that some units may share the same directory, so care should be
240241
/// taken in those cases!
241242
fn pkg_dir(&self, unit: &Unit) -> String {
242-
let separator = match self.ws.gctx().cli_unstable().build_dir_new_layout {
243+
let separator = match is_new_build_dir_layout_enabled(self.ws.gctx()) {
243244
true => "/",
244245
false => "-",
245246
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::sync::{Arc, Mutex};
77
use crate::core::PackageId;
88
use crate::core::compiler::compilation::{self, UnitOutput};
99
use crate::core::compiler::{self, Unit, UserIntent, artifact};
10+
use crate::core::features::is_new_build_dir_layout_enabled;
1011
use crate::util::cache_lock::CacheLockMode;
1112
use crate::util::errors::CargoResult;
1213
use annotate_snippets::{Level, Message};
@@ -413,7 +414,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
413414
.root_output
414415
.insert(kind, artifact_dir.dest().to_path_buf());
415416
}
416-
if self.bcx.gctx.cli_unstable().build_dir_new_layout {
417+
if is_new_build_dir_layout_enabled(self.bcx.gctx) {
417418
for (unit, _) in self.bcx.unit_graph.iter() {
418419
let dep_dir = self.files().deps_dir(unit);
419420
paths::create_dir_all(&dep_dir)?;

src/cargo/core/compiler/layout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
104104
use crate::core::Workspace;
105105
use crate::core::compiler::CompileTarget;
106+
use crate::core::features::is_new_build_dir_layout_enabled;
106107
use crate::util::flock::is_on_nfs_mount;
107108
use crate::util::{CargoResult, FileLock};
108109
use cargo_util::paths;
@@ -129,7 +130,7 @@ impl Layout {
129130
dest: &str,
130131
must_take_artifact_dir_lock: bool,
131132
) -> CargoResult<Layout> {
132-
let is_new_layout = ws.gctx().cli_unstable().build_dir_new_layout;
133+
let is_new_layout = is_new_build_dir_layout_enabled(ws.gctx());
133134
let mut root = ws.target_dir();
134135
let mut build_root = ws.build_dir();
135136
if let Some(target) = target {

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ use self::unit_graph::UnitDep;
9595
use crate::core::compiler::future_incompat::FutureIncompatReport;
9696
use crate::core::compiler::timings::SectionTiming;
9797
pub use crate::core::compiler::unit::{Unit, UnitInterner};
98+
use crate::core::features::is_new_build_dir_layout_enabled;
9899
use crate::core::manifest::TargetSourcePath;
99100
use crate::core::profiles::{PanicStrategy, Profile, StripInner};
100101
use crate::core::{Feature, PackageId, Target, Verbosity};
@@ -1682,7 +1683,7 @@ fn build_deps_args(
16821683
unit: &Unit,
16831684
) -> CargoResult<()> {
16841685
let bcx = build_runner.bcx;
1685-
if build_runner.bcx.gctx.cli_unstable().build_dir_new_layout {
1686+
if is_new_build_dir_layout_enabled(build_runner.bcx.gctx) {
16861687
let mut map = BTreeMap::new();
16871688

16881689
// Recursively add all dependency args to rustc process

src/cargo/core/features.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,3 +1554,8 @@ pub fn cargo_docs_link(path: &str) -> String {
15541554
};
15551555
format!("https://doc.rust-lang.org/{url_channel}cargo/{path}")
15561556
}
1557+
1558+
/// Returns true of the new build dir layout is enabeld.
1559+
pub fn is_new_build_dir_layout_enabled(gctx: &GlobalContext) -> bool {
1560+
gctx.cli_unstable().build_dir_new_layout
1561+
}

src/cargo/ops/cargo_clean.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::core::compiler::{CompileKind, CompileMode, Layout, RustcTargetData};
2+
use crate::core::features::is_new_build_dir_layout_enabled;
23
use crate::core::profiles::Profiles;
34
use crate::core::{PackageIdSpec, PackageIdSpecQuery, TargetKind, Workspace};
45
use crate::ops;
@@ -194,7 +195,7 @@ fn clean_specs(
194195

195196
clean_ctx.progress = Box::new(CleaningPackagesBar::new(clean_ctx.gctx, packages.len()));
196197

197-
if clean_ctx.gctx.cli_unstable().build_dir_new_layout {
198+
if is_new_build_dir_layout_enabled(clean_ctx.gctx) {
198199
for pkg in packages {
199200
clean_ctx.progress.on_cleaning_package(&pkg.name())?;
200201

0 commit comments

Comments
 (0)