Skip to content

Commit 0e3f69b

Browse files
author
Matthias Koeppe
committed
build/bin/sage-spkg: Make spkg-check an installed script
1 parent a127b63 commit 0e3f69b

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

build/bin/sage-spkg

+45-24
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ export SAGE_DESTDIR="${SAGE_BUILD_DIR}/${PKG_NAME}/inst"
355355
# end of spkg-install.
356356
export SAGE_DESTDIR_LOCAL="${SAGE_DESTDIR}${SAGE_INST_LOCAL}"
357357

358-
INSTALLED_SCRIPTS="prerm piprm postrm"
359-
WRAPPED_SCRIPTS="build install check preinst postinst $INSTALLED_SCRIPTS"
358+
INSTALLED_SCRIPTS_DEST="$SAGE_SPKG_SCRIPTS/$PKG_BASE"
359+
INSTALLED_SCRIPTS="prerm piprm postrm check"
360+
WRAPPED_SCRIPTS="build install preinst pipinst postinst $INSTALLED_SCRIPTS"
360361

361362

362363
warning_for_experimental_packages() { ############################
@@ -490,7 +491,7 @@ if [ -z "$PKG_NAME_UPSTREAM" ]; then
490491
if [ -d "$PKG_SCRIPTS"/src ]; then
491492
ln -s $(cd "$PKG_SCRIPTS"/src && pwd -P) "$PKG_NAME"/src
492493
fi
493-
for a in build install check preinst postinst; do # replace by use of $WRAPPED_SCRIPTS later
494+
for a in $WRAPPED_SCRIPTS; do
494495
if [ -r "$PKG_SCRIPTS"/spkg-$a.in ]; then
495496
cp "$PKG_SCRIPTS"/spkg-$a.in "$PKG_NAME"/
496497
elif [ -x "$PKG_SCRIPTS"/spkg-$a ]; then
@@ -544,6 +545,7 @@ prepare_for_installation() { #####################################
544545
write_script_wrapper() {
545546
local script="$1"
546547
local script_dir="$2"
548+
local fallback_script_dir="$3"
547549

548550
trap "echo >&2 Error: Unexpected error writing wrapper script for $script; exit \$_" ERR
549551

@@ -584,14 +586,21 @@ if [ \$? -ne 0 ]; then
584586
exit 1
585587
fi
586588
587-
cd "\$SAGE_PKG_DIR"
589+
__EOF__
590+
if [ -n "$fallback_script_dir" ]; then
591+
cat >> "$tmpscript" <<__EOF__
592+
cd "\$SAGE_PKG_DIR" 2>/dev/null || cd "$fallback_script_dir"
593+
594+
__EOF__
595+
else
596+
cat >> "$tmpscript" <<__EOF__
588597
if [ \$? -ne 0 ]; then
589598
echo >&2 "Error: could not cd to the package build directory \$SAGE_PKG_DIR"
590599
exit 1
591600
fi
592601
593602
__EOF__
594-
603+
fi
595604
cat "$script.in" >> "$tmpscript"
596605
mv "$tmpscript" "$script"
597606
chmod +x "$script"
@@ -607,20 +616,29 @@ touch spkg-piprm.in
607616
# or sdh_store_and_pip_install_wheel.
608617
touch spkg-pipinst.in
609618

610-
for script in $WRAPPED_SCRIPTS pipinst; do # pipinst can be added to WRAPPED_SCRIPTS later
619+
for script in $WRAPPED_SCRIPTS; do
611620
# 'Installed' scripts are not run immediately out of the package build
612-
# directory, and may be run later, so set their root directory to
613-
# $SAGE_ROOT
614-
if echo "$INSTALLED_SCRIPTS" | grep -w "$script" > /dev/null; then
615-
script_dir="$SAGE_ROOT"
616-
else
617-
script_dir="$(pwd)"
618-
fi
621+
# directory, and may be run later.
622+
# For the installed *rm scripts, set their root directory to $SAGE_ROOT.
623+
# For the installed check scripts, some need the temporary build directory,
624+
# others don't. So try to run out of the temporary build directory
625+
# but fall back to $SAGE_ROOT.
626+
case $script in
627+
check) script_dir="$(pwd)"
628+
fallback_script_dir="\$SAGE_ROOT"
629+
;;
630+
*rm) script_dir="\$SAGE_ROOT"
631+
fallback_script_dir=
632+
;;
633+
*) script_dir="$(pwd)"
634+
fallback_script_dir=
635+
;;
636+
esac
619637

