diff --git a/.ignore b/.ignore
index 73f8d72..3b623db 100644
--- a/.ignore
+++ b/.ignore
@@ -1,2 +1,3 @@
snapshots
*.svg
+build.rs
diff --git a/.run_status.toml b/.run_status.toml
index 2488011..e67f0d2 100644
--- a/.run_status.toml
+++ b/.run_status.toml
@@ -1,8 +1,8 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 110
-coverage = 48.89
+coverage = 48.83
[last_run_clean.run_duration]
-secs = 26
-nanos = 63691553
+secs = 27
+nanos = 30003945
diff --git a/Cargo.toml b/Cargo.toml
index 37fd960..0f1839e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,6 @@
[workspace]
resolver = "3"
members = ["bin_efo", "lib_efo"]
-version = "0.1"
[workspace.dependencies]
serde = { version = "1.0.228", features = ["derive"] }
diff --git a/badges/version.svg b/badges/version.svg
index c835340..d9c9825 100644
--- a/badges/version.svg
+++ b/badges/version.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/bin_efo/build.rs b/bin_efo/build.rs
new file mode 100644
index 0000000..c815c22
--- /dev/null
+++ b/bin_efo/build.rs
@@ -0,0 +1,66 @@
+// build.rs
+use std::process::Command;
+use std::str;
+
+/// Helper that runs a command and returns its stdout as a trimmed UTF‑8 string.
+fn run_cmd(cmd: &mut Command) -> String {
+ let out = cmd.output().expect("failed to run command");
+ if !out.status.success() {
+ panic!(
+ "command {:?} failed with status {:?}\nstderr: {}",
+ cmd,
+ out.status,
+ String::from_utf8_lossy(&out.stderr)
+ );
+ }
+
+ str::from_utf8(&out.stdout)
+ .expect("command produced non‑UTF8 output")
+ .trim()
+ .to_owned()
+}
+
+fn main() {
+ let git_hash = run_cmd(Command::new("git").args(["rev-parse", "--short", "HEAD"]));
+ println!("cargo:rustc-env=GIT_HASH={}", git_hash);
+
+ let args = &["rev-parse", "--abbrev-ref", "HEAD"];
+ let git_branch = run_cmd(Command::new("git").args(args));
+ println!("cargo:rustc-env=GIT_BRANCH={}", git_branch);
+
+ // Prefer the explicit env var – it mirrors the real user choice
+ let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
+ .map(|v| v.trim().to_owned())
+ .unwrap_or_else(|_| {
+ // Try rustup first; if that fails, fall back to rustc
+ let raw = run_cmd(Command::new("rustup").args(["show", "active-toolchain"]));
+
+ // rustup output may look like:
+ // stable-x86_64-unknown-linux-gnu (overridden by environment variable)
+ // We only want the part before the first '('
+ raw.split('(').next().unwrap().trim().to_owned()
+ });
+
+ println!("cargo:rustc-env=TOOLCHAIN={}", toolchain);
+
+ let rustc_version = run_cmd(Command::new("rustc").args(["--version"]));
+ println!("cargo:rustc-env=RUSTC_VERSION={}", rustc_version);
+ println!(
+ "cargo:rustc-env=EFO_SHORT_VERSION={} ({}{})",
+ env!("CARGO_PKG_VERSION"),
+ git_branch,
+ git_hash,
+ );
+ println!(
+ "cargo:rustc-env=EFO_FULL_VERSION={} ({}{}) {} {}",
+ env!("CARGO_PKG_VERSION"),
+ git_branch,
+ git_hash,
+ toolchain,
+ rustc_version,
+ );
+
+ // println!("cargo:rerun-if-changed=.git/HEAD");
+ // println!("cargo:rerun-if-changed=.git/refs/heads");
+ // println!("cargo:rerun-if-changed=.git/refs/remotes");
+}
diff --git a/bin_efo/src/main.rs b/bin_efo/src/main.rs
index e01f5aa..47eed3c 100644
--- a/bin_efo/src/main.rs
+++ b/bin_efo/src/main.rs
@@ -43,6 +43,7 @@ mod success;
/// It uses `clap` to parse the top-level sub-commands (`init`, `epoch`, …)
/// and stores them in the `command` field.
#[derive(Parser, Debug)]
+#[command(version = env!("EFO_SHORT_VERSION"))]
#[command(name = "efo")]
#[command(about = "Epoch Forge - manage organisations over time")]
struct Cli {
@@ -101,6 +102,14 @@ enum TopLevelCmd {
fn main() -> miette::Result<()> {
env_logger::init();
+ log::trace!(
+ "System version: {} ({}{}) {} {}",
+ env!("CARGO_PKG_VERSION"),
+ env!("GIT_BRANCH"),
+ env!("GIT_HASH"),
+ env!("TOOLCHAIN"),
+ env!("RUSTC_VERSION"),
+ );
let cli = Cli::parse();
if let Err(e) = exec_dispatch(cli) {
diff --git a/lib_efo/build.rs b/lib_efo/build.rs
new file mode 100644
index 0000000..c815c22
--- /dev/null
+++ b/lib_efo/build.rs
@@ -0,0 +1,66 @@
+// build.rs
+use std::process::Command;
+use std::str;
+
+/// Helper that runs a command and returns its stdout as a trimmed UTF‑8 string.
+fn run_cmd(cmd: &mut Command) -> String {
+ let out = cmd.output().expect("failed to run command");
+ if !out.status.success() {
+ panic!(
+ "command {:?} failed with status {:?}\nstderr: {}",
+ cmd,
+ out.status,
+ String::from_utf8_lossy(&out.stderr)
+ );
+ }
+
+ str::from_utf8(&out.stdout)
+ .expect("command produced non‑UTF8 output")
+ .trim()
+ .to_owned()
+}
+
+fn main() {
+ let git_hash = run_cmd(Command::new("git").args(["rev-parse", "--short", "HEAD"]));
+ println!("cargo:rustc-env=GIT_HASH={}", git_hash);
+
+ let args = &["rev-parse", "--abbrev-ref", "HEAD"];
+ let git_branch = run_cmd(Command::new("git").args(args));
+ println!("cargo:rustc-env=GIT_BRANCH={}", git_branch);
+
+ // Prefer the explicit env var – it mirrors the real user choice
+ let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
+ .map(|v| v.trim().to_owned())
+ .unwrap_or_else(|_| {
+ // Try rustup first; if that fails, fall back to rustc
+ let raw = run_cmd(Command::new("rustup").args(["show", "active-toolchain"]));
+
+ // rustup output may look like:
+ // stable-x86_64-unknown-linux-gnu (overridden by environment variable)
+ // We only want the part before the first '('
+ raw.split('(').next().unwrap().trim().to_owned()
+ });
+
+ println!("cargo:rustc-env=TOOLCHAIN={}", toolchain);
+
+ let rustc_version = run_cmd(Command::new("rustc").args(["--version"]));
+ println!("cargo:rustc-env=RUSTC_VERSION={}", rustc_version);
+ println!(
+ "cargo:rustc-env=EFO_SHORT_VERSION={} ({}{})",
+ env!("CARGO_PKG_VERSION"),
+ git_branch,
+ git_hash,
+ );
+ println!(
+ "cargo:rustc-env=EFO_FULL_VERSION={} ({}{}) {} {}",
+ env!("CARGO_PKG_VERSION"),
+ git_branch,
+ git_hash,
+ toolchain,
+ rustc_version,
+ );
+
+ // println!("cargo:rerun-if-changed=.git/HEAD");
+ // println!("cargo:rerun-if-changed=.git/refs/heads");
+ // println!("cargo:rerun-if-changed=.git/refs/remotes");
+}
diff --git a/lib_efo/src/epoch/epoch_config.rs b/lib_efo/src/epoch/epoch_config.rs
index 841a68f..5b9d611 100644
--- a/lib_efo/src/epoch/epoch_config.rs
+++ b/lib_efo/src/epoch/epoch_config.rs
@@ -43,6 +43,9 @@ pub struct EpochConfig {
/// The epoch ID that the binary should consider “current”.
pub epoch_id: EpochId,
+ /// The version of the file loaded, and hopefully of all the project
+ pub version: String,
+
/// Optional human-friendly tags (e.g. `"winter-B"`, `"post-war"`).
pub tags: HashMap,
// TODO(6): Can become important
@@ -61,6 +64,7 @@ impl Default for EpochConfig {
epoch_id: EpochId::new(0),
tags: HashMap::new(),
list_existing_epochs: HashMap::new(),
+ version: env!("EFO_SHORT_VERSION").to_string(),
}
}
}
@@ -80,7 +84,7 @@ impl EpochConfig {
.map_err(|e| EpochError::Serde {
source: e,
file_name: path.to_string_lossy().to_string(),
- help: None,
+ version: format!("Current version: {}", env!("EFO_SHORT_VERSION")),
})?;
Ok(config.initialize()?)
} else {
@@ -90,6 +94,15 @@ impl EpochConfig {
}
}
+ /// Output the current version vs the filesystem version
+ pub fn version(&self) -> String {
+ format!(
+ "Program version {}.\nFilesystem version: {}.",
+ self.version,
+ env!("EFO_SHORT_VERSION")
+ )
+ }
+
/// Initialize the epoch structure in depth.
///
/// Scans the default configuration folder for sub-directories that are
@@ -127,6 +140,7 @@ impl EpochConfig {
/// * `Err(EpochError::Io { .. })` if the file could not be read.
pub fn try_load(&mut self, epoch_id: &EpochId) -> Result<(), EpochError> {
// Preload the epoch
+ let version = self.version();
let value = self
.list_existing_epochs
.get_mut(epoch_id)
@@ -141,7 +155,7 @@ impl EpochConfig {
serde_json::from_str(&read_to_string?).map_err(|e| EpochError::Serde {
source: e,
file_name: path.to_string(),
- help: None,
+ version,
})?;
log::info!("Fully loaded Epoch {:?}", epoch_id);
@@ -429,7 +443,7 @@ impl EpochConfig {
"List of epoch, most recent shown first".bright_green()
);
// TODO: Make a method for this
- for elt in items_to_log.iter() {
+ for elt in items_to_log.iter().rev() {
let star = if elt.epoch_id == self.epoch_id {
" "
} else {
diff --git a/lib_efo/src/epoch/epoch_traits.rs b/lib_efo/src/epoch/epoch_traits.rs
index ce48cd6..4e6384d 100644
--- a/lib_efo/src/epoch/epoch_traits.rs
+++ b/lib_efo/src/epoch/epoch_traits.rs
@@ -69,7 +69,7 @@ pub trait ConfigWritable: Serialize {
serde_json::to_string_pretty(self).map_err(|e| EpochError::Serde {
source: e,
file_name: action,
- help: None,
+ version: format!("Current Version:{}", env!("EFO_SHORT_VERSION")),
})
}
diff --git a/lib_efo/src/error.rs b/lib_efo/src/error.rs
index 693793d..ecb5e0d 100644
--- a/lib_efo/src/error.rs
+++ b/lib_efo/src/error.rs
@@ -180,15 +180,15 @@ pub enum EpochError {
/// Serialization / deserialization errors that are not caught above.
#[error("Serialization error from {file_name}")]
#[diagnostic(code(EpochError::SerdeError))]
+ #[diagnostic(help("You may have updated efo to an incompatible version.\n{version}"))]
Serde {
/// The source error
#[source]
source: serde_json::Error,
/// The file that was being written
file_name: String,
- /// An optionnal help message
- #[help]
- help: Option,
+ /// A version number vs file version number
+ version: String,
},
/// The epoch tree is in an incorrect state.