Skip to content

Commit

Permalink
feat: Merge branch 'windows'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Dec 1, 2023
2 parents 553852d + 8e4a6cc commit a559325
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 69 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]
name: ci

jobs:
build_and_test:
test_coverage:
name: cargo-run-bin
runs-on: ubuntu-latest
steps:
Expand All @@ -30,3 +30,26 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.info

test:
name: cargo-run-bin
strategy:
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
with:
cache-directories: ".bin"
- name: Install deps
run: |
cargo install --path .
cargo nextest --help
- name: Test
run: |
cargo build
cargo nextest run
83 changes: 49 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ name = "cargo-bin"
path = "src/main.rs"

[dependencies]
anyhow = "1.0.40"
clap = "4.3.19"
owo-colors = "3.5.0"
serde = { version = "1.0.149", features = ["derive"] }
toml = "0.5.9"
toml_edit = "0.19.14"
version_check = "0.9.3"
which = "4.4.0"
anyhow = "=1.0.40"
cfg-if = "=1.0.0"
clap = "=4.3.19"
owo-colors = "=3.5.0"
serde = { version = "=1.0.149", features = ["derive"] }
toml = "=0.5.9"
toml_edit = "=0.19.14"
version_check = "=0.9.3"
which = "=4.4.0"

[dev-dependencies]
assert_cmd = "2.0.12"
cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] }
insta = { version = "1.31.0", features = ["yaml"] }
assert_cmd = "=2.0.12"
cargo-husky = { version = "=1.5.0", default-features = false, features = ["user-hooks"] }
insta = { version = "=1.31.0", features = ["yaml"] }

[package.metadata.bin]
cargo-binstall = { version = "1.4.4" }
cargo-binstall = { version = "1.4.6" }
cargo-cmd = { version = "0.3.1" }
cargo-deny = { version = "0.13.5" }
cargo-insta = { version = "1.31.0", locked = true }
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.71.1"
channel = "1.74.0"
components = ["rustfmt", "clippy", "llvm-tools-preview"]
24 changes: 16 additions & 8 deletions src/binary.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::env;
use std::fs;
use std::io;
use std::os::fd::AsFd;
use std::path;
use std::process;

use anyhow::anyhow;
use anyhow::bail;
use anyhow::Result;
use cfg_if::cfg_if;
use version_check as rustc;
use which::which;

Expand All @@ -22,11 +22,10 @@ pub fn cargo_install(
binary_package: metadata::BinaryPackage,
cache_path: path::PathBuf,
) -> Result<()> {
let stderr = io::stderr().as_fd().try_clone_to_owned()?;
let mut cmd_prefix = process::Command::new("cargo");

cmd_prefix
.stdout::<std::process::Stdio>(stderr.into())
.stdout(io::stderr())
.stderr(process::Stdio::inherit())
.arg("install")
.arg("--root")
Expand Down Expand Up @@ -74,12 +73,10 @@ pub fn cargo_install(
}

pub fn binstall(binary_package: metadata::BinaryPackage, cache_path: path::PathBuf) -> Result<()> {
let stderr = io::stderr().as_fd().try_clone_to_owned()?;

let mut cmd_prefix = process::Command::new("cargo");

cmd_prefix
.stdout::<std::process::Stdio>(stderr.into())
.stdout(io::stderr())
.stderr(process::Stdio::inherit())
.arg("binstall")
.arg("--no-confirm")
Expand Down Expand Up @@ -130,7 +127,15 @@ pub fn install(binary_package: metadata::BinaryPackage) -> Result<String> {
.join(format!("rust-{rust_version}"))
.join(binary_package.package.clone())
.join(binary_package.version.clone());
let cache_bin_path = cache_path.join("bin").join(bin_name);

let mut cache_bin_path = cache_path.join("bin").join(bin_name);
cache_bin_path = cache_bin_path.clone();

cfg_if! {
if #[cfg(not(target_family = "unix"))] {
cache_bin_path.set_extension("exe");
}
}

if !path::Path::new(&cache_bin_path).exists() {
fs::create_dir_all(&cache_path)?;
Expand Down Expand Up @@ -161,7 +166,10 @@ pub fn run(bin_path: String, args: Vec<String>) -> Result<()> {
.to_str()
.unwrap();
if bin_name.starts_with("cargo-") {
final_args = vec![bin_name.to_string().replace("cargo-", "")];
final_args = vec![bin_name
.to_string()
.replace("cargo-", "")
.replace(".exe", "")];
final_args.append(&mut args.clone());
}

Expand Down
11 changes: 10 additions & 1 deletion src/binary_test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use cfg_if::cfg_if;

use super::*;

mod install {
Expand All @@ -15,7 +17,14 @@ mod install {
.unwrap();

let cache_bin_path = install(nextest.clone()).unwrap();
assert!(cache_bin_path.ends_with("/bin/cargo-nextest"));

cfg_if! {
if #[cfg(not(target_family = "unix"))] {
assert!(cache_bin_path.ends_with("\\bin\\cargo-nextest.exe"));
} else {
assert!(cache_bin_path.ends_with("/bin/cargo-nextest"));
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ pub fn run() -> Result<()> {
app.print_long_help()?;
} else {
let mut args: Vec<_> = env::args().collect();
let start_index = args.iter().position(|e| return e.ends_with("/cargo-bin"));
let start_index = args
.iter()
.position(|e| return e.ends_with("/cargo-bin") || e.ends_with("cargo-bin.exe"));
if start_index.is_none() || start_index.unwrap() == (args.len() + 1) {
app.print_long_help()?;
return Ok(());
Expand Down
Loading

0 comments on commit a559325

Please sign in to comment.