Refactor: Extract new crate binstalk-manifests (#511)
* Refactor: Extract new crate binstalk-manifests * Fix clippy warning in mod `binstall_crates_v1` * Rm unused deps in binstalk * Update release-pr Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
565be9ae4c
commit
fc6d9ab956
|
@ -9,6 +9,7 @@ on:
|
|||
options:
|
||||
- bin
|
||||
- binstalk
|
||||
- binstalk-manifests
|
||||
- detect-targets
|
||||
- detect-wasi
|
||||
- fs-lock
|
||||
|
|
|
@ -109,6 +109,7 @@ name = "binstalk"
|
|||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"binstalk-manifests",
|
||||
"binstall-tar",
|
||||
"bytes",
|
||||
"bzip2",
|
||||
|
@ -119,7 +120,6 @@ dependencies = [
|
|||
"digest",
|
||||
"env_logger",
|
||||
"flate2",
|
||||
"fs-lock",
|
||||
"futures-util",
|
||||
"generic-array",
|
||||
"home",
|
||||
|
@ -134,15 +134,11 @@ dependencies = [
|
|||
"scopeguard",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde-tuple-vec-map",
|
||||
"serde_json",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tinytemplate",
|
||||
"tokio",
|
||||
"toml_edit",
|
||||
"tower",
|
||||
"trust-dns-resolver",
|
||||
"url",
|
||||
|
@ -151,6 +147,28 @@ dependencies = [
|
|||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "binstalk-manifests"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"compact_str",
|
||||
"detect-targets",
|
||||
"fs-lock",
|
||||
"home",
|
||||
"miette",
|
||||
"once_cell",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde-tuple-vec-map",
|
||||
"serde_json",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"toml_edit",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "binstall-tar"
|
||||
version = "0.4.39"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
members = [
|
||||
"crates/bin",
|
||||
"crates/binstalk",
|
||||
"crates/binstalk-manifests",
|
||||
"crates/detect-wasi",
|
||||
"crates/fs-lock",
|
||||
"crates/normalize-path",
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
[package]
|
||||
name = "binstalk-manifests"
|
||||
description = "The binstall toolkit for manipulating with manifest"
|
||||
repository = "https://github.com/cargo-bins/cargo-binstall"
|
||||
documentation = "https://docs.rs/binstalk-manifests"
|
||||
version = "0.1.0"
|
||||
rust-version = "1.61.0"
|
||||
authors = ["ryan <ryan@kurte.nz>"]
|
||||
edition = "2021"
|
||||
license = "GPL-3.0"
|
||||
|
||||
[dependencies]
|
||||
compact_str = { version = "0.6.0", features = ["serde"] }
|
||||
fs-lock = { version = "0.1.0", path = "../fs-lock" }
|
||||
home = "0.5.4"
|
||||
miette = "5.4.1"
|
||||
once_cell = "1.16.0"
|
||||
semver = { version = "1.0.14", features = ["serde"] }
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
serde-tuple-vec-map = "1.0.1"
|
||||
serde_json = "1.0.87"
|
||||
strum = "0.24.1"
|
||||
strum_macros = "0.24.3"
|
||||
thiserror = "1.0.37"
|
||||
toml_edit = { version = "0.15.0", features = ["easy"] }
|
||||
url = { version = "2.3.1", features = ["serde"] }
|
||||
|
||||
[dev-dependencies]
|
||||
detect-targets = { version = "0.1.2", path = "../detect-targets" }
|
||||
tempfile = "3.3.0"
|
|
@ -20,7 +20,7 @@ use miette::Diagnostic;
|
|||
use serde::Serialize;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::fs::create_if_not_exist;
|
||||
use crate::helpers::create_if_not_exist;
|
||||
|
||||
use super::crate_info::CrateInfo;
|
||||
|
||||
|
@ -171,7 +171,7 @@ impl<'a> IntoIterator for &'a Records {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::manifests::crate_info::CrateSource;
|
||||
use crate::crate_info::CrateSource;
|
||||
|
||||
use compact_str::CompactString;
|
||||
use detect_targets::TARGET;
|
||||
|
@ -224,14 +224,14 @@ mod test {
|
|||
},
|
||||
];
|
||||
|
||||
append_to_path(&path, metadata_vec.clone()).unwrap();
|
||||
append_to_path(path, metadata_vec.clone()).unwrap();
|
||||
|
||||
let mut iter = metadata_vec.into_iter();
|
||||
iter.next().unwrap();
|
||||
|
||||
let mut metadata_set: BTreeSet<_> = iter.collect();
|
||||
|
||||
let mut records = Records::load_from_path(&path).unwrap();
|
||||
let mut records = Records::load_from_path(path).unwrap();
|
||||
assert_records_eq!(&records, &metadata_set);
|
||||
|
||||
records.remove("b");
|
||||
|
@ -239,7 +239,7 @@ mod test {
|
|||
records.overwrite().unwrap();
|
||||
|
||||
metadata_set.remove("b");
|
||||
let records = Records::load_from_path(&path).unwrap();
|
||||
let records = Records::load_from_path(path).unwrap();
|
||||
assert_records_eq!(&records, &metadata_set);
|
||||
// Drop the exclusive file lock
|
||||
drop(records);
|
||||
|
@ -253,10 +253,10 @@ mod test {
|
|||
bins: vec!["1".into(), "2".into()],
|
||||
other: Default::default(),
|
||||
};
|
||||
append_to_path(&path, [new_metadata.clone()]).unwrap();
|
||||
append_to_path(path, [new_metadata.clone()]).unwrap();
|
||||
metadata_set.insert(new_metadata);
|
||||
|
||||
let records = Records::load_from_path(&path).unwrap();
|
||||
let records = Records::load_from_path(path).unwrap();
|
||||
assert_records_eq!(&records, &metadata_set);
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ use miette::Diagnostic;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::fs::create_if_not_exist;
|
||||
use crate::helpers::create_if_not_exist;
|
||||
|
||||
use super::crate_info::CrateInfo;
|
||||
|
||||
|
@ -131,7 +131,7 @@ pub enum CratesTomlParseError {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::manifests::crate_info::CrateSource;
|
||||
use crate::crate_info::CrateSource;
|
||||
|
||||
use detect_targets::TARGET;
|
||||
use semver::Version;
|
|
@ -8,8 +8,8 @@ use thiserror::Error;
|
|||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
helpers::statics::cratesio_url,
|
||||
manifests::crate_info::{CrateInfo, CrateSource, SourceType},
|
||||
crate_info::{CrateInfo, CrateSource, SourceType},
|
||||
helpers::cratesio_url,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
|
|
@ -7,7 +7,7 @@ use semver::Version;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
use crate::helpers::statics::cratesio_url;
|
||||
use crate::helpers::cratesio_url;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct CrateInfo {
|
|
@ -0,0 +1,25 @@
|
|||
use std::{fs, io, path::Path};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use url::Url;
|
||||
|
||||
/// Returned file is readable and writable.
|
||||
pub(crate) fn create_if_not_exist(path: impl AsRef<Path>) -> io::Result<fs::File> {
|
||||
let path = path.as_ref();
|
||||
|
||||
let mut options = fs::File::options();
|
||||
options.read(true).write(true);
|
||||
|
||||
options
|
||||
.clone()
|
||||
.create_new(true)
|
||||
.open(path)
|
||||
.or_else(|_| options.open(path))
|
||||
}
|
||||
|
||||
pub(crate) fn cratesio_url() -> &'static Url {
|
||||
static CRATESIO: Lazy<Url, fn() -> Url> =
|
||||
Lazy::new(|| Url::parse("https://github.com/rust-lang/crates.io-index").unwrap());
|
||||
|
||||
&CRATESIO
|
||||
}
|
|
@ -8,6 +8,8 @@
|
|||
//! [Binstall's `.crates-v1.json`][binstall_crates_v1]);
|
||||
//! - manifests that specify which packages _to_ install (currently none).
|
||||
|
||||
mod helpers;
|
||||
|
||||
pub mod binstall_crates_v1;
|
||||
pub mod cargo_crates_v1;
|
||||
pub mod cargo_toml_binstall;
|
|
@ -11,6 +11,7 @@ license = "GPL-3.0"
|
|||
|
||||
[dependencies]
|
||||
async-trait = "0.1.58"
|
||||
binstalk-manifests = { version = "0.1.0", path = "../binstalk-manifests" }
|
||||
bytes = "1.2.1"
|
||||
bzip2 = "0.4.3"
|
||||
cargo_toml = "0.13.0"
|
||||
|
@ -19,7 +20,6 @@ crates_io_api = { version = "0.8.1", default-features = false }
|
|||
detect-targets = { version = "0.1.2", path = "../detect-targets" }
|
||||
digest = "0.10.5"
|
||||
flate2 = { version = "1.0.24", default-features = false }
|
||||
fs-lock = { version = "0.1.0", path = "../fs-lock" }
|
||||
futures-util = { version = "0.3.25", default-features = false, features = ["std"] }
|
||||
generic-array = "0.14.6"
|
||||
home = "0.5.4"
|
||||
|
@ -34,10 +34,7 @@ reqwest = { version = "0.11.12", features = ["stream", "gzip", "brotli", "deflat
|
|||
scopeguard = "1.1.0"
|
||||
semver = { version = "1.0.14", features = ["serde"] }
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
serde-tuple-vec-map = "1.0.1"
|
||||
serde_json = "1.0.87"
|
||||
strum = "0.24.1"
|
||||
strum_macros = "0.24.3"
|
||||
# Use a fork here since we need PAX support, but the upstream
|
||||
# does not hav the PR merged yet.
|
||||
#
|
||||
|
@ -48,7 +45,6 @@ thiserror = "1.0.37"
|
|||
tinytemplate = "1.2.1"
|
||||
# parking_lot - for OnceCell::const_new
|
||||
tokio = { version = "1.21.2", features = ["macros", "rt", "process", "sync", "signal", "time", "parking_lot"], default-features = false }
|
||||
toml_edit = { version = "0.15.0", features = ["easy"] }
|
||||
tower = { version = "0.4.13", features = ["limit", "util"] }
|
||||
trust-dns-resolver = { version = "0.21.2", optional = true, default-features = false, features = ["dnssec-ring"] }
|
||||
url = { version = "2.3.1", features = ["serde"] }
|
||||
|
|
|
@ -3,20 +3,6 @@ use std::{fs, io, path::Path};
|
|||
use log::debug;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
/// Returned file is readable and writable.
|
||||
pub fn create_if_not_exist(path: impl AsRef<Path>) -> io::Result<fs::File> {
|
||||
let path = path.as_ref();
|
||||
|
||||
let mut options = fs::File::options();
|
||||
options.read(true).write(true);
|
||||
|
||||
options
|
||||
.clone()
|
||||
.create_new(true)
|
||||
.open(path)
|
||||
.or_else(|_| options.open(path))
|
||||
}
|
||||
|
||||
/// Atomically install a file.
|
||||
///
|
||||
/// This is a blocking function, must be called in `block_in_place` mode.
|
||||
|
|
|
@ -2,5 +2,4 @@ pub mod download;
|
|||
pub mod jobserver_client;
|
||||
pub mod remote;
|
||||
pub mod signal;
|
||||
pub mod statics;
|
||||
pub mod tasks;
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use url::Url;
|
||||
|
||||
pub fn cratesio_url() -> &'static Url {
|
||||
static CRATESIO: Lazy<Url, fn() -> Url> =
|
||||
Lazy::new(|| Url::parse("https://github.com/rust-lang/crates.io-index").unwrap());
|
||||
|
||||
&CRATESIO
|
||||
}
|
|
@ -4,8 +4,8 @@ pub mod errors;
|
|||
pub mod fetchers;
|
||||
pub mod fs;
|
||||
pub mod helpers;
|
||||
pub mod manifests;
|
||||
pub mod ops;
|
||||
|
||||
pub use binstalk_manifests as manifests;
|
||||
pub use detect_targets::{get_desired_targets, DesiredTargets};
|
||||
pub use home;
|
||||
|
|
Loading…
Reference in New Issue