Skip to content

Commit

Permalink
Trac #29052: Create build/bin/sage-build-env-config and call it from …
Browse files Browse the repository at this point in the history
…build/make/deps; add sage --buildsh

This is part of #21707 - "Split `sage-env` into 5".

We set up a new `configure`-generated, to-be-`source`d shell script
`build/bin/sage-build-env-config` to which we move environment variable
settings from `src/bin/sage-env[-config]` that are only needed for:

1. Sage-the-distribution while building spkgs,
2. Sage-the-distribution for building sagelib.

The new script is used in addition to `src/bin/sage-env` in these two
contexts.

We add a command `sage --buildsh`, like `sage --sh` but using the larger
environment.

--------

Follow-up:
- `build/make/install` contains more environment settings that should be
reviewed for moving to `sage-build-env-config`

URL: https://trac.sagemath.org/29052
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Dima Pasechnik, Volker Braun
  • Loading branch information
Release Manager committed Feb 27, 2020
2 parents 30ca11e + 2ab9b09 commit 610a582
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ gitlab-build-docker.log
/src/build
/src/Makefile
/src/bin/sage-env-config
/build/bin/sage-build-env-config

87 changes: 87 additions & 0 deletions build/bin/sage-build-env-config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -*- shell-script -*-

###########################################################################
#
# Set some environment variables for building Sage (the distribution).
#
# NOTES:
# - You must *source* this script instead of executing.
# - Use "return" instead of "exit" to signal a failure. Since this
# file is sourced, an "exit" here will actually exit src/bin/sage,
# which is probably not intended.
# - All environment variables set here should be *exported*, otherwise
# they won't be available in child programs.
#
# If you want to set all environment variables for your shell like
# they are during the build of Sage packages, type
#
# sage --buildsh
#
##########################################################################

# This is usually blank if the system GMP is used, or $SAGE_LOCAL otherwise
export SAGE_GMP_PREFIX="@SAGE_GMP_PREFIX@"
export SAGE_GMP_INCLUDE="@SAGE_GMP_INCLUDE@"
if [ -n "$SAGE_GMP_PREFIX" ]; then
# Many packages that depend on GMP accept a --with-gmp=<prefix> flag to
# their ./configure scripts. When using the system's GMP this is not
# generally necessary, but when using the GMP package installed in
# SAGE_LOCAL it is useful to pass it. We define this variable to
# pass to these packages' ./configure scripts. When using the system
# GMP its value is just blank (for many of these packages passing
# --with-gmp without an argument is actually a bug)
export SAGE_CONFIGURE_GMP="--with-gmp=$SAGE_GMP_PREFIX"
fi

# The MPFR case is very close to the GMP case above
# This is usually blank if the system MPFR is used, or $SAGE_LOCAL otherwise
export SAGE_MPFR_PREFIX="@SAGE_MPFR_PREFIX@"
if [ -n "$SAGE_MPFR_PREFIX" ]; then
# Some packages that depend on MPFR accept a --with-mpfr=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_MPFR="--with-mpfr=$SAGE_MPFR_PREFIX"
fi

# The MPC case is very close to the MPFR case above
# This is usually blank if the system MPC is used, or $SAGE_LOCAL otherwise
export SAGE_MPC_PREFIX="@SAGE_MPC_PREFIX@"
if [ -n "$SAGE_MPC_PREFIX" ]; then
# Some packages that depend on MPC accept a --with-mpc=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_MPC="--with-mpc=$SAGE_MPC_PREFIX"
fi

# Location of system crti.o, in case we build our own gcc
export SAGE_CRTI_DIR="@SAGE_CRTI_DIR@"

# This is usually blank if the system NTL is used, or $SAGE_LOCAL otherwise
export SAGE_NTL_PREFIX="@SAGE_NTL_PREFIX@"
if [ -n "$SAGE_NTL_PREFIX" ]; then
# Many packages that depend on NTL accept a --with-ntl=<prefix> flag to
# their ./configure scripts. When using the system's NTL this is not
# generally necessary, but when using the NTL package installed in
# SAGE_LOCAL it is useful to pass it.
export SAGE_CONFIGURE_NTL="--with-ntl=$SAGE_NTL_PREFIX"
fi

# The FLINT case is very close to the MPFR case above
# This is usually blank if the system FLINT is used, or $SAGE_LOCAL otherwise
export SAGE_FLINT_PREFIX="@SAGE_FLINT_PREFIX@"
if [ -n "$SAGE_FLINT_PREFIX" ]; then
# Some packages that depend on FLINT accept a --with-flint=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_FLINT="--with-flint=$SAGE_FLINT_PREFIX"
fi

