Skip to content

Commit

Permalink
add commit-sha to cli (#2411)
Browse files Browse the repository at this point in the history
closes #2280

now it'll show a nice git version instead of just the pkg version. 
```sh
> ./glaredb
GlareDB (v0.8.0-11-g167702f)
```

you can read more about how the {git_version} is generated
[here](https://docs.rs/built/0.7.1/built/#git2).

TLDR; it uses the head (if its a tag, it uses just that, otherwise it
uses a concatonation of the last tag + the commit)


## note for development purposes. 

It does cache this in your `target` dir, so if it's not showing the
current commit, it's likely that this generated file is cached.
  • Loading branch information
universalmind303 authored Jan 11, 2024
1 parent 3a6686a commit 4e59620
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/glaredb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ predicates = "3.0.4"
assert_cmd = "2.0.12"
tokio-postgres = "0.7.8"
tempfile = { workspace = true }

[build-dependencies]
built = { version = "0.7.1", features = ["git2"] }
3 changes: 3 additions & 0 deletions crates/glaredb/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}
8 changes: 7 additions & 1 deletion crates/glaredb/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::args::server::ServerArgs;
use crate::args::{LocalArgs, MetastoreArgs, PgProxyArgs, RpcProxyArgs};
use crate::built_info;
use crate::local::LocalSession;
use crate::metastore::Metastore;
use crate::proxy::{PgProxy, RpcProxy};
Expand Down Expand Up @@ -117,7 +118,12 @@ impl RunCommand for LocalArgs {
};

if query.is_none() {
println!("GlareDB (v{})", env!("CARGO_PKG_VERSION"));
// git should always be present, but just in case, we'll fall back to the version
if let Some(git_version) = built_info::GIT_VERSION {
println!("GlareDB ({git_version})",);
} else {
println!("GlareDB (v{})", env!("CARGO_PKG_VERSION"));
}
}

let local = LocalSession::connect(self.opts).await?;
Expand Down
5 changes: 5 additions & 0 deletions crates/glaredb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ mod prompt;
pub mod proxy;

pub mod server;

pub mod built_info {
// The file has been placed there by the build script.
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

0 comments on commit 4e59620

Please sign in to comment.