]> git.proxmox.com Git - rustc.git/blame - src/bootstrap/bin/rustdoc.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / bootstrap / bin / rustdoc.rs
CommitLineData
54a0048b
SL
1//! Shim which is passed to Cargo as "rustdoc" when running the bootstrap.
2//!
3//! See comments in `src/bootstrap/rustc.rs` for more information.
4
5use std::env;
e1599b0c 6use std::ffi::OsString;
dfeec247
XL
7use std::path::PathBuf;
8use std::process::Command;
54a0048b
SL
9
10fn main() {
11 let args = env::args_os().skip(1).collect::<Vec<_>>();
9e0c209e 12 let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
2c00a5a8 13 let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
9e0c209e 14 let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
32a655c1 15 let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
9fa01778 16 let mut has_unstable = false;
a7813a04 17
2c00a5a8
XL
18 use std::str::FromStr;
19
20 let verbose = match env::var("RUSTC_VERBOSE") {
21 Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
22 Err(_) => 0,
23 };
24
5bcae85e 25 let mut dylib_path = bootstrap::util::dylib_path();
8faf50e0 26 dylib_path.insert(0, PathBuf::from(libdir.clone()));
54a0048b 27
60c5eb7d 28 //FIXME(misdreavus): once stdsimd uses cfg(doc) instead of cfg(dox), remove the `--cfg dox`
b7449926 29 //arguments here
54a0048b
SL
30 let mut cmd = Command::new(rustdoc);
31 cmd.args(&args)
c30ab7b3
SL
32 .arg("--cfg")
33 .arg(format!("stage{}", stage))
34 .arg("--cfg")
35 .arg("dox")
32a655c1 36 .arg("--sysroot")
532ac7d7 37 .arg(&sysroot)
dfeec247 38 .env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
cc61c64b 39
041b39d2
XL
40 // Force all crates compiled by this compiler to (a) be unstable and (b)
41 // allow the `rustc_private` feature to link to other unstable crates
42 // also in the sysroot.
43 if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
44 cmd.arg("-Z").arg("force-unstable-if-unmarked");
cc61c64b 45 }
abe05a73 46 if let Some(linker) = env::var_os("RUSTC_TARGET_LINKER") {
e1599b0c
XL
47 let mut arg = OsString::from("-Clinker=");
48 arg.push(&linker);
49 cmd.arg(arg);
abe05a73
XL
50 }
51
52 // Bootstrap's Cargo-command builder sets this variable to the current Rust version; let's pick
53 // it up so we can make rustdoc print this into the docs
54 if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
9fa01778 55 cmd.arg("--crate-version").arg(version);
9fa01778
XL
56 }
57
58 // Needed to be able to run all rustdoc tests.
74b04a01 59 if env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES").is_some() {
9fa01778
XL
60 // This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized
61 if !has_unstable {
dfeec247 62 cmd.arg("-Z").arg("unstable-options");
9fa01778
XL
63 }
64 cmd.arg("--generate-redirect-pages");
65 has_unstable = true;
66 }
67
68 // Needed to be able to run all rustdoc tests.
69 if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
70 // This "unstable-options" can be removed when `--resource-suffix` is stabilized
71 if !has_unstable {
dfeec247 72 cmd.arg("-Z").arg("unstable-options");
9fa01778
XL
73 }
74 cmd.arg("--resource-suffix").arg(x);
abe05a73 75 }
cc61c64b 76
2c00a5a8 77 if verbose > 1 {
532ac7d7
XL
78 eprintln!(
79 "rustdoc command: {:?}={:?} {:?}",
80 bootstrap::util::dylib_path_var(),
81 env::join_paths(&dylib_path).unwrap(),
82 cmd,
83 );
84 eprintln!("sysroot: {:?}", sysroot);
8faf50e0 85 eprintln!("libdir: {:?}", libdir);
2c00a5a8
XL
86 }
87
54a0048b
SL
88 std::process::exit(match cmd.status() {
89 Ok(s) => s.code().unwrap_or(1),
90 Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
91 })
92}