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 Sep 22, 2023
1 parent 8368b8d commit f90638b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 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 @@ -71,7 +71,7 @@ fn test_no_subcommand() {
let sanitized = stdout.replace(|c: char| c.is_ascii_hexdigit(), "?");
assert_matches!(
sanitized.as_str(),
"jj ?.?.?\n" | "jj ?.?.?-????????-????????????????\n" | "jj ?.?.?-nix-????????????????\n"
"jj ?.?.?\n" | "jj ?.?.?-????????-????????????????\n"
);

let stdout = test_env.jj_cmd_success(test_env.env_root(), &["-R", "repo"]);
Expand Down
12 changes: 10 additions & 2 deletions 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 @@ -72,10 +77,11 @@
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
libiconv
];
];
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";
postInstall = ''
$out/bin/jj util mangen > ./jj.1
Expand Down Expand Up @@ -136,6 +142,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 f90638b

Please sign in to comment.