Skip to content
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

rustc: Start "stabilizing" some flags #19900

Merged
merged 1 commit into from
Dec 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ fn compile_test_and_save_bitcode(config: &Config, props: &TestProps,
// FIXME (#9639): This needs to handle non-utf8 paths
let mut link_args = vec!("-L".to_string(),
aux_dir.as_str().unwrap().to_string());
let llvm_args = vec!("--emit=bc,obj".to_string(),
let llvm_args = vec!("--emit=llvm-bc,obj".to_string(),
"--crate-type=lib".to_string());
link_args.extend(llvm_args.into_iter());
let args = make_compile_args(config,
Expand Down
2 changes: 1 addition & 1 deletion src/etc/rust-lldb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TMPFILE=`mktemp /tmp/rust-lldb-commands.XXXXXX`
trap "rm -f $TMPFILE; exit" INT TERM EXIT

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

# Write the LLDB script to the tempfile
echo "command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\"" >> $TMPFILE
Expand Down
260 changes: 190 additions & 70 deletions src/librustc/session/config.rs

Large diffs are not rendered by default.

119 changes: 63 additions & 56 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub use syntax::diagnostic;

use rustc_trans::back::link;
use rustc::session::{config, Session, build_session};
use rustc::session::config::Input;
use rustc::session::config::{Input, PrintRequest};
use rustc::lint::Lint;
use rustc::lint;
use rustc::metadata;
Expand Down Expand Up @@ -101,6 +101,8 @@ fn run_compiler(args: &[String]) {
}

let sopts = config::build_session_options(&matches);
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
let ofile = matches.opt_str("o").map(|o| Path::new(o));
let (input, input_file_path) = match matches.free.len() {
0u => {
if sopts.describe_lints {
Expand All @@ -109,13 +111,10 @@ fn run_compiler(args: &[String]) {
describe_lints(&ls, false);
return;
}

let sess = build_session(sopts, None, descriptions);
if sess.debugging_opt(config::PRINT_SYSROOT) {
println!("{}", sess.sysroot().display());
if print_crate_info(&sess, None, &odir, &ofile) {
return;
}

early_error("no input filename given");
}
1u => {
Expand All @@ -133,13 +132,14 @@ fn run_compiler(args: &[String]) {

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

let pretty = matches.opt_default("pretty", "normal").map(|a| {
pretty::parse_pretty(&sess, a.as_slice())
});
match pretty {
match pretty.into_iter().next() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @alexcrichton , why did you put in this code that, AFAICT, is the identity function on Option<T> ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I think I forgot to remove this after some other refactoring in this area, feel free to remove though!

Some((ppm, opt_uii)) => {
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
return;
Expand All @@ -161,10 +161,6 @@ fn run_compiler(args: &[String]) {
return;
}

if print_crate_info(&sess, &input, &odir, &ofile) {
return;
}

driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
}

Expand All @@ -185,12 +181,8 @@ pub fn commit_date_str() -> Option<&'static str> {

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

println!("{} {}", binary, option_env!("CFG_VERSION").unwrap_or("unknown version"));
if verbose {
Expand All @@ -201,18 +193,27 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
println!("host: {}", config::host_triple());
println!("release: {}", unw(release_str()));
}
None
}

fn usage() {
fn usage(verbose: bool) {
let groups = if verbose {
config::optgroups()
} else {
config::short_optgroups()
};
let message = format!("Usage: rustc [OPTIONS] INPUT");
let extra_help = if verbose {
""
} else {
"\n --help -v Print the full set of options rustc accepts"
};
println!("{}\n\
Additional help:
-C help Print codegen options
-W help Print 'lint' options and default settings
-Z help Print internal options for debugging rustc\n",
getopts::usage(message.as_slice(),
config::optgroups().as_slice()));
-Z help Print internal options for debugging rustc{}\n",
getopts::usage(message.as_slice(), groups.as_slice()),
extra_help);
}

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

if args.is_empty() {
usage();
usage(false);
return None;
}

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

if matches.opt_present("h") || matches.opt_present("help") {
usage();
usage(matches.opt_present("verbose"));
return None;
}

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

if matches.opt_present("version") {
match version("rustc", &matches) {
Some(err) => early_error(err.as_slice()),
None => return None
}
version("rustc", &matches);
return None;
}

Some(matches)
}

fn print_crate_info(sess: &Session,
input: &Input,
input: Option<&Input>,
odir: &Option<Path>,
ofile: &Option<Path>)
-> bool {
let (crate_name, crate_file_name) = sess.opts.print_metas;
// these nasty nested conditions are to avoid doing extra work
if crate_name || crate_file_name {
let attrs = parse_crate_attrs(sess, input);
let t_outputs = driver::build_output_filenames(input,
odir,
ofile,
attrs.as_slice(),
sess);
let id = link::find_crate_name(Some(sess), attrs.as_slice(), input);

if crate_name {
println!("{}", id);
}
if crate_file_name {
let crate_types = driver::collect_crate_types(sess, attrs.as_slice());
let metadata = driver::collect_crate_metadata(sess, attrs.as_slice());
*sess.crate_metadata.borrow_mut() = metadata;
for &style in crate_types.iter() {
let fname = link::filename_for_input(sess, style, id.as_slice(),
&t_outputs.with_extension(""));
println!("{}", fname.filename_display());
if sess.opts.prints.len() == 0 { return false }

let attrs = input.map(|input| parse_crate_attrs(sess, input));
for req in sess.opts.prints.iter() {
match *req {
PrintRequest::Sysroot => println!("{}", sess.sysroot().display()),
PrintRequest::FileNames |
PrintRequest::CrateName => {
let input = match input {
Some(input) => input,
None => early_error("no input file provided"),
};
let attrs = attrs.as_ref().unwrap().as_slice();
let t_outputs = driver::build_output_filenames(input,
odir,
ofile,
attrs,
sess);
let id = link::find_crate_name(Some(sess), attrs.as_slice(),
input);
if *req == PrintRequest::CrateName {
println!("{}", id);
continue
}
let crate_types = driver::collect_crate_types(sess, attrs);
let metadata = driver::collect_crate_metadata(sess, attrs);
*sess.crate_metadata.borrow_mut() = metadata;
for &style in crate_types.iter() {
let fname = link::filename_for_input(sess, style,
id.as_slice(),
&t_outputs.with_extension(""));
println!("{}", fname.filename_display());
}
}
}

true
} else {
false
}
return true;
}

fn parse_crate_attrs(sess: &Session, input: &Input) ->
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ pub fn run_passes(sess: &Session,
modules_config.emit_obj = true;
metadata_config.emit_obj = true;
},
config::OutputTypeDepInfo => {}
}
}

Expand Down Expand Up @@ -779,6 +780,7 @@ pub fn run_passes(sess: &Session,
link_obj(&crate_output.temp_path(config::OutputTypeObject));
}
}
config::OutputTypeDepInfo => {}
}
}
let user_wants_bitcode = user_wants_bitcode;
Expand Down
9 changes: 2 additions & 7 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,8 @@ pub fn main_args(args: &[String]) -> int {
usage(args[0].as_slice());
return 0;
} else if matches.opt_present("version") {
match rustc_driver::version("rustdoc", &matches) {
Some(err) => {
println!("{}", err);
return 1
},
None => return 0
}
rustc_driver::version("rustdoc", &matches);
return 0;
}

if matches.opt_strs("passes") == ["list"] {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/dep-info-custom/Makefile.foo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LIB := $(shell $(RUSTC) --crate-file-name --crate-type=lib lib.rs)
LIB := $(shell $(RUSTC) --print file-names --crate-type=lib lib.rs)

$(TMPDIR)/$(LIB):
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --crate-type=lib lib.rs
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-make/dep-info/Makefile.foo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LIB := $(shell $(RUSTC) --crate-file-name --crate-type=lib lib.rs)
LIB := $(shell $(RUSTC) --print file-names --crate-type=lib lib.rs)

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

-include $(TMPDIR)/foo.d
2 changes: 1 addition & 1 deletion src/test/run-make/issue-7349/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# used in the inner functions should each appear only once in the generated IR.

all:
$(RUSTC) foo.rs --emit=ir
$(RUSTC) foo.rs --emit=llvm-ir
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]
[ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ]
2 changes: 1 addition & 1 deletion src/test/run-make/libs-through-symlinks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ifdef IS_WINDOWS
all:
else

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

all:
mkdir -p $(TMPDIR)/outdir
Expand Down
10 changes: 5 additions & 5 deletions src/test/run-make/output-type-permutations/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all:
rm $(TMPDIR)/$(call BIN,bar)
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

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

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

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

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

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

$(RUSTC) foo.rs --emit=bc,link --crate-type=rlib
$(RUSTC) foo.rs --emit=llvm-bc,link --crate-type=rlib
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
rm $(TMPDIR)/bar.bc
rm $(TMPDIR)/foo.bc
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/sepcomp-cci-copies/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

all:
$(RUSTC) cci_lib.rs
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*cci_fn)" -eq "2" ]
2 changes: 1 addition & 1 deletion src/test/run-make/sepcomp-inlining/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# function should be defined in only one compilation unit.

all:
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ i32\ .*inlined)" -eq "1" ]
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ available_externally\ i32\ .*inlined)" -eq "2" ]
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ i32\ .*normal)" -eq "1" ]
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/sepcomp-separate/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# wind up in three different compilation units.

all:
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*magic_fn)" -eq "3" ]
8 changes: 3 additions & 5 deletions src/test/run-make/version/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-include ../tools.mk

all:
$(RUSTC) -v
$(RUSTC) -v verbose
$(RUSTC) -v bad_arg && exit 1 || exit 0
$(RUSTC) --version verbose
$(RUSTC) --version bad_arg && exit 1 || exit 0
$(RUSTC) -V
$(RUSTC) -vV
$(RUSTC) --version --verbose
2 changes: 1 addition & 1 deletion src/test/run-make/volatile-intrinsics/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ all:
$(RUSTC) main.rs
$(call RUN,main)
# ... and the loads/stores must not be optimized out.
$(RUSTC) main.rs --emit=ir
$(RUSTC) main.rs --emit=llvm-ir
grep "load volatile" $(TMPDIR)/main.ll
grep "store volatile" $(TMPDIR)/main.ll