Save and log build commit
Signed-off-by: Evan Lloyd New-Schmidt <evan@new-schmidt.com>
This commit is contained in:
parent
8fe572b7a2
commit
b924301bfe
2 changed files with 48 additions and 1 deletions
32
build.rs
Normal file
32
build.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use std::process::Command;
|
||||
|
||||
/// Pass git-describe through CARGO_GIT_VERSION env variable
|
||||
///
|
||||
/// NOTE: Cargo.toml still needs to be updated on releases
|
||||
fn set_version_from_git() {
|
||||
let cmd = Command::new("git")
|
||||
.arg("describe")
|
||||
.arg("--always")
|
||||
.arg("--dirty")
|
||||
.arg("--tags")
|
||||
.output();
|
||||
|
||||
match cmd {
|
||||
Ok(output) if output.status.success() => {
|
||||
let version = String::from_utf8_lossy(&output.stdout);
|
||||
let version = version.trim();
|
||||
println!("cargo:rustc-env=CARGO_GIT_VERSION={}", version);
|
||||
// rerun when git checks out another ref or any ref changes
|
||||
println!("cargo:rerun-if-changed=.git/refs/");
|
||||
println!("cargo:rerun-if-changed=.git/HEAD");
|
||||
}
|
||||
_ => {
|
||||
// crates.io builds without git, so ignore here
|
||||
eprintln!("git describe failed; ignoring");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
set_version_from_git();
|
||||
}
|
17
src/main.rs
17
src/main.rs
|
@ -15,11 +15,24 @@ use om_wikiparser::{
|
|||
wm::{parse_wikidata_file, parse_wikipedia_file, Page, WikipediaTitleNorm},
|
||||
};
|
||||
|
||||
/// Get the version returned by `git describe`, e.g.:
|
||||
/// - `v2.0` if a git tag
|
||||
/// - the commit hash `034ac04` if not a tag
|
||||
/// - `034ac04-dirty` if uncommited changes are present,
|
||||
/// or the crate version if not available (if installed from crates.io).
|
||||
///
|
||||
/// See `build.rs` file for more info.
|
||||
fn version() -> &'static str {
|
||||
option_env!("CARGO_GIT_VERSION")
|
||||
.or(option_env!("CARGO_PKG_VERSION"))
|
||||
.unwrap_or("unknown")
|
||||
}
|
||||
|
||||
/// Extract article HTML from Wikipedia Enterprise HTML dumps.
|
||||
///
|
||||
/// Expects an uncompressed dump connected to stdin.
|
||||
#[derive(Parser)]
|
||||
#[command(version)]
|
||||
#[command(version = crate::version())]
|
||||
struct Args {
|
||||
/// Directory to write the extracted articles to.
|
||||
output_dir: PathBuf,
|
||||
|
@ -174,6 +187,8 @@ fn main() -> anyhow::Result<()> {
|
|||
.exit()
|
||||
}
|
||||
|
||||
info!("{} {}", Args::command().get_name(), version());
|
||||
|
||||
let wikipedia_titles = if let Some(path) = args.wikipedia_urls {
|
||||
info!("Loading article urls from {path:?}");
|
||||
let urls = parse_wikipedia_file(path)?;
|
||||
|
|
Loading…
Add table
Reference in a new issue