Merge pull request #34291 from timokau/sage-fix-shebangs

sage: 8.0 -> 8.1, fix sandbox build

authored by Michael Raskin and committed by GitHub bfc4d04d 5bb712d5

+128 -30
+28 -6
pkgs/applications/science/math/sage/default.nix
··· 18 18 # - https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/sagemath 19 19 20 20 { stdenv 21 + , bash 21 22 , fetchurl 22 23 , perl 23 24 , gfortran ··· 26 27 , gettext 27 28 , which 28 29 , texlive 30 + , texinfo 29 31 , hevea 30 32 }: 31 33 32 34 stdenv.mkDerivation rec { 33 - version = "8.0"; 35 + version = "8.1"; 34 36 name = "sage-${version}"; 35 37 38 + # Modified version of patchShebangs that patches to the sage-internal version if possible 39 + # and falls back to the system version if not. 40 + patchSageShebangs = ./patchSageShebangs.sh; 36 41 src = fetchurl { 37 42 # Note that the source is *not* fetched from github, since that doesn't 38 43 # the upstream folder with all the source tarballs of the spkgs. ··· 70 75 "http://www-ftp.lip6.fr/pub/math/sagemath/src/sage-${version}.tar.gz" 71 76 "http://ftp.ntua.gr/pub/sagemath/src/sage-${version}.tar.gz" 72 77 ]; 73 - sha256 = "1a9rhb8jby6fdqa2s7n2fl9jwqqlsl7qz7dbpbwvg6jwlrvni7fg"; 78 + sha256 = "1cpcs1mr0yii64s152xmxyd450bfzjb22jjj0zh9y3n6g9alzpyq"; 74 79 }; 75 80 76 81 postPatch = '' 77 82 substituteAllInPlace src/bin/sage-env 83 + bash=${bash} substituteAllInPlace build/bin/sage-spkg 78 84 ''; 79 85 80 86 installPhase = '' ··· 84 90 outputs = [ "out" "doc" ]; 85 91 86 92 buildInputs = [ 93 + bash # needed for the build 87 94 perl # needed for the build 88 95 python # needed for the build 89 - gfortran # needed to build giac 96 + gfortran # needed to build giac, openblas 90 97 autoreconfHook # needed to configure sage with prefix 91 98 gettext # needed to build the singular spkg 92 99 hevea # needed to build the docs of the giac spkg 93 100 which # needed in configure of mpir 94 101 # needed to build the docs of the giac spkg 102 + texinfo # needed to build maxima 95 103 (texlive.combine { inherit (texlive) 96 104 scheme-basic 97 105 collection-pstricks # needed by giac ··· 102 110 }) 103 111 ]; 104 112 113 + nativeBuildInputs = [ gfortran perl which ]; 114 + 105 115 patches = [ 106 116 # fix usages of /bin/rm 107 117 ./spkg-singular.patch 108 118 # help python find the crypt library 109 - ./spkg-python2.patch 110 - ./spkg-python3.patch 119 + # patches python3 and indirectly python2, since those installation files are symlinked 120 + ./spkg-python.patch 111 121 # fix usages of /usr/bin/perl 112 122 ./spkg-git.patch 113 123 # fix usages of /bin/cp and add necessary argument to function call 114 124 ./spkg-giac.patch 115 125 # environment 116 126 ./env.patch 127 + # adjust wrapper shebang and patch shebangs after each spkg build 128 + ./shebangs.patch 117 129 ]; 118 130 119 131 enableParallelBuilding = true; ··· 144 156 preBuild = '' 145 157 # TODO do this conditionally 146 158 export SAGE_SPKG_INSTALL_DOCS='no' 147 - patchShebangs build 159 + # symlink python to make sure the shebangs are patched to the sage path 160 + # while still being able to use python before building it 161 + # (this is important because otherwise sage will try to install python 162 + # packages globally later on) 163 + ln -s "${python}/bin/python2" $out/bin/python2 164 + ln -s "$out/bin/python2" $out/bin/python 165 + touch $out/bin/python3 166 + bash $patchSageShebangs . 148 167 ''; 149 168 150 169 postBuild = '' ··· 153 172 rm -rf "$out/sage-root/src/.git" 154 173 rm -r "$out/sage-root/logs" 155 174 # Fix dependency cycle between out and doc 175 + rm -f "$out/sage-root/config.log" 156 176 rm -f "$out/sage-root/config.status" 157 177 rm -f "$out/sage-root/build/make/Makefile-auto" 158 178 rm -f "$out/sage-home/.sage/gap/libgap-workspace-"* 179 + # Make sure all shebangs are properly patched 180 + bash $patchSageShebangs $out 159 181 ''; 160 182 161 183 # TODO there are some doctest failures, which seem harmless.
+51
pkgs/applications/science/math/sage/patchSageShebangs.sh
··· 1 + # This is a slightly modified version of nix's default patchShebangs 2 + 3 + dir="$1" 4 + 5 + echo "patching sage internal script interpreter paths in $( readlink -f "$dir")" 6 + 7 + find "$dir" -type f -perm -0100 | while read f; do 8 + if [ "$(head -1 "$f" | head -c+2)" != '#!' ]; then 9 + # missing shebang => not a script 10 + continue 11 + fi 12 + 13 + oldInterpreterLine=$(head -1 "$f" | tail -c+3) 14 + read -r oldPath arg0 args <<< "$oldInterpreterLine" 15 + 16 + if $(echo "$oldPath" | grep -q "/bin/env$"); then 17 + # Check for unsupported 'env' functionality: 18 + # - options: something starting with a '-' 19 + # - environment variables: foo=bar 20 + if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then 21 + echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" 22 + exit 1 23 + fi 24 + executable="$arg0" 25 + else 26 + if [ "$oldPath" = "" ]; then 27 + # If no interpreter is specified linux will use /bin/sh. Set 28 + # oldpath="/bin/sh" so that we get /nix/store/.../sh. 29 + oldPath="/bin/sh" 30 + fi 31 + executable="$(basename "$oldPath")" 32 + args="$arg0 $args" 33 + fi 34 + 35 + newPath="$(echo "$out/bin/$executable $args" | sed 's/[[:space:]]*$//')" 36 + if [[ ! -x "$newPath" ]] ; then 37 + newPath="$(command -v "$executable" || true)" 38 + fi 39 + 40 + # Strip trailing whitespace introduced when no arguments are present 41 + newInterpreterLine="$(echo "$newPath $args" | sed 's/[[:space:]]*$//')" 42 + 43 + if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then 44 + if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then 45 + echo "$f: sage interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\"" 46 + # escape the escape chars so that sed doesn't interpret them 47 + escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g') 48 + sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f" 49 + fi 50 + fi 51 + done
+36
pkgs/applications/science/math/sage/shebangs.patch
··· 1 + diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg 2 + index 83e61a7e0d..942ba206c7 100755 3 + --- a/build/bin/sage-spkg 4 + +++ b/build/bin/sage-spkg 5 + @@ -648,8 +648,12 @@ if ! sage-apply-patches; then 6 + error_msg "Error applying patches" 7 + exit 1 8 + fi 9 + + 10 + +@bash@/bin/bash @patchSageShebangs@ . 11 + + 12 + cd .. 13 + 14 + + 15 + ################################################################## 16 + # The package has been extracted, prepare for installation 17 + ################################################################## 18 + @@ -671,7 +675,7 @@ write_script_wrapper() { 19 + local tmpscript="$(dirname "$script")/.tmp-${script##*/}" 20 + 21 + cat > "$tmpscript" <<__EOF__ 22 + -#!/usr/bin/env bash 23 + +#! @bash@/bin/bash 24 + 25 + export SAGE_ROOT="$SAGE_ROOT" 26 + export SAGE_SRC="$SAGE_SRC" 27 + @@ -833,6 +837,9 @@ if [ "$UNAME" = "CYGWIN" ]; then 28 + sage-rebase.sh "$SAGE_LOCAL" 2>/dev/null 29 + fi 30 + 31 + +@bash@/bin/bash @patchSageShebangs@ . 32 + +@bash@/bin/bash @patchSageShebangs@ "$out/bin" 33 + + 34 + echo "Successfully installed $PKG_NAME" 35 + 36 + if [ "$SAGE_CHECK" = "yes" ]; then
+13
pkgs/applications/science/math/sage/spkg-python.patch
··· 1 + diff --git a/build/pkgs/python3/spkg-build b/build/pkgs/python3/spkg-build 2 + index 56db087ae5..b450703c5f 100644 3 + --- a/build/pkgs/python3/spkg-build 4 + +++ b/build/pkgs/python3/spkg-build 5 + @@ -27,6 +27,8 @@ fi 6 + export EXTRA_CFLAGS="`testcflags.sh -Wno-unused` $CFLAGS" 7 + unset CFLAGS 8 + 9 + +export LDFLAGS="$LDFLAGS -lcrypt" 10 + + 11 + if [ "$UNAME" = Darwin ]; then 12 + PYTHON_CONFIGURE="--disable-toolbox-glue $PYTHON_CONFIGURE" 13 +
-12
pkgs/applications/science/math/sage/spkg-python2.patch
··· 1 - --- old/build/pkgs/python2/spkg-install 2017-07-21 14:10:00.000000000 -0500 2 - +++ new/build/pkgs/python2/spkg-install 2017-10-15 11:26:54.823134067 -0500 3 - @@ -22,6 +22,9 @@ 4 - 5 - cd src 6 - 7 - +LDFLAGS="-lcrypt $LDFLAGS" 8 - +export LDFLAGS 9 - + 10 - if [ "$SAGE_DEBUG" = "yes" ]; then 11 - echo "Building Python with pydebug" 12 - PYTHON_CONFIGURE="$PYTHON_CONFIGURE --with-pydebug"
-12
pkgs/applications/science/math/sage/spkg-python3.patch
··· 1 - --- old/build/pkgs/python3/spkg-install 2017-07-21 14:10:00.000000000 -0500 2 - +++ new/build/pkgs/python3/spkg-install 2017-10-15 13:11:17.769261404 -0500 3 - @@ -22,6 +22,9 @@ 4 - 5 - cd src 6 - 7 - +LDFLAGS="-lcrypt $LDFLAGS" 8 - +export LDFLAGS 9 - + 10 - if [ "$SAGE_DEBUG" = "yes" ]; then 11 - echo "Building Python with pydebug" 12 - PYTHON_CONFIGURE="$PYTHON_CONFIGURE --with-pydebug"