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

sage: 8.0 -> 8.1, fix sandbox build
This commit is contained in:
Michael Raskin 2018-01-26 23:24:27 +00:00 committed by GitHub
commit bfc4d04de7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 128 additions and 30 deletions

View file

@ -18,6 +18,7 @@
# - https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/sagemath
{ stdenv
, bash
, fetchurl
, perl
, gfortran
@ -26,13 +27,17 @@
, gettext
, which
, texlive
, texinfo
, hevea
}:
stdenv.mkDerivation rec {
version = "8.0";
version = "8.1";
name = "sage-${version}";
# Modified version of patchShebangs that patches to the sage-internal version if possible
# and falls back to the system version if not.
patchSageShebangs = ./patchSageShebangs.sh;
src = fetchurl {
# Note that the source is *not* fetched from github, since that doesn't
# the upstream folder with all the source tarballs of the spkgs.
@ -70,11 +75,12 @@ stdenv.mkDerivation rec {
"http://www-ftp.lip6.fr/pub/math/sagemath/src/sage-${version}.tar.gz"
"http://ftp.ntua.gr/pub/sagemath/src/sage-${version}.tar.gz"
];
sha256 = "1a9rhb8jby6fdqa2s7n2fl9jwqqlsl7qz7dbpbwvg6jwlrvni7fg";
sha256 = "1cpcs1mr0yii64s152xmxyd450bfzjb22jjj0zh9y3n6g9alzpyq";
};
postPatch = ''
substituteAllInPlace src/bin/sage-env
bash=${bash} substituteAllInPlace build/bin/sage-spkg
'';
installPhase = ''
@ -84,14 +90,16 @@ stdenv.mkDerivation rec {
outputs = [ "out" "doc" ];
buildInputs = [
bash # needed for the build
perl # needed for the build
python # needed for the build
gfortran # needed to build giac
gfortran # needed to build giac, openblas
autoreconfHook # needed to configure sage with prefix
gettext # needed to build the singular spkg
hevea # needed to build the docs of the giac spkg
which # needed in configure of mpir
# needed to build the docs of the giac spkg
texinfo # needed to build maxima
(texlive.combine { inherit (texlive)
scheme-basic
collection-pstricks # needed by giac
@ -102,18 +110,22 @@ stdenv.mkDerivation rec {
})
];
nativeBuildInputs = [ gfortran perl which ];
patches = [
# fix usages of /bin/rm
./spkg-singular.patch
# help python find the crypt library
./spkg-python2.patch
./spkg-python3.patch
# patches python3 and indirectly python2, since those installation files are symlinked
./spkg-python.patch
# fix usages of /usr/bin/perl
./spkg-git.patch
# fix usages of /bin/cp and add necessary argument to function call
./spkg-giac.patch
# environment
./env.patch
# adjust wrapper shebang and patch shebangs after each spkg build
./shebangs.patch
];
enableParallelBuilding = true;
@ -144,7 +156,14 @@ stdenv.mkDerivation rec {
preBuild = ''
# TODO do this conditionally
export SAGE_SPKG_INSTALL_DOCS='no'
patchShebangs build
# symlink python to make sure the shebangs are patched to the sage path
# while still being able to use python before building it
# (this is important because otherwise sage will try to install python
# packages globally later on)
ln -s "${python}/bin/python2" $out/bin/python2
ln -s "$out/bin/python2" $out/bin/python
touch $out/bin/python3
bash $patchSageShebangs .
'';
postBuild = ''
@ -153,9 +172,12 @@ stdenv.mkDerivation rec {
rm -rf "$out/sage-root/src/.git"
rm -r "$out/sage-root/logs"
# Fix dependency cycle between out and doc
rm -f "$out/sage-root/config.log"
rm -f "$out/sage-root/config.status"
rm -f "$out/sage-root/build/make/Makefile-auto"
rm -f "$out/sage-home/.sage/gap/libgap-workspace-"*
# Make sure all shebangs are properly patched
bash $patchSageShebangs $out
'';
# TODO there are some doctest failures, which seem harmless.

View file

@ -0,0 +1,51 @@
# This is a slightly modified version of nix's default patchShebangs
dir="$1"
echo "patching sage internal script interpreter paths in $( readlink -f "$dir")"
find "$dir" -type f -perm -0100 | while read f; do
if [ "$(head -1 "$f" | head -c+2)" != '#!' ]; then
# missing shebang => not a script
continue
fi
oldInterpreterLine=$(head -1 "$f" | tail -c+3)
read -r oldPath arg0 args <<< "$oldInterpreterLine"
if $(echo "$oldPath" | grep -q "/bin/env$"); then
# Check for unsupported 'env' functionality:
# - options: something starting with a '-'
# - environment variables: foo=bar
if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
exit 1
fi
executable="$arg0"
else
if [ "$oldPath" = "" ]; then
# If no interpreter is specified linux will use /bin/sh. Set
# oldpath="/bin/sh" so that we get /nix/store/.../sh.
oldPath="/bin/sh"
fi
executable="$(basename "$oldPath")"
args="$arg0 $args"
fi
newPath="$(echo "$out/bin/$executable $args" | sed 's/[[:space:]]*$//')"
if [[ ! -x "$newPath" ]] ; then
newPath="$(command -v "$executable" || true)"
fi
# Strip trailing whitespace introduced when no arguments are present
newInterpreterLine="$(echo "$newPath $args" | sed 's/[[:space:]]*$//')"
if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
echo "$f: sage interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
# escape the escape chars so that sed doesn't interpret them
escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
fi
fi
done

View file

@ -0,0 +1,36 @@
diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg
index 83e61a7e0d..942ba206c7 100755
--- a/build/bin/sage-spkg
+++ b/build/bin/sage-spkg
@@ -648,8 +648,12 @@ if ! sage-apply-patches; then
error_msg "Error applying patches"
exit 1
fi
+
+@bash@/bin/bash @patchSageShebangs@ .
+
cd ..
+
##################################################################
# The package has been extracted, prepare for installation
##################################################################
@@ -671,7 +675,7 @@ write_script_wrapper() {
local tmpscript="$(dirname "$script")/.tmp-${script##*/}"
cat > "$tmpscript" <<__EOF__
-#!/usr/bin/env bash
+#! @bash@/bin/bash
export SAGE_ROOT="$SAGE_ROOT"
export SAGE_SRC="$SAGE_SRC"
@@ -833,6 +837,9 @@ if [ "$UNAME" = "CYGWIN" ]; then
sage-rebase.sh "$SAGE_LOCAL" 2>/dev/null
fi
+@bash@/bin/bash @patchSageShebangs@ .
+@bash@/bin/bash @patchSageShebangs@ "$out/bin"
+
echo "Successfully installed $PKG_NAME"
if [ "$SAGE_CHECK" = "yes" ]; then

View file

@ -0,0 +1,13 @@
diff --git a/build/pkgs/python3/spkg-build b/build/pkgs/python3/spkg-build
index 56db087ae5..b450703c5f 100644
--- a/build/pkgs/python3/spkg-build
+++ b/build/pkgs/python3/spkg-build
@@ -27,6 +27,8 @@ fi
export EXTRA_CFLAGS="`testcflags.sh -Wno-unused` $CFLAGS"
unset CFLAGS
+export LDFLAGS="$LDFLAGS -lcrypt"
+
if [ "$UNAME" = Darwin ]; then
PYTHON_CONFIGURE="--disable-toolbox-glue $PYTHON_CONFIGURE"

View file

@ -1,12 +0,0 @@
--- old/build/pkgs/python2/spkg-install 2017-07-21 14:10:00.000000000 -0500
+++ new/build/pkgs/python2/spkg-install 2017-10-15 11:26:54.823134067 -0500
@@ -22,6 +22,9 @@
cd src
+LDFLAGS="-lcrypt $LDFLAGS"
+export LDFLAGS
+
if [ "$SAGE_DEBUG" = "yes" ]; then
echo "Building Python with pydebug"
PYTHON_CONFIGURE="$PYTHON_CONFIGURE --with-pydebug"

View file

@ -1,12 +0,0 @@
--- old/build/pkgs/python3/spkg-install 2017-07-21 14:10:00.000000000 -0500
+++ new/build/pkgs/python3/spkg-install 2017-10-15 13:11:17.769261404 -0500
@@ -22,6 +22,9 @@
cd src
+LDFLAGS="-lcrypt $LDFLAGS"
+export LDFLAGS
+
if [ "$SAGE_DEBUG" = "yes" ]; then
echo "Building Python with pydebug"
PYTHON_CONFIGURE="$PYTHON_CONFIGURE --with-pydebug"