mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-16 23:56:37 +00:00
Add support to disable strategies via crate Cargo.toml
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
ac19952110
commit
f7643e1da1
6 changed files with 36 additions and 2 deletions
|
@ -85,6 +85,7 @@ pub fn install_crates(
|
||||||
pkg_url: args.pkg_url,
|
pkg_url: args.pkg_url,
|
||||||
pkg_fmt: args.pkg_fmt,
|
pkg_fmt: args.pkg_fmt,
|
||||||
bin_dir: args.bin_dir,
|
bin_dir: args.bin_dir,
|
||||||
|
disabled_strategies: None,
|
||||||
signing: None,
|
signing: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{borrow::Cow, fmt, iter, path::Path, sync::Arc};
|
use std::{borrow::Cow, fmt, iter, path::Path, sync::Arc};
|
||||||
|
|
||||||
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhReleaseArtifact, GhReleaseArtifactUrl};
|
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhReleaseArtifact, GhReleaseArtifactUrl};
|
||||||
|
use binstalk_types::cargo_toml_binstall::Strategy;
|
||||||
use compact_str::{CompactString, ToCompactString};
|
use compact_str::{CompactString, ToCompactString};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use leon::Template;
|
use leon::Template;
|
||||||
|
@ -396,6 +397,10 @@ impl super::Fetcher for GhCrateMeta {
|
||||||
FETCHER_GH_CRATE_META
|
FETCHER_GH_CRATE_META
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn strategy(&self) -> Strategy {
|
||||||
|
Strategy::CrateMetaData
|
||||||
|
}
|
||||||
|
|
||||||
fn is_third_party(&self) -> bool {
|
fn is_third_party(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::{path::Path, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use binstalk_downloader::{download::DownloadError, remote::Error as RemoteError};
|
use binstalk_downloader::{download::DownloadError, remote::Error as RemoteError};
|
||||||
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhRepo, RepoInfo as GhRepoInfo};
|
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhRepo, RepoInfo as GhRepoInfo};
|
||||||
use binstalk_types::cargo_toml_binstall::SigningAlgorithm;
|
use binstalk_types::cargo_toml_binstall::{SigningAlgorithm, Strategy};
|
||||||
use thiserror::Error as ThisError;
|
use thiserror::Error as ThisError;
|
||||||
use tokio::{sync::OnceCell, task::JoinError, time::sleep};
|
use tokio::{sync::OnceCell, task::JoinError, time::sleep};
|
||||||
pub use url::ParseError as UrlParseError;
|
pub use url::ParseError as UrlParseError;
|
||||||
|
@ -134,6 +134,9 @@ pub trait Fetcher: Send + Sync {
|
||||||
/// [`Fetcher::fetch_and_extract`].
|
/// [`Fetcher::fetch_and_extract`].
|
||||||
fn fetcher_name(&self) -> &'static str;
|
fn fetcher_name(&self) -> &'static str;
|
||||||
|
|
||||||
|
/// The strategy used by this fetcher
|
||||||
|
fn strategy(&self) -> Strategy;
|
||||||
|
|
||||||
/// Should return true if the remote is from a third-party source
|
/// Should return true if the remote is from a third-party source
|
||||||
fn is_third_party(&self) -> bool;
|
fn is_third_party(&self) -> bool;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use binstalk_downloader::remote::Method;
|
use binstalk_downloader::remote::Method;
|
||||||
use binstalk_types::cargo_toml_binstall::{PkgFmt, PkgMeta, PkgSigning};
|
use binstalk_types::cargo_toml_binstall::{PkgFmt, PkgMeta, PkgSigning, Strategy};
|
||||||
use tokio::sync::OnceCell;
|
use tokio::sync::OnceCell;
|
||||||
use tracing::{error, info, trace};
|
use tracing::{error, info, trace};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -252,6 +252,10 @@ by rust officially."#,
|
||||||
"QuickInstall"
|
"QuickInstall"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn strategy(&self) -> Strategy {
|
||||||
|
Strategy::QuickInstall
|
||||||
|
}
|
||||||
|
|
||||||
fn is_third_party(&self) -> bool {
|
fn is_third_party(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,9 @@ pub struct PkgMeta {
|
||||||
/// Package signing configuration
|
/// Package signing configuration
|
||||||
pub signing: Option<PkgSigning>,
|
pub signing: Option<PkgSigning>,
|
||||||
|
|
||||||
|
/// Stratgies to disable
|
||||||
|
pub disabled_strategies: Option<Box<[Strategy]>>,
|
||||||
|
|
||||||
/// Target specific overrides
|
/// Target specific overrides
|
||||||
pub overrides: BTreeMap<String, PkgOverride>,
|
pub overrides: BTreeMap<String, PkgOverride>,
|
||||||
}
|
}
|
||||||
|
@ -118,10 +121,16 @@ impl PkgMeta {
|
||||||
.or_else(|| self.bin_dir.clone()),
|
.or_else(|| self.bin_dir.clone()),
|
||||||
|
|
||||||
signing: pkg_overrides
|
signing: pkg_overrides
|
||||||
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|pkg_override| pkg_override.signing.clone())
|
.find_map(|pkg_override| pkg_override.signing.clone())
|
||||||
.or_else(|| self.signing.clone()),
|
.or_else(|| self.signing.clone()),
|
||||||
|
|
||||||
|
disabled_strategies: pkg_overrides
|
||||||
|
.into_iter()
|
||||||
|
.find_map(|pkg_override| pkg_override.disabled_strategies.clone())
|
||||||
|
.or_else(|| self.disabled_strategies.clone()),
|
||||||
|
|
||||||
overrides: Default::default(),
|
overrides: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +151,9 @@ pub struct PkgOverride {
|
||||||
/// Path template override for binary files in packages
|
/// Path template override for binary files in packages
|
||||||
pub bin_dir: Option<String>,
|
pub bin_dir: Option<String>,
|
||||||
|
|
||||||
|
/// Stratgies to disable
|
||||||
|
pub disabled_strategies: Option<Box<[Strategy]>>,
|
||||||
|
|
||||||
/// Package signing configuration
|
/// Package signing configuration
|
||||||
pub signing: Option<PkgSigning>,
|
pub signing: Option<PkgSigning>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,8 @@ async fn resolve_inner(
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.filter_map(|(f, target_data)| {
|
.filter_map(|(f, target_data)| {
|
||||||
|
let disabled_strategies = target_data.meta.disabled_strategies.clone();
|
||||||
|
|
||||||
let fetcher = f(
|
let fetcher = f(
|
||||||
opts.client.clone(),
|
opts.client.clone(),
|
||||||
gh_api_client.clone(),
|
gh_api_client.clone(),
|
||||||
|
@ -141,6 +143,13 @@ async fn resolve_inner(
|
||||||
target_data,
|
target_data,
|
||||||
opts.signature_policy,
|
opts.signature_policy,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let Some(disabled_strategies) = disabled_strategies.as_deref() {
|
||||||
|
if disabled_strategies.contains(&fetcher.strategy()) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filter_fetcher_by_name_predicate(fetcher.fetcher_name()).then_some(fetcher)
|
filter_fetcher_by_name_predicate(fetcher.fetcher_name()).then_some(fetcher)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue