Split into two crates: lib and cli

That has a number of advantages:

- #193 the build.rs is only run for the CLI, so the Windows manifest is
  not embedded in the library anymore, opening it up for downstreams.

- it sets the stage for decoupling the version numbers of the CLI and
  library, to have the library increase its major more often, while the
  CLI retains compatibility further… that is, to have both follow semver

- it removes the CLI-only dependencies from the library

- it makes compilation a bit faster as compiling the library and the
  CLI's other dependencies can happen in parallel

One major disadvantage:

- installing via cargo changes from watchexec to watchexec-cli. Most
  installs are from prebuilt and from packages, but that's still a
  potential stumble.

And of course, the CLI APIs in the library are gone (they were already
deprecated, though).

We also take this opportunity to get rid of the clear_screen code and
use our new clearscreen library. #99 #171 #185
This commit is contained in:
Félix Saparelli 2021-05-01 03:27:17 +12:00
parent 898f83e29c
commit 1f3f4ada35
23 changed files with 360 additions and 80 deletions

260
Cargo.lock generated
View File

@ -54,6 +54,20 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "clearscreen"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c82f1b520b14a9bf08bcc5d20ff07adf06d7bd3f9b4d672bcbc1c386301239fe"
dependencies = [
"log",
"nix",
"terminfo",
"thiserror",
"which",
"winapi 0.3.9",
]
[[package]]
name = "darling"
version = "0.12.4"
@ -120,6 +134,33 @@ dependencies = [
"syn",
]
[[package]]
name = "dirs"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
dependencies = [
"cfg-if 0.1.10",
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.9",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "embed-resource"
version = "1.6.2"
@ -193,6 +234,28 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "getrandom"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.10.2+wasi-snapshot-preview1",
]
[[package]]
name = "glob"
version = "0.3.0"
@ -356,6 +419,16 @@ dependencies = [
"libc",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"memchr",
"version_check",
]
[[package]]
name = "notify"
version = "4.0.16"
@ -374,6 +447,50 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "phf"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12"
dependencies = [
"phf_shared",
]
[[package]]
name = "phf_codegen"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815"
dependencies = [
"phf_generator",
"phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526"
dependencies = [
"phf_shared",
"rand",
]
[[package]]
name = "phf_shared"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7"
dependencies = [
"siphasher",
]
[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "proc-macro2"
version = "1.0.26"
@ -392,6 +509,57 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom 0.1.16",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
"rand_pcg",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom 0.1.16",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_pcg"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
dependencies = [
"rand_core",
]
[[package]]
name = "redox_syscall"
version = "0.2.6"
@ -401,6 +569,16 @@ dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
"getrandom 0.2.2",
"redox_syscall",
]
[[package]]
name = "regex"
version = "1.4.6"
@ -427,6 +605,12 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "siphasher"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27"
[[package]]
name = "slab"
version = "0.4.3"
@ -460,6 +644,19 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "terminfo"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76971977e6121664ec1b960d1313aacfa75642adc93b9d4d53b247bd4cb1747e"
dependencies = [
"dirs",
"fnv",
"nom",
"phf",
"phf_codegen",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -470,6 +667,26 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-width"
version = "0.1.8"
@ -482,6 +699,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "vswhom"
version = "0.1.0"
@ -513,14 +736,24 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "watchexec"
version = "1.15.3"
dependencies = [
"clap",
"clearscreen",
"derive_builder",
"embed-resource",
"env_logger",
"glob",
"globset",
"lazy_static",
@ -531,6 +764,27 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "watchexec-cli"
version = "1.15.3"
dependencies = [
"clap",
"embed-resource",
"env_logger",
"log",
"watchexec",
]
[[package]]
name = "which"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe"
dependencies = [
"either",
"libc",
]
[[package]]
name = "winapi"
version = "0.2.8"

View File

@ -1,52 +1,8 @@
[package]
name = "watchexec"
version = "1.15.3"
authors = ["Matt Green <mattgreenrocks@gmail.com>", "Félix Saparelli <felix@passcod.name>"]
license = "Apache-2.0"
description = "Executes commands in response to file modifications"
keywords = ["watcher", "inotify", "fsevents", "kqueue"]
categories = ["command-line-utilities"]
documentation = "https://github.com/watchexec/watchexec"
homepage = "https://github.com/watchexec/watchexec"
repository = "https://github.com/watchexec/watchexec"
readme = "README.md"
edition = "2018"
exclude = ["/pkg", "/bin", "/.github"]
[[bin]]
name = "watchexec"
[dependencies]
derive_builder = "0.10.0"
glob = "0.3.0"
globset = "0.4.6"
lazy_static = "1.1.0"
log = "0.4.14"
notify = "4.0.15"
walkdir = "2.3.2"
[dependencies.clap]
version = "2.33.3"
default-features = false
features = ["wrap_help"]
[dependencies.env_logger]
version = "0.8.3"
default-features = false
features = []
[target.'cfg(unix)'.dependencies]
nix = "0.20.0"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3.9"
features = ["ioapiset", "jobapi2", "tlhelp32"]
[build-dependencies]
embed-resource = "1.6.1"
[workspace]
members = [
"lib",
"cli",
]
[profile.dev]
panic = "abort"
@ -55,12 +11,3 @@ panic = "abort"
lto = true
panic = "abort"
codegen-units = 1
[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/{ version }/{ name }-{ version }-{ target }.tar.xz"
bin-dir = "{ name }-{ version }-{ target }/{ bin }{ format }"
pkg-fmt = "txz"
[package.metadata.binstall.overrides.x86_64-pc-windows-msvc]
pkg-url = "{ repo }/releases/download/{ version }/{ name }-{ version }-{ target }.zip"
pkg-fmt = "zip"

View File

@ -101,11 +101,11 @@ On Windows, you may prefer to use Powershell:
Requires Rust 1.43 or later.
$ cargo install watchexec
$ cargo install watchexec-cli
#### [Binstall](https://github.com/ryankurte/cargo-binstall)
$ cargo binstall watchexec
$ cargo binstall watchexec-cli
#### Pre-built

View File

@ -27,8 +27,8 @@ git pull --rebase --autostash $upstream $mainbranch
echo "Fetching tags from upstream"
git fetch --tags "$upstream"
extver=$(grep -P '^version =' Cargo.toml | head -n1 | cut -d'"' -f2)
echo "(Version from Cargo.toml: $extver)"
extver=$(grep -P '^version =' cli/Cargo.toml | head -n1 | cut -d'"' -f2)
echo "(Version from cli/Cargo.toml: $extver)"
newver="$1"
@ -40,8 +40,9 @@ fi
date=$(date +%Y-%m-%d)
echo "Next version to be $newver ($date), creating..."
sed -E -i "s/version=\"$extver.0\"/version=\"$newver.0\"/1" watchexec.exe.manifest
sed -E -i "s/^version = \"$extver\"/version = \"$newver\"/1" Cargo.toml
sed -E -i "s/version=\"$extver.0\"/version=\"$newver.0\"/1" cli/watchexec.exe.manifest
sed -E -i "s/^version = \"$extver\"/version = \"$newver\"/1" cli/Cargo.toml
sed -E -i "s/^version = \"$extver\"/version = \"$newver\"/1" lib/Cargo.toml
cargo check

46
cli/Cargo.toml Normal file
View File

@ -0,0 +1,46 @@
[package]
name = "watchexec-cli"
version = "1.15.3"
authors = ["Matt Green <mattgreenrocks@gmail.com>", "Félix Saparelli <felix@passcod.name>"]
license = "Apache-2.0"
description = "Executes commands in response to file modifications"
keywords = ["watcher", "filesystem", "cli", "watchexec"]
categories = ["command-line-utilities"]
documentation = "https://github.com/watchexec/watchexec"
homepage = "https://github.com/watchexec/watchexec"
repository = "https://github.com/watchexec/watchexec"
readme = "../README.md"
edition = "2018"
[[bin]]
name = "watchexec"
path = "src/main.rs"
[dependencies]
log = "0.4.14"
watchexec = { path = "../lib" }
[dependencies.clap]
version = "2.33.3"
default-features = false
features = ["wrap_help"]
[dependencies.env_logger]
version = "0.8.3"
default-features = false
features = []
[build-dependencies]
embed-resource = "1.6.1"
[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/{ version }/watchexec-{ version }-{ target }.tar.xz"
bin-dir = "watchexec-{ version }-{ target }/{ bin }{ format }"
pkg-fmt = "txz"
[package.metadata.binstall.overrides.x86_64-pc-windows-msvc]
pkg-url = "{ repo }/releases/download/{ version }/watchexec-{ version }-{ target }.zip"
pkg-fmt = "zip"

32
lib/Cargo.toml Normal file
View File

@ -0,0 +1,32 @@
[package]
name = "watchexec"
version = "1.15.3"
authors = ["Matt Green <mattgreenrocks@gmail.com>", "Félix Saparelli <felix@passcod.name>"]
license = "Apache-2.0"
description = "Executes commands in response to file modifications"
keywords = ["watcher", "filesystem", "watchexec"]
documentation = "https://github.com/watchexec/watchexec"
homepage = "https://github.com/watchexec/watchexec"
repository = "https://github.com/watchexec/watchexec"
readme = "../README.md"
edition = "2018"
[dependencies]
clearscreen = "1.0.2"
derive_builder = "0.10.0"
glob = "0.3.0"
globset = "0.4.6"
lazy_static = "1.1.0"
log = "0.4.14"
notify = "4.0.15"
walkdir = "2.3.2"
[target.'cfg(unix)'.dependencies]
nix = "0.20.0"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3.9"
features = ["ioapiset", "jobapi2", "tlhelp32"]

View File

@ -2,6 +2,7 @@ use std::{error::Error as StdError, fmt, io, sync::PoisonError};
pub type Result<T> = ::std::result::Result<T, Error>;
#[non_exhaustive]
pub enum Error {
Canonicalization(String, io::Error),
Glob(globset::Error),
@ -9,6 +10,7 @@ pub enum Error {
Notify(notify::Error),
Generic(String),
PoisonedLock,
ClearScreen(clearscreen::Error),
}
impl StdError for Error {}
@ -49,6 +51,15 @@ impl<'a, T> From<PoisonError<T>> for Error {
}
}
impl From<clearscreen::Error> for Error {
fn from(err: clearscreen::Error) -> Self {
match err {
clearscreen::Error::Io(err) => Self::Io(err),
other => Self::ClearScreen(other),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (error_type, error) = match self {
@ -61,6 +72,7 @@ impl fmt::Display for Error {
Self::Io(err) => ("I/O", err.to_string()),
Self::Notify(err) => ("Notify", err.to_string()),
Self::PoisonedLock => ("Internal", "poisoned lock".to_string()),
Self::ClearScreen(err) => ("ClearScreen", err.to_string()),
};
write!(f, "{} error: {}", error_type, error)

View File

@ -20,8 +20,6 @@ extern crate log;
#[macro_use]
extern crate lazy_static;
mod args;
pub mod cli;
pub mod config;
pub mod error;
mod gitignore;
@ -35,12 +33,3 @@ mod watcher;
pub use process::Shell;
pub use run::{run, watch, Handler};
#[deprecated(since = "1.15.0", note = "Config has moved to config::Config")]
pub type Args = config::Config;
#[deprecated(
since = "1.15.0",
note = "ConfigBuilder has moved to config::ConfigBuilder"
)]
pub type ArgsBuilder = config::ConfigBuilder;

View File

@ -1,4 +1,3 @@
use crate::cli::clear_screen;
use crate::config::Config;
use crate::error::{Error, Result};
use crate::gitignore;
@ -187,7 +186,7 @@ impl ExecHandler {
fn spawn(&self, ops: &[PathOp]) -> Result<()> {
if self.args.clear_screen {
clear_screen();
clearscreen::clear()?;
}
debug!("Launching command");