From c35d9ec1d603521f3f5bf48935178f94619f9bc2 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 11 Jun 2024 13:23:32 +0800 Subject: [PATCH 1/4] refactor: Bump MSRV to 1.75 for async in trait Signed-off-by: Xuanwo --- .github/workflows/ci.yml | 18 +++++----- Cargo.toml | 2 +- README.md | 2 +- snap/snapcraft.yaml | 74 ++++++++++++++++++++-------------------- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b8749cc4..2ba5e95be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: ci -on: [push, pull_request] +on: [ push, pull_request ] jobs: lint: @@ -9,8 +9,8 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macOS-latest, windows-latest] - component: [clippy] + os: [ ubuntu-latest, macOS-latest, windows-latest ] + component: [ clippy ] include: - component: rustfmt cargo_cmd: fmt -- --check @@ -26,7 +26,7 @@ jobs: with: components: ${{ matrix.component }} # Oldest supported version, keep in sync with README.md - toolchain: "1.70.0" + toolchain: "1.75.0" - name: clippy version run: cargo clippy --version @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - feature: [azure, gcs, gha, memcached, redis, s3, webdav] + feature: [ azure, gcs, gha, memcached, redis, s3, webdav ] steps: - name: Clone repository uses: actions/checkout@v4 @@ -67,10 +67,10 @@ jobs: include: - os: ubuntu-20.04 # Oldest supported version, keep in sync with README.md - rustc: "1.70.0" + rustc: "1.75.0" - os: ubuntu-22.04 # Oldest supported version, keep in sync with README.md - rustc: "1.70.0" + rustc: "1.75.0" extra_desc: dist-server extra_args: --no-default-features --features=dist-tests test_dist_ -- --test-threads 1 - os: ubuntu-20.04 @@ -91,7 +91,7 @@ jobs: - os: macos-14 - os: windows-2019 # Oldest supported version, keep in sync with README.md - rustc: "1.70.0" + rustc: "1.75.0" - os: windows-2019 rustc: nightly allow_failure: true @@ -330,7 +330,7 @@ jobs: release: name: release runs-on: ubuntu-latest - needs: [build, lint, test] + needs: [ build, lint, test ] if: ${{ startsWith(github.ref, 'refs/tags/') }} steps: - name: Clone repository diff --git a/Cargo.toml b/Cargo.toml index b69c47e3f..3394e054a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "sccache" -rust-version = "1.70.0" +rust-version = "1.75.0" version = "0.8.1" categories = ["command-line-utilities", "development-tools::build-utils"] diff --git a/README.md b/README.md index 1a6396be0..8fa5a6e6c 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ And you can build code as usual without any additional flags in the command line Build Requirements ------------------ -sccache is a [Rust](https://www.rust-lang.org/) program. Building it requires `cargo` (and thus`rustc`). sccache currently requires **Rust 1.70.0**. We recommend you install Rust via [Rustup](https://rustup.rs/). +sccache is a [Rust](https://www.rust-lang.org/) program. Building it requires `cargo` (and thus`rustc`). sccache currently requires **Rust 1.75.0**. We recommend you install Rust via [Rustup](https://rustup.rs/). Build ----- diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index ee928c4aa..5fec59f49 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -4,22 +4,22 @@ adopt-info: sccache summary: sccache is ccache with cloud storage description: | - sccache is a ccache-like compiler caching tool. It is used as a compiler - wrapper and avoids compilation when possible, storing cached results either - on local disk or in one of several cloud storage backends. - - sccache includes support for caching the compilation of C/C++ code, Rust, as - well as NVIDIA's CUDA using nvcc. - - sccache also provides icecream-style distributed compilation (automatic - packaging of local toolchains) for all supported compilers (including Rust). - The distributed compilation system includes several security features that - icecream lacks such as authentication, transport layer encryption, and - sandboxed compiler execution on build servers. See the distributed quickstart - guide for more information. - - sccache is also available as a GitHub Actions to facilitate the deployment - using GitHub Actions cache. + sccache is a ccache-like compiler caching tool. It is used as a compiler + wrapper and avoids compilation when possible, storing cached results either + on local disk or in one of several cloud storage backends. + + sccache includes support for caching the compilation of C/C++ code, Rust, as + well as NVIDIA's CUDA using nvcc. + + sccache also provides icecream-style distributed compilation (automatic + packaging of local toolchains) for all supported compilers (including Rust). + The distributed compilation system includes several security features that + icecream lacks such as authentication, transport layer encryption, and + sandboxed compiler execution on build servers. See the distributed quickstart + guide for more information. + + sccache is also available as a GitHub Actions to facilitate the deployment + using GitHub Actions cache. website: https://github.com/mozilla/sccache contact: https://github.com/mozilla/sccache/issues license: "Apache-2.0" @@ -27,26 +27,26 @@ grade: stable confinement: classic apps: - sccache: - command: bin/sccache - sccache-dist: - command: bin/sccache-dist + sccache: + command: bin/sccache + sccache-dist: + command: bin/sccache-dist parts: - sccache: - plugin: rust - rust-channel: 1.70.0 - rust-use-global-lto: true - source: . - override-pull: | - craftctl default - craftctl set version="$( git -C "${CRAFT_PART_SRC}" describe --tags )" - build-packages: - - libssl-dev - - make - - pkg-config - rust-features: - - all - - dist-server - build-attributes: - - enable-patchelf + sccache: + plugin: rust + rust-channel: 1.75.0 + rust-use-global-lto: true + source: . + override-pull: | + craftctl default + craftctl set version="$( git -C "${CRAFT_PART_SRC}" describe --tags )" + build-packages: + - libssl-dev + - make + - pkg-config + rust-features: + - all + - dist-server + build-attributes: + - enable-patchelf From 7157166f476c34ad55f35fa876093c780dfc0937 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 11 Jun 2024 13:29:10 +0800 Subject: [PATCH 2/4] Fix clippy Signed-off-by: Xuanwo --- src/bin/sccache-dist/build.rs | 50 +++++++++++++-------------- src/bin/sccache-dist/cmdline/parse.rs | 2 +- src/bin/sccache-dist/main.rs | 4 +-- tests/dist.rs | 2 +- tests/harness/mod.rs | 22 ++++++------ 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/bin/sccache-dist/build.rs b/src/bin/sccache-dist/build.rs index c670d7ed5..815674661 100644 --- a/src/bin/sccache-dist/build.rs +++ b/src/bin/sccache-dist/build.rs @@ -351,8 +351,8 @@ impl OverlayBuilder { // first, otherwise proc and dev get hidden let mut cmd = Command::new(bubblewrap); cmd.arg("--die-with-parent") - .args(&["--cap-drop", "ALL"]) - .args(&[ + .args(["--cap-drop", "ALL"]) + .args([ "--unshare-user", "--unshare-cgroup", "--unshare-ipc", @@ -363,8 +363,8 @@ impl OverlayBuilder { .arg("--bind") .arg(&target_dir) .arg("/") - .args(&["--proc", "/proc"]) - .args(&["--dev", "/dev"]) + .args(["--proc", "/proc"]) + .args(["--dev", "/dev"]) .arg("--chdir") .arg(cwd); @@ -467,7 +467,7 @@ const DOCKER_SHELL_INIT: &str = "while true; do /busybox sleep 365d && /busybox // Check the diff and clean up the FS fn docker_diff(cid: &str) -> Result { Command::new("docker") - .args(&["diff", cid]) + .args(["diff", cid]) .check_stdout_trim() .context("Failed to Docker diff container") } @@ -475,7 +475,7 @@ fn docker_diff(cid: &str) -> Result { // Force remove the container fn docker_rm(cid: &str) -> Result<()> { Command::new("docker") - .args(&["rm", "-f", cid]) + .args(["rm", "-f", cid]) .check_run() .context("Failed to force delete container") } @@ -506,7 +506,7 @@ impl DockerBuilder { info!("Performing initial Docker cleanup"); let containers = Command::new("docker") - .args(&["ps", "-a", "--format", "{{.ID}} {{.Image}}"]) + .args(["ps", "-a", "--format", "{{.ID}} {{.Image}}"]) .check_stdout_trim() .context("Unable to list all Docker containers")?; if !containers.is_empty() { @@ -519,7 +519,7 @@ impl DockerBuilder { let image_name = iter .next() .context("Malformed container listing - no image name")?; - if iter.next() != None { + if iter.next().is_some() { bail!("Malformed container listing - third field on row") } if image_name.starts_with("sccache-builder-") { @@ -528,7 +528,7 @@ impl DockerBuilder { } if !containers_to_rm.is_empty() { Command::new("docker") - .args(&["rm", "-f"]) + .args(["rm", "-f"]) .args(containers_to_rm) .check_run() .context("Failed to start command to remove old containers")?; @@ -536,7 +536,7 @@ impl DockerBuilder { } let images = Command::new("docker") - .args(&["images", "--format", "{{.ID}} {{.Repository}}"]) + .args(["images", "--format", "{{.ID}} {{.Repository}}"]) .check_stdout_trim() .context("Failed to list all docker images")?; if !images.is_empty() { @@ -549,7 +549,7 @@ impl DockerBuilder { let image_name = iter .next() .context("Malformed image listing - no image name")?; - if iter.next() != None { + if iter.next().is_some() { bail!("Malformed image listing - third field on row") } if image_name.starts_with("sccache-builder-") { @@ -558,7 +558,7 @@ impl DockerBuilder { } if !images_to_rm.is_empty() { Command::new("docker") - .args(&["rmi"]) + .args(["rmi"]) .args(images_to_rm) .check_run() .context("Failed to remove image")? @@ -575,7 +575,7 @@ impl DockerBuilder { fn get_container(&self, tc: &Toolchain, tccache: &Mutex) -> Result { let container = { let mut map = self.container_lists.lock().unwrap(); - map.entry(tc.clone()).or_insert_with(Vec::new).pop() + map.entry(tc.clone()).or_default().pop() }; match container { Some(cid) => Ok(cid), @@ -602,7 +602,7 @@ impl DockerBuilder { fn clean_container(&self, cid: &str) -> Result<()> { // Clean up any running processes Command::new("docker") - .args(&["exec", cid, "/busybox", "kill", "-9", "-1"]) + .args(["exec", cid, "/busybox", "kill", "-9", "-1"]) .check_run() .context("Failed to run kill on all processes in container")?; @@ -617,7 +617,7 @@ impl DockerBuilder { let changepath = iter .next() .context("Malformed container diff - no change path")?; - if iter.next() != None { + if iter.next().is_some() { bail!("Malformed container diff - third field on row") } // TODO: If files are created in this dir, it gets marked as modified. @@ -641,7 +641,7 @@ impl DockerBuilder { } lastpath = Some(changepath); if let Err(e) = Command::new("docker") - .args(&["exec", cid, "/busybox", "rm", "-rf", changepath]) + .args(["exec", cid, "/busybox", "rm", "-rf", changepath]) .check_run() { // We do a final check anyway, so just continue @@ -695,7 +695,7 @@ impl DockerBuilder { fn make_image(tc: &Toolchain, tccache: &Mutex) -> Result { let cid = Command::new("docker") - .args(&["create", BASE_DOCKER_IMAGE, "/busybox", "true"]) + .args(["create", BASE_DOCKER_IMAGE, "/busybox", "true"]) .check_stdout_trim() .context("Failed to create docker container")?; @@ -713,7 +713,7 @@ impl DockerBuilder { trace!("Copying in toolchain"); Command::new("docker") - .args(&["cp", "-", &format!("{}:/", cid)]) + .args(["cp", "-", &format!("{}:/", cid)]) .check_piped(&mut |stdin| { io::copy(&mut toolchain_rdr, stdin)?; Ok(()) @@ -723,12 +723,12 @@ impl DockerBuilder { let imagename = format!("sccache-builder-{}", &tc.archive_id); Command::new("docker") - .args(&["commit", &cid, &imagename]) + .args(["commit", &cid, &imagename]) .check_run() .context("Failed to commit container after build")?; Command::new("docker") - .args(&["rm", "-f", &cid]) + .args(["rm", "-f", &cid]) .check_run() .context("Failed to remove temporary build container")?; @@ -737,7 +737,7 @@ impl DockerBuilder { fn start_container(image: &str) -> Result { Command::new("docker") - .args(&[ + .args([ "run", "-d", image, @@ -765,7 +765,7 @@ impl DockerBuilder { trace!("copying in inputs"); Command::new("docker") - .args(&["cp", "-", &format!("{}:/", cid)]) + .args(["cp", "-", &format!("{}:/", cid)]) .check_piped(&mut |stdin| { io::copy(&mut inputs_rdr, stdin)?; Ok(()) @@ -784,7 +784,7 @@ impl DockerBuilder { trace!("creating output directories"); assert!(!output_paths.is_empty()); let mut cmd = Command::new("docker"); - cmd.args(&["exec", cid, "/busybox", "mkdir", "-p"]).arg(cwd); + cmd.args(["exec", cid, "/busybox", "mkdir", "-p"]).arg(cwd); for path in output_paths.iter() { // If it doesn't have a parent, nothing needs creating let output_parent = if let Some(p) = Path::new(path).parent() { @@ -812,7 +812,7 @@ impl DockerBuilder { cmd.arg("-e").arg(env); } let shell_cmd = "cd \"$1\" && shift && exec \"$@\""; - cmd.args(&[cid, "/busybox", "sh", "-c", shell_cmd]); + cmd.args([cid, "/busybox", "sh", "-c", shell_cmd]); cmd.arg(&executable); cmd.arg(cwd); cmd.arg(executable); @@ -826,7 +826,7 @@ impl DockerBuilder { let abspath = cwd.join(&path); // Resolve in case it's relative since we copy it from the root level // TODO: this isn't great, but cp gives it out as a tar let output = Command::new("docker") - .args(&["exec", cid, "/busybox", "cat"]) + .args(["exec", cid, "/busybox", "cat"]) .arg(abspath) .output() .context("Failed to start command to retrieve output file")?; diff --git a/src/bin/sccache-dist/cmdline/parse.rs b/src/bin/sccache-dist/cmdline/parse.rs index 2ba7aa3b3..54a990fb5 100644 --- a/src/bin/sccache-dist/cmdline/parse.rs +++ b/src/bin/sccache-dist/cmdline/parse.rs @@ -131,7 +131,7 @@ fn get_clap_command() -> ClapCommand { ]) .group( ArgGroup::new("key_source_mutual_exclusion") - .args(&["config", "secret-key"]) + .args(["config", "secret-key"]) .required(true), ), ) diff --git a/src/bin/sccache-dist/main.rs b/src/bin/sccache-dist/main.rs index 16f262291..83d530060 100644 --- a/src/bin/sccache-dist/main.rs +++ b/src/bin/sccache-dist/main.rs @@ -145,7 +145,7 @@ fn run(command: Command) -> Result { server_id, }) => { let header = jwt::Header::new(jwt::Algorithm::HS256); - let secret_key = BASE64_URL_SAFE_ENGINE.decode(&secret_key)?; + let secret_key = BASE64_URL_SAFE_ENGINE.decode(secret_key)?; let token = create_jwt_server_token(server_id, &header, &secret_key) .context("Failed to create server token")?; println!("{}", token); @@ -191,7 +191,7 @@ fn run(command: Command) -> Result { } scheduler_config::ServerAuth::JwtHS256 { secret_key } => { let secret_key = BASE64_URL_SAFE_ENGINE - .decode(&secret_key) + .decode(secret_key) .context("Secret key base64 invalid")?; if secret_key.len() != 256 / 8 { bail!("Size of secret key incorrect") diff --git a/tests/dist.rs b/tests/dist.rs index f9c0ec883..3db27d115 100644 --- a/tests/dist.rs +++ b/tests/dist.rs @@ -33,7 +33,7 @@ fn basic_compile(tmpdir: &Path, sccache_cfg_path: &Path, sccache_cached_cfg_path let obj_file = "x.o"; write_source(tmpdir, source_file, "#if !defined(SCCACHE_TEST_DEFINE)\n#error SCCACHE_TEST_DEFINE is not defined\n#endif\nint x() { return 5; }"); sccache_command() - .args(&[ + .args([ std::env::var("CC") .unwrap_or_else(|_| "gcc".to_string()) .as_str(), diff --git a/tests/harness/mod.rs b/tests/harness/mod.rs index 16a039847..f5997934c 100644 --- a/tests/harness/mod.rs +++ b/tests/harness/mod.rs @@ -231,7 +231,7 @@ impl DistSystem { pub fn new(sccache_dist: &Path, tmpdir: &Path) -> Self { // Make sure the docker image is available, building it if necessary let mut child = Command::new("docker") - .args(&["build", "-q", "-t", DIST_IMAGE, "-"]) + .args(["build", "-q", "-t", DIST_IMAGE, "-"]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -265,7 +265,7 @@ impl DistSystem { let scheduler_cfg_container_path = Path::new(CONFIGS_CONTAINER_PATH).join(scheduler_cfg_relpath); let scheduler_cfg = sccache_scheduler_cfg(); - fs::File::create(&scheduler_cfg_path) + fs::File::create(scheduler_cfg_path) .unwrap() .write_all(&serde_json::to_vec(&scheduler_cfg).unwrap()) .unwrap(); @@ -273,7 +273,7 @@ impl DistSystem { // Create the scheduler let scheduler_name = make_container_name("scheduler"); let output = Command::new("docker") - .args(&[ + .args([ "run", "--name", &scheduler_name, @@ -341,7 +341,7 @@ impl DistSystem { let server_name = make_container_name("server"); let output = Command::new("docker") - .args(&[ + .args([ "run", // Important for the bubblewrap builder "--privileged", @@ -436,7 +436,7 @@ impl DistSystem { match handle { ServerHandle::Container { cid, url: _ } => { let output = Command::new("docker") - .args(&["restart", cid]) + .args(["restart", cid]) .output() .unwrap(); check_output(&output); @@ -519,29 +519,29 @@ impl Drop for DistSystem { if let Some(scheduler_name) = self.scheduler_name.as_ref() { droperr!(Command::new("docker") - .args(&["logs", scheduler_name]) + .args(["logs", scheduler_name]) .output() .map(|o| logs.push((scheduler_name, o)))); droperr!(Command::new("docker") - .args(&["kill", scheduler_name]) + .args(["kill", scheduler_name]) .output() .map(|o| outputs.push((scheduler_name, o)))); droperr!(Command::new("docker") - .args(&["rm", "-f", scheduler_name]) + .args(["rm", "-f", scheduler_name]) .output() .map(|o| outputs.push((scheduler_name, o)))); } for server_name in self.server_names.iter() { droperr!(Command::new("docker") - .args(&["logs", server_name]) + .args(["logs", server_name]) .output() .map(|o| logs.push((server_name, o)))); droperr!(Command::new("docker") - .args(&["kill", server_name]) + .args(["kill", server_name]) .output() .map(|o| outputs.push((server_name, o)))); droperr!(Command::new("docker") - .args(&["rm", "-f", server_name]) + .args(["rm", "-f", server_name]) .output() .map(|o| outputs.push((server_name, o)))); } From 7883a211f72df943e152ec0a1bcd11c3369aa241 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 11 Jun 2024 13:38:11 +0800 Subject: [PATCH 3/4] Fix clippy Signed-off-by: Xuanwo --- src/compiler/diab.rs | 2 +- src/compiler/gcc.rs | 2 +- src/compiler/msvc.rs | 2 +- src/compiler/nvcc.rs | 4 ++-- src/compiler/nvhpc.rs | 4 ++-- src/compiler/tasking_vx.rs | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/diab.rs b/src/compiler/diab.rs index 951f429f9..093253cb3 100644 --- a/src/compiler/diab.rs +++ b/src/compiler/diab.rs @@ -323,7 +323,7 @@ where .args(&parsed_args.preprocessor_args) .args(&parsed_args.common_args) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { diff --git a/src/compiler/gcc.rs b/src/compiler/gcc.rs index dde1d4a58..f987e0ce0 100644 --- a/src/compiler/gcc.rs +++ b/src/compiler/gcc.rs @@ -726,7 +726,7 @@ fn preprocess_cmd( } cmd.arg(&parsed_args.input) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); debug!("cmd after -arch rewrite: {:?}", cmd); } diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 2a1824335..4ec7bf155 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -891,7 +891,7 @@ pub fn preprocess_cmd( .args(&parsed_args.dependency_args) .args(&parsed_args.common_args) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if is_clang { diff --git a/src/compiler/nvcc.rs b/src/compiler/nvcc.rs index 0514ade08..3915acea7 100644 --- a/src/compiler/nvcc.rs +++ b/src/compiler/nvcc.rs @@ -143,7 +143,7 @@ impl CCompilerImpl for Nvcc { dep_cmd .args(&transformed_deps) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { @@ -169,7 +169,7 @@ impl CCompilerImpl for Nvcc { cmd.arg("-E") .arg(no_line_num_flag) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { trace!("preprocess: {:?}", cmd); diff --git a/src/compiler/nvhpc.rs b/src/compiler/nvhpc.rs index a09eb6cac..a1fad1878 100644 --- a/src/compiler/nvhpc.rs +++ b/src/compiler/nvhpc.rs @@ -120,7 +120,7 @@ impl CCompilerImpl for Nvhpc { dep_cmd .args(&transformed_deps) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { @@ -135,7 +135,7 @@ impl CCompilerImpl for Nvhpc { //NVHPC doesn't support disabling line info when outputting to console cmd.arg("-E") .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { trace!("preprocess: {:?}", cmd); diff --git a/src/compiler/tasking_vx.rs b/src/compiler/tasking_vx.rs index 909f7b05d..0fd4bd10c 100644 --- a/src/compiler/tasking_vx.rs +++ b/src/compiler/tasking_vx.rs @@ -304,7 +304,7 @@ where .args(&parsed_args.preprocessor_args) .args(&parsed_args.common_args) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { @@ -334,7 +334,7 @@ where .args(&parsed_args.preprocessor_args) .args(&parsed_args.common_args) .env_clear() - .envs(env_vars.iter().map(|(k, v)| (k, v))) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { From d7d2d8eed9419a872214443874f7759c9062713d Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 11 Jun 2024 13:43:09 +0800 Subject: [PATCH 4/4] Remove ref_env Signed-off-by: Xuanwo --- src/compiler/compiler.rs | 4 ++-- src/compiler/rust.rs | 18 +++++++++--------- src/util.rs | 5 ----- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index d1c4692d4..a37d20775 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -31,7 +31,7 @@ use crate::dist::pkg; #[cfg(feature = "dist-client")] use crate::lru_disk_cache; use crate::mock_command::{exit_status, CommandChild, CommandCreatorSync, RunCommand}; -use crate::util::{fmt_duration_as_secs, ref_env, run_input_output}; +use crate::util::{fmt_duration_as_secs, run_input_output}; use crate::{counted_array, dist}; use async_trait::async_trait; use filetime::FileTime; @@ -1100,7 +1100,7 @@ where child.arg(&rustc_executable); } - child.env_clear().envs(ref_env(env)).args(&["-vV"]); + child.env_clear().envs(env.to_vec()).args(&["-vV"]); let rustc_vv = run_input_output(child, None).await.map(|output| { if let Ok(stdout) = String::from_utf8(output.stdout.clone()) { diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index 0a4f73905..c72fdc51b 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -26,7 +26,7 @@ use crate::dist::pkg; use crate::lru_disk_cache::{LruCache, Meter}; use crate::mock_command::{CommandCreatorSync, RunCommand}; use crate::util::{fmt_duration_as_secs, hash_all, hash_all_archives, run_input_output, Digest}; -use crate::util::{ref_env, HashToDigest, OsStrExt}; +use crate::util::{HashToDigest, OsStrExt}; use crate::{counted_array, dist}; use async_trait::async_trait; use filetime::FileTime; @@ -242,7 +242,7 @@ where .arg("-o") .arg(&dep_file) .env_clear() - .envs(ref_env(env_vars)) + .envs(env_vars.to_vec()) .current_dir(cwd); trace!("[{}]: get dep-info: {:?}", crate_name, cmd); // Output of command is in file under dep_file, so we ignore stdout&stderr @@ -364,7 +364,7 @@ where cmd.args(&arguments) .args(&["--print", "file-names"]) .env_clear() - .envs(ref_env(env_vars)) + .envs(env_vars.to_vec()) .current_dir(cwd); if log_enabled!(Trace) { trace!("get_compiler_outputs: {:?}", cmd); @@ -406,7 +406,7 @@ impl Rust { .stderr(process::Stdio::null()) .arg("--print=sysroot") .env_clear() - .envs(ref_env(env_vars)); + .envs(env_vars.to_vec()); let sysroot_and_libs = async move { let output = run_input_output(cmd, None).await?; //debug!("output.and_then: {}", output); @@ -549,7 +549,7 @@ where child .current_dir(&cwd) .env_clear() - .envs(ref_env(env)) + .envs(env.to_vec()) .args(&["which", "rustc"]); Box::pin(async move { @@ -632,7 +632,7 @@ impl RustupProxy { // verify rustc is proxy let mut child = creator.new_command_sync(compiler_executable); - child.env_clear().envs(ref_env(env)).args(&["+stable"]); + child.env_clear().envs(env.to_vec()).args(&["+stable"]); let state = run_input_output(child, None).await.map(move |output| { if output.status.success() { trace!("proxy: Found a compiler proxy managed by rustup"); @@ -695,7 +695,7 @@ impl RustupProxy { Ok(ProxyPath::Candidate(proxy_executable)) => { // verify the candidate is a rustup let mut child = creator.new_command_sync(&proxy_executable); - child.env_clear().envs(ref_env(env)).args(&["--version"]); + child.env_clear().envs(env.to_vec()).args(&["--version"]); let rustup_candidate_check = run_input_output(child, None).await?; let stdout = String::from_utf8(rustup_candidate_check.stdout) @@ -2305,7 +2305,7 @@ impl RlibDepReader { .arg(&temp_rlib) .arg("-") .env_clear() - .envs(ref_env(env_vars)); + .envs(env_vars.to_vec()); let process::Output { status, @@ -2377,7 +2377,7 @@ impl RlibDepReader { cmd.args(["-Z", "ls"]) .arg(rlib) .env_clear() - .envs(ref_env(env_vars)) + .envs(env_vars.to_vec()) .env("RUSTC_BOOTSTRAP", "1"); // TODO: this is fairly naughty let process::Output { diff --git a/src/util.rs b/src/util.rs index 18b1a15a5..4fc45af2e 100644 --- a/src/util.rs +++ b/src/util.rs @@ -833,11 +833,6 @@ impl<'a> Hasher for HashToDigest<'a> { } } -/// Turns a slice of environment var tuples into the type expected by Command::envs. -pub fn ref_env(env: &[(OsString, OsString)]) -> impl Iterator { - env.iter().map(|(k, v)| (k, v)) -} - /// Pipe `cmd`'s stdio to `/dev/null`, unless a specific env var is set. #[cfg(not(windows))] pub fn daemonize() -> Result<()> {