620638
script="spkg-$script"
621639

622640
if [ -f "$script.in" ]; then
623-
write_script_wrapper "$(pwd)/$script" "$script_dir"
641+
write_script_wrapper "$(pwd)/$script" "$script_dir" "$fallback_script_dir"
624642
fi
625643
done
626644
} ####################################### prepare_for_installation
@@ -735,15 +753,14 @@ install_scripts() { ##############################################
735753
# Some spkg scripts, if they exist, should also be installed to
736754
# $SAGE_SPKG_SCRIPTS; they are not included in the package's manifest, but are
737755
# removed by sage-spkg-uninstall
738-
INSTALLED_SCRIPTS_DEST="$SAGE_SPKG_SCRIPTS/$PKG_BASE"
739756

740-
if [ ! -f $INSTALLED_SCRIPTS_DEST/spkg-requirements.txt ]; then
757+
if [ ! -f "$INSTALLED_SCRIPTS_DEST"/spkg-requirements.txt ]; then
741758
# No packages to uninstall with pip, so remove the prepared uninstall script
742759
# and the prepared deferred installation script
743760
rm -f spkg-piprm spkg-piprm.in spkg-pipinst spkg-pipinst.in
744761
fi
745762

746-
for script in $INSTALLED_SCRIPTS pipinst; do # pipinst can be added to WRAPPED_SCRIPTS later
763+
for script in $INSTALLED_SCRIPTS; do
747764
script="spkg-$script"
748765

749766
if [ -f "$script" ]; then
@@ -788,9 +805,14 @@ run_test_suite() { ###############################################
788805
# SAGE_INST_LOCAL. It might make more sense to run the tests before, but the
789806
# spkg-check scripts were written before use of DESTDIR installs, and so
790807
# fail in many cases. This might be good to change later.
791-
if [ -f spkg-check ]; then
808+
if ! cd "$SAGE_BUILD_DIR/$PKG_NAME" 2>/dev/null; then
809+
cd "$PKG_SCRIPTS" || exit $?
810+
fi
811+
812+
if [ -f "$INSTALLED_SCRIPTS_DEST"/spkg-check ]; then
792813
echo "Running the test suite for $PKG_NAME..."
793-
time ./spkg-check
814+
export PKG_BASE
815+
time "$INSTALLED_SCRIPTS_DEST"/spkg-check
794816
if [ $? -ne 0 ]; then
795817
TEST_SUITE_RESULT="failed"
796818
if [ "$SAGE_CHECK" = "warn" ]; then
@@ -805,8 +827,10 @@ run_test_suite() { ###############################################
805827
TEST_SUITE_RESULT="passed"
806828
echo "Passed the test suite for $PKG_NAME."
807829
fi
808-
elif [ -f spkg-check.in ]; then
809-
echo "The test suite for $PKG_NAME requires the temporary build directory."
830+
elif [ -f "$PKG_SCRIPTS"/spkg-check.in -o -f "$PKG_SCRIPTS"/spkg-check ]; then
831+
echo "The test suite for $PKG_NAME cannot be run because the script"
832+
echo "$INSTALLED_SCRIPTS_DEST/spkg-check"
833+
echo "is missing. Install/re-install package $PKG_NAME to run the test suite."
810834
exit 1
811835
else
812836
echo "Package $PKG_NAME has no test suite."
@@ -899,9 +923,6 @@ if [ $POST_INSTALL = 1 ]; then
899923
fi
900924

901925
if [ "$SAGE_CHECK" = "yes" -o "$SAGE_CHECK" = "warn" ]; then
902-
if ! cd "$SAGE_BUILD_DIR/$PKG_NAME" 2>/dev/null; then
903-
cd "$PKG_SCRIPTS" || exit $?
904-
fi
905926
run_test_suite
906927
fi
907928

0 commit comments

Comments
 (0)