Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {

/// Returns the directory where the artifacts for the given unit are
/// initially created.
pub fn out_dir(&self, unit: &Unit) -> PathBuf {
pub fn output_dir(&self, unit: &Unit) -> PathBuf {
// Docscrape units need to have doc/ set as the out_dir so sources for reverse-dependencies
// will be put into doc/ and not into deps/ where the *.examples files are stored.
if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
self.host.build_dir().root()
}

/// Returns the host `deps` directory path.
/// Returns the host `deps` directory path for a given build unit.
pub fn host_deps(&self, unit: &Unit) -> PathBuf {
let dir = self.pkg_dir(unit);
self.host.build_dir().deps(&dir)
Expand All @@ -289,9 +289,11 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
/// specified unit. (new layout)
///
/// New features should consider using this so we can avoid their migrations.
pub fn deps_dir_new_layout(&self, unit: &Unit) -> PathBuf {
pub fn out_dir_new_layout(&self, unit: &Unit) -> PathBuf {
let dir = self.pkg_dir(unit);
self.layout(unit.kind).build_dir().deps_new_layout(&dir)
self.layout(unit.kind)
.build_dir()
.out_force_new_layout(&dir)
}

/// Directory where the fingerprint for the given unit should go.
Expand Down Expand Up @@ -511,10 +513,10 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
}
CompileMode::Doc => {
let path = if bcx.build_config.intent.wants_doc_json_output() {
self.out_dir(unit)
self.output_dir(unit)
.join(format!("{}.json", unit.target.crate_name()))
} else {
self.out_dir(unit)
self.output_dir(unit)
.join(unit.target.crate_name())
.join("index.html")
};
Expand All @@ -530,7 +532,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
// `-Zrustdoc-mergeable-info` always uses the new layout.
outputs.push(OutputFile {
path: self
.deps_dir_new_layout(unit)
.out_dir_new_layout(unit)
.join(unit.target.crate_name())
.with_extension("json"),
hardlink: None,
Expand Down Expand Up @@ -609,7 +611,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
unit: &Unit,
bcx: &BuildContext<'a, 'gctx>,
) -> CargoResult<Vec<OutputFile>> {
let out_dir = self.out_dir(unit);
let out_dir = self.output_dir(unit);

let info = bcx.target_data.info(unit.kind);
let triple = bcx.target_data.short_name(&unit.kind);
Expand Down
12 changes: 6 additions & 6 deletions src/cargo/core/compiler/build_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,17 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
for unit in units_with_build_script {
for dep in &self.bcx.unit_graph[unit] {
if dep.unit.mode.is_run_custom_build() {
let out_dir = self
.files()
.build_script_out_dir(&dep.unit)
.display()
.to_string();
let out_dir = if self.bcx.gctx.cli_unstable().build_dir_new_layout {
self.files().out_dir_new_layout(&dep.unit)
} else {
self.files().build_script_out_dir(&dep.unit)
};
let script_meta = self.get_run_build_script_metadata(&dep.unit);
self.compilation
.extra_env
.entry(script_meta)
.or_insert_with(Vec::new)
.push(("OUT_DIR".to_string(), out_dir));
.push(("OUT_DIR".to_string(), out_dir.display().to_string()));
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
.map(|d| &d.unit)
.expect("running a script not depending on an actual script");
let script_dir = build_runner.files().build_script_dir(build_script_unit);
let script_out_dir = build_runner.files().build_script_out_dir(unit);

let script_out_dir = if bcx.gctx.cli_unstable().build_dir_new_layout {
build_runner.files().out_dir_new_layout(unit)
} else {
build_runner.files().build_script_out_dir(unit)
};
let script_run_dir = build_runner.files().build_script_run_dir(unit);

if let Some(deps) = unit.pkg.manifest().metabuild() {
Expand Down Expand Up @@ -505,6 +510,7 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul

paths::create_dir_all(&script_dir)?;
paths::create_dir_all(&script_out_dir)?;
paths::create_dir_all(&script_run_dir)?;

let nightly_features_allowed = build_runner.bcx.gctx.nightly_features_allowed;
let targets: Vec<Target> = unit.pkg.targets().to_vec();
Expand Down Expand Up @@ -1366,7 +1372,11 @@ fn prev_build_output(
build_runner: &mut BuildRunner<'_, '_>,
unit: &Unit,
) -> (Option<BuildOutput>, PathBuf) {
let script_out_dir = build_runner.files().build_script_out_dir(unit);
let script_out_dir = if build_runner.bcx.gctx.cli_unstable().build_dir_new_layout {
build_runner.files().out_dir_new_layout(unit)
} else {
build_runner.files().build_script_out_dir(unit)
};
let script_run_dir = build_runner.files().build_script_run_dir(unit);
let root_output_file = script_run_dir.join("root-output");
let output_file = script_run_dir.join("output");
Expand Down
10 changes: 5 additions & 5 deletions src/cargo/core/compiler/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,16 @@ impl BuildDirLayout {
/// Fetch the deps path.
pub fn deps(&self, pkg_dir: &str) -> PathBuf {
if self.is_new_layout {
self.deps_new_layout(pkg_dir)
self.out_force_new_layout(pkg_dir)
} else {
self.legacy_deps().to_path_buf()
}
}
/// Fetch the deps path. (new layout)
/// Fetch the output path for build units. (new layout only)
///
/// New features should consider using this so we can avoid their migrations.
pub fn deps_new_layout(&self, pkg_dir: &str) -> PathBuf {
self.build_unit(pkg_dir).join("deps")
pub fn out_force_new_layout(&self, pkg_dir: &str) -> PathBuf {
self.build_unit(pkg_dir).join("out")
}
/// Fetch the deps path. (old layout)
pub fn legacy_deps(&self) -> &Path {
Expand Down Expand Up @@ -377,7 +377,7 @@ impl BuildDirLayout {
/// Fetch the build script execution path.
pub fn build_script_execution(&self, pkg_dir: &str) -> PathBuf {
if self.is_new_layout {
self.build_unit(pkg_dir).join("build-script")
self.build_unit(pkg_dir).join("run")
} else {
self.build().join(pkg_dir)
}
Expand Down
22 changes: 15 additions & 7 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fn rustc(
let name = unit.pkg.name();

let outputs = build_runner.outputs(unit)?;
let root = build_runner.files().out_dir(unit);
let root = build_runner.files().output_dir(unit);

// Prepare the native lib state (extra `-L` and `-l` flags).
let build_script_outputs = Arc::clone(&build_runner.build_script_outputs);
Expand Down Expand Up @@ -865,7 +865,7 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
add_cap_lints(bcx, unit, &mut rustdoc);

unit.kind.add_target_arg(&mut rustdoc);
let doc_dir = build_runner.files().out_dir(unit);
let doc_dir = build_runner.files().output_dir(unit);
rustdoc.arg("-o").arg(&doc_dir);
rustdoc.args(&features_args(unit));
rustdoc.args(&check_cfg_args(unit));
Expand Down Expand Up @@ -902,7 +902,7 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
rustdoc.arg("--merge=none");
let mut arg = OsString::from("--parts-out-dir=");
// `-Zrustdoc-mergeable-info` always uses the new layout.
arg.push(build_runner.files().deps_dir_new_layout(unit));
arg.push(build_runner.files().out_dir_new_layout(unit));
rustdoc.arg(arg);
}

Expand Down Expand Up @@ -969,7 +969,7 @@ fn rustdoc(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<W
let mut rustdoc = prepare_rustdoc(build_runner, unit)?;

let crate_name = unit.target.crate_name();
let doc_dir = build_runner.files().out_dir(unit);
let doc_dir = build_runner.files().output_dir(unit);
// Create the documentation directory ahead of time as rustdoc currently has
// a bug where concurrent invocations will race to create this directory if
// it doesn't already exist.
Expand Down Expand Up @@ -1402,7 +1402,7 @@ fn build_base_args(
}

cmd.arg("--out-dir")
.arg(&build_runner.files().out_dir(unit));
.arg(&build_runner.files().output_dir(unit));

fn opt(cmd: &mut ProcessBuilder, key: &str, prefix: &str, val: Option<&OsStr>) {
if let Some(val) = val {
Expand Down Expand Up @@ -1749,7 +1749,11 @@ fn build_deps_args(
// Add `OUT_DIR` environment variables for build scripts
let first_custom_build_dep = deps.iter().find(|dep| dep.unit.mode.is_run_custom_build());
if let Some(dep) = first_custom_build_dep {
let out_dir = &build_runner.files().build_script_out_dir(&dep.unit);
let out_dir = if bcx.gctx.cli_unstable().build_dir_new_layout {
build_runner.files().out_dir_new_layout(&dep.unit)
} else {
build_runner.files().build_script_out_dir(&dep.unit)
};
cmd.env("OUT_DIR", &out_dir);
}

Expand All @@ -1764,7 +1768,11 @@ fn build_deps_args(
if is_multiple_build_scripts_enabled {
for dep in deps {
if dep.unit.mode.is_run_custom_build() {
let out_dir = &build_runner.files().build_script_out_dir(&dep.unit);
let out_dir = if bcx.gctx.cli_unstable().build_dir_new_layout {
build_runner.files().out_dir_new_layout(&dep.unit)
} else {
build_runner.files().build_script_out_dir(&dep.unit)
};
let target_name = dep.unit.target.name();
let out_dir_prefix = target_name
.strip_prefix("build-script-")
Expand Down
Loading