diff options
| author | bors <bors@rust-lang.org> | 2022-05-25 23:02:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-25 23:02:37 +0000 |
| commit | 464ec64df70e1f6ee64ec2f2b62eae8ff405bef4 (patch) | |
| tree | f2ae70252d660c42f8e42ae0887e84f984682075 /src/tools | |
| parent | 4cbaac699c14b7ac7cc80e54823b2ef6afeb64af (diff) | |
| parent | f74e61ec055a71304cbc03ae117a7b069482cb48 (diff) | |
| download | rust-464ec64df70e1f6ee64ec2f2b62eae8ff405bef4.tar.gz rust-464ec64df70e1f6ee64ec2f2b62eae8ff405bef4.zip | |
Auto merge of #97409 - GuillaumeGomez:rollup-808v9ge, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - #97317 (Allow to click on setting text) - #97375 (Simplify implementation of `-Z gcc-ld`) - #97394 (Add more eslint rules) - #97407 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/lld-wrapper/Cargo.toml | 6 | ||||
| -rw-r--r-- | src/tools/lld-wrapper/src/main.rs | 95 | ||||
| -rw-r--r-- | src/tools/rustdoc-gui/tester.js | 18 |
3 files changed, 55 insertions, 64 deletions
diff --git a/src/tools/lld-wrapper/Cargo.toml b/src/tools/lld-wrapper/Cargo.toml index 66a586fd6c3..bf5138b16d5 100644 --- a/src/tools/lld-wrapper/Cargo.toml +++ b/src/tools/lld-wrapper/Cargo.toml @@ -3,9 +3,3 @@ name = "lld-wrapper" version = "0.1.0" edition = "2021" license = "MIT OR Apache-2.0" - -[dependencies] - -[features] -ld = [] -ld64 = [] \ No newline at end of file diff --git a/src/tools/lld-wrapper/src/main.rs b/src/tools/lld-wrapper/src/main.rs index 8d19a054a1d..90bd24a75e0 100644 --- a/src/tools/lld-wrapper/src/main.rs +++ b/src/tools/lld-wrapper/src/main.rs @@ -1,5 +1,4 @@ -//! Script to invoke the bundled rust-lld with the correct flavor. The flavor is selected by -//! feature. +//! Script to invoke the bundled rust-lld with the correct flavor. //! //! lld supports multiple command line interfaces. If `-flavor <flavor>` are passed as the first //! two arguments the `<flavor>` command line interface is used to process the remaining arguments. @@ -8,59 +7,33 @@ //! In Rust with `-Z gcc-ld=lld` we have gcc or clang invoke rust-lld. Since there is no way to //! make gcc/clang pass `-flavor <flavor>` as the first two arguments in the linker invocation //! and since Windows does not support symbolic links for files this wrapper is used in place of a -//! symbolic link. It execs `../rust-lld -flavor ld` if the feature `ld` is enabled and -//! `../rust-lld -flavor ld64` if `ld64` is enabled. On Windows it spawns a `..\rust-lld.exe` +//! symbolic link. It execs `../rust-lld -flavor <flavor>` by propagating the flavor argument +//! passed to the wrapper as the first two arguments. On Windows it spawns a `..\rust-lld.exe` //! child process. -#[cfg(not(any(feature = "ld", feature = "ld64")))] -compile_error!("One of the features ld and ld64 must be enabled."); - -#[cfg(all(feature = "ld", feature = "ld64"))] -compile_error!("Only one of the feature ld or ld64 can be enabled."); - -#[cfg(feature = "ld")] -const FLAVOR: &str = "ld"; - -#[cfg(feature = "ld64")] -const FLAVOR: &str = "ld64"; - -use std::env; use std::fmt::Display; use std::path::{Path, PathBuf}; -use std::process; +use std::{env, process}; -trait ResultExt<T, E> { +trait UnwrapOrExitWith<T> { fn unwrap_or_exit_with(self, context: &str) -> T; } -impl<T, E> ResultExt<T, E> for Result<T, E> -where - E: Display, -{ +impl<T> UnwrapOrExitWith<T> for Option<T> { fn unwrap_or_exit_with(self, context: &str) -> T { - match self { - Ok(t) => t, - Err(e) => { - eprintln!("lld-wrapper: {}: {}", context, e); - process::exit(1); - } - } + self.unwrap_or_else(|| { + eprintln!("lld-wrapper: {}", context); + process::exit(1); + }) } } -trait OptionExt<T> { - fn unwrap_or_exit_with(self, context: &str) -> T; -} - -impl<T> OptionExt<T> for Option<T> { +impl<T, E: Display> UnwrapOrExitWith<T> for Result<T, E> { fn unwrap_or_exit_with(self, context: &str) -> T { - match self { - Some(t) => t, - None => { - eprintln!("lld-wrapper: {}", context); - process::exit(1); - } - } + self.unwrap_or_else(|err| { + eprintln!("lld-wrapper: {}: {}", context, err); + process::exit(1); + }) } } @@ -81,14 +54,28 @@ fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf { } /// Returns the command for invoking rust-lld with the correct flavor. +/// LLD only accepts the flavor argument at the first two arguments, so move it there. /// /// Exits on error. fn get_rust_lld_command(current_exe_path: &Path) -> process::Command { let rust_lld_path = get_rust_lld_path(current_exe_path); let mut command = process::Command::new(rust_lld_path); + + let mut flavor = None; + let args = env::args_os() + .skip(1) + .filter(|arg| match arg.to_str().and_then(|s| s.strip_prefix("-rustc-lld-flavor=")) { + Some(suffix) => { + flavor = Some(suffix.to_string()); + false + } + None => true, + }) + .collect::<Vec<_>>(); + command.arg("-flavor"); - command.arg(FLAVOR); - command.args(env::args_os().skip(1)); + command.arg(flavor.unwrap_or_exit_with("-rustc-lld-flavor=<flavor> is not passed")); + command.args(args); command } @@ -101,20 +88,14 @@ fn exec_lld(mut command: process::Command) { #[cfg(not(unix))] fn exec_lld(mut command: process::Command) { - // Windows has no exec(), spawn a child process and wait for it + // Windows has no exec(), spawn a child process and wait for it. let exit_status = command.status().unwrap_or_exit_with("error running rust-lld child process"); - if !exit_status.success() { - match exit_status.code() { - Some(code) => { - // return the original lld exit code - process::exit(code) - } - None => { - eprintln!("lld-wrapper: rust-lld child process exited with error: {}", exit_status,); - process::exit(1); - } - } - } + let code = exit_status + .code() + .ok_or(exit_status) + .unwrap_or_exit_with("rust-lld child process exited with error"); + // Return the original lld exit code. + process::exit(code); } fn main() { diff --git a/src/tools/rustdoc-gui/tester.js b/src/tools/rustdoc-gui/tester.js index 8532410a1bf..4599e12de5f 100644 --- a/src/tools/rustdoc-gui/tester.js +++ b/src/tools/rustdoc-gui/tester.js @@ -19,6 +19,7 @@ function showHelp() { console.log(" --help : show this message then quit"); console.log(" --tests-folder [PATH] : location of the .GOML tests folder"); console.log(" --jobs [NUMBER] : number of threads to run tests on"); + console.log(" --executable-path [PATH] : path of the browser's executable to be used"); } function isNumeric(s) { @@ -34,6 +35,8 @@ function parseOptions(args) { "show_text": false, "no_headless": false, "jobs": -1, + "executable_path": null, + "no_sandbox": false, }; var correspondances = { "--doc-folder": "doc_folder", @@ -41,13 +44,16 @@ function parseOptions(args) { "--debug": "debug", "--show-text": "show_text", "--no-headless": "no_headless", + "--executable-path": "executable_path", + "--no-sandbox": "no_sandbox", }; for (var i = 0; i < args.length; ++i) { if (args[i] === "--doc-folder" || args[i] === "--tests-folder" || args[i] === "--file" - || args[i] === "--jobs") { + || args[i] === "--jobs" + || args[i] === "--executable-path") { i += 1; if (i >= args.length) { console.log("Missing argument after `" + args[i - 1] + "` option."); @@ -68,6 +74,9 @@ function parseOptions(args) { } else if (args[i] === "--help") { showHelp(); process.exit(0); + } else if (args[i] === "--no-sandbox") { + console.log("`--no-sandbox` is being used. Be very careful!"); + opts[correspondances[args[i]]] = true; } else if (correspondances[args[i]]) { opts[correspondances[args[i]]] = true; } else { @@ -147,10 +156,17 @@ async function main(argv) { if (opts["show_text"]) { args.push("--show-text"); } + if (opts["no_sandbox"]) { + args.push("--no-sandbox"); + } if (opts["no_headless"]) { args.push("--no-headless"); headless = false; } + if (opts["executable_path"] !== null) { + args.push("--executable-path"); + args.push(opts["executable_path"]); + } options.parseArguments(args); } catch (error) { console.error(`invalid argument: ${error}`); |
