From 1ffc580a632ac2bb95ba4f0e815eaac7d8194d4d Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 29 Sep 2023 23:40:10 +0900 Subject: [PATCH] tests: Allow to run tests in parallel even if the LLVM tool is not installed --- .github/workflows/ci.yml | 2 +- tests/auxiliary/mod.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbf42c09..21ee09a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: with: persist-credentials: false - name: Install Rust - run: rustup toolchain add ${{ matrix.rust }} --no-self-update --component llvm-tools-preview && rustup default ${{ matrix.rust }} + run: rustup toolchain add ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} - run: rustup toolchain add nightly --no-self-update - uses: taiki-e/install-action@cargo-hack - uses: taiki-e/install-action@cargo-minimal-versions diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs index cbdd4b4f..1565ded2 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -7,6 +7,7 @@ use std::{ mem, path::{Path, PathBuf}, process::{Command, ExitStatus, Stdio}, + sync::OnceLock, }; use anyhow::{Context as _, Result}; @@ -19,7 +20,16 @@ pub fn fixtures_path() -> &'static Utf8Path { Utf8Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures")) } +fn ensure_llvm_tools_installed() { + static TEST_VERSION: OnceLock<()> = OnceLock::new(); + TEST_VERSION.get_or_init(|| { + // Install component first to avoid component installation conflicts. + let _ = Command::new("rustup").args(["component", "add", "llvm-tools-preview"]).output(); + }); +} + pub fn cargo_llvm_cov(subcommand: &str) -> Command { + ensure_llvm_tools_installed(); let mut cmd = Command::new(env!("CARGO_BIN_EXE_cargo-llvm-cov")); cmd.arg("llvm-cov"); if !subcommand.is_empty() {