mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-30 01:00:02 +00:00
Feature: SupportdDisable of strategies for crate using Cargo.toml
(#1828)
* Refactor: Move `Strategy` to `binstalk-types` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add serialisation test for `Strategy` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add support to disable strategies via crate `Cargo.toml` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add e2e-test Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `Cargo.toml` disabled strategy checking for compile strategy Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize `resolve_inner`: Cache meta override Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add compile-time length checking for `Strategy` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * More optimization Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix order of override: cli options alwayus takes precedence Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add missing manifest for e2e-test Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
09d61d081d
commit
3f29fbe83a
11 changed files with 206 additions and 57 deletions
|
@ -18,3 +18,6 @@ serde = { version = "1.0.163", features = ["derive"] }
|
|||
strum = "0.26.1"
|
||||
strum_macros = "0.26.1"
|
||||
url = { version = "2.3.1", features = ["serde"] }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use std::{borrow::Cow, collections::BTreeMap};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::{EnumCount, VariantArray};
|
||||
|
||||
mod package_formats;
|
||||
#[doc(inline)]
|
||||
|
@ -19,6 +20,41 @@ pub struct Meta {
|
|||
pub binstall: Option<PkgMeta>,
|
||||
}
|
||||
|
||||
/// Strategies to use for binary discovery
|
||||
#[derive(
|
||||
Debug,
|
||||
Copy,
|
||||
Clone,
|
||||
Eq,
|
||||
PartialEq,
|
||||
Ord,
|
||||
PartialOrd,
|
||||
EnumCount,
|
||||
VariantArray,
|
||||
Deserialize,
|
||||
Serialize,
|
||||
)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Strategy {
|
||||
/// Attempt to download official pre-built artifacts using
|
||||
/// information provided in `Cargo.toml`.
|
||||
CrateMetaData,
|
||||
/// Query third-party QuickInstall for the crates.
|
||||
QuickInstall,
|
||||
/// Build the crates from source using `cargo-build`.
|
||||
Compile,
|
||||
}
|
||||
|
||||
impl Strategy {
|
||||
pub const fn to_str(self) -> &'static str {
|
||||
match self {
|
||||
Strategy::CrateMetaData => "crate-meta-data",
|
||||
Strategy::QuickInstall => "quick-install",
|
||||
Strategy::Compile => "compile",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Metadata for binary installation use.
|
||||
///
|
||||
/// Exposed via `[package.metadata]` in `Cargo.toml`
|
||||
|
@ -37,6 +73,9 @@ pub struct PkgMeta {
|
|||
/// Package signing configuration
|
||||
pub signing: Option<PkgSigning>,
|
||||
|
||||
/// Stratgies to disable
|
||||
pub disabled_strategies: Option<Box<[Strategy]>>,
|
||||
|
||||
/// Target specific overrides
|
||||
pub overrides: BTreeMap<String, PkgOverride>,
|
||||
}
|
||||
|
@ -82,10 +121,16 @@ impl PkgMeta {
|
|||
.or_else(|| self.bin_dir.clone()),
|
||||
|
||||
signing: pkg_overrides
|
||||
.clone()
|
||||
.into_iter()
|
||||
.find_map(|pkg_override| pkg_override.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(),
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +151,9 @@ pub struct PkgOverride {
|
|||
/// Path template override for binary files in packages
|
||||
pub bin_dir: Option<String>,
|
||||
|
||||
/// Stratgies to disable
|
||||
pub disabled_strategies: Option<Box<[Strategy]>>,
|
||||
|
||||
/// Package signing configuration
|
||||
pub signing: Option<PkgSigning>,
|
||||
}
|
||||
|
@ -141,3 +189,20 @@ pub enum SigningAlgorithm {
|
|||
/// [minisign](https://jedisct1.github.io/minisign/)
|
||||
Minisign,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::VariantArray;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_strategy_ser() {
|
||||
Strategy::VARIANTS.iter().for_each(|strategy| {
|
||||
assert_eq!(
|
||||
serde_json::to_string(&strategy).unwrap(),
|
||||
format!(r#""{}""#, strategy.to_str())
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue