Skip to content

Commit

Permalink
Fixes for GHC HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Sep 20, 2024
1 parent 26e6735 commit 663ae4f
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ let
# GHCJS 8.10 does not have these
"Cabal-syntax"
"exceptions"
"file-io"
"ghc"
"ghc-bignum"
"ghc-experimental"
Expand All @@ -422,6 +423,79 @@ let
evalPackages.jq
];
} (let varname = x: builtins.replaceStrings ["-"] ["_"] x; in ''
PACKAGE_VERSION=${ghc.version}
ProjectVersion=${ghc.version}
# The following logic is from GHC m4/setup_project_version.m4
# Split PACKAGE_VERSION into (possibly empty) parts
VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\([^.]*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
VERSION_TMP=`echo $PACKAGE_VERSION | sed 's/^\([^.]*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
VERSION_MINOR=`echo $VERSION_TMP | sed 's/^\([^.]*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
ProjectPatchLevel=`echo $VERSION_TMP | sed 's/^\([^.]*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
# Calculate project version as an integer, using 2 digits for minor version
case $VERSION_MINOR in
?) ProjectVersionInt=''${VERSION_MAJOR}0''${VERSION_MINOR} ;;
??) ProjectVersionInt=''${VERSION_MAJOR}''${VERSION_MINOR} ;;
*) echo bad minor version in $PACKAGE_VERSION; exit 1 ;;
esac
# AC_SUBST([ProjectVersionInt])
# The project patchlevel is zero unless stated otherwise
test -z "$ProjectPatchLevel" && ProjectPatchLevel=0
# Save split version of ProjectPatchLevel
ProjectPatchLevel1=`echo $ProjectPatchLevel | sed 's/^\([^.]*\)\(\.\{0,1\}\(.*\)\)$/\1/'`
ProjectPatchLevel2=`echo $ProjectPatchLevel | sed 's/^\([^.]*\)\(\.\{0,1\}\(.*\)\)$/\3/'`
# The project patchlevel1/2 is zero unless stated otherwise
test -z "$ProjectPatchLevel1" && ProjectPatchLevel1=0
test -z "$ProjectPatchLevel2" && ProjectPatchLevel2=0
# AC_SUBST([ProjectPatchLevel1])
# AC_SUBST([ProjectPatchLevel2])
# Remove dots from the patch level; this allows us to have versions like 6.4.1.20050508
ProjectPatchLevel=`echo $ProjectPatchLevel | sed 's/\.//'`
# AC_SUBST([ProjectPatchLevel])
# The version of the GHC package changes every day, since the
# patchlevel is the current date. We don't want to force
# recompilation of the entire compiler when this happens, so for
# GHC HEAD we omit the patchlevel from the package version number.
#
# The ProjectPatchLevel1 > 20000000 iff GHC HEAD. If it's for a stable
# release like 7.10.1 or for a release candidate such as 7.10.1.20141224
# then we don't omit the patchlevel components.
ProjectVersionMunged="$ProjectVersion"
if test "$ProjectPatchLevel1" -gt 20000000; then
ProjectVersionMunged="''${VERSION_MAJOR}.''${VERSION_MINOR}"
fi
# AC_SUBST([ProjectVersionMunged])
# The version used for libraries tightly coupled with GHC (e.g.
# ghc-internal) which need a major version bump for every minor/patchlevel
# GHC version.
# Example: for GHC=9.10.1, ProjectVersionForLib=9.1001
#
# Just like with project version munged, we don't want to use the
# patchlevel version which changes every day, so if using GHC HEAD, the
# patchlevel = 00.
case $VERSION_MINOR in
?) ProjectVersionForLibUpperHalf=''${VERSION_MAJOR}.0''${VERSION_MINOR} ;;
??) ProjectVersionForLibUpperHalf=''${VERSION_MAJOR}.''${VERSION_MINOR} ;;
*) echo bad minor version in $PACKAGE_VERSION; exit 1 ;;
esac
# GHC HEAD uses patch level version > 20000000
case $ProjectPatchLevel1 in
?) ProjectVersionForLib=''${ProjectVersionForLibUpperHalf}0''${ProjectPatchLevel1} ;;
??) ProjectVersionForLib=''${ProjectVersionForLibUpperHalf}''${ProjectPatchLevel1} ;;
*) ProjectVersionForLib=''${ProjectVersionForLibUpperHalf}00
esac
PKGS=""
${pkgs.lib.concatStrings
(builtins.map (name: ''
Expand All @@ -441,7 +515,7 @@ let
fi
if [[ "$cabal_file" != "" ]]; then
fixed_cabal_file=$(mktemp)
cat $cabal_file | sed -e 's/@ProjectVersionMunged@/${ghc.version}/g' -e 's/default: *@[A-Za-z0-9]*@/default: False/g' -e 's/@Suffix@//g' > $fixed_cabal_file
cat $cabal_file | sed -e "s/@ProjectVersionMunged@/$ProjectVersionMunged/g" -e "s/@ProjectVersionForLib@/$ProjectVersionForLib/g" -e 's/default: *@[A-Za-z0-9]*@/default: False/g' -e 's/@Suffix@//g' > $fixed_cabal_file
json_cabal_file=$(mktemp)
cabal2json $fixed_cabal_file > $json_cabal_file
Expand Down

0 comments on commit 663ae4f

Please sign in to comment.