Skip to content

Commit

Permalink
Try #255:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Sep 18, 2019
2 parents 1553064 + 7fd6a3a commit 44f5be2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn build(
ctoml: &cargo::Toml,
home: &Home,
rustflags: &Rustflags,
src: &Src,
sysroot: &Sysroot,
hash: u64,
verbose: bool,
Expand Down Expand Up @@ -98,6 +99,10 @@ version = "0.0.0"
stoml.push_str(&profile.to_string())
}

// rust-src comes with a lockfile for libstd. Use it.
let lockfile = src.path().join("..").join("Cargo.lock");
fs::copy(lockfile, &td.join("Cargo.lock")).chain_err(|| "couldn't copy lock file")?;

util::write(&td.join("Cargo.toml"), &stoml)?;
util::mkdir(&td.join("src"))?;
util::write(&td.join("src/lib.rs"), "")?;
Expand Down Expand Up @@ -239,6 +244,7 @@ pub fn update(
&ctoml,
home,
rustflags,
src,
sysroot,
hash,
verbose,
Expand Down
53 changes: 33 additions & 20 deletions tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Project {
let td = TempDir::new("xargo").chain_err(|| "couldn't create a temporary directory")?;

xargo()?
.args(&["init", "--lib", "--vcs", "none", "--name", name])
.args(&["init", "-q", "--lib", "--vcs", "none", "--name", name])
.current_dir(td.path())
.run()?;

Expand All @@ -202,10 +202,9 @@ impl Project {

/// Calls `xargo build`
fn build(&self, target: &str) -> Result<()> {
xargo()?
.args(&["build", "--target", target])
.current_dir(self.td.path())
.run()
// Be less verbose
self.build_and_get_stderr(Some(target))?;
Ok(())
}

/// Calls `xargo build` and collects STDERR
Expand Down Expand Up @@ -239,7 +238,8 @@ impl Project {
xargo()?
.args(&["doc", "--target", target])
.current_dir(self.td.path())
.run()
.run_and_get_stderr()?;
Ok(())
}

/// Adds a `Xargo.toml` to the project
Expand Down Expand Up @@ -272,7 +272,8 @@ struct HProject {

impl HProject {
fn new(test: bool) -> Result<Self> {
// There can only be one instance of this type at any point in time
// There can only be one instance of this type at any point in time.
// Needed to make sure we don't try to build multiple HOST libstds in parallel.
lazy_static! {
static ref ONCE: Mutex<()> = Mutex::new(());
}
Expand All @@ -282,7 +283,7 @@ impl HProject {
let td = TempDir::new("xargo").chain_err(|| "couldn't create a temporary directory")?;

xargo()?
.args(&["init", "--lib", "--vcs", "none", "--name", "host"])
.args(&["init", "-q", "--lib", "--vcs", "none", "--name", "host"])
.current_dir(td.path())
.run()?;

Expand All @@ -303,6 +304,12 @@ impl HProject {
})
}

fn build(&self, verb: &str) -> Result<()> {
// Calling "run_and_get_stderr" to be less verbose
xargo()?.arg(verb).current_dir(self.td.path()).run_and_get_stderr()?;
Ok(())
}

/// Calls `xargo build` and collects STDERR
fn build_and_get_stderr(&self) -> Result<String> {
let mut cmd = xargo()?;
Expand Down Expand Up @@ -763,12 +770,12 @@ fn host_twice() {
/// Check multi stage sysroot builds with `xargo test`
#[cfg(feature = "dev")]
#[test]
fn test() {
fn host_libtest() {
fn run() -> Result<()> {
let project = HProject::new(true)?;

if std::env::var("TRAVIS_RUST_VERSION").ok().map_or(false,
|var| var.starts_with("nightly-2018"))
|var| var.starts_with("nightly-"))
{
// Testing an old version on CI, we need a different Xargo.toml.
project.xargo_toml(
Expand All @@ -791,9 +798,7 @@ features = [\"panic_unwind\"]
)?;
}

xargo()?.arg("test").current_dir(project.td.path()).run()?;

Ok(())
project.build("test")
}

run!()
Expand All @@ -802,7 +807,7 @@ features = [\"panic_unwind\"]
/// Check multi stage sysroot builds with `xargo build`
#[cfg(feature = "dev")]
#[test]
fn alloc() {
fn host_liballoc() {
fn run() -> Result<()> {
let project = HProject::new(false)?;

Expand All @@ -816,15 +821,15 @@ stage = 1
",
)?;

xargo()?.arg("build").current_dir(project.td.path()).run()?;

Ok(())
project.build("build")
}

run!()
}

/// Test having a `[patch]` section
/// Test having a `[patch]` section.
/// The tag in the toml file needs to be updated any time the version of
/// cc used by rustc is updated.
#[cfg(feature = "dev")]
#[test]
fn host_patch() {
Expand All @@ -837,17 +842,25 @@ features = ["panic_unwind"]
[patch.crates-io.cc]
git = "https://github.com/alexcrichton/cc-rs"
tag = "1.0.25"
"#,
)?;
let stderr = project.build_and_get_stderr()?;

assert!(stderr
.lines()
.any(|line| line.contains("Compiling cc ")
&& line.contains("https://github.com/alexcrichton/cc-rs")));
&& line.contains("https://github.com/alexcrichton/cc-rs")),
"Looks like patching did not work. stderr:\n{}", stderr
);

Ok(())
}

run!()
// Only run this on pinned nightlies, to avoid having to update the version number all the time.
let is_pinned = std::env::var("TRAVIS_RUST_VERSION").ok().map_or(false,
|var| var.starts_with("nightly-"));
if is_pinned {
run!()
}
}

0 comments on commit 44f5be2

Please sign in to comment.