From 76797b5c2a600fe0791d61bf93fcd97cedac636b Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 13 Mar 2020 14:59:41 -0700 Subject: [PATCH] switch from bash script to rust program --- crates/cargo-test-support/src/paths.rs | 37 ++++++++++++++------------ tests/testsuite/cache_messages.rs | 7 +++-- tests/testsuite/check.rs | 28 +++++++++---------- tests/testsuite/fix.rs | 5 ++-- 4 files changed, 37 insertions(+), 40 deletions(-) diff --git a/crates/cargo-test-support/src/paths.rs b/crates/cargo-test-support/src/paths.rs index ea9eb3d3549..64886dd6eb5 100644 --- a/crates/cargo-test-support/src/paths.rs +++ b/crates/cargo-test-support/src/paths.rs @@ -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"; @@ -265,21 +266,23 @@ pub fn sysroot() -> String { sysroot.trim().to_string() } -#[cfg(unix)] -pub fn echo_wrapper() -> std::io::Result { - 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::>(); + 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") } diff --git a/tests/testsuite/cache_messages.rs b/tests/testsuite/cache_messages.rs index 1217cb4ae76..0503306b943 100644 --- a/tests/testsuite/cache_messages.rs +++ b/tests/testsuite/cache_messages.rs @@ -447,7 +447,6 @@ fn caching_large_output() { } #[cargo_test] -#[cfg(unix)] fn rustc_workspace_wrapper() { use cargo_test_support::paths; @@ -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 @@ -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 [..]") diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 69a33241070..aecf66105c6 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -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() @@ -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() @@ -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() @@ -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() @@ -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(); diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index e1af41732b4..2fe1fd783fd 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -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() @@ -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(); }