Skip to content

Commit

Permalink
nix: send the Git date to build.rs
Browse files Browse the repository at this point in the history
Thanks to @thoughtpolice for providing the original version of the nix code; I
edited it a bit.
  • Loading branch information
ilyagr committed Oct 24, 2023
1 parent 5ecfc57 commit e6ce325
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 7 additions & 5 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ fn main() -> std::io::Result<()> {

/// Return the committer date in YYYYMMDD format and the git hash
fn get_git_date_and_hash() -> Option<(String, String)> {
if let Some(nix_hash) = std::env::var("NIX_JJ_GIT_HASH")
.ok()
.filter(|s| !s.is_empty())
{
return Some(("nix".to_string(), nix_hash));
if let (Ok(nix_hash), Ok(nix_date)) = (
std::env::var("NIX_JJ_GIT_HASH"),
std::env::var("NIX_JJ_GIT_DATE"),
) {
if !nix_hash.is_empty() && !nix_date.is_empty() {
return Some((nix_date, nix_hash));
}
}

fn trim_and_split_on_vbar(bytes: &[u8]) -> (String, String) {
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn test_no_subcommand() {
sanitized.as_str(),
"jj ?.??.?\n"
| "jj ?.??.?-????????-????????????????\n"
| "jj ?.??.?-nix-????????????????\n"
| "jj ?.??.?-nix-????????-????????????????\n"
);

let stdout = test_env.jj_cmd_success(test_env.env_root(), &["-R", "repo"]);
Expand Down
10 changes: 9 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
} //
(flake-utils.lib.eachDefaultSystem (system:
let
# TODO(aseipp): Use dirtyRev and dirtyShortRev to record dirty checkout
# when we update `build.rs` to understand dirty checkouts.
gitRev = self.rev or "";
gitDate = builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "");

pkgs = import nixpkgs {
inherit system;
overlays = [
Expand Down Expand Up @@ -76,7 +81,8 @@

ZSTD_SYS_USE_PKG_CONFIG = "1";
LIBSSH2_SYS_USE_PKG_CONFIG = "1";
NIX_JJ_GIT_HASH = self.rev or "";
NIX_JJ_GIT_HASH = gitRev;
NIX_JJ_GIT_DATE = gitDate;
CARGO_INCREMENTAL = "0";

preCheck = "export RUST_BACKTRACE=1";
Expand Down Expand Up @@ -132,6 +138,8 @@
export RUST_BACKTRACE=1
export ZSTD_SYS_USE_PKG_CONFIG=1
export LIBSSH2_SYS_USE_PKG_CONFIG=1
export NIX_JJ_GIT_HASH="${gitRev}"
export NIX_JJ_GIT_DATE="${gitDate};
'';
};
}));
Expand Down

0 comments on commit e6ce325

Please sign in to comment.