diff --git a/Cargo.lock b/Cargo.lock index d16b1f9..abf7ef2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -931,7 +931,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vsg_bridge_ls" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 694e927..2d85780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "vsg_bridge_ls" description = "A very featureless VSG to lsp bridge" -version = "0.1.0" +version = "0.2.0" edition = "2021" rust-version = "1.85.1" categories =["developement-tools"] diff --git a/README.md b/README.md index 3eecf2d..93e54ef 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,12 @@ Activate the environment and verify both executables: . .venv/bin/activate command -v vsg command -v vsg_bridge_ls -vsg_bridge_ls --help +vsg_bridge_ls --version ``` +The version includes both the Cargo release and build commit, for example +`0.2.0+git.0123abcd`, so editor logs can identify the exact binary. + ## 3. Configure Helix Add this minimal setup to `~/.config/helix/languages.toml`: diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..656f8eb --- /dev/null +++ b/build.rs @@ -0,0 +1,29 @@ +use std::fs; +use std::process::Command; + +fn main() { + println!("cargo:rerun-if-changed=.git/HEAD"); + if let Ok(head) = fs::read_to_string(".git/HEAD") { + if let Some(reference) = head.trim().strip_prefix("ref: ") { + println!("cargo:rerun-if-changed=.git/{reference}"); + } + } + + let revision = if std::path::Path::new(".git").exists() { + Command::new("git") + .args(["rev-parse", "--short=8", "HEAD"]) + .output() + .ok() + .filter(|output| output.status.success()) + .and_then(|output| String::from_utf8(output.stdout).ok()) + .map(|revision| revision.trim().to_owned()) + .filter(|revision| { + !revision.is_empty() && revision.bytes().all(|byte| byte.is_ascii_hexdigit()) + }) + .unwrap_or_else(|| "unknown".to_owned()) + } else { + "unknown".to_owned() + }; + + println!("cargo:rustc-env=VSG_BRIDGE_GIT_SHA={revision}"); +} diff --git a/src/lib.rs b/src/lib.rs index 733bfe1..db1b94c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,9 +19,16 @@ use tower_lsp::{LspService, Server}; pub use runner::{ProcessVsgRunner, VsgRunner}; pub use server::Backend; +/// Package version paired with the source revision used for this build. +pub const VERSION: &str = concat!( + env!("CARGO_PKG_VERSION"), + "+git.", + env!("VSG_BRIDGE_GIT_SHA") +); + /// Command-line configuration for the language server. #[derive(Clone, Debug, Parser, PartialEq, Eq)] -#[command(version, about, long_about = None)] +#[command(version = VERSION, about, long_about = None)] pub struct Options { /// VSG configuration files, in the order in which VSG should load them. #[arg(short, long)] @@ -71,10 +78,10 @@ where mod tests { //! Unit tests for command-line option translation. - use super::{run, Options}; + use super::{run, Options, VERSION}; use crate::VsgRunner; use anyhow::Result; - use clap::Parser; + use clap::{CommandFactory, Parser}; use std::sync::Arc; use tokio::io::{AsyncReadExt, AsyncWriteExt}; @@ -145,6 +152,17 @@ mod tests { assert!(!options.experimental_multi_rule_line_fix); } + /// CLI version output identifies both the release and source revision. + #[test] + fn version_includes_source_revision() { + assert_eq!(Options::command().get_version(), Some(VERSION)); + assert!(VERSION.starts_with("0.2.0+git.")); + assert!(VERSION + .strip_prefix("0.2.0+git.") + .is_some_and(|revision| revision == "unknown" + || (revision.len() == 8 && revision.bytes().all(|byte| byte.is_ascii_hexdigit())))); + } + /// The multi-rule line action requires an explicit runtime opt-in. #[test] fn parses_experimental_multi_rule_line_flag() {