rustc: Default #[crate_name] on input, not output

This commit is contained in:
Alex Crichton 2014-07-05 12:37:43 -07:00
parent 15b680ae86
commit 56f7101551
7 changed files with 29 additions and 33 deletions

View file

@ -11,7 +11,7 @@
use back::archive::{Archive, METADATA_FILENAME};
use back::rpath;
use back::svh::Svh;
use driver::driver::{CrateTranslation, OutputFilenames};
use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput};
use driver::config::NoDebugInfo;
use driver::session::Session;
use driver::config;
@ -545,10 +545,9 @@ pub mod write {
* system linkers understand.
*/
// FIXME (#9639): This needs to handle non-utf8 `out_filestem` values
pub fn find_crate_name(sess: Option<&Session>,
attrs: &[ast::Attribute],
out_filestem: &str) -> String {
input: &Input) -> String {
use syntax::crateid::CrateId;
let validate = |s: String, span: Option<Span>| {
@ -591,11 +590,17 @@ pub fn find_crate_name(sess: Option<&Session>,
}
None => {}
}
return validate(from_str(out_filestem).unwrap_or_else(|| {
let mut s = out_filestem.chars().filter(|c| c.is_XID_continue());
from_str(s.collect::<String>().as_slice())
.or(from_str("rust-out")).unwrap()
}), None)
match *input {
FileInput(ref path) => {
match path.filestem_str() {
Some(s) => return validate(s.to_string(), None),
None => {}
}
}
_ => {}
}
"rust-out".to_string()
}
pub fn build_link_meta(sess: &Session, krate: &ast::Crate,

View file

@ -77,7 +77,7 @@ pub fn compile_input(sess: Session,
krate.attrs.as_slice(),
&sess);
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
outputs.out_filestem.as_slice());
input);
let (expanded_crate, ast_map)
= match phase_2_configure_and_expand(&sess, krate, id.as_slice()) {
None => return,
@ -652,8 +652,7 @@ pub fn pretty_print_input(sess: Session,
ppm: PpMode,
ofile: Option<Path>) {
let krate = phase_1_parse_input(&sess, cfg, input);
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
input.filestem().as_slice());
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(), input);
let (krate, ast_map, is_expanded) = match ppm {
PpmExpanded | PpmExpandedIdentified | PpmTyped | PpmFlowGraph(_) => {

View file

@ -303,8 +303,7 @@ fn print_crate_info(sess: &Session,
ofile,
attrs.as_slice(),
sess);
let id = link::find_crate_name(Some(sess), attrs.as_slice(),
t_outputs.out_filestem.as_slice());
let id = link::find_crate_name(Some(sess), attrs.as_slice(), input);
if crate_name {
println!("{}", id);

View file

@ -119,14 +119,7 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
// Figure out the name of this crate
let input = driver::FileInput(cx.src.clone());
let t_outputs = driver::build_output_filenames(&input,
&None,
&None,
self.attrs.as_slice(),
cx.sess());
let name = link::find_crate_name(None,
self.attrs.as_slice(),
t_outputs.out_filestem.as_slice());
let name = link::find_crate_name(None, self.attrs.as_slice(), &input);
// Clean the crate, translating the entire libsyntax AST to one that is
// understood by rustdoc.

View file

@ -84,8 +84,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
use rustc::driver::driver::{FileInput,
phase_1_parse_input,
phase_2_configure_and_expand,
phase_3_run_analysis_passes,
build_output_filenames};
phase_3_run_analysis_passes};
use rustc::driver::config::build_configuration;
let input = FileInput(cpath.clone());
@ -118,10 +117,8 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
let krate = phase_1_parse_input(&sess, cfg, &input);
let t_outputs = build_output_filenames(&input, &None, &None,
krate.attrs.as_slice(), &sess);
let name = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
t_outputs.out_filestem.as_slice());
&input);
let (krate, ast_map)
= phase_2_configure_and_expand(&sess, krate, name.as_slice())

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate bar = "#a"; //~ ERROR: invalid character in crate name: `#`
extern crate bar = "#a"; //~ ERROR: invalid character `#` in crate name: `#a`
fn main() {}

View file

@ -1,9 +1,12 @@
-include ../tools.mk
all:
$(RUSTC) foo.rs -o $(TMPDIR)/.foo 2>&1 \
| grep "invalid character in crate name:"
$(RUSTC) foo.rs -o $(TMPDIR)/.foo.bar 2>&1 \
| grep "invalid character in crate name:"
$(RUSTC) foo.rs -o $(TMPDIR)/+foo+bar 2>&1 \
| grep "invalid character in crate name:"
cp foo.rs $(TMPDIR)/.foo.rs
$(RUSTC) $(TMPDIR)/.foo.rs 2>&1 \
| grep "invalid character.*in crate name:"
cp foo.rs $(TMPDIR)/.foo.bar
$(RUSTC) $(TMPDIR)/.foo.bar 2>&1 \
| grep "invalid character.*in crate name:"
cp foo.rs $(TMPDIR)/+foo+bar
$(RUSTC) $(TMPDIR)/+foo+bar 2>&1 \
| grep "invalid character.*in crate name:"