use crate::cache::{Cache, Interned, INTERNER};
use crate::config::{SplitDebuginfo, TargetSelection};
-use crate::dist;
use crate::doc;
use crate::flags::{Color, Subcommand};
use crate::install;
use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir, output, t};
use crate::EXTRA_CHECK_CFGS;
use crate::{check, compile, Crate};
+use crate::{clean, dist};
use crate::{Build, CLang, DocTests, GitRepo, Mode};
pub use crate::Compiler;
pub fn build_triple(&self) -> TargetSelection {
self.builder.build.build
}
+
+ /// Return a `-p=x -p=y` string suitable for passing to a cargo invocation.
+ pub fn cargo_crates_in_set(&self) -> Interned<Vec<String>> {
+ let mut crates = Vec::new();
+ for krate in &self.paths {
+ let path = krate.assert_single_path();
+ let crate_name = self.builder.crate_paths[&path.path];
+ crates.push(format!("-p={crate_name}"));
+ }
+ INTERNER.intern_list(crates)
+ }
}
struct StepDescription {
run::GenerateCopyright,
),
Kind::Setup => describe!(setup::Profile),
- // These commands either don't use paths, or they're special-cased in Build::build()
- Kind::Clean | Kind::Format => vec![],
+ Kind::Clean => describe!(clean::CleanAll, clean::Rustc, clean::Std),
+ // special-cased in Build::build()
+ Kind::Format => vec![],
}
}
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
Subcommand::Run { ref paths, .. } => (Kind::Run, &paths[..]),
+ Subcommand::Clean { ref paths, .. } => (Kind::Clean, &paths[..]),
Subcommand::Format { .. } => (Kind::Format, &[][..]),
Subcommand::Setup { profile: ref path } => (
Kind::Setup,
path.as_ref().map_or([].as_slice(), |path| std::slice::from_ref(path)),
),
- Subcommand::Clean { .. } => {
- panic!()
- }
};
Self::new_internal(build, kind, paths.to_owned())
None
}
+ /// Like `cargo`, but only passes flags that are valid for all commands.
+ pub fn bare_cargo(
+ &self,
+ compiler: Compiler,
+ mode: Mode,
+ target: TargetSelection,
+ cmd: &str,
+ ) -> Command {
+ let mut cargo = Command::new(&self.initial_cargo);
+ // Run cargo from the source root so it can find .cargo/config.
+ // This matters when using vendoring and the working directory is outside the repository.
+ cargo.current_dir(&self.src);
+
+ let out_dir = self.stage_out(compiler, mode);
+ cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd);
+
+ // Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger`
+ // from out of tree it shouldn't matter, since x.py is only used for
+ // building in-tree.
+ let color_logs = ["RUSTDOC_LOG_COLOR", "RUSTC_LOG_COLOR", "RUST_LOG_COLOR"];
+ match self.build.config.color {
+ Color::Always => {
+ cargo.arg("--color=always");
+ for log in &color_logs {
+ cargo.env(log, "always");
+ }
+ }
+ Color::Never => {
+ cargo.arg("--color=never");
+ for log in &color_logs {
+ cargo.env(log, "never");
+ }
+ }
+ Color::Auto => {} // nothing to do
+ }
+
+ if cmd != "install" {
+ cargo.arg("--target").arg(target.rustc_target_arg());
+ } else {
+ assert_eq!(target, compiler.host);
+ }
+
+ if self.config.rust_optimize {
+ // FIXME: cargo bench/install do not accept `--release`
+ if cmd != "bench" && cmd != "install" {
+ cargo.arg("--release");
+ }
+ }
+
+ // Remove make-related flags to ensure Cargo can correctly set things up
+ cargo.env_remove("MAKEFLAGS");
+ cargo.env_remove("MFLAGS");
+
+ cargo
+ }
+
/// Prepares an invocation of `cargo` to be run.
///
/// This will create a `Command` that represents a pending execution of
target: TargetSelection,
cmd: &str,
) -> Cargo {
- let mut cargo = Command::new(&self.initial_cargo);
+ let mut cargo = self.bare_cargo(compiler, mode, target, cmd);
let out_dir = self.stage_out(compiler, mode);
- // Run cargo from the source root so it can find .cargo/config.
- // This matters when using vendoring and the working directory is outside the repository.
- cargo.current_dir(&self.src);
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
// so we need to explicitly clear out if they've been updated.
self.clear_if_dirty(&my_out, &rustdoc);
}
- cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd);
-
let profile_var = |name: &str| {
let profile = if self.config.rust_optimize { "RELEASE" } else { "DEV" };
format!("CARGO_PROFILE_{}_{}", profile, name)
cargo.env("REAL_LIBRARY_PATH", e);
}
- // Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger`
- // from out of tree it shouldn't matter, since x.py is only used for
- // building in-tree.
- let color_logs = ["RUSTDOC_LOG_COLOR", "RUSTC_LOG_COLOR", "RUST_LOG_COLOR"];
- match self.build.config.color {
- Color::Always => {
- cargo.arg("--color=always");
- for log in &color_logs {
- cargo.env(log, "always");
- }
- }
- Color::Never => {
- cargo.arg("--color=never");
- for log in &color_logs {
- cargo.env(log, "never");
- }
- }
- Color::Auto => {} // nothing to do
- }
-
- if cmd != "install" {
- cargo.arg("--target").arg(target.rustc_target_arg());
- } else {
- assert_eq!(target, compiler.host);
- }
-
// Set a flag for `check`/`clippy`/`fix`, so that certain build
// scripts can do less work (i.e. not building/requiring LLVM).
if cmd == "check" || cmd == "clippy" || cmd == "fix" {
}
cargo.arg("-j").arg(self.jobs().to_string());
- // Remove make-related flags to ensure Cargo can correctly set things up
- cargo.env_remove("MAKEFLAGS");
- cargo.env_remove("MFLAGS");
// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
// Force cargo to output binaries with disambiguating hashes in the name
}
}
- if self.config.rust_optimize {
- // FIXME: cargo bench/install do not accept `--release`
- if cmd != "bench" && cmd != "install" {
- cargo.arg("--release");
- }
- }
-
if self.config.locked_deps {
cargo.arg("--locked");
}