-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #23160: Add a library of common helper functions for use in spkg…
…-install This idea has come up before but not been implemented. My implementation simply adds a collection of shell functions with names prefixed by `sdh_` for Sage distribution helpers (this is somewhat inspired by, but much simpler than, the `dh_` programs from the `debhelper` package in Debian). These functions are exported by `sage-spkg`, and so are immediately usable by any `spkg-build`, `spkg-install`, or similar scripts executed from `sage-spkg` (these are still not required to be shell scripts, but as most are having such a library is convenient). One piece of boilerplate I replaced with a function is the check in most `spkg-install`s for `$SAGE_LOCAL`. A downside to this is that if the script is run outside the correct environment, then rather than getting a useful error message we just get that `sdh_check_vars` is undefined. I have two thoughts on this: 1) In general these scripts shouldn't be run directly in the first place. In the case that they are (such as testing) the person developing the package should have some awareness of the fact that these scripts are being run from `sage-spkg` and assume `sage-env` has been sourced. 2) Most of the time these scripts are run, it's after they've been copied to a temporary build directory for the package. If nothing else, `sage-spkg` could create a wrapper around these scripts that automatically sets some default assumptions (such as sourcing `sage-env` and the new `sage-dist-helpers`). In general, though, I think having a library of helper functions will be a big improvement to the consistency and legibility of theses scripts. This ticket also updates the `spkg-install` for `patch` for demonstration purposes only. I don't intend with this to go on a mass rewriting of install scripts, but having this will be helpful for some other work (e.g. #22509, #22510). URL: https://trac.sagemath.org/23160 Reported by: embray Ticket author(s): Erik Bray Reviewer(s): Jeroen Demeyer
- Loading branch information
Showing
3 changed files
with
111 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Shell functions for making spkg-install scripts a little easier to write, | ||
# eliminating duplication. All Sage helper functions begin with sdh_ (for | ||
# Sage-distribution helper). Consult the below documentation for the list of | ||
# available helper functions: | ||
# | ||
# - sdh_check_vars [VARIABLE ...] | ||
# | ||
# Check that one or more variables are defined and non-empty, and exit with | ||
# an error if any are undefined or empty. Variable names should be given | ||
# without the '$' to prevent unwanted expansion. | ||
# | ||
# - sdh_guard | ||
# | ||
# Wrapper for `sdh_check_vars` that checks some common variables without | ||
# which many/most packages won't build correctly (SAGE_ROOT, SAGE_LOCAL, | ||
# SAGE_SHARE). This is important to prevent installation to unintended | ||
# locations. | ||
# | ||
# - sdh_configure [...] | ||
# | ||
# Runs `./configure --prefix="$SAGE_LOCAL"`. Additional arguments to | ||
# `./configure` may be given as arguments. | ||
# | ||
# - sdh_make [...] | ||
# | ||
# Runs `$MAKE` with the default target. Additional arguments to `make` may | ||
# be given as arguments. | ||
# | ||
# - sdh_make_install [...] | ||
# | ||
# Runs `$SAGE_SUDO $MAKE install`. Additional arguments to `make` may be | ||
# given as arguments. | ||
|
||
set -o allexport | ||
|
||
sdh_check_vars() { | ||
local varname | ||
while [ -n "$1" ]; do | ||
if [ -z "$(eval "echo "\${${1}+isset}"")" ]; then | ||
echo >&2 "${1} undefined ... exiting" | ||
echo >&2 "Maybe run 'sage --sh'?" | ||
exit 1 | ||
fi | ||
shift | ||
done | ||
} | ||
|
||
|
||
sdh_guard() { | ||
sdh_check_vars SAGE_ROOT SAGE_LOCAL SAGE_SHARE | ||
} | ||
|
||
|
||
sdh_configure() { | ||
local ret | ||
./configure --prefix="$SAGE_LOCAL" "$@" | ||
ret=$? | ||
if [ $ret -ne 0 ]; then | ||
echo >&2 "Error configuring $PKG_NAME" | ||
exit $ret | ||
fi | ||
} | ||
|
||
|
||
sdh_make() { | ||
local ret | ||
${MAKE:-make} "$@" | ||
ret=$? | ||
if [ $ret -ne 0 ]; then | ||
echo >&2 "Error building $PKG_NAME" | ||
exit $ret | ||
fi | ||
} | ||
|
||
|
||
sdh_make_install() { | ||
local ret | ||
$SAGE_SUDO ${MAKE:-make} install "$@" | ||
ret=$? | ||
if [ $ret -ne 0 ]; then | ||
echo >&2 "Error installing $PKG_NAME" | ||
exit $ret | ||
fi | ||
} | ||
|
||
|
||
set +o allexport |