New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Rust code #57318

Closed
wants to merge 1 commit into
base: master
from
File filter...
Filter file types
The table of contents is too big for display.
+125,472 −87,080
Diff settings

Always

Just for now

@@ -2,8 +2,8 @@
// `src/bootstrap/native.rs` for why this is needed when compiling LLD.

use std::env;
use std::process::{self, Stdio, Command};
use std::io::{self, Write};
use std::process::{self, Command, Stdio};

fn main() {
let real_llvm_config = env::var_os("LLVM_CONFIG_REAL").unwrap();
Copy path View file
@@ -11,7 +11,7 @@ extern crate bootstrap;

use std::env;

use bootstrap::{Config, Build};
use bootstrap::{Build, Config};

fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
Copy path View file
@@ -37,12 +37,15 @@ fn main() {
// Dirty code for borrowing issues
let mut new = None;
if let Some(current_as_str) = args[i].to_str() {
if (&*args[i - 1] == "-C" && current_as_str.starts_with("metadata")) ||
current_as_str.starts_with("-Cmetadata") {
if (&*args[i - 1] == "-C" && current_as_str.starts_with("metadata"))
|| current_as_str.starts_with("-Cmetadata")
{
new = Some(format!("{}-{}", current_as_str, s));
}
}
if let Some(new) = new { args[i] = new.into(); }
if let Some(new) = new {
args[i] = new.into();
}
}
}

@@ -60,7 +63,8 @@ fn main() {

// Detect whether or not we're a build script depending on whether --target
// is passed (a bit janky...)
let target = args.windows(2)
let target = args
.windows(2)
.find(|w| &*w[0] == "--target")
.and_then(|w| w[1].to_str());
let version = args.iter().find(|w| &**w == "-vV");
@@ -93,8 +97,10 @@ fn main() {
cmd.args(&args)
.arg("--cfg")
.arg(format!("stage{}", stage))
.env(bootstrap::util::dylib_path_var(),
env::join_paths(&dylib_path).unwrap());
.env(
bootstrap::util::dylib_path_var(),
env::join_paths(&dylib_path).unwrap(),
);
let mut maybe_crate = None;

// Print backtrace in case of ICE
@@ -132,9 +138,7 @@ fn main() {
cmd.arg(format!("-Clinker={}", target_linker));
}

let crate_name = args.windows(2)
.find(|a| &*a[0] == "--crate-name")
.unwrap();
let crate_name = args.windows(2).find(|a| &*a[0] == "--crate-name").unwrap();
let crate_name = &*crate_name[1];
maybe_crate = Some(crate_name);

@@ -150,8 +154,7 @@ fn main() {
// `compiler_builtins` are unconditionally compiled with panic=abort to
// workaround undefined references to `rust_eh_unwind_resume` generated
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
if crate_name == "panic_abort" ||
crate_name == "compiler_builtins" && stage != "0" {
if crate_name == "panic_abort" || crate_name == "compiler_builtins" && stage != "0" {
cmd.arg("-C").arg("panic=abort");
}

@@ -163,7 +166,13 @@ fn main() {
cmd.arg("-Cdebuginfo=1");
}
let debug_assertions = match env::var("RUSTC_DEBUG_ASSERTIONS") {
Ok(s) => if s == "true" { "y" } else { "n" },
Ok(s) => {
if s == "true" {
"y"
} else {
"n"
}
}
Err(..) => "n",
};

@@ -172,7 +181,8 @@ fn main() {
if crate_name == "compiler_builtins" {
cmd.arg("-C").arg("debug-assertions=no");
} else {
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
cmd.arg("-C")
.arg(format!("debug-assertions={}", debug_assertions));
}

if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
@@ -182,10 +192,12 @@ fn main() {
// Emit save-analysis info.
if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {
cmd.arg("-Zsave-analysis");
cmd.env("RUST_SAVE_ANALYSIS_CONFIG",
"{\"output_file\": null,\"full_docs\": false,\
\"pub_only\": true,\"reachable_only\": false,\
\"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}");
cmd.env(
"RUST_SAVE_ANALYSIS_CONFIG",
"{\"output_file\": null,\"full_docs\": false,\
\"pub_only\": true,\"reachable_only\": false,\
\"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}",
);
}

// Dealing with rpath here is a little special, so let's go into some
@@ -216,17 +228,17 @@ fn main() {
// to change a flag in a binary?
if env::var("RUSTC_RPATH") == Ok("true".to_string()) {
let rpath = if target.contains("apple") {

// Note that we need to take one extra step on macOS to also pass
// `-Wl,-instal_name,@rpath/...` to get things to work right. To
// do that we pass a weird flag to the compiler to get it to do
// so. Note that this is definitely a hack, and we should likely
// flesh out rpath support more fully in the future.
cmd.arg("-Z").arg("osx-rpath-install-name");
Some("-Wl,-rpath,@loader_path/../lib")
} else if !target.contains("windows") &&
!target.contains("wasm32") &&
!target.contains("fuchsia") {
} else if !target.contains("windows")
&& !target.contains("wasm32")
&& !target.contains("fuchsia")
{
Some("-Wl,-rpath,$ORIGIN/../lib")
} else {
None
@@ -246,7 +258,10 @@ fn main() {
}

// When running miri tests, we need to generate MIR for all libraries
if env::var("TEST_MIRI").ok().map_or(false, |val| val == "true") {
if env::var("TEST_MIRI")
.ok()
.map_or(false, |val| val == "true")
{
// The flags here should be kept in sync with `add_miri_default_args`
// in miri's `src/lib.rs`.
cmd.arg("-Zalways-encode-mir");
@@ -310,7 +325,10 @@ fn main() {
Ok(s) if s.success() => std::process::exit(0),
e => e,
};
println!("\nDid not run successfully: {:?}\n{:?}\n-------------", e, cmd);
println!(
"\nDid not run successfully: {:?}\n{:?}\n-------------",
e, cmd
);
exec_cmd(&mut on_fail).expect("could not run the backup command");
std::process::exit(1);
}
@@ -324,11 +342,13 @@ fn main() {
let dur = start.elapsed();

let is_test = args.iter().any(|a| a == "--test");
eprintln!("[RUSTC-TIMING] {} test:{} {}.{:03}",
krate.to_string_lossy(),
is_test,
dur.as_secs(),
dur.subsec_nanos() / 1_000_000);
eprintln!(
"[RUSTC-TIMING] {} test:{} {}.{:03}",
krate.to_string_lossy(),
is_test,
dur.as_secs(),
dur.subsec_nanos() / 1_000_000
);

match status.code() {
Some(i) => std::process::exit(i),
Copy path View file
@@ -7,8 +7,8 @@
extern crate bootstrap;

use std::env;
use std::process::Command;
use std::path::PathBuf;
use std::process::Command;

fn main() {
let args = env::args_os().skip(1).collect::<Vec<_>>();
@@ -37,8 +37,10 @@ fn main() {
.arg("dox")
.arg("--sysroot")
.arg(sysroot)
.env(bootstrap::util::dylib_path_var(),
env::join_paths(&dylib_path).unwrap());
.env(
bootstrap::util::dylib_path_var(),
env::join_paths(&dylib_path).unwrap(),
);

// Force all crates compiled by this compiler to (a) be unstable and (b)
// allow the `rustc_private` feature to link to other unstable crates
@@ -47,16 +49,20 @@ fn main() {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}
if let Some(linker) = env::var_os("RUSTC_TARGET_LINKER") {
cmd.arg("--linker").arg(linker).arg("-Z").arg("unstable-options");
cmd.arg("--linker")
.arg(linker)
.arg("-Z")
.arg("unstable-options");
}

// Bootstrap's Cargo-command builder sets this variable to the current Rust version; let's pick
// it up so we can make rustdoc print this into the docs
if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
// This "unstable-options" can be removed when `--crate-version` is stabilized
cmd.arg("-Z")
.arg("unstable-options")
.arg("--crate-version").arg(version);
.arg("unstable-options")
.arg("--crate-version")
.arg(version);
}

if verbose > 1 {
@@ -10,12 +10,12 @@ fn main() {
env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
let mut cfg = cc::Build::new();
cfg.cargo_metadata(false)
.out_dir("/")
.target(&target)
.host(&target)
.opt_level(0)
.warnings(false)
.debug(false);
.out_dir("/")
.target(&target)
.host(&target)
.opt_level(0)
.warnings(false)
.debug(false);
let compiler = cfg.get_compiler();

// Invoke sccache with said compiler
Copy path View file
@@ -22,7 +22,7 @@ use crate::native;
use crate::test;
use crate::tool;
use crate::util::{add_lib_path, exe, libdir};
use crate::{Build, DocTests, Mode, GitRepo};
use crate::{Build, DocTests, GitRepo, Mode};

pub use crate::Compiler;

@@ -708,7 +708,7 @@ impl<'a> Builder<'a> {
"build" => self.cargo_out(compiler, mode, target),

// This is the intended out directory for crate documentation.
"doc" | "rustdoc" => self.crate_doc_out(target),
"doc" | "rustdoc" => self.crate_doc_out(target),

_ => self.stage_out(compiler, mode),
};
@@ -748,41 +748,38 @@ impl<'a> Builder<'a> {
match mode {
Mode::Std => {
self.clear_if_dirty(&my_out, &self.rustc(compiler));
},
}
Mode::Test => {
self.clear_if_dirty(&my_out, &libstd_stamp);
},
}
Mode::Rustc => {
self.clear_if_dirty(&my_out, &self.rustc(compiler));
self.clear_if_dirty(&my_out, &libstd_stamp);
self.clear_if_dirty(&my_out, &libtest_stamp);
},
}
Mode::Codegen => {
self.clear_if_dirty(&my_out, &librustc_stamp);
},
Mode::ToolBootstrap => { },
}
Mode::ToolBootstrap => {}
Mode::ToolStd => {
self.clear_if_dirty(&my_out, &libstd_stamp);
},
}
Mode::ToolTest => {
self.clear_if_dirty(&my_out, &libstd_stamp);
self.clear_if_dirty(&my_out, &libtest_stamp);
},
}
Mode::ToolRustc => {
self.clear_if_dirty(&my_out, &libstd_stamp);
self.clear_if_dirty(&my_out, &libtest_stamp);
self.clear_if_dirty(&my_out, &librustc_stamp);
},
}
}
}

cargo
.env("CARGO_TARGET_DIR", out_dir)
.arg(cmd);
cargo.env("CARGO_TARGET_DIR", out_dir).arg(cmd);

if cmd != "install" {
cargo.arg("--target")
.arg(target);
cargo.arg("--target").arg(target);
} else {
assert_eq!(target, compiler.host);
}
@@ -896,7 +893,10 @@ impl<'a> Builder<'a> {
cargo.env("RUSTC_ERROR_FORMAT", error_format);
}
if cmd != "build" && cmd != "check" && cmd != "rustc" && want_rustdoc {
cargo.env("RUSTDOC_LIBDIR", self.sysroot_libdir(compiler, self.config.build));
cargo.env(
"RUSTDOC_LIBDIR",
self.sysroot_libdir(compiler, self.config.build),
);
}

if mode.is_tool() {
@@ -1114,10 +1114,12 @@ impl<'a> Builder<'a> {
cargo.arg("-v");
}

match (mode, self.config.rust_codegen_units_std, self.config.rust_codegen_units) {
(Mode::Std, Some(n), _) |
(Mode::Test, Some(n), _) |
(_, _, Some(n)) => {
match (
mode,
self.config.rust_codegen_units_std,
self.config.rust_codegen_units,
) {
(Mode::Std, Some(n), _) | (Mode::Test, Some(n), _) | (_, _, Some(n)) => {
cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
}
_ => {
@@ -1860,10 +1862,7 @@ mod __test {
#[test]
fn test_exclude() {
let mut config = configure(&[], &[]);
config.exclude = vec![
"src/test/run-pass".into(),
"src/tools/tidy".into(),
];
config.exclude = vec!["src/test/run-pass".into(), "src/tools/tidy".into()];
config.cmd = Subcommand::Test {
paths: Vec::new(),
test_args: Vec::new(),
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.