# This is usually blank if the system PARI is used, or $SAGE_LOCAL otherwise
export SAGE_PARI_PREFIX="@SAGE_PARI_PREFIX@"
if [ -n "$SAGE_PARI_PREFIX" ]; then
# Some packages that depend on PARI accept a --with-pari=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_PARI="--with-pari=$SAGE_PARI_PREFIX"
fi
export SAGE_PARI_CFG="@SAGE_PARI_CFG@"

export SAGE_GLPK_PREFIX="@SAGE_GLPK_PREFIX@"
export SAGE_FREETYPE_PREFIX="@SAGE_FREETYPE_PREFIX@"
export SAGE_ARB_LIBRARY="@SAGE_ARB_LIBRARY@"
2 changes: 1 addition & 1 deletion build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ export PKG_NAME="$PKG_NAME"
export PKG_BASE="$PKG_BASE"
export PKG_VER="$PKG_VER"
for lib in "\$SAGE_ROOT/build/bin/sage-dist-helpers" "\$SAGE_SRC/bin/sage-env" ; do
for lib in "\$SAGE_ROOT/build/bin/sage-dist-helpers" "\$SAGE_SRC/bin/sage-env" "\$SAGE_ROOT/build/bin/sage-build-env-config"; do
source "\$lib"
if [ \$? -ne 0 ]; then
echo >&2 "Error: failed to source \$lib"
Expand Down
4 changes: 2 additions & 2 deletions build/make/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ endif
define SCRIPT_PACKAGE_templ
$(1): $(2)
$(AM_V_at)cd '$$(SAGE_ROOT)' && \
source '$$(SAGE_ROOT)/src/bin/sage-env' && \
source '$$(SAGE_ROOT)/src/bin/sage-env' && source '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
sage-logger -p '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' '$$(SAGE_LOGS)/$(1).log'

$(1)-clean:
-$(AM_V_at)cd '$$(SAGE_ROOT)' && \
source '$$(SAGE_ROOT)/src/bin/sage-env' && \
source '$$(SAGE_ROOT)/src/bin/sage-env' && source '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
'$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-uninstall'

endef
Expand Down
2 changes: 1 addition & 1 deletion build/make/deps
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ sagelib: \
$(inst_zn_poly) \
$(PCFILES)
$(AM_V_at)if [ -z "$$SAGE_INSTALL_FETCH_ONLY" ]; then \
cd $(SAGE_SRC) && source bin/sage-env && \
cd $(SAGE_SRC) && source bin/sage-env && source $(SAGE_ROOT)/build/bin/sage-build-env-config && \
sage-logger -p 'time $(MAKE) sage' '$(SAGE_LOGS)/sagelib-$(SAGE_VERSION).log'; \
fi

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ AC_SUBST_FILE([SAGE_MAKE_DEPS])

dnl AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([build/make/Makefile-auto build/make/Makefile src/Makefile])
AC_CONFIG_FILES([src/bin/sage-env-config])
AC_CONFIG_FILES([src/bin/sage-env-config build/bin/sage-build-env-config])

AC_CONFIG_FILES([build/pkgs/sage_conf/src/sage_conf.py build/pkgs/sage_conf/src/setup.cfg])

