Skip to content

Commit f8f2c7a

Browse files
committed
auto merge of #19900 : alexcrichton/rust/compiler-flags, r=cmr
This commit shuffles around some CLI flags of the compiler to some more stable locations with some renamings. The changes made were: * The `-v` flag has been repurposes as the "verbose" flag. The version flag has been renamed to `-V`. * The `-h` screen has been split into two parts. Most top-level options (not all) show with `-h`, and the remaining options (generally obscure) can be shown with `--help -v` which is a "verbose help screen" * The `-V` flag (version flag now) has lost its argument as it is now requested with `rustc -vV` "verbose version". * The `--emit` option has had its `ir` and `bc` variants renamed to `llvm-ir` and `llvm-bc` to emphasize that they are LLVM's IR/bytecode. * The `--emit` option has grown a new variant, `dep-info`, which subsumes the `--dep-info` CLI argument. The `--dep-info` flag is now deprecated. * The `--parse-only`, `--no-trans`, `--no-analysis`, and `--pretty` flags have moved behind the `-Z` family of flags. * The `--debuginfo` and `--opt-level` flags were moved behind the top-level `-C` flag. * The `--print-file-name` and `--print-crate-name` flags were moved behind one global `--print` flag which now accepts one of `crate-name`, `file-names`, or `sysroot`. This global `--print` flag is intended to serve as a mechanism for learning various metadata about the compiler itself. * The top-level `--pretty` flag was moved to a number of `-Z` options. No warnings are currently enabled to allow tools like Cargo to have time to migrate to the new flags before spraying warnings to all users. cc #19051
2 parents 8f51ad2 + 117984b commit f8f2c7a

File tree

16 files changed

+276
-154
lines changed

16 files changed

+276
-154
lines changed

