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:
Jiahao XU 2022-11-08 11:50:02 +11:00 committed by GitHub
parent 565be9ae4c
commit fc6d9ab956
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 96 additions and 47 deletions

View file

@ -9,6 +9,7 @@ on:
options: options:
- bin - bin
- binstalk - binstalk
- binstalk-manifests
- detect-targets - detect-targets
- detect-wasi - detect-wasi
- fs-lock - fs-lock

28
Cargo.lock generated
View file

@ -109,6 +109,7 @@ name = "binstalk"
version = "0.4.1" version = "0.4.1"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"binstalk-manifests",
"binstall-tar", "binstall-tar",
"bytes", "bytes",
"bzip2", "bzip2",
@ -119,7 +120,6 @@ dependencies = [
"digest", "digest",
"env_logger", "env_logger",
"flate2", "flate2",
"fs-lock",
"futures-util", "futures-util",
"generic-array", "generic-array",
"home", "home",
@ -134,15 +134,11 @@ dependencies = [
"scopeguard", "scopeguard",
"semver", "semver",
"serde", "serde",
"serde-tuple-vec-map",
"serde_json",
"strum", "strum",
"strum_macros",
"tempfile", "tempfile",
"thiserror", "thiserror",
"tinytemplate", "tinytemplate",
"tokio", "tokio",
"toml_edit",
"tower", "tower",
"trust-dns-resolver", "trust-dns-resolver",
"url", "url",
@ -151,6 +147,28 @@ dependencies = [
"zstd", "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]] [[package]]
name = "binstall-tar" name = "binstall-tar"
version = "0.4.39" version = "0.4.39"

View file

@ -2,6 +2,7 @@
members = [ members = [
"crates/bin", "crates/bin",
"crates/binstalk", "crates/binstalk",
"crates/binstalk-manifests",
"crates/detect-wasi", "crates/detect-wasi",
"crates/fs-lock", "crates/fs-lock",
"crates/normalize-path", "crates/normalize-path",

View file

@ -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"

View file

@ -20,7 +20,7 @@ use miette::Diagnostic;
use serde::Serialize; use serde::Serialize;
use thiserror::Error; use thiserror::Error;
use crate::fs::create_if_not_exist; use crate::helpers::create_if_not_exist;
use super::crate_info::CrateInfo; use super::crate_info::CrateInfo;
@ -171,7 +171,7 @@ impl<'a> IntoIterator for &'a Records {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::manifests::crate_info::CrateSource; use crate::crate_info::CrateSource;
use compact_str::CompactString; use compact_str::CompactString;
use detect_targets::TARGET; 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(); let mut iter = metadata_vec.into_iter();
iter.next().unwrap(); iter.next().unwrap();
let mut metadata_set: BTreeSet<_> = iter.collect(); 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); assert_records_eq!(&records, &metadata_set);
records.remove("b"); records.remove("b");
@ -239,7 +239,7 @@ mod test {
records.overwrite().unwrap(); records.overwrite().unwrap();
metadata_set.remove("b"); 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); assert_records_eq!(&records, &metadata_set);
// Drop the exclusive file lock // Drop the exclusive file lock
drop(records); drop(records);
@ -253,10 +253,10 @@ mod test {
bins: vec!["1".into(), "2".into()], bins: vec!["1".into(), "2".into()],
other: Default::default(), other: Default::default(),
}; };
append_to_path(&path, [new_metadata.clone()]).unwrap(); append_to_path(path, [new_metadata.clone()]).unwrap();
metadata_set.insert(new_metadata); 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); assert_records_eq!(&records, &metadata_set);
} }
} }

View file

@ -22,7 +22,7 @@ use miette::Diagnostic;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
use crate::fs::create_if_not_exist; use crate::helpers::create_if_not_exist;
use super::crate_info::CrateInfo; use super::crate_info::CrateInfo;
@ -131,7 +131,7 @@ pub enum CratesTomlParseError {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::manifests::crate_info::CrateSource; use crate::crate_info::CrateSource;
use detect_targets::TARGET; use detect_targets::TARGET;
use semver::Version; use semver::Version;

View file

@ -8,8 +8,8 @@ use thiserror::Error;
use url::Url; use url::Url;
use crate::{ use crate::{
helpers::statics::cratesio_url, crate_info::{CrateInfo, CrateSource, SourceType},
manifests::crate_info::{CrateInfo, CrateSource, SourceType}, helpers::cratesio_url,
}; };
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)] #[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]

