Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
switch from bash script to rust program
  • Loading branch information
yaahc committed Mar 13, 2020
commit 76797b5c2a600fe0791d61bf93fcd97cedac636b
37 changes: 20 additions & 17 deletions crates/cargo-test-support/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
use crate::{basic_manifest, project};

static CARGO_INTEGRATION_TEST_DIR: &str = "cit";

Expand Down Expand Up @@ -265,21 +266,23 @@ pub fn sysroot() -> String {
sysroot.trim().to_string()
}

#[cfg(unix)]
pub fn echo_wrapper() -> std::io::Result<std::path::PathBuf> {
use std::os::unix::fs::PermissionsExt;
let wrapper_path = root().join("rustc-echo-wrapper");
std::fs::write(
&wrapper_path,
r#"#! /bin/bash

echo "WRAPPER CALLED: $*"
"$@""#,
)?;

let mut perms = std::fs::metadata(&wrapper_path)?.permissions();
perms.set_mode(0o755);
std::fs::set_permissions(&wrapper_path, perms)?;

Ok(wrapper_path)
pub fn echo_wrapper() -> std::path::PathBuf {
let p = project()
.at("rustc-echo-wrapper")
.file("Cargo.toml", &basic_manifest("rustc-echo-wrapper", "1.0.0"))
.file(
"src/main.rs",
r#"
fn main() {
let args = std::env::args().collect::<Vec<_>>();
eprintln!("WRAPPER CALLED: {}", args[1..].join(" "));
let status = std::process::Command::new(&args[1])
.args(&args[2..]).status().unwrap();
std::process::exit(status.code().unwrap_or(1));
}
"#,
)
.build();
p.cargo("build").run();
p.bin("rustc-echo-wrapper")
}
7 changes: 3 additions & 4 deletions tests/testsuite/cache_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ fn caching_large_output() {
}

#[cargo_test]
#[cfg(unix)]
fn rustc_workspace_wrapper() {
use cargo_test_support::paths;

Expand All @@ -460,9 +459,9 @@ fn rustc_workspace_wrapper() {
.build();

p.cargo("check -Zunstable-options -v")
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper().unwrap())
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
.masquerade_as_nightly_cargo()
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name foo src/lib.rs [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name foo src/lib.rs [..]")
.run();

// Check without a wrapper should rebuild
Expand All @@ -479,7 +478,7 @@ fn rustc_workspace_wrapper() {

// Again, reading from the cache.
p.cargo("check -Zunstable-options -v")
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper().unwrap())
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
.masquerade_as_nightly_cargo()
.with_stderr_contains("[FRESH] foo [..]")
.with_stdout_does_not_contain("WRAPPER CALLED: rustc --crate-name foo src/lib.rs [..]")
Expand Down
28 changes: 12 additions & 16 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ fn error_from_deep_recursion() -> Result<(), fmt::Error> {
}

#[cargo_test]
#[cfg(unix)]
fn rustc_workspace_wrapper_affects_all_workspace_members() {
use cargo_test_support::paths;
let p = project()
Expand All @@ -801,15 +800,14 @@ fn rustc_workspace_wrapper_affects_all_workspace_members() {
.build();

p.cargo("check -Zunstable-options")
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper().unwrap())
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
.masquerade_as_nightly_cargo()
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name baz [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name baz [..]")
.run();
}

#[cargo_test]
#[cfg(unix)]
fn rustc_workspace_wrapper_includes_path_deps() {
use cargo_test_support::paths;
let p = project()
Expand All @@ -836,16 +834,15 @@ fn rustc_workspace_wrapper_includes_path_deps() {
.build();

p.cargo("check --workspace -Zunstable-options")
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper().unwrap())
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
.masquerade_as_nightly_cargo()
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name foo [..]")
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name baz [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name foo [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name baz [..]")
.run();
}

#[cargo_test]
#[cfg(unix)]
fn rustc_workspace_wrapper_respects_primary_units() {
use cargo_test_support::paths;
let p = project()
Expand All @@ -863,15 +860,14 @@ fn rustc_workspace_wrapper_respects_primary_units() {
.build();

p.cargo("check -p bar -Zunstable-options")
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper().unwrap())
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
.masquerade_as_nightly_cargo()
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stdout_does_not_contain("WRAPPER CALLED: rustc --crate-name baz [..]")
.run();
}

#[cargo_test]
#[cfg(unix)]
fn rustc_workspace_wrapper_excludes_published_deps() {
use cargo_test_support::paths;
let p = project()
Expand All @@ -898,10 +894,10 @@ fn rustc_workspace_wrapper_excludes_published_deps() {
Package::new("baz", "1.0.0").publish();

p.cargo("check --workspace -v -Zunstable-options")
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper().unwrap())
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
.masquerade_as_nightly_cargo()
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name foo [..]")
.with_stdout_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name foo [..]")
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
.with_stderr_contains("[CHECKING] baz [..]")
.with_stdout_does_not_contain("WRAPPER CALLED: rustc --crate-name baz [..]")
.run();
Expand Down
5 changes: 2 additions & 3 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ fn does_not_crash_with_rustc_workspace_wrapper() {
}

#[cargo_test]
#[cfg(unix)]
fn uses_workspace_wrapper_and_primary_wrapper_override() {
// We don't have /usr/bin/env on Windows.
let p = project()
Expand All @@ -1127,9 +1126,9 @@ fn uses_workspace_wrapper_and_primary_wrapper_override() {
.build();

p.cargo("fix --allow-no-vcs --verbose -Zunstable-options")
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper().unwrap())
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
.masquerade_as_nightly_cargo()
.with_stdout_contains("WRAPPER CALLED: rustc src/lib.rs --crate-name foo [..]")
.with_stderr_contains("WRAPPER CALLED: rustc src/lib.rs --crate-name foo [..]")
.run();
}

Expand Down