gn: get revNum and revShort in src's postFetch

Signed-off-by: Marcin Serwin <marcin@serwin.dev>
This commit is contained in:
Marcin Serwin
2025-08-09 08:52:24 +02:00
parent b0986e899d
commit 44f44058e6
+27 -24
View File
@@ -3,38 +3,30 @@
lib,
fetchgit,
cctools,
writeText,
ninja,
python3,
}:
let
# Note: Please use the recommended version for Chromium stable, i.e. from
# <nixpkgs>/pkgs/applications/networking/browsers/chromium/info.json
rev = "85cc21e94af590a267c1c7a47020d9b420f8a033";
revNum = "2233"; # git describe $rev --match initial-commit | cut -d- -f3
version = "2025-04-28";
sha256 = "sha256-+nKP2hBUKIqdNfDz1vGggXSdCuttOt0GwyGUQ3Z1ZHI=";
revShort = builtins.substring 0 7 rev;
lastCommitPosition = writeText "last_commit_position.h" ''
#ifndef OUT_LAST_COMMIT_POSITION_H_
#define OUT_LAST_COMMIT_POSITION_H_
#define LAST_COMMIT_POSITION_NUM ${revNum}
#define LAST_COMMIT_POSITION "${revNum} (${revShort})"
#endif // OUT_LAST_COMMIT_POSITION_H_
'';
in
stdenv.mkDerivation {
pname = "gn-unstable";
inherit version;
version = "2025-04-28";
src = fetchgit {
# Note: The TAR-Archives (+archive/${rev}.tar.gz) are not deterministic!
url = "https://gn.googlesource.com/gn";
inherit rev sha256;
# Note: Please use the recommended version for Chromium stable, i.e. from
# <nixpkgs>/pkgs/applications/networking/browsers/chromium/info.json
rev = "85cc21e94af590a267c1c7a47020d9b420f8a033";
hash = "sha256-SYpWYvGGNLMZPR1LdKKgubbv+4QcxRw8EYp7cNI5wQQ=";
leaveDotGit = true;
deepClone = true;
postFetch = ''
cd "$out"
mkdir .nix-files
git rev-parse --short=12 HEAD > .nix-files/REV_SHORT
git describe --match initial-commit | cut -d- -f3 > .nix-files/REV_NUM
find "$out" -name .git -print0 | xargs -0 rm -rf
'';
};
nativeBuildInputs = [
@@ -50,9 +42,20 @@ stdenv.mkDerivation {
# cc1plus: error: '-Wformat-security' ignored without '-Wformat' [-Werror=format-security]
hardeningDisable = [ "format" ];
buildPhase = ''
configurePhase = ''
python build/gen.py --no-last-commit-position
ln -s ${lastCommitPosition} out/last_commit_position.h
cat > out/last_commit_position.h << EOF
#ifndef OUT_LAST_COMMIT_POSITION_H_
#define OUT_LAST_COMMIT_POSITION_H_
#define LAST_COMMIT_POSITION_NUM $(<.nix-files/REV_NUM)
#define LAST_COMMIT_POSITION "$(<.nix-files/REV_NUM) ($(<.nix-files/REV_SHORT))"
#endif // OUT_LAST_COMMIT_POSITION_H_
EOF
'';
buildPhase = ''
ninja -j $NIX_BUILD_CORES -C out gn
'';