rustc: Repurpose the --crate-name CLI flag

In a cargo-driven world the primary location for the name of a crate will be in
its manifest, not in the source file itself. The purpose of this flag is to
reduce required duplication for new cargo projects.

This is a breaking change because the existing --crate-name flag actually
printed the crate name. This flag was renamed to --print-crate-name, and to
maintain consistence, the --crate-file-name flag was renamed to
--print-file-name.

To maintain backwards compatibility, the --crate-file-name flag is still
recognized, but it is deprecated.

[breaking-change]
This commit is contained in:
Alex Crichton 2014-07-01 17:07:06 -07:00
parent 812637e683
commit 41ed455db8
6 changed files with 54 additions and 10 deletions

View File

@ -556,6 +556,16 @@ pub fn find_crate_name(sess: Option<&Session>,
s
};
match sess {
Some(sess) => {
match sess.opts.crate_name {
Some(ref s) => return validate(s.clone(), None),
None => {}
}
}
None => {}
}
let crate_name = attrs.iter().find(|at| at.check_name("crate_name"))
.and_then(|at| at.value_str().map(|s| (at, s)));
match crate_name {

View File

@ -11,7 +11,7 @@
//! Contains infrastructure for configuring the compiler, including parsing
//! command line options.
use driver::early_error;
use driver::{early_error, early_warn};
use driver::driver;
use driver::session::Session;
@ -96,6 +96,7 @@ pub struct Options {
pub cg: CodegenOptions,
pub color: ColorConfig,
pub externs: HashMap<String, Vec<String>>,
pub crate_name: Option<String>,
}
/// Some reasonable defaults
@ -122,6 +123,7 @@ pub fn basic_options() -> Options {
cg: basic_codegen_options(),
color: Auto,
externs: HashMap::new(),
crate_name: None,
}
}
@ -511,9 +513,12 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
"[bin|lib|rlib|dylib|staticlib]"),
optmulti("", "emit", "Comma separated list of types of output for the compiler to emit",
"[asm|bc|ir|obj|link]"),
optflag("", "crate-name", "Output the crate name and exit"),
optflag("", "crate-file-name", "Output the file(s) that would be written if compilation \
optopt("", "crate-name", "Specify the name of the crate being built",
"NAME"),
optflag("", "print-crate-name", "Output the crate name and exit"),
optflag("", "print-file-name", "Output the file(s) that would be written if compilation \
continued and exit"),
optflag("", "crate-file-name", "deprecated in favor of --print-file-name"),
optflag("g", "", "Equivalent to --debuginfo=2"),
optopt("", "debuginfo", "Emit DWARF debug info to the objects created:
0 = no debug info,
@ -716,8 +721,13 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
matches.opt_str("dep-info")
.map(|p| Path::new(p)));
let print_metas = (matches.opt_present("crate-name"),
let print_metas = (matches.opt_present("print-crate-name"),
matches.opt_present("print-file-name") ||
matches.opt_present("crate-file-name"));
if matches.opt_present("crate-file-name") {
early_warn("the --crate-file-name argument has been renamed to \
--print-file-name");
}
let cg = build_codegen_options(matches);
let color = match matches.opt_str("color").as_ref().map(|s| s.as_slice()) {
@ -749,6 +759,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
locs.push(location.to_string());
}
let crate_name = matches.opt_str("crate-name");
Options {
crate_types: crate_types,
gc: gc,
@ -771,6 +783,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
cg: cg,
color: color,
externs: externs,
crate_name: crate_name,
}
}

View File

@ -389,6 +389,11 @@ pub fn early_error(msg: &str) -> ! {
fail!(diagnostic::FatalError);
}
pub fn early_warn(msg: &str) {
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto);
emitter.emit(None, msg, diagnostic::Warning);
}
pub fn list_metadata(sess: &Session, path: &Path,
out: &mut io::Writer) -> io::IoResult<()> {
metadata::loader::list_file_metadata(sess.targ_cfg.os, path, out)

View File

@ -1,9 +1,9 @@
-include ../tools.mk
all:
[ `$(RUSTC) --crate-name crate.rs` = "foo" ]
[ `$(RUSTC) --crate-file-name crate.rs` = "foo" ]
[ `$(RUSTC) --crate-file-name --crate-type=lib --test crate.rs` = "foo" ]
[ `$(RUSTC) --crate-file-name --test lib.rs` = "mylib" ]
$(RUSTC) --crate-file-name lib.rs
$(RUSTC) --crate-file-name rlib.rs
[ `$(RUSTC) --print-crate-name crate.rs` = "foo" ]
[ `$(RUSTC) --print-file-name crate.rs` = "foo" ]
[ `$(RUSTC) --print-file-name --crate-type=lib --test crate.rs` = "foo" ]
[ `$(RUSTC) --print-file-name --test lib.rs` = "mylib" ]
$(RUSTC) --print-file-name lib.rs
$(RUSTC) --print-file-name rlib.rs

View File

@ -0,0 +1,5 @@
-include ../tools.mk
all:
$(RUSTC) --crate-name foo bar.rs
rm $(TMPDIR)/libfoo.rlib

View File

@ -0,0 +1,11 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rlib"]