Commit 17822b57 authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato
Browse files

Add version to the api and use it in the cli

parent c68d68c6
......@@ -45,6 +45,7 @@ arrayvec = "0.4.10"
[build-dependencies]
nasm-rs = { version = "0.1", path = "nasm_rs/", optional = true }
vergen = "3"
[target.'cfg(unix)'.build-dependencies]
pkg-config = "0.3.12"
......@@ -58,6 +59,7 @@ pretty_assertions = "0.6"
interpolate_name = "0.2.2"
rand = "0.6"
rand_chacha = "0.1"
semver = "0.9"
[[bin]]
name = "rav1e"
......
......@@ -71,4 +71,6 @@ fn main() {
if os == "windows" && cfg!(feature = "decode_test") {
panic!("Unsupported feature on this platform!");
}
vergen::generate_cargo_keys(vergen::ConstantsFlags::all()).expect("Unable to generate the cargo keys!");
}
......@@ -35,8 +35,13 @@ pub struct CliOptions {
}
pub fn parse_cli() -> CliOptions {
let ver_short = version::short();
let ver_long = version::full();
let ver = version::full();
let mut app = App::new("rav1e")
.version(env!("CARGO_PKG_VERSION"))
.version(ver.as_str())
.long_version(ver_long.as_str())
.version_short(ver_short.as_str())
.about("AV1 video encoder")
.setting(AppSettings::DeriveDisplayOrder)
.setting(AppSettings::SubcommandsNegateReqs)
......
......@@ -61,6 +61,92 @@ pub use crate::util::{CastFromPrimitive, Pixel};
pub use crate::frame::Frame;
/// Version information
///
/// The information is recovered from `Cargo.toml` and `git describe`, when available.
///
/// ```
/// use rav1e::version;
/// use semver::Version;
///
/// let major = version::major();
/// let minor = version::minor();
/// let patch = version::patch();
///
/// let short = version::short();
///
/// let v1 = Version::new(major, minor, patch);
/// let v2 = Version::parse(&short).unwrap();
///
/// assert_eq!(v1, v2);
///```
///
pub mod version {
/// Major version component
///
/// It is increased every time a release presents a incompatible API change.
pub fn major() -> u64 {
env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap()
}
/// Minor version component
///
/// It is increased every time a release presents new functionalities are added
/// in a backwards-compatible manner.
pub fn minor() -> u64 {
env!("CARGO_PKG_VERSION_MINOR").parse().unwrap()
}
/// Patch version component
///
/// It is increased every time a release provides only backwards-compatible bugfixes.
pub fn patch() -> u64 {
env!("CARGO_PKG_VERSION_PATCH").parse().unwrap()
}
/// Version information as presented in `[package]` `version`.
///
/// e.g. `0.1.0``
///
/// Can be parsed by [semver](https://crates.io/crates/semver).
pub fn short() -> String {
env!("CARGO_PKG_VERSION").to_string()
}
/// Version information as presented in `[package] version` followed by the
/// short commit hash if present.
///
/// e.g. `0.1.0 - g743d464`
///
pub fn long() -> String {
let s = short();
let hash = hash();
if hash.is_empty() {
s
} else {
format!("{} - {}", s, hash)
}
}
/// Commit hash (short)
///
/// Short hash of the git commit used by this build
///
/// e.g. `g743d464`
///
pub fn hash() -> String {
env!("VERGEN_SHA_SHORT").to_string()
}
/// Version information with the information
/// provided by `git describe --tags`.
///
/// e.g. `0.1.0 (v0.1.0-1-g743d464)`
///
pub fn full() -> String {
let semver = env!("VERGEN_SEMVER_LIGHTWEIGHT");
format!("{} ({})", short(), semver)
}
}
#[cfg(all(test, any(feature="decode_test", feature="decode_test_dav1d")))]
mod test_encode_decode;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment