Skip to content

Commit 5205b97

Browse files
committed
Auto merge of #75539 - ehuss:fix-crate-version-rustdoc-bootstrap, r=Mark-Simulacrum
Fix crate-version with rustdoc in bootstrap. Cargo will now automatically use the `--crate-version` flag (see rust-lang/cargo#8509). Cargo has special handling to avoid passing the flag if it is passed in via RUSTDOCFLAGS, but the `rustdoc` wrapper circumvents that check. This causes a problem because rustdoc will fail if the flag is passed in twice. Fix this by using RUSTDOCFLAGS. This will be necessary when 1.47 is promoted to beta, but should be safe to do now.
2 parents f7aac25 + 85a9cfa commit 5205b97

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

src/bootstrap/bin/rustdoc.rs

-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ fn main() {
4848
cmd.arg(arg);
4949
}
5050

51-
// Bootstrap's Cargo-command builder sets this variable to the current Rust version; let's pick
52-
// it up so we can make rustdoc print this into the docs
53-
if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
54-
cmd.arg("--crate-version").arg(version);
55-
}
56-
5751
// Needed to be able to run all rustdoc tests.
5852
if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
5953
// This "unstable-options" can be removed when `--resource-suffix` is stabilized

src/bootstrap/builder.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ impl<'a> Builder<'a> {
745745
.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler))
746746
.env("CFG_RELEASE_CHANNEL", &self.config.channel)
747747
.env("RUSTDOC_REAL", self.rustdoc(compiler))
748-
.env("RUSTDOC_CRATE_VERSION", self.rust_version())
749748
.env("RUSTC_BOOTSTRAP", "1")
750749
.arg("-Winvalid_codeblock_attributes");
751750
if self.config.deny_warnings {
@@ -1271,7 +1270,11 @@ impl<'a> Builder<'a> {
12711270
}
12721271

12731272
// For `cargo doc` invocations, make rustdoc print the Rust version into the docs
1274-
cargo.env("RUSTDOC_CRATE_VERSION", self.rust_version());
1273+
// This replaces spaces with newlines because RUSTDOCFLAGS does not
1274+
// support arguments with regular spaces. Hopefully someday Cargo will
1275+
// have space support.
1276+
let rust_version = self.rust_version().replace(' ', "\n");
1277+
rustdocflags.arg("--crate-version").arg(&rust_version);
12751278

12761279
// Environment variables *required* throughout the build
12771280
//
@@ -1448,14 +1451,14 @@ impl Rustflags {
14481451

14491452
fn env(&mut self, env: &str) {
14501453
if let Ok(s) = env::var(env) {
1451-
for part in s.split_whitespace() {
1454+
for part in s.split(' ') {
14521455
self.arg(part);
14531456
}
14541457
}
14551458
}
14561459

14571460
fn arg(&mut self, arg: &str) -> &mut Self {
1458-
assert_eq!(arg.split_whitespace().count(), 1);
1461+
assert_eq!(arg.split(' ').count(), 1);
14591462
if !self.0.is_empty() {
14601463
self.0.push_str(" ");
14611464
}

src/bootstrap/test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ impl Step for RustdocTheme {
599599
.env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
600600
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
601601
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
602-
.env("RUSTDOC_CRATE_VERSION", builder.rust_version())
603602
.env("RUSTC_BOOTSTRAP", "1");
604603
if let Some(linker) = builder.linker(self.compiler.host, true) {
605604
cmd.env("RUSTC_TARGET_LINKER", linker);

0 commit comments

Comments
 (0)