codegen_llvm_back: improve common patterns
This commit is contained in:
parent
4286c3c1b0
commit
3dbb2cc864
6 changed files with 30 additions and 57 deletions
|
@ -185,13 +185,8 @@ impl<'a> ArchiveBuilder<'a> {
|
|||
/// Combine the provided files, rlibs, and native libraries into a single
|
||||
/// `Archive`.
|
||||
pub fn build(&mut self) {
|
||||
let kind = match self.llvm_archive_kind() {
|
||||
Ok(kind) => kind,
|
||||
Err(kind) => {
|
||||
self.config.sess.fatal(&format!("Don't know how to build archive of type: {}",
|
||||
kind));
|
||||
}
|
||||
};
|
||||
let kind = self.llvm_archive_kind().unwrap_or_else(|kind|
|
||||
self.config.sess.fatal(&format!("Don't know how to build archive of type: {}", kind)));
|
||||
|
||||
if let Err(e) = self.build_with_llvm(kind) {
|
||||
self.config.sess.fatal(&format!("failed to build archive: {}", e));
|
||||
|
|
|
@ -107,13 +107,10 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
|
|||
}
|
||||
|
||||
pub fn remove(sess: &Session, path: &Path) {
|
||||
match fs::remove_file(path) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
sess.err(&format!("failed to remove {}: {}",
|
||||
path.display(),
|
||||
e));
|
||||
}
|
||||
if let Err(e) = fs::remove_file(path) {
|
||||
sess.err(&format!("failed to remove {}: {}",
|
||||
path.display(),
|
||||
e));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +181,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
|
|||
// the objects as they're losslessly contained inside the archives.
|
||||
let output_linked = sess.crate_types.borrow()
|
||||
.iter()
|
||||
.any(|x| *x != config::CrateType::Rlib && *x != config::CrateType::Staticlib);
|
||||
.any(|&x| x != config::CrateType::Rlib && x != config::CrateType::Staticlib);
|
||||
if !output_linked {
|
||||
return false
|
||||
}
|
||||
|
@ -289,13 +286,10 @@ fn link_binary_output(sess: &Session,
|
|||
// final destination, with a `fs::rename` call. In order for the rename to
|
||||
// always succeed, the temporary file needs to be on the same filesystem,
|
||||
// which is why we create it inside the output directory specifically.
|
||||
let metadata_tmpdir = match TempFileBuilder::new()
|
||||
let metadata_tmpdir = TempFileBuilder::new()
|
||||
.prefix("rmeta")
|
||||
.tempdir_in(out_filename.parent().unwrap())
|
||||
{
|
||||
Ok(tmpdir) => tmpdir,
|
||||
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
|
||||
};
|
||||
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));
|
||||
let metadata = emit_metadata(sess, codegen_results, &metadata_tmpdir);
|
||||
if let Err(e) = fs::rename(metadata, &out_filename) {
|
||||
sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
||||
|
@ -303,10 +297,8 @@ fn link_binary_output(sess: &Session,
|
|||
out_filenames.push(out_filename);
|
||||
}
|
||||
|
||||
let tmpdir = match TempFileBuilder::new().prefix("rustc").tempdir() {
|
||||
Ok(tmpdir) => tmpdir,
|
||||
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
|
||||
};
|
||||
let tmpdir = TempFileBuilder::new().prefix("rustc").tempdir().unwrap_or_else(|err|
|
||||
sess.fatal(&format!("couldn't create a temp dir: {}", err)));
|
||||
|
||||
if outputs.outputs.should_codegen() {
|
||||
let out_filename = out_filename(sess, crate_type, outputs, crate_name);
|
||||
|
@ -869,9 +861,8 @@ fn link_natively(sess: &Session,
|
|||
sess.opts.debuginfo != DebugInfo::None &&
|
||||
!preserve_objects_for_their_debuginfo(sess)
|
||||
{
|
||||
match Command::new("dsymutil").arg(out_filename).output() {
|
||||
Ok(..) => {}
|
||||
Err(e) => sess.fatal(&format!("failed to run dsymutil: {}", e)),
|
||||
if let Err(e) = Command::new("dsymutil").arg(out_filename).output() {
|
||||
sess.fatal(&format!("failed to run dsymutil: {}", e))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -919,12 +919,6 @@ impl ThinLTOImports {
|
|||
}
|
||||
|
||||
fn module_name_to_str(c_str: &CStr) -> &str {
|
||||
match c_str.to_str() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
bug!("Encountered non-utf8 LLVM module name `{}`: {}",
|
||||
c_str.to_string_lossy(),
|
||||
e)
|
||||
}
|
||||
}
|
||||
c_str.to_str().unwrap_or_else(|e|
|
||||
bug!("Encountered non-utf8 LLVM module name `{}`: {}", c_str.to_string_lossy(), e))
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ const WASM_EXTERNAL_KIND_GLOBAL: u8 = 3;
|
|||
/// https://github.com/llvm-mirror/llvm/commit/0f32e1365, although support still
|
||||
/// needs to be added, tracked at https://bugs.llvm.org/show_bug.cgi?id=37168
|
||||
pub fn rewrite_imports(path: &Path, import_map: &FxHashMap<String, String>) {
|
||||
if import_map.len() == 0 {
|
||||
if import_map.is_empty() {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ impl<'a> Iterator for WasmSections<'a> {
|
|||
type Item = (u8, &'a [u8]);
|
||||
|
||||
fn next(&mut self) -> Option<(u8, &'a [u8])> {
|
||||
if self.0.data.len() == 0 {
|
||||
if self.0.data.is_empty() {
|
||||
return None
|
||||
}
|
||||
|
||||
|
|
|
@ -1440,15 +1440,12 @@ fn execute_copy_from_cache_work_item(cgcx: &CodegenContext,
|
|||
module.name,
|
||||
source_file,
|
||||
obj_out.display());
|
||||
match link_or_copy(&source_file, &obj_out) {
|
||||
Ok(_) => { }
|
||||
Err(err) => {
|
||||
let diag_handler = cgcx.create_diag_handler();
|
||||
diag_handler.err(&format!("unable to copy {} to {}: {}",
|
||||
source_file.display(),
|
||||
obj_out.display(),
|
||||
err));
|
||||
}
|
||||
if let Err(err) = link_or_copy(&source_file, &obj_out) {
|
||||
let diag_handler = cgcx.create_diag_handler();
|
||||
diag_handler.err(&format!("unable to copy {} to {}: {}",
|
||||
source_file.display(),
|
||||
obj_out.display(),
|
||||
err));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -343,17 +343,13 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
}
|
||||
|
||||
fn debuginfo(&mut self) {
|
||||
match self.sess.opts.debuginfo {
|
||||
DebugInfo::None => {
|
||||
// If we are building without debuginfo enabled and we were called with
|
||||
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
|
||||
// found when linking to get rid of symbols from libstd.
|
||||
match self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
|
||||
Some(true) => { self.linker_arg("-S"); },
|
||||
_ => {},
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
if let DebugInfo::None = self.sess.opts.debuginfo {
|
||||
// If we are building without debuginfo enabled and we were called with
|
||||
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
|
||||
// found when linking to get rid of symbols from libstd.
|
||||
if let Some(true) = self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
|
||||
self.linker_arg("-S");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue