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

Cleanup rustc/driver #55008

Merged
merged 10 commits into from
Oct 15, 2018
65 changes: 30 additions & 35 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use serialize::json;

use std::any::Any;
use std::env;
use std::ffi::{OsStr, OsString};
use std::ffi::OsString;
use std::fs;
use std::io::{self, Write};
use std::iter;
Expand Down Expand Up @@ -1021,6 +1021,7 @@ where
.cloned()
.collect();
missing_fragment_specifiers.sort();

for span in missing_fragment_specifiers {
let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
let msg = "missing fragment specifier";
Expand Down Expand Up @@ -1472,7 +1473,7 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[Pa
.collect();
let mut file = fs::File::create(&deps_filename)?;
for path in out_filenames {
write!(file, "{}: {}\n\n", path.display(), files.join(" "))?;
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering wether the previous version was like that to avoid flushing on every line (I believe that is a behavior difference between write and writeln, although looking around https://llogiq.github.io/2017/06/01/perf-pitfalls.html https://www.reddit.com/r/rust/comments/6hoayo/how_do_i_write_to_stdout_without_line_buffering/ it seems like I might be wrong).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point; this change is contained in a single commit, so in case of any issues it can be easily reverted. I can also pull it back if you prefer.

}

// Emit a fake target for each input file to the compilation. This
Expand All @@ -1484,15 +1485,12 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[Pa
Ok(())
})();

match result {
Ok(()) => {}
Err(e) => {
sess.fatal(&format!(
"error writing dependencies to `{}`: {}",
deps_filename.display(),
e
));
}
if let Err(e) = result {
sess.fatal(&format!(
"error writing dependencies to `{}`: {}",
deps_filename.display(),
e
));
}
}

Expand Down Expand Up @@ -1520,6 +1518,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
Symbol::intern("proc-macro"),
Symbol::intern("bin")
];

if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().node {
let span = spanned.span;
let lev_candidate = find_best_match_for_name(
Expand Down Expand Up @@ -1551,7 +1550,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
}
None
}
_ => {
None => {
session
.struct_span_err(a.span, "`crate_type` requires a value")
.note("for example: `#![crate_type=\"lib\"]`")
Expand Down Expand Up @@ -1581,25 +1580,26 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
base.push(::rustc_codegen_utils::link::default_output_for_target(
session,
));
} else {
base.sort();
base.dedup();
}
base.sort();
base.dedup();
}

base.into_iter()
.filter(|crate_type| {
let res = !::rustc_codegen_utils::link::invalid_output_for_target(session, *crate_type);
base.retain(|crate_type| {
let res = !::rustc_codegen_utils::link::invalid_output_for_target(session, *crate_type);

if !res {
session.warn(&format!(
"dropping unsupported crate type `{}` for target `{}`",
*crate_type, session.opts.target_triple
));
}
if !res {
session.warn(&format!(
"dropping unsupported crate type `{}` for target `{}`",
*crate_type, session.opts.target_triple
));
}

res
})
.collect()
res
});

base
}

pub fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguator {
Expand Down Expand Up @@ -1650,17 +1650,14 @@ pub fn build_output_filenames(
// "-" as input file will cause the parser to read from stdin so we
// have to make up a name
// We want to toss everything after the final '.'
let dirpath = match *odir {
Some(ref d) => d.clone(),
None => PathBuf::new(),
};
let dirpath = (*odir).as_ref().cloned().unwrap_or_default();

// If a crate name is present, we use it as the link name
let stem = sess.opts
.crate_name
.clone()
.or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
.unwrap_or(input.filestem());
.unwrap_or_else(|| input.filestem());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should work: .unwrap_or_else(input.filestem);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be cool, but unfortunately the compiler recognizes this as E0615.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's annoying but can see how it happens. Thanks for checking.


OutputFilenames {
out_directory: dirpath,
Expand Down Expand Up @@ -1693,13 +1690,11 @@ pub fn build_output_filenames(
sess.warn("ignoring -C extra-filename flag due to -o flag");
}

let cur_dir = Path::new("");

OutputFilenames {
out_directory: out_file.parent().unwrap_or(cur_dir).to_path_buf(),
out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
out_filestem: out_file
.file_stem()
.unwrap_or(OsStr::new(""))
.unwrap_or_default()
.to_str()
.unwrap()
.to_string(),
Expand Down
Loading