src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ fn compile_test_and_save_bitcode(config: &Config, props: &TestProps,
16661666
// FIXME (#9639): This needs to handle non-utf8 paths
16671667
let mut link_args = vec!("-L".to_string(),
16681668
aux_dir.as_str().unwrap().to_string());
1669-
let llvm_args = vec!("--emit=bc,obj".to_string(),
1669+
let llvm_args = vec!("--emit=llvm-bc,obj".to_string(),
16701670
"--crate-type=lib".to_string());
16711671
link_args.extend(llvm_args.into_iter());
16721672
let args = make_compile_args(config,

src/etc/rust-lldb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TMPFILE=`mktemp /tmp/rust-lldb-commands.XXXXXX`
1919
trap "rm -f $TMPFILE; exit" INT TERM EXIT
2020

2121
# Find out where to look for the pretty printer Python module
22-
RUSTC_SYSROOT=`rustc -Zprint-sysroot`
22+
RUSTC_SYSROOT=`rustc --print sysroot`
2323

2424
# Write the LLDB script to the tempfile
2525
echo "command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\"" >> $TMPFILE

src/librustc/session/config.rs

+190-70
Large diffs are not rendered by default.

src/librustc_driver/lib.rs

+63-56
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use syntax::diagnostic;
4747

4848
use rustc_trans::back::link;
4949
use rustc::session::{config, Session, build_session};
50-
use rustc::session::config::Input;
50+
use rustc::session::config::{Input, PrintRequest};
5151
use rustc::lint::Lint;
5252
use rustc::lint;
5353
use rustc::metadata;
@@ -102,6 +102,8 @@ fn run_compiler(args: &[String]) {
102102
}
103103

104104
let sopts = config::build_session_options(&matches);
105+
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
106+
let ofile = matches.opt_str("o").map(|o| Path::new(o));
105107
let (input, input_file_path) = match matches.free.len() {
106108
0u => {
107109
if sopts.describe_lints {
@@ -110,13 +112,10 @@ fn run_compiler(args: &[String]) {
110112
describe_lints(&ls, false);
111113
return;
112114
}
113-
114115
let sess = build_session(sopts, None, descriptions);
115-
if sess.debugging_opt(config::PRINT_SYSROOT) {
116-
println!("{}", sess.sysroot().display());
116+
if print_crate_info(&sess, None, &odir, &ofile) {
117117
return;
118118
}
119-
120119
early_error("no input filename given");
121120
}
122121
1u => {
@@ -134,13 +133,14 @@ fn run_compiler(args: &[String]) {
134133

135134
let sess = build_session(sopts, input_file_path, descriptions);
136135
let cfg = config::build_configuration(&sess);
137-
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
138-
let ofile = matches.opt_str("o").map(|o| Path::new(o));
136+
if print_crate_info(&sess, Some(&input), &odir, &ofile) {
137+
return
138+
}
139139

140140
let pretty = matches.opt_default("pretty", "normal").map(|a| {
141141
pretty::parse_pretty(&sess, a.as_slice())
142142
});
143-
match pretty {
143+
match pretty.into_iter().next() {
144144
Some((ppm, opt_uii)) => {
145145
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
146146
return;
@@ -162,10 +162,6 @@ fn run_compiler(args: &[String]) {
162162
return;
163163
}
164164

165-
if print_crate_info(&sess, &input, &odir, &ofile) {
166-
return;
167-
}
168-
169165
driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
170166
}
171167

@@ -186,12 +182,8 @@ pub fn commit_date_str() -> Option<&'static str> {
186182

187183
/// Prints version information and returns None on success or an error
188184
/// message on panic.
189-
pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
190-
let verbose = match matches.opt_str("version").as_ref().map(|s| s.as_slice()) {
191-
None => false,
192-
Some("verbose") => true,
193-
Some(s) => return Some(format!("Unrecognized argument: {}", s))
194-
};
185+
pub fn version(binary: &str, matches: &getopts::Matches) {
186+
let verbose = matches.opt_present("verbose");
195187

196188
println!("{} {}", binary, option_env!("CFG_VERSION").unwrap_or("unknown version"));
197189
if verbose {
@@ -202,18 +194,27 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
202194
println!("host: {}", config::host_triple());
203195
println!("release: {}", unw(release_str()));
204196
}
205-
None
206197
}
207198

208-
fn usage() {
199+
fn usage(verbose: bool) {
200+
let groups = if verbose {
201+
config::optgroups()
202+
} else {
203+
config::short_optgroups()
204+
};
209205
let message = format!("Usage: rustc [OPTIONS] INPUT");
206+
let extra_help = if verbose {
207+
""
208+
} else {
209+
"\n --help -v Print the full set of options rustc accepts"
210+
};
210211
println!("{}\n\
211212
Additional help:
212213
-C help Print codegen options
213214
-W help Print 'lint' options and default settings
214-
-Z help Print internal options for debugging rustc\n",
215-
getopts::usage(message.as_slice(),
216-
config::optgroups().as_slice()));
215+
-Z help Print internal options for debugging rustc{}\n",
216+
getopts::usage(message.as_slice(), groups.as_slice()),
217+
extra_help);
217218
}
218219

219220
fn describe_lints(lint_store: &lint::LintStore, loaded_plugins: bool) {
@@ -361,7 +362,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
361362
let _binary = args.remove(0).unwrap();
362363

363364
if args.is_empty() {
364-
usage();
365+
usage(false);
365366
return None;
366367
}
367368

@@ -374,7 +375,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
374375
};
375376

376377
if matches.opt_present("h") || matches.opt_present("help") {
377-
usage();
378+
usage(matches.opt_present("verbose"));
378379
return None;
379380
}
380381

@@ -398,49 +399,55 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
398399
}
399400

400401
if matches.opt_present("version") {
401-
match version("rustc", &matches) {
402-
Some(err) => early_error(err.as_slice()),
403-
None => return None
404-
}
402+
version("rustc", &matches);
403+
return None;
405404
}
406405

407406
Some(matches)
408407
}
409408

410409
fn print_crate_info(sess: &Session,
411-
input: &Input,
410+
input: Option<&Input>,
412411
odir: &Option<Path>,
413412
ofile: &Option<Path>)
414413
-> bool {
415-
let (crate_name, crate_file_name) = sess.opts.print_metas;
416-
// these nasty nested conditions are to avoid doing extra work
417-
if crate_name || crate_file_name {
418-
let attrs = parse_crate_attrs(sess, input);
419-
let t_outputs = driver::build_output_filenames(input,
420-
odir,
421-
ofile,
422-
attrs.as_slice(),
423-
sess);
424-
let id = link::find_crate_name(Some(sess), attrs.as_slice(), input);
425-
426-
if crate_name {
427-
println!("{}", id);
428-
}
429-
if crate_file_name {
430-
let crate_types = driver::collect_crate_types(sess, attrs.as_slice());
431-
let metadata = driver::collect_crate_metadata(sess, attrs.as_slice());
432-
*sess.crate_metadata.borrow_mut() = metadata;
433-
for &style in crate_types.iter() {
434-
let fname = link::filename_for_input(sess, style, id.as_slice(),
435-
&t_outputs.with_extension(""));
436-
println!("{}", fname.filename_display());
414+
if sess.opts.prints.len() == 0 { return false }
415+
416+
let attrs = input.map(|input| parse_crate_attrs(sess, input));
417+
for req in sess.opts.prints.iter() {
418+
match *req {
419+
PrintRequest::Sysroot => println!("{}", sess.sysroot().display()),
420+
PrintRequest::FileNames |
421+
PrintRequest::CrateName => {
422+
let input = match input {
423+
Some(input) => input,
424+
None => early_error("no input file provided"),
425+
};
426+
let attrs = attrs.as_ref().unwrap().as_slice();
427+
let t_outputs = driver::build_output_filenames(input,
428+
odir,
429+
ofile,
430+
attrs,
431+
sess);
432+
let id = link::find_crate_name(Some(sess), attrs.as_slice(),
433+
input);
434+
if *req == PrintRequest::CrateName {
435+
println!("{}", id);
436+
continue
437+
}
438+
let crate_types = driver::collect_crate_types(sess, attrs);
439+
let metadata = driver::collect_crate_metadata(sess, attrs);
440+
*sess.crate_metadata.borrow_mut() = metadata;
441+
for &style in crate_types.iter() {
442+
let fname = link::filename_for_input(sess, style,
443+
id.as_slice(),
444+
&t_outputs.with_extension(""));
445+
println!("{}", fname.filename_display());
446+
}
437447
}
438448
}
439-
440-
true
441-
} else {
442-
false
443449
}
450+
return true;
444451
}
445452

446453
fn parse_crate_attrs(sess: &Session, input: &Input) ->

src/librustc_trans/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ pub fn run_passes(sess: &Session,
605605
modules_config.emit_obj = true;
606606
metadata_config.emit_obj = true;
607607
},
608+
config::OutputTypeDepInfo => {}
608609
}
609610
}
610611

@@ -777,6 +778,7 @@ pub fn run_passes(sess: &Session,
777778
link_obj(&crate_output.temp_path(config::OutputTypeObject));
778779
}
779780
}
781+
config::OutputTypeDepInfo => {}
780782
}
781783
}
782784
let user_wants_bitcode = user_wants_bitcode;

src/librustdoc/lib.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,8 @@ pub fn main_args(args: &[String]) -> int {
173173
usage(args[0].as_slice());
174174
return 0;
175175
} else if matches.opt_present("version") {
176-
match rustc_driver::version("rustdoc", &matches) {
177-
Some(err) => {
178-
println!("{}", err);
179-
return 1
180-
},
181-
None => return 0
182-
}
176+
rustc_driver::version("rustdoc", &matches);
177+
return 0;
183178
}
184179

185180
if matches.opt_strs("passes") == ["list"] {

src/test/run-make/dep-info-custom/Makefile.foo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LIB := $(shell $(RUSTC) --crate-file-name --crate-type=lib lib.rs)
1+
LIB := $(shell $(RUSTC) --print file-names --crate-type=lib lib.rs)
22

33
$(TMPDIR)/$(LIB):
44
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --crate-type=lib lib.rs
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
LIB := $(shell $(RUSTC) --crate-file-name --crate-type=lib lib.rs)
1+
LIB := $(shell $(RUSTC) --print file-names --crate-type=lib lib.rs)
22

33
$(TMPDIR)/$(LIB):
4-
$(RUSTC) --dep-info --crate-type=lib lib.rs
4+
$(RUSTC) --emit dep-info,link --crate-type=lib lib.rs
55
touch $(TMPDIR)/done
66

77
-include $(TMPDIR)/foo.d

src/test/run-make/issue-7349/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
# used in the inner functions should each appear only once in the generated IR.
77

88
all:
9-
$(RUSTC) foo.rs --emit=ir
9+
$(RUSTC) foo.rs --emit=llvm-ir
1010
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]
1111
[ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ]

src/test/run-make/libs-through-symlinks/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ifdef IS_WINDOWS
44
all:
55
else
66

7-
NAME := $(shell $(RUSTC) --crate-file-name foo.rs)
7+
NAME := $(shell $(RUSTC) --print file-names foo.rs)
88

99
all:
1010
mkdir -p $(TMPDIR)/outdir

src/test/run-make/output-type-permutations/Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all:
1212
rm $(TMPDIR)/$(call BIN,bar)
1313
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
1414

15-
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link
15+
$(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link
1616
rm $(TMPDIR)/bar.ll
1717
rm $(TMPDIR)/bar.bc
1818
rm $(TMPDIR)/bar.s
@@ -24,11 +24,11 @@ all:
2424
rm $(TMPDIR)/foo
2525
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
2626

27-
$(RUSTC) foo.rs --emit=bc -o $(TMPDIR)/foo
27+
$(RUSTC) foo.rs --emit=llvm-bc -o $(TMPDIR)/foo
2828
rm $(TMPDIR)/foo
2929
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
3030

31-
$(RUSTC) foo.rs --emit=ir -o $(TMPDIR)/foo
31+
$(RUSTC) foo.rs --emit=llvm-ir -o $(TMPDIR)/foo
3232
rm $(TMPDIR)/foo
3333
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
3434

@@ -56,7 +56,7 @@ all:
5656
rm $(TMPDIR)/$(call BIN,foo)
5757
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
5858

59-
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link --crate-type=staticlib
59+
$(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link --crate-type=staticlib
6060
rm $(TMPDIR)/bar.ll
6161
rm $(TMPDIR)/bar.s
6262
rm $(TMPDIR)/bar.o
@@ -65,7 +65,7 @@ all:
6565
# Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later
6666
# comparison.
6767

68-
$(RUSTC) foo.rs --emit=bc,link --crate-type=rlib
68+
$(RUSTC) foo.rs --emit=llvm-bc,link --crate-type=rlib
6969
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
7070
rm $(TMPDIR)/bar.bc
7171
rm $(TMPDIR)/foo.bc

src/test/run-make/sepcomp-cci-copies/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
all:
77
$(RUSTC) cci_lib.rs
8-
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
8+
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
99
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*cci_fn)" -eq "2" ]

src/test/run-make/sepcomp-inlining/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# function should be defined in only one compilation unit.
77

88
all:
9-
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
9+
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
1010
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ i32\ .*inlined)" -eq "1" ]
1111
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ available_externally\ i32\ .*inlined)" -eq "2" ]
1212
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ i32\ .*normal)" -eq "1" ]

src/test/run-make/sepcomp-separate/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
# wind up in three different compilation units.
66

77
all:
8-
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
8+
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
99
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*magic_fn)" -eq "3" ]

src/test/run-make/version/Makefile

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
-include ../tools.mk
22

33
all:
4-
$(RUSTC) -v
5-
$(RUSTC) -v verbose
6-
$(RUSTC) -v bad_arg && exit 1 || exit 0
7-
$(RUSTC) --version verbose
8-
$(RUSTC) --version bad_arg && exit 1 || exit 0
4+
$(RUSTC) -V
5+
$(RUSTC) -vV
6+
$(RUSTC) --version --verbose

src/test/run-make/volatile-intrinsics/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ all:
55
$(RUSTC) main.rs
66
$(call RUN,main)
77
# ... and the loads/stores must not be optimized out.
8-
$(RUSTC) main.rs --emit=ir
8+
$(RUSTC) main.rs --emit=llvm-ir
99
grep "load volatile" $(TMPDIR)/main.ll
1010
grep "store volatile" $(TMPDIR)/main.ll

0 commit comments

Comments
 (0)