rustc: Default #[crate_name] on input, not output
This commit is contained in:
parent
15b680ae86
commit
56f7101551
7 changed files with 29 additions and 33 deletions
|
@ -11,7 +11,7 @@
|
||||||
use back::archive::{Archive, METADATA_FILENAME};
|
use back::archive::{Archive, METADATA_FILENAME};
|
||||||
use back::rpath;
|
use back::rpath;
|
||||||
use back::svh::Svh;
|
use back::svh::Svh;
|
||||||
use driver::driver::{CrateTranslation, OutputFilenames};
|
use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput};
|
||||||
use driver::config::NoDebugInfo;
|
use driver::config::NoDebugInfo;
|
||||||
use driver::session::Session;
|
use driver::session::Session;
|
||||||
use driver::config;
|
use driver::config;
|
||||||
|
@ -545,10 +545,9 @@ pub mod write {
|
||||||
* system linkers understand.
|
* system linkers understand.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// FIXME (#9639): This needs to handle non-utf8 `out_filestem` values
|
|
||||||
pub fn find_crate_name(sess: Option<&Session>,
|
pub fn find_crate_name(sess: Option<&Session>,
|
||||||
attrs: &[ast::Attribute],
|
attrs: &[ast::Attribute],
|
||||||
out_filestem: &str) -> String {
|
input: &Input) -> String {
|
||||||
use syntax::crateid::CrateId;
|
use syntax::crateid::CrateId;
|
||||||
|
|
||||||
let validate = |s: String, span: Option<Span>| {
|
let validate = |s: String, span: Option<Span>| {
|
||||||
|
@ -591,11 +590,17 @@ pub fn find_crate_name(sess: Option<&Session>,
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
return validate(from_str(out_filestem).unwrap_or_else(|| {
|
match *input {
|
||||||
let mut s = out_filestem.chars().filter(|c| c.is_XID_continue());
|
FileInput(ref path) => {
|
||||||
from_str(s.collect::<String>().as_slice())
|
match path.filestem_str() {
|
||||||
.or(from_str("rust-out")).unwrap()
|
Some(s) => return validate(s.to_string(), None),
|
||||||
}), None)
|
None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
"rust-out".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_link_meta(sess: &Session, krate: &ast::Crate,
|
pub fn build_link_meta(sess: &Session, krate: &ast::Crate,
|
||||||
|
|
|
@ -77,7 +77,7 @@ pub fn compile_input(sess: Session,
|
||||||
krate.attrs.as_slice(),
|
krate.attrs.as_slice(),
|
||||||
&sess);
|
&sess);
|
||||||
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
|
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
|
||||||
outputs.out_filestem.as_slice());
|
input);
|
||||||
let (expanded_crate, ast_map)
|
let (expanded_crate, ast_map)
|
||||||
= match phase_2_configure_and_expand(&sess, krate, id.as_slice()) {
|
= match phase_2_configure_and_expand(&sess, krate, id.as_slice()) {
|
||||||
None => return,
|
None => return,
|
||||||
|
@ -652,8 +652,7 @@ pub fn pretty_print_input(sess: Session,
|
||||||
ppm: PpMode,
|
ppm: PpMode,
|
||||||
ofile: Option<Path>) {
|
ofile: Option<Path>) {
|
||||||
let krate = phase_1_parse_input(&sess, cfg, input);
|
let krate = phase_1_parse_input(&sess, cfg, input);
|
||||||
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
|
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(), input);
|
||||||
input.filestem().as_slice());
|
|
||||||
|
|
||||||
let (krate, ast_map, is_expanded) = match ppm {
|
let (krate, ast_map, is_expanded) = match ppm {
|
||||||
PpmExpanded | PpmExpandedIdentified | PpmTyped | PpmFlowGraph(_) => {
|
PpmExpanded | PpmExpandedIdentified | PpmTyped | PpmFlowGraph(_) => {
|
||||||
|
|
|
@ -303,8 +303,7 @@ fn print_crate_info(sess: &Session,
|
||||||
ofile,
|
ofile,
|
||||||
attrs.as_slice(),
|
attrs.as_slice(),
|
||||||
sess);
|
sess);
|
||||||
let id = link::find_crate_name(Some(sess), attrs.as_slice(),
|
let id = link::find_crate_name(Some(sess), attrs.as_slice(), input);
|
||||||
t_outputs.out_filestem.as_slice());
|
|
||||||
|
|
||||||
if crate_name {
|
if crate_name {
|
||||||
println!("{}", id);
|
println!("{}", id);
|
||||||
|
|
|
@ -119,14 +119,7 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
|
||||||
|
|
||||||
// Figure out the name of this crate
|
// Figure out the name of this crate
|
||||||
let input = driver::FileInput(cx.src.clone());
|
let input = driver::FileInput(cx.src.clone());
|
||||||
let t_outputs = driver::build_output_filenames(&input,
|
let name = link::find_crate_name(None, self.attrs.as_slice(), &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());
|
|
||||||
|
|
||||||
// Clean the crate, translating the entire libsyntax AST to one that is
|
// Clean the crate, translating the entire libsyntax AST to one that is
|
||||||
// understood by rustdoc.
|
// understood by rustdoc.
|
||||||
|
|
|
@ -84,8 +84,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
|
||||||
use rustc::driver::driver::{FileInput,
|
use rustc::driver::driver::{FileInput,
|
||||||
phase_1_parse_input,
|
phase_1_parse_input,
|
||||||
phase_2_configure_and_expand,
|
phase_2_configure_and_expand,
|
||||||
phase_3_run_analysis_passes,
|
phase_3_run_analysis_passes};
|
||||||
build_output_filenames};
|
|
||||||
use rustc::driver::config::build_configuration;
|
use rustc::driver::config::build_configuration;
|
||||||
|
|
||||||
let input = FileInput(cpath.clone());
|
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 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(),
|
let name = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
|
||||||
t_outputs.out_filestem.as_slice());
|
&input);
|
||||||
|
|
||||||
let (krate, ast_map)
|
let (krate, ast_map)
|
||||||
= phase_2_configure_and_expand(&sess, krate, name.as_slice())
|
= phase_2_configure_and_expand(&sess, krate, name.as_slice())
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// 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() {}
|
fn main() {}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
-include ../tools.mk
|
-include ../tools.mk
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(RUSTC) foo.rs -o $(TMPDIR)/.foo 2>&1 \
|
cp foo.rs $(TMPDIR)/.foo.rs
|
||||||
| grep "invalid character in crate name:"
|
$(RUSTC) $(TMPDIR)/.foo.rs 2>&1 \
|
||||||
$(RUSTC) foo.rs -o $(TMPDIR)/.foo.bar 2>&1 \
|
| grep "invalid character.*in crate name:"
|
||||||
| grep "invalid character in crate name:"
|
cp foo.rs $(TMPDIR)/.foo.bar
|
||||||
$(RUSTC) foo.rs -o $(TMPDIR)/+foo+bar 2>&1 \
|
$(RUSTC) $(TMPDIR)/.foo.bar 2>&1 \
|
||||||
| grep "invalid character in crate name:"
|
| grep "invalid character.*in crate name:"
|
||||||
|
cp foo.rs $(TMPDIR)/+foo+bar
|
||||||
|
$(RUSTC) $(TMPDIR)/+foo+bar 2>&1 \
|
||||||
|
| grep "invalid character.*in crate name:"
|
||||||
|
|
Loading…
Reference in a new issue