Skip to content

Commit 6dbe5bc

Browse files
committed
Parse --print KIND=PATH command line syntax
1 parent 2f01742 commit 6dbe5bc

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,13 +2011,7 @@ fn parse_output_types(
20112011
if !unstable_opts.parse_only {
20122012
for list in matches.opt_strs("emit") {
20132013
for output_type in list.split(',') {
2014-
let (shorthand, path) = match output_type.split_once('=') {
2015-
None => (output_type, None),
2016-
Some((shorthand, "-")) => (shorthand, Some(OutFileName::Stdout)),
2017-
Some((shorthand, path)) => {
2018-
(shorthand, Some(OutFileName::Real(PathBuf::from(path))))
2019-
}
2020-
};
2014+
let (shorthand, path) = split_out_file_name(output_type);
20212015
let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| {
20222016
handler.early_error(format!(
20232017
"unknown emission type: `{shorthand}` - expected one of: {display}",
@@ -2034,6 +2028,14 @@ fn parse_output_types(
20342028
OutputTypes(output_types)
20352029
}
20362030

2031+
fn split_out_file_name(arg: &str) -> (&str, Option<OutFileName>) {
2032+
match arg.split_once('=') {
2033+
None => (arg, None),
2034+
Some((kind, "-")) => (kind, Some(OutFileName::Stdout)),
2035+
Some((kind, path)) => (kind, Some(OutFileName::Real(PathBuf::from(path)))),
2036+
}
2037+
}
2038+
20372039
fn should_override_cgus_and_disable_thinlto(
20382040
handler: &EarlyErrorHandler,
20392041
output_types: &OutputTypes,
@@ -2128,6 +2130,8 @@ fn collect_print_requests(
21282130
];
21292131

21302132
prints.extend(matches.opt_strs("print").into_iter().map(|req| {
2133+
let (req, out) = split_out_file_name(&req);
2134+
21312135
let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
21322136
Some((_, PrintKind::TargetSpec)) => {
21332137
if unstable_opts.unstable_options {
@@ -2159,7 +2163,9 @@ fn collect_print_requests(
21592163
));
21602164
}
21612165
};
2162-
PrintRequest { kind, out: OutFileName::Stdout }
2166+
2167+
let out = out.unwrap_or(OutFileName::Stdout);
2168+
PrintRequest { kind, out }
21632169
}));
21642170

21652171
prints

0 commit comments

Comments
 (0)