Expand Down
34 changes: 25 additions & 9 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ usage_advanced() {
echo " -R [...] -- run Sage's R with given arguments"
echo " -scons [...] -- run Sage's scons"
echo " -sh [...] -- run \$SHELL ($SHELL) with Sage environment variables"
echo " as they are set in the runtime of Sage"
echo " -buildsh [...] -- run \$SHELL ($SHELL) with Sage environment variables"
echo " as they are set while building Sage and its packages"
echo " -singular [...] -- run Sage's singular with given arguments"
echo " -sqlite3 [...] -- run Sage's sqlite3 with given arguments"
echo " -twistd [...] -- run Twisted server"
Expand Down Expand Up @@ -660,13 +663,26 @@ if [ "$1" = '-git-branch' -o "$1" = '--git-branch' ]; then
exec git --git-dir="$SAGE_ROOT"/.git rev-parse --abbrev-ref HEAD
fi

if [ "$1" = '-sh' -o "$1" = '--sh' ]; then
if [ "$1" = '-sh' -o "$1" = '--sh' -o "$1" = '-buildsh' -o "$1" = '--buildsh' ]; then
# AUTHORS:
# - Carl Witty and William Stein: initial version
# - Craig Citro: add options for not loading profile
# - Martin Albrecht: fix zshell prompt (#11866)
# - John Palmieri: shorten the prompts, and don't print messages if
# there are more arguments to 'sage -sh' (#11790)
if [ -z "$SAGE_SHPROMPT_PREFIX" ]; then
SAGE_SHPROMPT_PREFIX=sage-sh
fi
if [ "$1" = '-buildsh' -o "$1" = '--buildsh' ]; then
if [ ! -r "$SAGE_ROOT"/build/bin/sage-build-env-config ]; then
echo "error: '$SAGE_ROOT' does not contain build/bin/sage-build-env-config. Run configure first."
exit 1
fi
. "$SAGE_ROOT"/build/bin/sage-build-env-config || (echo "error: Error sourcing $SAGE_ROOT/build/bin/sage-build-env-config"; exit 1)
export SAGE_SHPROMPT_PREFIX=sage-buildsh
# We export it so that recursive invocation of 'sage-sh' from a sage-buildsh shows the sage-buildsh prompt;
# this makes sense because all environment variables set in build/bin/sage-build-env-config are exported.
fi
shift
# If $SHELL is unset, default to bash
if [ -z "$SHELL" ]; then
Expand All @@ -693,9 +709,9 @@ if [ "$1" = '-sh' -o "$1" = '--sh' ]; then
bash)
SHELL_OPTS="--norc"
if [ "$color_prompt" = yes ]; then
PS1="\[$(tput rev)\](sage-sh)\[$(tput sgr0)\] \u@\h:\W\$ "
PS1="\[$(tput rev)\]($SAGE_SHPROMPT_PREFIX)\[$(tput sgr0)\] \u@\h:\W\$ "
else
PS1="(sage-sh) \u@\h:\w\$ "
PS1="($SAGE_SHPROMPT_PREFIX) \u@\h:\w\$ "
fi
export PS1
;;
Expand All @@ -708,9 +724,9 @@ if [ "$1" = '-sh' -o "$1" = '--sh' ]; then
ksh)
SHELL_OPTS="-p"
if [ "$color_prompt" = yes ] ; then
PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
PS1="$(tput rev)($SAGE_SHPROMPT_PREFIX)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
else
PS1="(sage-sh) $USER@`hostname -s`:\${PWD##*/}$ "
PS1="($SAGE_SHPROMPT_PREFIX) $USER@`hostname -s`:\${PWD##*/}$ "
fi
export PS1
;;
Expand All @@ -719,9 +735,9 @@ if [ "$1" = '-sh' -o "$1" = '--sh' ]; then
# bash, but this is not guaranteed), so we don't set
# SHELL_OPTS.
if [ "$color_prompt" = yes ] ; then
PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
PS1="$(tput rev)($SAGE_SHPROMPT_PREFIX)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
else
PS1="(sage-sh) $USER@`hostname -s`:\${PWD}$ "
PS1="($SAGE_SHPROMPT_PREFIX) $USER@`hostname -s`:\${PWD}$ "
fi
export PS1
;;
Expand All @@ -732,7 +748,7 @@ if [ "$1" = '-sh' -o "$1" = '--sh' ]; then
SHELL_OPTS="-f"
;;
zsh)
PS1="%S(sage-sh)%s %n@%m:%~$ "
PS1="%S($SAGE_SHPROMPT_PREFIX)%s %n@%m:%~$ "
# In zsh, the system /etc/zshenv is *always* run,
# and this may change the path (like on OSX), so we'll
# create a temporary .zshenv to reset the path
Expand All @@ -744,7 +760,7 @@ EOF
export PS1
;;
*)
export PS1='(sage-sh) $ '
export PS1='($SAGE_SHPROMPT_PREFIX) $ '
;;
esac
if [ -n "$oldPS1" ]; then
Expand Down
67 changes: 0 additions & 67 deletions src/bin/sage-env-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,73 +36,6 @@ if [ "$SAGE_PYTHON_VERSION" = 3 ]; then
export SAGE_PYTHON3=yes
fi