View file

@ -7,7 +7,7 @@ use semver::Version;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
use crate::helpers::statics::cratesio_url; use crate::helpers::cratesio_url;
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CrateInfo { pub struct CrateInfo {

View file

@ -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
}

View file

@ -8,6 +8,8 @@
//! [Binstall's `.crates-v1.json`][binstall_crates_v1]); //! [Binstall's `.crates-v1.json`][binstall_crates_v1]);
//! - manifests that specify which packages _to_ install (currently none). //! - manifests that specify which packages _to_ install (currently none).
mod helpers;
pub mod binstall_crates_v1; pub mod binstall_crates_v1;
pub mod cargo_crates_v1; pub mod cargo_crates_v1;
pub mod cargo_toml_binstall; pub mod cargo_toml_binstall;

View file

@ -11,6 +11,7 @@ license = "GPL-3.0"
[dependencies] [dependencies]
async-trait = "0.1.58" async-trait = "0.1.58"
binstalk-manifests = { version = "0.1.0", path = "../binstalk-manifests" }
bytes = "1.2.1" bytes = "1.2.1"
bzip2 = "0.4.3" bzip2 = "0.4.3"
cargo_toml = "0.13.0" 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" } detect-targets = { version = "0.1.2", path = "../detect-targets" }
digest = "0.10.5" digest = "0.10.5"
flate2 = { version = "1.0.24", default-features = false } 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"] } futures-util = { version = "0.3.25", default-features = false, features = ["std"] }
generic-array = "0.14.6" generic-array = "0.14.6"
home = "0.5.4" home = "0.5.4"
@ -34,10 +34,7 @@ reqwest = { version = "0.11.12", features = ["stream", "gzip", "brotli", "deflat
scopeguard = "1.1.0" scopeguard = "1.1.0"
semver = { version = "1.0.14", features = ["serde"] } semver = { version = "1.0.14", features = ["serde"] }
serde = { version = "1.0.147", features = ["derive"] } serde = { version = "1.0.147", features = ["derive"] }
serde-tuple-vec-map = "1.0.1"
serde_json = "1.0.87"
strum = "0.24.1" strum = "0.24.1"
strum_macros = "0.24.3"
# Use a fork here since we need PAX support, but the upstream # Use a fork here since we need PAX support, but the upstream
# does not hav the PR merged yet. # does not hav the PR merged yet.
# #
@ -48,7 +45,6 @@ thiserror = "1.0.37"
tinytemplate = "1.2.1" tinytemplate = "1.2.1"
# parking_lot - for OnceCell::const_new # parking_lot - for OnceCell::const_new
tokio = { version = "1.21.2", features = ["macros", "rt", "process", "sync", "signal", "time", "parking_lot"], default-features = false } 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"] } tower = { version = "0.4.13", features = ["limit", "util"] }
trust-dns-resolver = { version = "0.21.2", optional = true, default-features = false, features = ["dnssec-ring"] } trust-dns-resolver = { version = "0.21.2", optional = true, default-features = false, features = ["dnssec-ring"] }
url = { version = "2.3.1", features = ["serde"] } url = { version = "2.3.1", features = ["serde"] }

View file

@ -3,20 +3,6 @@ use std::{fs, io, path::Path};
use log::debug; use log::debug;
use tempfile::NamedTempFile; 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. /// Atomically install a file.
/// ///
/// This is a blocking function, must be called in `block_in_place` mode. /// This is a blocking function, must be called in `block_in_place` mode.

View file

@ -2,5 +2,4 @@ pub mod download;
pub mod jobserver_client; pub mod jobserver_client;
pub mod remote; pub mod remote;
pub mod signal; pub mod signal;
pub mod statics;
pub mod tasks; pub mod tasks;

View file

@ -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
}

View file

@ -4,8 +4,8 @@ pub mod errors;
pub mod fetchers; pub mod fetchers;
pub mod fs; pub mod fs;
pub mod helpers; pub mod helpers;
pub mod manifests;
pub mod ops; pub mod ops;
pub use binstalk_manifests as manifests;
pub use detect_targets::{get_desired_targets, DesiredTargets}; pub use detect_targets::{get_desired_targets, DesiredTargets};
pub use home; pub use home;