diff options
author | Daniel Mueller <deso@posteo.net> | 2019-08-15 08:12:14 -0700 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-08-15 08:12:14 -0700 |
commit | b66803a4e6a42913d0154e433065c5e478f8c1c1 (patch) | |
tree | b5ee5828e249fe9cf7f627e9ea2c32d6c1afce58 /cc/tests/support | |
parent | 99234b3e77889e370a24657aee729d43ff457156 (diff) | |
download | nitrocli-b66803a4e6a42913d0154e433065c5e478f8c1c1.tar.gz nitrocli-b66803a4e6a42913d0154e433065c5e478f8c1c1.tar.bz2 |
Update cc crate to 1.0.40
This change updates the cc crate to version 1.0.40.
Import subrepo cc/:cc at 6ad3da7558ec3ccb4dc9c2ed1487fc139469d41e
Diffstat (limited to 'cc/tests/support')
-rw-r--r-- | cc/tests/support/mod.rs | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/cc/tests/support/mod.rs b/cc/tests/support/mod.rs index 72ca3fa..7d74719 100644 --- a/cc/tests/support/mod.rs +++ b/cc/tests/support/mod.rs @@ -1,10 +1,11 @@ #![allow(dead_code)] use std::env; -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; +use std::io; use std::io::prelude::*; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use cc; use tempdir::TempDir; @@ -26,9 +27,10 @@ impl Test { if gcc.ends_with("deps") { gcc.pop(); } + let td = TempDir::new_in(&gcc, "gcc-test").unwrap(); gcc.push(format!("gcc-shim{}", env::consts::EXE_SUFFIX)); Test { - td: TempDir::new("gcc-test").unwrap(), + td: td, gcc: gcc, msvc: false, } @@ -48,17 +50,18 @@ impl Test { } pub fn shim(&self, name: &str) -> &Test { - let fname = format!("{}{}", name, env::consts::EXE_SUFFIX); - fs::hard_link(&self.gcc, self.td.path().join(&fname)) - .or_else(|_| fs::copy(&self.gcc, self.td.path().join(&fname)).map(|_| ())) - .unwrap(); + link_or_copy( + &self.gcc, + self.td + .path() + .join(&format!("{}{}", name, env::consts::EXE_SUFFIX)), + ) + .unwrap(); self } pub fn gcc(&self) -> cc::Build { let mut cfg = cc::Build::new(); - let mut path = env::split_paths(&env::var_os("PATH").unwrap()).collect::<Vec<_>>(); - path.insert(0, self.td.path().to_owned()); let target = if self.msvc { "x86_64-pc-windows-msvc" } else { @@ -70,7 +73,7 @@ impl Test { .opt_level(2) .debug(false) .out_dir(self.td.path()) - .__set_env("PATH", env::join_paths(path).unwrap()) + .__set_env("PATH", self.path()) .__set_env("GCCTEST_OUT_DIR", self.td.path()); if self.msvc { cfg.compiler(self.td.path().join("cl")); @@ -79,6 +82,12 @@ impl Test { cfg } + fn path(&self) -> OsString { + let mut path = env::split_paths(&env::var_os("PATH").unwrap()).collect::<Vec<_>>(); + path.insert(0, self.td.path().to_owned()); + env::join_paths(path).unwrap() + } + pub fn cmd(&self, i: u32) -> Execution { let mut s = String::new(); File::open(self.td.path().join(format!("out{}", i))) @@ -131,3 +140,22 @@ impl Execution { self } } + +/// Hard link an executable or copy it if that fails. +/// +/// We first try to hard link an executable to save space. If that fails (as on Windows with +/// different mount points, issue #60), we copy. +#[cfg(not(target_os = "macos"))] +fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> { + let from = from.as_ref(); + let to = to.as_ref(); + fs::hard_link(from, to).or_else(|_| fs::copy(from, to).map(|_| ())) +} + +/// Copy an executable. +/// +/// On macOS, hard linking the executable leads to strange failures (issue #419), so we just copy. +#[cfg(target_os = "macos")] +fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> { + fs::copy(from, to).map(|_| ()) +} |