# This is usually blank if the system GMP is used, or $SAGE_LOCAL otherwise
export SAGE_GMP_PREFIX="@SAGE_GMP_PREFIX@"
export SAGE_GMP_INCLUDE="@SAGE_GMP_INCLUDE@"
if [ -n "$SAGE_GMP_PREFIX" ]; then
# Many packages that depend on GMP accept a --with-gmp=<prefix> flag to
# their ./configure scripts. When using the system's GMP this is not
# generally necessary, but when using the GMP package installed in
# SAGE_LOCAL it is useful to pass it. We define this variable to
# pass to these packages' ./configure scripts. When using the system
# GMP its value is just blank (for many of these packages passing
# --with-gmp without an argument is actually a bug)
export SAGE_CONFIGURE_GMP="--with-gmp=$SAGE_GMP_PREFIX"
fi

# The MPFR case is very close to the GMP case above
# This is usually blank if the system MPFR is used, or $SAGE_LOCAL otherwise
export SAGE_MPFR_PREFIX="@SAGE_MPFR_PREFIX@"
if [ -n "$SAGE_MPFR_PREFIX" ]; then
# Some packages that depend on MPFR accept a --with-mpfr=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_MPFR="--with-mpfr=$SAGE_MPFR_PREFIX"
fi

# The MPC case is very close to the MPFR case above
# This is usually blank if the system MPC is used, or $SAGE_LOCAL otherwise
export SAGE_MPC_PREFIX="@SAGE_MPC_PREFIX@"
if [ -n "$SAGE_MPC_PREFIX" ]; then
# Some packages that depend on MPC accept a --with-mpc=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_MPC="--with-mpc=$SAGE_MPC_PREFIX"
fi

# Location of system crti.o, in case we build our own gcc
export SAGE_CRTI_DIR="@SAGE_CRTI_DIR@"

# This is usually blank if the system NTL is used, or $SAGE_LOCAL otherwise
export SAGE_NTL_PREFIX="@SAGE_NTL_PREFIX@"
if [ -n "$SAGE_NTL_PREFIX" ]; then
# Many packages that depend on NTL accept a --with-ntl=<prefix> flag to
# their ./configure scripts. When using the system's NTL this is not
# generally necessary, but when using the NTL package installed in
# SAGE_LOCAL it is useful to pass it.
export SAGE_CONFIGURE_NTL="--with-ntl=$SAGE_NTL_PREFIX"
fi

# The FLINT case is very close to the MPFR case above
# This is usually blank if the system FLINT is used, or $SAGE_LOCAL otherwise
export SAGE_FLINT_PREFIX="@SAGE_FLINT_PREFIX@"
if [ -n "$SAGE_FLINT_PREFIX" ]; then
# Some packages that depend on FLINT accept a --with-flint=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_FLINT="--with-flint=$SAGE_FLINT_PREFIX"
fi

# This is usually blank if the system PARI is used, or $SAGE_LOCAL otherwise
export SAGE_PARI_PREFIX="@SAGE_PARI_PREFIX@"
if [ -n "$SAGE_PARI_PREFIX" ]; then
# Some packages that depend on PARI accept a --with-pari=<prefix> flag to
# their ./configure scripts. Thus we deal with this just as with GMP above.
export SAGE_CONFIGURE_PARI="--with-pari=$SAGE_PARI_PREFIX"
fi
export SAGE_PARI_CFG="@SAGE_PARI_CFG@"

export SAGE_GLPK_PREFIX="@SAGE_GLPK_PREFIX@"
export SAGE_FREETYPE_PREFIX="@SAGE_FREETYPE_PREFIX@"
export SAGE_ARB_LIBRARY="@SAGE_ARB_LIBRARY@"

export SAGE_PKG_CONFIG_PATH="@SAGE_PKG_CONFIG_PATH@"
if [ -n "$SAGE_PKG_CONFIG_PATH" ]; then
# set up external pkg-config to look into SAGE_LOCAL/lib/pkgconfig/
Expand Down
2 changes: 2 additions & 0 deletions src/doc/en/reference/repl/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Command-line options for Sage
- ``--singular [...]`` -- run Sage's singular with the given arguments
- ``--twistd [...]`` -- run Twisted server
- ``--sh [...]`` -- run a shell with Sage environment variables set
- ``--buildsh [...]`` -- run a shell with Sage environment variables
as they are set in the runtime of Sage
- ``--gdb`` -- run Sage under the control of gdb
- ``--gdb-ipython`` -- run Sage's IPython under the control of gdb
- ``--cleaner`` -- run the Sage cleaner. This cleans up after Sage,
Expand Down

0 comments on commit 610a582

Please sign in to comment.