Rollup merge of #82261 - ojeda:rustdoc-argfile, r=jyn514
rustdoc: Support argument files Factors out the `rustc_driver` logic that handles argument files so that rustdoc supports them as well, e.g.: rustdoc `@argfile` This is needed to be able to generate docs for projects that already use argument files when compiling them, e.g. projects that pass a huge number of `--cfg` arguments. The feature was stabilized for `rustc` in #66172.
This commit is contained in:
commit
d9bc16cf36
11 changed files with 77 additions and 13 deletions
|
@ -3,7 +3,7 @@ use std::fmt;
|
|||
use std::fs;
|
||||
use std::io;
|
||||
|
||||
pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
|
||||
fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
|
||||
if let Some(path) = arg.strip_prefix('@') {
|
||||
let file = match fs::read_to_string(path) {
|
||||
Ok(file) => file,
|
||||
|
@ -18,6 +18,20 @@ pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn arg_expand_all(at_args: &[String]) -> Vec<String> {
|
||||
let mut args = Vec::new();
|
||||
for arg in at_args {
|
||||
match arg_expand(arg.clone()) {
|
||||
Ok(arg) => args.extend(arg),
|
||||
Err(err) => rustc_session::early_error(
|
||||
rustc_session::config::ErrorOutputType::default(),
|
||||
&format!("Failed to load argument file: {}", err),
|
||||
),
|
||||
}
|
||||
}
|
||||
args
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Utf8Error(Option<String>),
|
||||
|
|
|
@ -55,7 +55,7 @@ use std::process::{self, Command, Stdio};
|
|||
use std::str;
|
||||
use std::time::Instant;
|
||||
|
||||
mod args;
|
||||
pub mod args;
|
||||
pub mod pretty;
|
||||
|
||||
/// Exit status code used for successful compilation and help output.
|
||||
|
@ -188,16 +188,8 @@ fn run_compiler(
|
|||
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
|
||||
>,
|
||||
) -> interface::Result<()> {
|
||||
let mut args = Vec::new();
|
||||
for arg in at_args {
|
||||
match args::arg_expand(arg.clone()) {
|
||||
Ok(arg) => args.extend(arg),
|
||||
Err(err) => early_error(
|
||||
ErrorOutputType::default(),
|
||||
&format!("Failed to load argument file: {}", err),
|
||||
),
|
||||
}
|
||||
}
|
||||
let args = args::arg_expand_all(at_args);
|
||||
|
||||
let diagnostic_output = emitter.map_or(DiagnosticOutput::Default, DiagnosticOutput::Raw);
|
||||
let matches = match handle_options(&args) {
|
||||
Some(matches) => matches,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue