From b40ca73e708fea46daaebe02b316ca28cc3ed5a7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 22 Jun 2023 16:55:10 -0700 Subject: [PATCH 1/9] build/bin/sage-spkg: WIP: More options --- build/bin/sage-spkg | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index b540c8e866f..5835c703eb7 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -90,20 +90,25 @@ Search Sage's list of packages (see 'sage --package list') for a matching package, and if a match is found, install it. Options: - -s: do not delete the temporary build directory - -c: after installing, run the test suite for the package; - exit with an error on test suite failures - -w: after installing, run the test suite for the package; - print a warning on test suite failures - -d: only download the package -y: automatically reply "y" for all prompts regarding experimental and old-style packages; warning: there is no guarantee that these packages will build correctly; use at your own risk -n: automatically reply "n" for all prompts regarding experimental and old-style packages + -d: only download the package -o: allow fetching the package from its upstream URL when it is not available from the Sage mirrors (yet) + -b: build and stage only, do not install or check + -x: only run the test suite; this may assume that: + * the package has been installed already and/or that + * the temporary build directory has not been deleted + -c: after installing, run the test suite for the package; + exit with an error on test suite failures + -w: after installing, run the test suite for the package; + print a warning on test suite failures + -s: do not delete the temporary build directory, even + when the installation was successful EOF } @@ -230,6 +235,8 @@ fi INFO=0 YES=0 KEEP_EXISTING=0 +BUILD=1 +INSTALL=1 while true; do case "$1" in --info) @@ -246,6 +253,8 @@ while true; do export SAGE_CHECK=yes;; -w|--check-warning-only) export SAGE_CHECK=warn;; + -x|--check-only) + INSTALL=1;; -k|--keep-existing) KEEP_EXISTING=yes;; -o|--allow-upstream) From 1f2cc9e432e126d4b0d66149e70647feeaa36dad Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 18 Nov 2023 19:07:24 -0800 Subject: [PATCH 2/9] build/bin/sage-spkg: Manage SAGE_KEEP_BUILT_SPKGS via stamp file .keep --- build/bin/sage-spkg | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index 5835c703eb7..0f2e8c0061b 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -460,6 +460,10 @@ echo "Setting up build directory for $PKG_NAME" cp -RLp "$PKG_SCRIPTS" "$PKG_NAME" cd "$PKG_NAME" || exit $? +if [ "$SAGE_KEEP_BUILT_SPKGS" = "yes" ]; then + touch .keep +fi + case "$PKG_SRC" in *.whl) # (Platform-independent) wheel @@ -823,7 +827,7 @@ echo "Successfully installed $PKG_NAME" ################################################################## # Delete the temporary build directory if required ################################################################## -if [ "x$SAGE_KEEP_BUILT_SPKGS" != "xyes" ]; then +if [ ! -e "$SAGE_BUILD_DIR/$PKG_NAME/.keep" ]; then echo "Deleting temporary build directory" echo "$SAGE_BUILD_DIR/$PKG_NAME" # On Solaris, the current working directory cannot be deleted, From f2339b28bf6d5ec1bb9b08acbe7ba5452b79fc95 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 19 Nov 2023 11:15:33 -0800 Subject: [PATCH 3/9] build/bin/sage-spkg: Split into separate bash functions --- build/bin/sage-spkg | 97 +++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index 0f2e8c0061b..7adef6f2a97 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -9,21 +9,7 @@ # # sage-spkg [] # -# Options can be: -# -s: do not delete temporary build directory -# -k: do not uninstall existing installation of this package before -# installing; instead simply overwrite existing files. -# -c: after installing, run the test suite for the spkg. This should -# override the settings of SAGE_CHECK. -# Exit with an error if the test suite fails. -# -w: after installing, run the test suite for the spkg. This should -# override the settings of SAGE_CHECK. -# Print a warning if the test suite fails. -# -d: only download the package -# -y: automatically reply "y" for all prompts regarding -# experimental and old-style packages -# -n: automatically reply "n" for all prompts regarding -# experimental and old-style packages +# Options: see usage() below. # # A package may assume that the following environment # variables are defined: @@ -100,15 +86,16 @@ Options: -o: allow fetching the package from its upstream URL when it is not available from the Sage mirrors (yet) -b: build and stage only, do not install or check - -x: only run the test suite; this may assume that: + -x: exclusively run the test suite; this may assume that: * the package has been installed already and/or that * the temporary build directory has not been deleted -c: after installing, run the test suite for the package; exit with an error on test suite failures -w: after installing, run the test suite for the package; print a warning on test suite failures - -s: do not delete the temporary build directory, even - when the installation was successful + -s: save (do not delete) the temporary build directory, + even when the installation was successful + -e: erase (delete) the temporary build directory EOF } @@ -254,7 +241,7 @@ while true; do -w|--check-warning-only) export SAGE_CHECK=warn;; -x|--check-only) - INSTALL=1;; + INSTALL=0;; -k|--keep-existing) KEEP_EXISTING=yes;; -o|--allow-upstream) @@ -267,10 +254,6 @@ while true; do shift done - -################################################################## -# Figure out the package filename, download it if needed. -################################################################## # One should be able to install a package using # sage -i @@ -322,8 +305,14 @@ fi PKG_BASE_VER=`echo $PKG_VER | sed 's/\.p[0-9][0-9]*$//'` PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini" | sed "s/VERSION/$PKG_BASE_VER/"` -# Warning for experimental packages -if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" -a $INFO = 0 ]; then + +if [ $INFO -ne 0 ]; then + exec sage-spkg-info $PKG_BASE +fi + + +warning_for_experimental_packages() { ############################ +if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" ]; then if [ $YES != 1 ]; then # We use /dev/tty here because our output may be redirected # to a logfile, or line-buffered. @@ -353,11 +342,10 @@ EOF echo > /dev/tty "OK, installing $PKG_NAME now..." fi fi +} ################################################################ +warning_for_experimental_packages -if [ $INFO -ne 0 ]; then - exec sage-spkg-info $PKG_BASE -fi - +ensure_pkg_src() { ############################################### # If we haven't found the package yet, we must download it if [ ! -f "$PKG_SRC" ]; then if [ -n "$PKG_NAME_UPSTREAM" ]; then @@ -394,12 +382,15 @@ if [ -n "$SAGE_SPKG_COPY_UPSTREAM" ]; then exit 1 fi fi +} ################################################################ +ensure_pkg_src + if [ -n "$SAGE_INSTALL_FETCH_ONLY" ]; then exit 0 fi ################################################################## -# Setup directories +setup_directories() { ################################################################## for dir in "$SAGE_SPKG_INST" "$SAGE_SPKG_SCRIPTS" "$SAGE_BUILD_DIR"; do @@ -451,9 +442,11 @@ if [ -e "$PKG_NAME" ]; then error_msg "Error (re)moving $PKG_NAME" exit 1 fi +} ################################################################ +setup_directories ################################################################## -# Extract the package +extract_the_package() { ################################################################## echo "Setting up build directory for $PKG_NAME" @@ -489,9 +482,12 @@ case "$PKG_SRC" in cd .. ;; esac +} ################################################################ +extract_the_package ################################################################## -# The package has been extracted, prepare for installation +# The package has been extracted, +prepare_for_installation() { ################################################################## # Rewrites the given bash pseudo-script with a boilerplate header that includes @@ -579,6 +575,12 @@ for script in $WRAPPED_SCRIPTS; do write_script_wrapper "$(pwd)/$script" "$script_dir" fi done +} ################################################################ +prepare_for_installation + +################################################################## +actually_build_and_install() { +################################################################## echo "****************************************************" echo "Host system:" @@ -618,10 +620,6 @@ if [ "$UNAME" = "CYGWIN" ]; then sage-flock -s $lock_type 200 fi -################################################################## -# Actually install -################################################################## - # Set the $SAGE_DESTDIR variable to be passed to the spkg-install # script (the script itself could set this, but better to standardize # this in one place) @@ -671,7 +669,10 @@ else exit 1 fi fi +} ################################################################ +actually_build_and_install +unload_destdir() { # To work around #26996: Remove the symlink set, or we get "cp: cannot overwrite directory" rm -f "$SAGE_DESTDIR_LOCAL/lib64" @@ -705,13 +706,14 @@ if [ -d "$SAGE_DESTDIR" ]; then rm -rf "$SAGE_DESTDIR" fi - # At this stage the path in $SAGE_DESTDIR no longer exists, so the variable # should be unset unset SAGE_DESTDIR unset SAGE_DESTDIR_LOCAL +} ################################################################ +unload_destdir - +install_scripts() { ############################################## # Some spkg scripts, if they exist, should also be installed to # $SAGE_SPKG_SCRIPTS; they are not included in the package's manifest, but are # removed by sage-spkg-uninstall @@ -739,8 +741,10 @@ for script in $INSTALLED_SCRIPTS; do fi fi done +} ################################################################ +install_scripts - +post_install() { ################################################# # Run the post-install script, if any if [ -f spkg-postinst ]; then echo "Running post-install script for $PKG_NAME." @@ -763,8 +767,10 @@ if [ "$UNAME" = "CYGWIN" ]; then sage-flock -x "$SAGE_LOCAL/var/lock/rebase.lock" \ sage-rebase.sh "$SAGE_LOCAL" 2>/dev/null fi +} ################################################################ +post_install - +run_test_suite() { ############################################### # Note: spkg-check tests are run after the package has been copied into # SAGE_INST_LOCAL. It might make more sense to run the tests before, but the # spkg-check scripts were written before use of DESTDIR installs, and so @@ -792,7 +798,10 @@ if [ "$SAGE_CHECK" = "yes" -o "$SAGE_CHECK" = "warn" ]; then TEST_SUITE_RESULT="not available" fi fi +} ################################################################ +run_test_suite +write_installation_record() { #################################### # For each line in $FILE_LIST, enclose in double quotes: NEW_LIST="" for f in $FILE_LIST; do @@ -819,13 +828,14 @@ cat > "$PKG_NAME_INSTALLED" << __EOF__ ] } __EOF__ - +} ################################################################ +write_installation_record echo "Successfully installed $PKG_NAME" ################################################################## -# Delete the temporary build directory if required +delete_the_temporary_build_directory_if_required() { ################################################################## if [ ! -e "$SAGE_BUILD_DIR/$PKG_NAME/.keep" ]; then echo "Deleting temporary build directory" @@ -838,6 +848,7 @@ else echo "You can safely delete the temporary build directory" echo "$SAGE_BUILD_DIR/$PKG_NAME" fi - +} ################################################################ +delete_the_temporary_build_directory_if_required echo "Finished installing $PKG_NAME" From aa8124c9f757e37bcaad47132a53906f733f92af Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 19 Nov 2023 11:45:41 -0800 Subject: [PATCH 4/9] build/bin/sage-spkg: Move function calls to the bottom of the file --- build/bin/sage-spkg | 109 +++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index 7adef6f2a97..f998a2dcf50 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -306,11 +306,6 @@ PKG_BASE_VER=`echo $PKG_VER | sed 's/\.p[0-9][0-9]*$//'` PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini" | sed "s/VERSION/$PKG_BASE_VER/"` -if [ $INFO -ne 0 ]; then - exec sage-spkg-info $PKG_BASE -fi - - warning_for_experimental_packages() { ############################ if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" ]; then if [ $YES != 1 ]; then @@ -342,8 +337,7 @@ EOF echo > /dev/tty "OK, installing $PKG_NAME now..." fi fi -} ################################################################ -warning_for_experimental_packages +} ############################## warning_for_experimental_packages ensure_pkg_src() { ############################################### # If we haven't found the package yet, we must download it @@ -382,16 +376,9 @@ if [ -n "$SAGE_SPKG_COPY_UPSTREAM" ]; then exit 1 fi fi -} ################################################################ -ensure_pkg_src +} ################################################# ensure_pkg_src -if [ -n "$SAGE_INSTALL_FETCH_ONLY" ]; then - exit 0 -fi - -################################################################## -setup_directories() { -################################################################## +setup_directories() { ############################################ for dir in "$SAGE_SPKG_INST" "$SAGE_SPKG_SCRIPTS" "$SAGE_BUILD_DIR"; do mkdir -p "$dir" @@ -442,12 +429,9 @@ if [ -e "$PKG_NAME" ]; then error_msg "Error (re)moving $PKG_NAME" exit 1 fi -} ################################################################ -setup_directories +} ############################################## setup_directories -################################################################## -extract_the_package() { -################################################################## +extract_the_package() { ########################################## echo "Setting up build directory for $PKG_NAME" cp -RLp "$PKG_SCRIPTS" "$PKG_NAME" @@ -482,13 +466,10 @@ case "$PKG_SRC" in cd .. ;; esac -} ################################################################ -extract_the_package +} ############################################ extract_the_package -################################################################## # The package has been extracted, -prepare_for_installation() { -################################################################## +prepare_for_installation() { ##################################### # Rewrites the given bash pseudo-script with a boilerplate header that includes # the shebang line and sourcing sage-env. Make sure the name of the script is @@ -575,12 +556,9 @@ for script in $WRAPPED_SCRIPTS; do write_script_wrapper "$(pwd)/$script" "$script_dir" fi done -} ################################################################ -prepare_for_installation +} ####################################### prepare_for_installation -################################################################## -actually_build_and_install() { -################################################################## +actually_build_and_install() { ################################### echo "****************************************************" echo "Host system:" @@ -591,15 +569,12 @@ echo "C compiler version:" $CC -v echo "****************************************************" -################################################################## # Poison the proxy variable to forbid downloads in spkg-install -################################################################## export http_proxy=http://192.0.2.0:5187/ export https_proxy=$http_proxy export ftp_proxy=$http_proxy export rsync_proxy=$http_proxy -################################################################## # We need to run sage-rebase.sh for each package installed, but it # can be dangerous to do this while other packages are installing # so we need to use a lock to manage when rebase is allowed to @@ -609,8 +584,6 @@ export rsync_proxy=$http_proxy # that. This also unfortunately slows down parallel builds since # all packages will eventually need to wait for this lock, but # again there's no simple way around that. -################################################################## - if [ "$UNAME" = "CYGWIN" ]; then # This is a global lock - so we use SAGE_LOCAL, not SAGE_INST_LOCAL. if [ ! -d "$SAGE_LOCAL/var/lock" ]; then @@ -669,11 +642,11 @@ else exit 1 fi fi -} ################################################################ -actually_build_and_install +} ##################################### actually_build_and_install -unload_destdir() { -# To work around #26996: Remove the symlink set, or we get "cp: cannot overwrite directory" +unload_destdir() { ############################################### +# To work around #26996: Remove the symlink set, +# or we get "cp: cannot overwrite directory" rm -f "$SAGE_DESTDIR_LOCAL/lib64" # All spkgs should eventually support this, but fall back on old behavior in @@ -710,8 +683,7 @@ fi # should be unset unset SAGE_DESTDIR unset SAGE_DESTDIR_LOCAL -} ################################################################ -unload_destdir +} ################################################# unload_destdir install_scripts() { ############################################## # Some spkg scripts, if they exist, should also be installed to @@ -741,8 +713,7 @@ for script in $INSTALLED_SCRIPTS; do fi fi done -} ################################################################ -install_scripts +} ################################################ install_scripts post_install() { ################################################# # Run the post-install script, if any @@ -767,8 +738,7 @@ if [ "$UNAME" = "CYGWIN" ]; then sage-flock -x "$SAGE_LOCAL/var/lock/rebase.lock" \ sage-rebase.sh "$SAGE_LOCAL" 2>/dev/null fi -} ################################################################ -post_install +} ################################################### post_install run_test_suite() { ############################################### # Note: spkg-check tests are run after the package has been copied into @@ -783,7 +753,8 @@ if [ "$SAGE_CHECK" = "yes" -o "$SAGE_CHECK" = "warn" ]; then if [ $? -ne 0 ]; then TEST_SUITE_RESULT="failed" if [ "$SAGE_CHECK" = "warn" ]; then - # The following warning message must be consistent with SAGE_ROOT/build/make/install (see trac:32781) + # The following warning message must be consistent + # with SAGE_ROOT/build/make/install (see #32781) error_msg "Warning: Failures testing package $PKG_NAME (ignored)" "make check" else error_msg "Error testing package $PKG_NAME" "make check" @@ -798,8 +769,7 @@ if [ "$SAGE_CHECK" = "yes" -o "$SAGE_CHECK" = "warn" ]; then TEST_SUITE_RESULT="not available" fi fi -} ################################################################ -run_test_suite +} ################################################# run_test_suite write_installation_record() { #################################### # For each line in $FILE_LIST, enclose in double quotes: @@ -828,15 +798,9 @@ cat > "$PKG_NAME_INSTALLED" << __EOF__ ] } __EOF__ -} ################################################################ -write_installation_record +} ###################################### write_installation_record -echo "Successfully installed $PKG_NAME" - - -################################################################## -delete_the_temporary_build_directory_if_required() { -################################################################## +delete_the_temporary_build_directory_if_required() { ############# if [ ! -e "$SAGE_BUILD_DIR/$PKG_NAME/.keep" ]; then echo "Deleting temporary build directory" echo "$SAGE_BUILD_DIR/$PKG_NAME" @@ -848,7 +812,36 @@ else echo "You can safely delete the temporary build directory" echo "$SAGE_BUILD_DIR/$PKG_NAME" fi -} ################################################################ +} ############### delete_the_temporary_build_directory_if_required + + +################################################################## +# MAIN +################################################################## + +if [ $INFO -ne 0 ]; then + exec sage-spkg-info $PKG_BASE +fi + +warning_for_experimental_packages +ensure_pkg_src + +if [ -n "$SAGE_INSTALL_FETCH_ONLY" ]; then + exit 0 +fi + +setup_directories +extract_the_package +prepare_for_installation +actually_build_and_install +unload_destdir +install_scripts +post_install +run_test_suite +write_installation_record + +echo "Successfully installed $PKG_NAME" + delete_the_temporary_build_directory_if_required echo "Finished installing $PKG_NAME" From 3af1f455206454bdaa7255a2f7fa4029beee5e31 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 19 Nov 2023 12:17:25 -0800 Subject: [PATCH 5/9] build/bin/sage-spkg: implement new options --- build/bin/sage-spkg | 76 +++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index f998a2dcf50..64faf19e166 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -75,6 +75,16 @@ Usage: sage {-i|-p} Search Sage's list of packages (see 'sage --package list') for a matching package, and if a match is found, install it. +Modes of operation: + -d: only download the package + -b: build and install (stage) only, do not run post-install + or check + -p: post-install only + -x: exclusively run the test suite; this may assume that: + * the package has been installed already and/or that + * the temporary build directory has not been deleted + -e: erase (delete) the temporary build directory only + Options: -y: automatically reply "y" for all prompts regarding experimental and old-style packages; warning: there @@ -82,20 +92,14 @@ Options: use at your own risk -n: automatically reply "n" for all prompts regarding experimental and old-style packages - -d: only download the package -o: allow fetching the package from its upstream URL when it is not available from the Sage mirrors (yet) - -b: build and stage only, do not install or check - -x: exclusively run the test suite; this may assume that: - * the package has been installed already and/or that - * the temporary build directory has not been deleted -c: after installing, run the test suite for the package; exit with an error on test suite failures -w: after installing, run the test suite for the package; print a warning on test suite failures -s: save (do not delete) the temporary build directory, even when the installation was successful - -e: erase (delete) the temporary build directory EOF } @@ -222,8 +226,9 @@ fi INFO=0 YES=0 KEEP_EXISTING=0 -BUILD=1 INSTALL=1 +POST_INSTALL=1 +ERASE_ONLY=0 while true; do case "$1" in --info) @@ -240,10 +245,16 @@ while true; do export SAGE_CHECK=yes;; -w|--check-warning-only) export SAGE_CHECK=warn;; + -b|--build-and-stage-only) + POST_INSTALL=0; export SAGE_CHECK=no;; + -p|--post-install-only) + INSTALL=0; export SAGE_CHECK=no;; -x|--check-only) - INSTALL=0;; + INSTALL=0; POST_INSTALL=0; export SAGE_CHECK=yes;; -k|--keep-existing) KEEP_EXISTING=yes;; + -e|--erase-build-directory-only) + ERASE_ONLY=1;; -o|--allow-upstream) SAGE_DOWNLOAD_FILE_OPTIONS+=" --allow-upstream";; -*) @@ -800,14 +811,18 @@ cat > "$PKG_NAME_INSTALLED" << __EOF__ __EOF__ } ###################################### write_installation_record -delete_the_temporary_build_directory_if_required() { ############# -if [ ! -e "$SAGE_BUILD_DIR/$PKG_NAME/.keep" ]; then +delete_the_temporary_build_directory() { ######################### echo "Deleting temporary build directory" echo "$SAGE_BUILD_DIR/$PKG_NAME" # On Solaris, the current working directory cannot be deleted, # so we "cd" out of $SAGE_BUILD_DIR/$PKG_NAME. See #12637. cd "$SAGE_BUILD_DIR" rm -rf "$SAGE_BUILD_DIR/$PKG_NAME" +} ########################### delete_the_temporary_build_directory + +delete_the_temporary_build_directory_if_required() { ############# +if [ ! -e "$SAGE_BUILD_DIR/$PKG_NAME/.keep" ]; then + delete_the_temporary_build_directory else echo "You can safely delete the temporary build directory" echo "$SAGE_BUILD_DIR/$PKG_NAME" @@ -823,25 +838,38 @@ if [ $INFO -ne 0 ]; then exec sage-spkg-info $PKG_BASE fi -warning_for_experimental_packages -ensure_pkg_src +if [ $ERASE_ONLY = 1 ]; then + delete_the_temporary_build_directory + exit 0 +fi + +if [ $INSTALL = 1 ]; then + warning_for_experimental_packages + ensure_pkg_src +fi if [ -n "$SAGE_INSTALL_FETCH_ONLY" ]; then exit 0 fi -setup_directories -extract_the_package -prepare_for_installation -actually_build_and_install -unload_destdir -install_scripts -post_install -run_test_suite -write_installation_record +if [ $INSTALL = 1 ]; then + setup_directories + extract_the_package + prepare_for_installation + actually_build_and_install +fi -echo "Successfully installed $PKG_NAME" +if [ $POST_INSTALL = 1 ]; then + unload_destdir + install_scripts + post_install +fi -delete_the_temporary_build_directory_if_required +run_test_suite -echo "Finished installing $PKG_NAME" +if [ $POST_INSTALL = 1 ]; then + write_installation_record + echo "Successfully installed $PKG_NAME" + delete_the_temporary_build_directory_if_required + echo "Finished installing $PKG_NAME" +fi From 8628f2e5a056bc4880d746cba6c66527e9c9ea7b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 19 Nov 2023 14:39:37 -0800 Subject: [PATCH 6/9] build/bin/sage-spkg: Move some variable settings to top --- build/bin/sage-spkg | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index 64faf19e166..8534d4ae37b 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -316,6 +316,20 @@ fi PKG_BASE_VER=`echo $PKG_VER | sed 's/\.p[0-9][0-9]*$//'` PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini" | sed "s/VERSION/$PKG_BASE_VER/"` +# Set the $SAGE_DESTDIR variable to be passed to the spkg-install +# script (the script itself could set this, but better to standardize +# this in one place) +export SAGE_DESTDIR="${SAGE_BUILD_DIR}/${PKG_NAME}/inst" + +# The actual prefix where the installation will be staged. This is the +# directory that you need to work in if you want to change the staged +# installation tree (before final installation to $SAGE_INST_LOCAL) at the +# end of spkg-install. +export SAGE_DESTDIR_LOCAL="${SAGE_DESTDIR}${SAGE_INST_LOCAL}" + +INSTALLED_SCRIPTS="prerm piprm postrm" +WRAPPED_SCRIPTS="build install check preinst postinst $INSTALLED_SCRIPTS" + warning_for_experimental_packages() { ############################ if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" ]; then @@ -543,10 +557,6 @@ __EOF__ trap - ERR } - -INSTALLED_SCRIPTS="prerm piprm postrm" -WRAPPED_SCRIPTS="build install check preinst postinst $INSTALLED_SCRIPTS" - # Prepare script for uninstallation of packages that use sdh_pip_install # or sdh_store_and_pip_install_wheel. echo 'sdh_pip_uninstall -r $SAGE_SPKG_SCRIPTS/$PKG_BASE/spkg-requirements.txt' > spkg-piprm.in @@ -604,17 +614,6 @@ if [ "$UNAME" = "CYGWIN" ]; then sage-flock -s $lock_type 200 fi -# Set the $SAGE_DESTDIR variable to be passed to the spkg-install -# script (the script itself could set this, but better to standardize -# this in one place) -export SAGE_DESTDIR="${SAGE_BUILD_DIR}/${PKG_NAME}/inst" - -# The actual prefix where the installation will be staged. This is the -# directory that you need to work in if you want to change the staged -# installation tree (before final installation to $SAGE_INST_LOCAL) at the -# end of spkg-install. -export SAGE_DESTDIR_LOCAL="${SAGE_DESTDIR}${SAGE_INST_LOCAL}" - # First uninstall the previous version of this package, if any if [ "$KEEP_EXISTING" != "yes" ]; then sage-spkg-uninstall "$PKG_BASE" "$SAGE_INST_LOCAL" From 5aa97fe1cc16d9a837c94d20728076bac2f3c249 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 19 Nov 2023 14:54:35 -0800 Subject: [PATCH 7/9] build/bin/sage-spkg: Fix build directory handling when using -x, -p --- build/bin/sage-spkg | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index 8534d4ae37b..d097cd83588 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -458,6 +458,7 @@ fi extract_the_package() { ########################################## +cd "$SAGE_BUILD_DIR" || exit $? echo "Setting up build directory for $PKG_NAME" cp -RLp "$PKG_SCRIPTS" "$PKG_NAME" cd "$PKG_NAME" || exit $? @@ -661,8 +662,8 @@ rm -f "$SAGE_DESTDIR_LOCAL/lib64" # All spkgs should eventually support this, but fall back on old behavior in # case DESTDIR=$SAGE_DESTDIR installation was not used -echo "Copying package files from temporary location $SAGE_DESTDIR to $SAGE_INST_LOCAL" if [ -d "$SAGE_DESTDIR" ]; then + echo "Copying package files from temporary location $SAGE_DESTDIR to $SAGE_INST_LOCAL" # Some `find` implementations will put superfluous slashes in the # output if we give them a directory name with a slash; so make sure # any trailing slash is removed; https://github.com/sagemath/sage/issues/26013 @@ -687,6 +688,9 @@ if [ -d "$SAGE_DESTDIR" ]; then # Remove the $SAGE_DESTDIR entirely once all files have been moved to their # final location. rm -rf "$SAGE_DESTDIR" +else + echo "The temporary location $SAGE_DESTDIR does not exist; has the build directory been deleted?" + exit 1 fi # At this stage the path in $SAGE_DESTDIR no longer exists, so the variable @@ -856,6 +860,8 @@ if [ $INSTALL = 1 ]; then extract_the_package prepare_for_installation actually_build_and_install +else + cd "$SAGE_BUILD_DIR/$PKG_NAME" || exit $? fi if [ $POST_INSTALL = 1 ]; then From d41c0320f06ae6ab709e1c759a91a36c1657fd7b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 23 Nov 2023 11:33:40 -0800 Subject: [PATCH 8/9] build/bin/sage-spkg: Add long switches for all mode switches, complain if more than one given --- build/bin/sage-spkg | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index d097cd83588..5902d991940 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -75,17 +75,21 @@ Usage: sage {-i|-p} Search Sage's list of packages (see 'sage --package list') for a matching package, and if a match is found, install it. -Modes of operation: - -d: only download the package - -b: build and install (stage) only, do not run post-install - or check - -p: post-install only - -x: exclusively run the test suite; this may assume that: +Modes of operation (provide at most one): + -d, --download-only: only download the package + -b, --build-and-stage-only: build and install (stage) only, + do not run post-install or check + -p, --post-install-only: post-install only + -x, --check-only: exclusively run the test suite; + this may assume that: * the package has been installed already and/or that * the temporary build directory has not been deleted - -e: erase (delete) the temporary build directory only + -e, --erase-build-directory-only: erase (delete) the temporary + build directory only + --info: print information on the package only + --help: print this help only -Options: +Other options: -y: automatically reply "y" for all prompts regarding experimental and old-style packages; warning: there is no guarantee that these packages will build correctly; @@ -229,15 +233,21 @@ KEEP_EXISTING=0 INSTALL=1 POST_INSTALL=1 ERASE_ONLY=0 +MODE_SWITCHES= while true; do case "$1" in --info) + MODE_SWITCHES+=", $1" INFO=1;; + --help) + usage + exit 0;; -y) YES=1;; -n) YES=-1;; - -d) + -d|--download-only) + MODE_SWITCHES+=", $1" SAGE_INSTALL_FETCH_ONLY=1;; -s) export SAGE_KEEP_BUILT_SPKGS=yes;; @@ -246,14 +256,18 @@ while true; do -w|--check-warning-only) export SAGE_CHECK=warn;; -b|--build-and-stage-only) + MODE_SWITCHES+=", $1" POST_INSTALL=0; export SAGE_CHECK=no;; -p|--post-install-only) + MODE_SWITCHES+=", $1" INSTALL=0; export SAGE_CHECK=no;; -x|--check-only) + MODE_SWITCHES+=", $1" INSTALL=0; POST_INSTALL=0; export SAGE_CHECK=yes;; -k|--keep-existing) KEEP_EXISTING=yes;; -e|--erase-build-directory-only) + MODE_SWITCHES+=", $1" ERASE_ONLY=1;; -o|--allow-upstream) SAGE_DOWNLOAD_FILE_OPTIONS+=" --allow-upstream";; @@ -264,7 +278,15 @@ while true; do esac shift done - +MODE_SWITCHES=${MODE_SWITCHES#, } +case "$MODE_SWITCHES" in + *,*) + echo >&2 "Error: at most one of the mode switches may be given, got $MODE_SWITCHES" + echo >&2 + usage + exit 1 + ;; +esac # One should be able to install a package using # sage -i From 756ae53a73b943c56dd5f1d4de7b649eaeff0beb Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 23 Nov 2023 11:37:34 -0800 Subject: [PATCH 9/9] build/bin/sage-spkg: Make it clearer that one can unload the staged installation only once --- build/bin/sage-spkg | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index 5902d991940..19553b3c139 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -79,7 +79,8 @@ Modes of operation (provide at most one): -d, --download-only: only download the package -b, --build-and-stage-only: build and install (stage) only, do not run post-install or check - -p, --post-install-only: post-install only + -p, --post-install-only: unload the staged installation + directory and run other post-installation steps only -x, --check-only: exclusively run the test suite; this may assume that: * the package has been installed already and/or that @@ -685,7 +686,7 @@ rm -f "$SAGE_DESTDIR_LOCAL/lib64" # All spkgs should eventually support this, but fall back on old behavior in # case DESTDIR=$SAGE_DESTDIR installation was not used if [ -d "$SAGE_DESTDIR" ]; then - echo "Copying package files from temporary location $SAGE_DESTDIR to $SAGE_INST_LOCAL" + echo "Moving package files from temporary location $SAGE_DESTDIR to $SAGE_INST_LOCAL" # Some `find` implementations will put superfluous slashes in the # output if we give them a directory name with a slash; so make sure # any trailing slash is removed; https://github.com/sagemath/sage/issues/26013 @@ -703,7 +704,7 @@ if [ -d "$SAGE_DESTDIR" ]; then # Copy files into $SAGE_INST_LOCAL $SAGE_SUDO cp -Rp "$PREFIX/." "$SAGE_INST_LOCAL" if [ $? -ne 0 ]; then - error_msg "Error copying files for $PKG_NAME." + error_msg "Error moving files for $PKG_NAME." exit 1 fi @@ -711,7 +712,7 @@ if [ -d "$SAGE_DESTDIR" ]; then # final location. rm -rf "$SAGE_DESTDIR" else - echo "The temporary location $SAGE_DESTDIR does not exist; has the build directory been deleted?" + echo "The temporary location $SAGE_DESTDIR does not exist; has it been unloaded already?" exit 1 fi