mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-14 14:46:37 +00:00
Address feedback, make e2e-test test both source/non-source.
This commit is contained in:
parent
a27560fce9
commit
90578aa10d
4 changed files with 44 additions and 13 deletions
|
@ -157,7 +157,10 @@ pub fn install_crates(
|
||||||
desired_targets,
|
desired_targets,
|
||||||
resolvers,
|
resolvers,
|
||||||
cargo_install_fallback,
|
cargo_install_fallback,
|
||||||
bins: args.bin,
|
bins: args.bin.map(|mut bins| {
|
||||||
|
bins.sort();
|
||||||
|
bins
|
||||||
|
}),
|
||||||
|
|
||||||
temp_dir: temp_dir.path().to_owned(),
|
temp_dir: temp_dir.path().to_owned(),
|
||||||
install_path,
|
install_path,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::{path::PathBuf, sync::Arc, time::Duration};
|
use std::{path::PathBuf, sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
use compact_str::CompactString;
|
||||||
use semver::VersionReq;
|
use semver::VersionReq;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -44,6 +45,8 @@ pub struct Options {
|
||||||
pub desired_targets: DesiredTargets,
|
pub desired_targets: DesiredTargets,
|
||||||
pub resolvers: Vec<Resolver>,
|
pub resolvers: Vec<Resolver>,
|
||||||
pub cargo_install_fallback: bool,
|
pub cargo_install_fallback: bool,
|
||||||
|
|
||||||
|
/// If provided, the names are sorted.
|
||||||
pub bins: Option<Vec<CompactString>>,
|
pub bins: Option<Vec<CompactString>>,
|
||||||
|
|
||||||
pub temp_dir: PathBuf,
|
pub temp_dir: PathBuf,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{borrow::Cow, env, ffi::OsStr, fmt, iter, path::Path, sync::Arc};
|
use std::{borrow::Cow, env, ffi::OsStr, fmt, iter, path::Path, sync::Arc};
|
||||||
|
|
||||||
|
use binstalk_bins::BinFile;
|
||||||
use command_group::AsyncCommandGroup;
|
use command_group::AsyncCommandGroup;
|
||||||
use compact_str::{CompactString, ToCompactString};
|
use compact_str::{CompactString, ToCompactString};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
|
@ -87,19 +88,27 @@ impl ResolutionFetch {
|
||||||
current_version: self.new_version,
|
current_version: self.new_version,
|
||||||
source: self.source,
|
source: self.source,
|
||||||
target: self.fetcher.target().to_compact_string(),
|
target: self.fetcher.target().to_compact_string(),
|
||||||
bins: opts
|
bins: Self::resolve_bins(&opts.bins, &self.bin_files),
|
||||||
.bins
|
|
||||||
.as_ref()
|
|
||||||
.map(|bins| bins.iter().cloned().map(Into::into).collect())
|
|
||||||
.unwrap_or_else(|| {
|
|
||||||
self.bin_files
|
|
||||||
.into_iter()
|
|
||||||
.map(|bin| bin.base_name)
|
|
||||||
.collect()
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_bins(
|
||||||
|
user_specified_bins: &Option<Vec<CompactString>>,
|
||||||
|
crate_bin_files: &[BinFile],
|
||||||
|
) -> Vec<CompactString> {
|
||||||
|
// We need to filter crate_bin_files by user_specified_bins in case the prebuilt doesn't
|
||||||
|
// have featured-gated (optional) binary (gated behind feature).
|
||||||
|
crate_bin_files
|
||||||
|
.iter()
|
||||||
|
.map(|bin| bin.base_name.clone())
|
||||||
|
.filter(|bin_name| {
|
||||||
|
user_specified_bins
|
||||||
|
.as_ref()
|
||||||
|
.map_or(true, |bins| bins.binary_search(bin_name).is_ok())
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print(&self, opts: &Options) {
|
pub fn print(&self, opts: &Options) {
|
||||||
let fetcher = &self.fetcher;
|
let fetcher = &self.fetcher;
|
||||||
let bin_files = &self.bin_files;
|
let bin_files = &self.bin_files;
|
||||||
|
@ -190,6 +199,10 @@ impl ResolutionSource {
|
||||||
cmd.arg("--no-track");
|
cmd.arg("--no-track");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(bins) = &opts.bins {
|
||||||
|
cmd.args(bins.iter().flat_map(|bin| ["--bin", bin.as_ref()]));
|
||||||
|
}
|
||||||
|
|
||||||
debug!("Running `{}`", format_cmd(&cmd));
|
debug!("Running `{}`", format_cmd(&cmd));
|
||||||
|
|
||||||
if !opts.dry_run {
|
if !opts.dry_run {
|
||||||
|
|
|
@ -8,8 +8,20 @@ CARGO_HOME=$(mktemp -d 2>/dev/null || mktemp -d -t 'cargo-home')
|
||||||
export CARGO_HOME
|
export CARGO_HOME
|
||||||
export PATH="$CARGO_HOME/bin:$PATH"
|
export PATH="$CARGO_HOME/bin:$PATH"
|
||||||
|
|
||||||
# Install a specific binary (e.g., ripgrep)
|
# Install a specific binary, ensuring we don't fallback to source.
|
||||||
"./$1" binstall --no-confirm ripgrep --bin rg
|
"./$1" binstall --no-confirm taplo-cli --bin taplo --disable-strategies compile
|
||||||
|
|
||||||
|
# Verify that the binary was installed and is executable
|
||||||
|
if ! command -v taplo >/dev/null 2>&1; then
|
||||||
|
echo "taplo was not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the binary to check it works
|
||||||
|
taplo --version
|
||||||
|
|
||||||
|
# Install a specific binary, but always compile from source.
|
||||||
|
"./$1" binstall --no-confirm ripgrep --bin rg --strategies compile
|
||||||
|
|
||||||
# Verify that the binary was installed and is executable
|
# Verify that the binary was installed and is executable
|
||||||
if ! command -v rg >/dev/null 2>&1; then
|
if ! command -v rg >/dev/null 2>&1; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue