Skip to content

Commit

Permalink
Merge pull request rust-lang#79 from gnzlbg/tar
Browse files Browse the repository at this point in the history
Add support for --target
  • Loading branch information
ibabushkin authored Dec 8, 2018
2 parents 358f50f + 9c40627 commit edc3141
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.
12 changes: 12 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ export RUST_BACKTRACE=full
cargo build
cargo test --verbose -- --nocapture

case "${TRAVIS_OS_NAME}" in
*"linux"*)
TEST_TARGET=x86_64-unknown-linux-gnu cargo test --verbose -- --nocapture
;;
*"windows"*)
TEST_TARGET=x86_64-pc-windows-msvc cargo test --verbose -- --nocapture
;;
*"macos"*)
TEST_TARGET=x86_64-apple-darwin cargo test --verbose -- --nocapture
;;
esac

# install
mkdir -p ~/rust/cargo/bin
cp target/debug/cargo-semver ~/rust/cargo/bin
Expand Down
12 changes: 10 additions & 2 deletions src/bin/cargo_semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,19 @@ fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()>

debug!("running rust-semverver on compiled crates");

let mut child = Command::new("rust-semverver")
let mut child = Command::new("rust-semverver");
child
.arg("--crate-type=lib")
.args(&["--extern", &*format!("old={}", stable_rlib.display())])
.args(&[format!("-L{}", stable_deps_output.display())])
.args(&["--extern", &*format!("new={}", current_rlib.display())])
.args(&[format!("-L{}", current_deps_output.display())])
.args(&[format!("-L{}", current_deps_output.display())]);

if let Some(target) = matches.opt_str("target") {
child.args(&["--target", &target]);
}

let mut child = child
.arg("-")
.stdin(Stdio::piped())
.env("RUST_SEMVER_CRATE_VERSION", stable_version)
Expand Down Expand Up @@ -328,6 +335,7 @@ fn main() {
"use a `name:version` string as current/new crate",
"NAME:VERSION",
);
opts.optopt("T", "target", "Build for the target triple", "<TRIPLE>");

let config = match Config::default() {
Ok(cfg) => cfg,
Expand Down
51 changes: 32 additions & 19 deletions tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,44 @@ mod features {
.try_clone()
.expect("could not create `stderr` file by cloning `stdout`");

success &= Command::new("rustc")
.args(&["--crate-type=lib", "-o", &old_rlib])
let target_args = std::env::var("TEST_TARGET").map(|t| ["--target".to_string(), t]);

let mut cmd = Command::new("rustc");
cmd.args(&["--crate-type=lib", "-o", &old_rlib])
.arg(path.join("old.rs"))
.env("RUST_BACKTRACE", "full")
.stdin(Stdio::null())
.status()
.expect("could not run rustc")
.success();
.stdin(Stdio::null());

if let Ok(target_args) = &target_args {
cmd.args(target_args);
}

success &= cmd.status().expect("could not run rustc").success();
assert!(success, "couldn't compile old");

success &= Command::new("rustc")
.args(&["--crate-type=lib", "-o", &new_rlib])
let mut cmd = Command::new("rustc");
cmd.args(&["--crate-type=lib", "-o", &new_rlib])
.arg(path.join("new.rs"))
.env("RUST_BACKTRACE", "full")
.stdin(Stdio::null())
.status()
.expect("could not run rustc")
.success();
.stdin(Stdio::null());

if let Ok(target_args) = &target_args {
cmd.args(target_args);
}

success &= cmd.status().expect("could not run rustc").success();

assert!(success, "couldn't compile new");

success &= Command::new(
let mut cmd = Command::new(
Path::new(".")
.join("target")
.join("debug")
.join("rust-semverver")
.to_str()
.unwrap(),
)
.args(&[
);
cmd.args(&[
"--crate-type=lib",
"-Zverbose",
"--extern",
Expand All @@ -65,10 +72,16 @@ mod features {
.env("RUST_SEMVER_CRATE_VERSION", "1.0.0")
.stdin(Stdio::null())
.stdout(Stdio::from(stdout))
.stderr(Stdio::from(stderr))
.status()
.expect("could not run rust-semverver")
.success();
.stderr(Stdio::from(stderr));

if let Ok(target_args) = &target_args {
cmd.args(target_args);
}

success &= cmd
.status()
.expect("could not run rust-semverver")
.success();

assert!(success, "rust-semverver");

Expand Down
23 changes: 14 additions & 9 deletions tests/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,20 @@ mod full {
let old_version = format!("{}:{}", crate_name, old_version);
let new_version = format!("{}:{}", crate_name, new_version);

success &= Command::new("./target/debug/cargo-semver")
.args(&["-S", &old_version, "-C", &new_version])
.env("RUST_BACKTRACE", "full")
.stdin(Stdio::null())
.stdout(out_pipe)
.stderr(err_pipe)
.status()
.expect("could not run cargo semver")
.success();
success &= {
let mut cmd = Command::new("./target/debug/cargo-semver");
cmd.args(&["-S", &old_version, "-C", &new_version])
.env("RUST_BACKTRACE", "full")
.stdin(Stdio::null())
.stdout(out_pipe)
.stderr(err_pipe);

if let Ok(target) = std::env::var("TEST_TARGET") {
cmd.args(&["--target", &target]);
}

cmd.status().expect("could not run cargo semver").success()
};

assert!(success, "cargo semver");

Expand Down

0 comments on commit edc3141

Please sign in to comment.