mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-04 11:10:02 +00:00
Auto detect pkg_fmt
(#310)
* Refactor: Extract `GhCrateMeta::find_baseline` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Update `Cargo.lock`: Update dep `compact_str` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix use of `fetchers`: Set `meta.pkg_fmt` using `fetcher.pkg_fmt()` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Derive `strum_macors::{Display, EnumIter}` for `PkgFmt` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Set typeof field `PkgMeta::pkg_fmt` to be `Option<PkgFmt>` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize `Fetcher::new` to take `&Arc<Data>` instead of `&Data` To avoid unnecessary `Data::clone` call in `GhCrateMeta` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize `GhCrateMeta::find_baseline`: Avoid unnecessary spawning for `let Err(_) = url` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize spawning in `GhCrateMeta::find_baseline` Ret `Option<Url>` instead of `(Url, bool)` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add new method `target_meta` to trait `Fetcher` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Simplify `resolve_inner` using `Fetcher::target_meta` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize loop in `resolve_inner`: Avoid cloning `PkgOverride` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Impl `PkgMeta::clone_without_overrides` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize `resolve_inner` loop: Use `PkgMeta::clone_without_overrides` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Simplify `Context::from_data` impl Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Extract `launch_baseline_find_tasks` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Simplify `<GhCrateMeta as Fetcher>::find` Instead of launching tasks in an opaque manner in `Self::find_baseline`, the new design returns an iterator which launches the tasks and thus have a unified `.await` point for all these tasks. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add `warn!`ing to report failure of `Context::render_url` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
b5ea9a2293
commit
6b5e8f6875
8 changed files with 106 additions and 66 deletions
|
@ -160,7 +160,7 @@ async fn resolve_inner(
|
|||
}
|
||||
}
|
||||
|
||||
let (mut meta, binaries) = (
|
||||
let (meta, binaries) = (
|
||||
package
|
||||
.metadata
|
||||
.as_ref()
|
||||
|
@ -175,23 +175,23 @@ async fn resolve_inner(
|
|||
|
||||
for target in desired_targets {
|
||||
debug!("Building metadata for target: {target}");
|
||||
let mut target_meta = meta.clone();
|
||||
let mut target_meta = meta.clone_without_overrides();
|
||||
|
||||
// Merge any overrides
|
||||
if let Some(o) = target_meta.overrides.get(target).cloned() {
|
||||
target_meta.merge(&o);
|
||||
if let Some(o) = meta.overrides.get(target) {
|
||||
target_meta.merge(o);
|
||||
}
|
||||
|
||||
target_meta.merge(&opts.cli_overrides);
|
||||
debug!("Found metadata: {target_meta:?}");
|
||||
|
||||
let fetcher_data = Data {
|
||||
let fetcher_data = Arc::new(Data {
|
||||
name: package.name.clone(),
|
||||
target: target.clone(),
|
||||
version: package.version.clone(),
|
||||
repo: package.repository.clone(),
|
||||
meta: target_meta,
|
||||
};
|
||||
});
|
||||
|
||||
fetchers.add(GhCrateMeta::new(&client, &fetcher_data).await);
|
||||
fetchers.add(QuickInstall::new(&client, &fetcher_data).await);
|
||||
|
@ -200,11 +200,7 @@ async fn resolve_inner(
|
|||
let resolution = match fetchers.first_available().await {
|
||||
Some(fetcher) => {
|
||||
// Build final metadata
|
||||
let fetcher_target = fetcher.target();
|
||||
if let Some(o) = meta.overrides.get(&fetcher_target.to_owned()).cloned() {
|
||||
meta.merge(&o);
|
||||
}
|
||||
meta.merge(&opts.cli_overrides);
|
||||
let meta = fetcher.target_meta();
|
||||
|
||||
// Generate temporary binary path
|
||||
let bin_path = temp_dir.join(format!("bin-{}", crate_name.name));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue