summaryrefslogtreecommitdiff
path: root/cc/tests/support
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-08-15 08:12:14 -0700
committerDaniel Mueller <deso@posteo.net>2019-08-15 08:12:14 -0700
commitb766d584b36b78c96e9ef60ec927214c74ede4ab (patch)
treef4032b79b7a51183947e9ccd6e363fe5946dd1d3 /cc/tests/support
parent155f9b7e7f36975240ef93f3daf983b228592a11 (diff)
downloadnitrocli-b766d584b36b78c96e9ef60ec927214c74ede4ab.tar.gz
nitrocli-b766d584b36b78c96e9ef60ec927214c74ede4ab.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.rs48
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(|_| ())
+}