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 this; I edited it a bit.
  • Loading branch information
ilyagr committed Aug 12, 2023
1 parent e87e099 commit 383ab92
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 10 additions & 4 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ 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())
if let Some((nix_hash, nix_date)) = std::iter::zip(
std::env::var("NIX_JJ_GIT_HASH")
.ok()
.filter(|s| !s.is_empty()),
std::env::var("NIX_JJ_GIT_DATE")
.ok()
.filter(|s| !s.is_empty()),
)
.next()
{
return Some(("nix".to_string(), nix_hash));
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
15 changes: 12 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
} //
(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 "";
gitShortRev = self.shortRev or "";
gitDate = builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101");

pkgs = import nixpkgs {
inherit system;
overlays = [
Expand Down Expand Up @@ -47,7 +53,7 @@
packages = {
jujutsu = ourRustPlatform.buildRustPackage rec {
pname = "jujutsu";
version = "unstable-${self.shortRev or "dirty"}";
version = "unstable-${gitShortRev}";
buildNoDefaultFeatures = true;
buildFeatures = [ "packaging" ];
cargoBuildFlags = ["--bin" "jj"]; # don't build and install the fake editors
Expand All @@ -73,10 +79,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 @@ -134,6 +141,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 383ab92

Please sign in to comment.