diff --git a/.github/scripts/tests.sh b/.github/scripts/tests.sh index a2feca2f9..39ef1afa6 100755 --- a/.github/scripts/tests.sh +++ b/.github/scripts/tests.sh @@ -7,7 +7,13 @@ unset CARGO_HOME # Install binaries using cargo-binstall # shellcheck disable=SC2086 -"./$1" binstall --log-level debug --no-confirm b3sum cargo-release cargo-binstall cargo-watch miniserve +"./$1" binstall --log-level debug --no-confirm \ + b3sum \ + cargo-release \ + cargo-binstall \ + cargo-watch \ + miniserve \ + sccache # Test that the installed binaries can be run b3sum --version diff --git a/crates/binstalk/src/bins.rs b/crates/binstalk/src/bins.rs index 939ba966a..0185478b8 100644 --- a/crates/binstalk/src/bins.rs +++ b/crates/binstalk/src/bins.rs @@ -52,7 +52,7 @@ pub fn infer_bin_dir_template(data: &Data) -> Cow<'static, str> { possible_dirs .into_iter() - .find(|dirname| Path::new(dirname).is_dir()) + .find(|dirname| data.bin_path.join(dirname).is_dir()) .map(|mut dir| { dir.reserve_exact(1 + default_bin_dir_template.len()); dir += "/"; @@ -68,7 +68,6 @@ pub struct BinFile { pub source: PathBuf, pub dest: PathBuf, pub link: Option, - pub pkg_fmt: Option, } impl BinFile { @@ -96,9 +95,7 @@ impl BinFile { binary_ext, }; - let pkg_fmt = data.meta.pkg_fmt; - - let source = if pkg_fmt == Some(PkgFmt::Bin) { + let source = if data.meta.pkg_fmt == Some(PkgFmt::Bin) { data.bin_path.clone() } else { // Generate install paths @@ -140,7 +137,6 @@ impl BinFile { source, dest, link, - pkg_fmt, }) } @@ -184,13 +180,11 @@ impl BinFile { self.dest.display() ); - if self.pkg_fmt == Some(PkgFmt::Bin) { - #[cfg(unix)] - fs::set_permissions( - &self.source, - std::os::unix::fs::PermissionsExt::from_mode(0o755), - )?; - } + #[cfg(unix)] + fs::set_permissions( + &self.source, + std::os::unix::fs::PermissionsExt::from_mode(0o755), + )?; atomic_install(&self.source, &self.dest)?; diff --git a/crates/binstalk/src/ops/resolve.rs b/crates/binstalk/src/ops/resolve.rs index 330ac7ab3..f47dccfcc 100644 --- a/crates/binstalk/src/ops/resolve.rs +++ b/crates/binstalk/src/ops/resolve.rs @@ -327,11 +327,36 @@ async fn download_extract_and_verify( no_symlinks, )?; - for bin_file in bin_files.iter() { - bin_file.check_source_exists()?; - } + let name = &package.name; + + binaries + .iter() + .zip(bin_files) + .filter_map(|(bin, bin_file)| { + match bin_file.check_source_exists() { + Ok(()) => Some(Ok(bin_file)), - Ok(bin_files) + // This binary is optional + Err(err) => { + let required_features = &bin.required_features; + + if required_features.is_empty() { + // This bin is not optional, error + Some(Err(err)) + } else { + // Optional, print a warning and continue. + let bin_name = bin.name.as_deref().unwrap(); + let features = required_features.join(","); + warn!( + "When resolving {name} bin {bin_name} is not found. \ + But since it requies features {features}, this bin is ignored." + ); + None + } + } + } + }) + .collect::, BinstallError>>() }) }