mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-15 16:30:03 +00:00
Impl try multiple default bin dirs (#417)
From @passcod : * Make bin-dir an Option * Use cargo-release as a test case * WIP: Try multiple default bin dirs * Update bins.rs * Update cargo_toml_binstall.rs From @NobodyXu : * Optimize & Prepare for support multi `bin-path`s * Ensure quickinstall bin_dir work as usual. * Rm dup entries in `FULL_FILENAMES` * Add second version of `NOVERSION_FILENAMES` * Impl multiple default `bin-dir`s * Improve doc for `BinFile::from_product` * Fix tests.sh Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Co-authored-by: Félix Saparelli <felix@passcod.name>
This commit is contained in:
parent
c27c3b80b5
commit
e034d69e12
8 changed files with 88 additions and 67 deletions
|
@ -22,7 +22,7 @@ use crate::{
|
|||
|
||||
use super::Data;
|
||||
|
||||
mod hosting;
|
||||
pub(crate) mod hosting;
|
||||
use hosting::RepositoryHost;
|
||||
|
||||
pub struct GhCrateMeta {
|
||||
|
@ -143,10 +143,10 @@ impl super::Fetcher for GhCrateMeta {
|
|||
}
|
||||
|
||||
async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> {
|
||||
let (url, _pkg_fmt) = self.resolution.get().unwrap(); // find() is called first
|
||||
debug!("Downloading package from: '{url}'");
|
||||
let (url, pkg_fmt) = self.resolution.get().unwrap(); // find() is called first
|
||||
debug!("Downloading package from: '{url}' dst:{dst:?} fmt:{pkg_fmt:?}");
|
||||
Download::new(self.client.clone(), url.clone())
|
||||
.and_extract(self.pkg_fmt(), dst)
|
||||
.and_extract(*pkg_fmt, dst)
|
||||
.await
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,20 @@ pub enum RepositoryHost {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
/// Make sure to update possible_dirs in `bins::BinFile`
|
||||
/// if you modified FULL_FILENAMES or NOVERSION_FILENAMES.
|
||||
pub const FULL_FILENAMES: &[&str] = &[
|
||||
"{ name }-{ target }-v{ version }.{ archive-format }",
|
||||
"{ name }-{ target }-{ version }.{ archive-format }",
|
||||
"{ name }-{ version }-{ target }.{ archive-format }",
|
||||
"{ name }-v{ version }-{ target }.{ archive-format }",
|
||||
];
|
||||
|
||||
pub const NOVERSION_FILENAMES: &[&str] = &[
|
||||
"{ name }-{ target }.{ archive-format }",
|
||||
"{ name }.{ archive-format }",
|
||||
];
|
||||
|
||||
impl RepositoryHost {
|
||||
pub fn guess_git_hosting_services(repo: &Url) -> Result<Self, BinstallError> {
|
||||
use RepositoryHost::*;
|
||||
|
@ -27,35 +41,24 @@ impl RepositoryHost {
|
|||
pub fn get_default_pkg_url_template(self) -> Option<Vec<String>> {
|
||||
use RepositoryHost::*;
|
||||
|
||||
let full_filenames = &[
|
||||
"{ name }-{ target }-v{ version }.{ archive-format }",
|
||||
"{ name }-{ target }-{ version }.{ archive-format }",
|
||||
"{ name }-{ version }-{ target }.{ archive-format }",
|
||||
"{ name }-v{ version }-{ target }.{ archive-format }",
|
||||
"{ name }-{ version }-{ target }.{ archive-format }",
|
||||
"{ name }-v{ version }-{ target }.{ archive-format }",
|
||||
];
|
||||
|
||||
let noversion_filenames = &["{ name }-{ target }.{ archive-format }"];
|
||||
|
||||
match self {
|
||||
GitHub => Some(apply_filenames_to_paths(
|
||||
&[
|
||||
"{ repo }/releases/download/{ version }",
|
||||
"{ repo }/releases/download/v{ version }",
|
||||
],
|
||||
&[full_filenames, noversion_filenames],
|
||||
&[FULL_FILENAMES, NOVERSION_FILENAMES],
|
||||
)),
|
||||
GitLab => Some(apply_filenames_to_paths(
|
||||
&[
|
||||
"{ repo }/-/releases/{ version }/downloads/binaries",
|
||||
"{ repo }/-/releases/v{ version }/downloads/binaries",
|
||||
],
|
||||
&[full_filenames, noversion_filenames],
|
||||
&[FULL_FILENAMES, NOVERSION_FILENAMES],
|
||||
)),
|
||||
BitBucket => Some(apply_filenames_to_paths(
|
||||
&["{ repo }/downloads"],
|
||||
&[full_filenames],
|
||||
&[FULL_FILENAMES],
|
||||
)),
|
||||
SourceForge => Some(
|
||||
apply_filenames_to_paths(
|
||||
|
@ -63,7 +66,7 @@ impl RepositoryHost {
|
|||
"{ repo }/files/binaries/{ version }",
|
||||
"{ repo }/files/binaries/v{ version }",
|
||||
],
|
||||
&[full_filenames, noversion_filenames],
|
||||
&[FULL_FILENAMES, NOVERSION_FILENAMES],
|
||||
)
|
||||
.into_iter()
|
||||
.map(|url| format!("{url}/download"))
|
||||
|
|
|
@ -61,6 +61,7 @@ impl super::Fetcher for QuickInstall {
|
|||
fn target_meta(&self) -> PkgMeta {
|
||||
let mut meta = self.data.meta.clone();
|
||||
meta.pkg_fmt = Some(self.pkg_fmt());
|
||||
meta.bin_dir = Some("{ bin }{ binary-ext }".to_string());
|
||||
meta
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue