Skip to content

Commit edc3141

Browse files
authored
Merge pull request rust-lang#79 from gnzlbg/tar
Add support for --target
2 parents 358f50f + 9c40627 commit edc3141

File tree

4 files changed

+68
-30
lines changed

4 files changed

+68
-30
lines changed

ci/run.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ export RUST_BACKTRACE=full
99
cargo build
1010
cargo test --verbose -- --nocapture
1111

12+
case "${TRAVIS_OS_NAME}" in
13+
*"linux"*)
14+
TEST_TARGET=x86_64-unknown-linux-gnu cargo test --verbose -- --nocapture
15+
;;
16+
*"windows"*)
17+
TEST_TARGET=x86_64-pc-windows-msvc cargo test --verbose -- --nocapture
18+
;;
19+
*"macos"*)
20+
TEST_TARGET=x86_64-apple-darwin cargo test --verbose -- --nocapture
21+
;;
22+
esac
23+
1224
# install
1325
mkdir -p ~/rust/cargo/bin
1426
cp target/debug/cargo-semver ~/rust/cargo/bin

src/bin/cargo_semver.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,19 @@ fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()>
240240

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

243-
let mut child = Command::new("rust-semverver")
243+
let mut child = Command::new("rust-semverver");
244+
child
244245
.arg("--crate-type=lib")
245246
.args(&["--extern", &*format!("old={}", stable_rlib.display())])
246247
.args(&[format!("-L{}", stable_deps_output.display())])
247248
.args(&["--extern", &*format!("new={}", current_rlib.display())])
248-
.args(&[format!("-L{}", current_deps_output.display())])
249+
.args(&[format!("-L{}", current_deps_output.display())]);
250+
251+
if let Some(target) = matches.opt_str("target") {
252+
child.args(&["--target", &target]);
253+
}
254+
255+
let mut child = child
249256
.arg("-")
250257
.stdin(Stdio::piped())
251258
.env("RUST_SEMVER_CRATE_VERSION", stable_version)
@@ -328,6 +335,7 @@ fn main() {
328335
"use a `name:version` string as current/new crate",
329336
"NAME:VERSION",
330337
);
338+
opts.optopt("T", "target", "Build for the target triple", "<TRIPLE>");
331339

332340
let config = match Config::default() {
333341
Ok(cfg) => cfg,

tests/examples.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,44 @@ mod features {
1818
.try_clone()
1919
.expect("could not create `stderr` file by cloning `stdout`");
2020

21-
success &= Command::new("rustc")
22-
.args(&["--crate-type=lib", "-o", &old_rlib])
21+
let target_args = std::env::var("TEST_TARGET").map(|t| ["--target".to_string(), t]);
22+
23+
let mut cmd = Command::new("rustc");
24+
cmd.args(&["--crate-type=lib", "-o", &old_rlib])
2325
.arg(path.join("old.rs"))
2426
.env("RUST_BACKTRACE", "full")
25-
.stdin(Stdio::null())
26-
.status()
27-
.expect("could not run rustc")
28-
.success();
27+
.stdin(Stdio::null());
28+
29+
if let Ok(target_args) = &target_args {
30+
cmd.args(target_args);
31+
}
2932

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

32-
success &= Command::new("rustc")
33-
.args(&["--crate-type=lib", "-o", &new_rlib])
36+
let mut cmd = Command::new("rustc");
37+
cmd.args(&["--crate-type=lib", "-o", &new_rlib])
3438
.arg(path.join("new.rs"))
3539
.env("RUST_BACKTRACE", "full")
36-
.stdin(Stdio::null())
37-
.status()
38-
.expect("could not run rustc")
39-
.success();
40+
.stdin(Stdio::null());
41+
42+
if let Ok(target_args) = &target_args {
43+
cmd.args(target_args);
44+
}
45+
46+
success &= cmd.status().expect("could not run rustc").success();
4047

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

43-
success &= Command::new(
50+
let mut cmd = Command::new(
4451
Path::new(".")
4552
.join("target")
4653
.join("debug")
4754
.join("rust-semverver")
4855
.to_str()
4956
.unwrap(),
50-
)
51-
.args(&[
57+
);
58+
cmd.args(&[
5259
"--crate-type=lib",
5360
"-Zverbose",
5461
"--extern",
@@ -65,10 +72,16 @@ mod features {
6572
.env("RUST_SEMVER_CRATE_VERSION", "1.0.0")
6673
.stdin(Stdio::null())
6774
.stdout(Stdio::from(stdout))
68-
.stderr(Stdio::from(stderr))
69-
.status()
70-
.expect("could not run rust-semverver")
71-
.success();
75+
.stderr(Stdio::from(stderr));
76+
77+
if let Ok(target_args) = &target_args {
78+
cmd.args(target_args);
79+
}
80+
81+
success &= cmd
82+
.status()
83+
.expect("could not run rust-semverver")
84+
.success();
7285

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

tests/full.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ mod full {
8888
let old_version = format!("{}:{}", crate_name, old_version);
8989
let new_version = format!("{}:{}", crate_name, new_version);
9090

91-
success &= Command::new("./target/debug/cargo-semver")
92-
.args(&["-S", &old_version, "-C", &new_version])
93-
.env("RUST_BACKTRACE", "full")
94-
.stdin(Stdio::null())
95-
.stdout(out_pipe)
96-
.stderr(err_pipe)
97-
.status()
98-
.expect("could not run cargo semver")
99-
.success();
91+
success &= {
92+
let mut cmd = Command::new("./target/debug/cargo-semver");
93+
cmd.args(&["-S", &old_version, "-C", &new_version])
94+
.env("RUST_BACKTRACE", "full")
95+
.stdin(Stdio::null())
96+
.stdout(out_pipe)
97+
.stderr(err_pipe);
98+
99+
if let Ok(target) = std::env::var("TEST_TARGET") {
100+
cmd.args(&["--target", &target]);
101+
}
102+
103+
cmd.status().expect("could not run cargo semver").success()
104+
};
100105

101106
assert!(success, "cargo semver");
102107

0 commit comments

Comments
 (0)