@@ -355,8 +355,9 @@ export SAGE_DESTDIR="${SAGE_BUILD_DIR}/${PKG_NAME}/inst"
355
355
# end of spkg-install.
356
356
export SAGE_DESTDIR_LOCAL=" ${SAGE_DESTDIR}${SAGE_INST_LOCAL} "
357
357
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 "
360
361
361
362
362
363
warning_for_experimental_packages () { # ###########################
@@ -490,7 +491,7 @@ if [ -z "$PKG_NAME_UPSTREAM" ]; then
490
491
if [ -d " $PKG_SCRIPTS " /src ]; then
491
492
ln -s $( cd " $PKG_SCRIPTS " /src && pwd -P) " $PKG_NAME " /src
492
493
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
494
495
if [ -r " $PKG_SCRIPTS " /spkg-$a .in ]; then
495
496
cp " $PKG_SCRIPTS " /spkg-$a .in " $PKG_NAME " /
496
497
elif [ -x " $PKG_SCRIPTS " /spkg-$a ]; then
@@ -544,6 +545,7 @@ prepare_for_installation() { #####################################
544
545
write_script_wrapper () {
545
546
local script=" $1 "
546
547
local script_dir=" $2 "
548
+ local fallback_script_dir=" $3 "
547
549
548
550
trap " echo >&2 Error: Unexpected error writing wrapper script for $script ; exit \$ _" ERR
549
551
@@ -584,14 +586,21 @@ if [ \$? -ne 0 ]; then
584
586
exit 1
585
587
fi
586
588
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__
588
597
if [ \$ ? -ne 0 ]; then
589
598
echo >&2 "Error: could not cd to the package build directory \$ SAGE_PKG_DIR"
590
599
exit 1
591
600
fi
592
601
593
602
__EOF__
594
-
603
+ fi
595
604
cat " $script .in" >> " $tmpscript "
596
605
mv " $tmpscript " " $script "
597
606
chmod +x " $script "
@@ -607,20 +616,29 @@ touch spkg-piprm.in
607
616
# or sdh_store_and_pip_install_wheel.
608
617
touch spkg-pipinst.in
609
618
610
- for script in $WRAPPED_SCRIPTS pipinst ; do # pipinst can be added to WRAPPED_SCRIPTS later
619
+ for script in $WRAPPED_SCRIPTS ; do
611
620
# '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
619
637
620
638
script=" spkg-$script "
621
639
622
640
if [ -f " $script .in" ]; then
623
- write_script_wrapper " $( pwd) /$script " " $script_dir "
641
+ write_script_wrapper " $( pwd) /$script " " $script_dir " " $fallback_script_dir "
624
642
fi
625
643
done
626
644
} # ###################################### prepare_for_installation
@@ -735,15 +753,14 @@ install_scripts() { ##############################################
735
753
# Some spkg scripts, if they exist, should also be installed to
736
754
# $SAGE_SPKG_SCRIPTS; they are not included in the package's manifest, but are
737
755
# removed by sage-spkg-uninstall
738
- INSTALLED_SCRIPTS_DEST=" $SAGE_SPKG_SCRIPTS /$PKG_BASE "
739
756
740
- if [ ! -f $INSTALLED_SCRIPTS_DEST /spkg-requirements.txt ]; then
757
+ if [ ! -f " $INSTALLED_SCRIPTS_DEST " /spkg-requirements.txt ]; then
741
758
# No packages to uninstall with pip, so remove the prepared uninstall script
742
759
# and the prepared deferred installation script
743
760
rm -f spkg-piprm spkg-piprm.in spkg-pipinst spkg-pipinst.in
744
761
fi
745
762
746
- for script in $INSTALLED_SCRIPTS pipinst ; do # pipinst can be added to WRAPPED_SCRIPTS later
763
+ for script in $INSTALLED_SCRIPTS ; do
747
764
script=" spkg-$script "
748
765
749
766
if [ -f " $script " ]; then
@@ -788,9 +805,14 @@ run_test_suite() { ###############################################
788
805
# SAGE_INST_LOCAL. It might make more sense to run the tests before, but the
789
806
# spkg-check scripts were written before use of DESTDIR installs, and so
790
807
# 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
792
813
echo " Running the test suite for $PKG_NAME ..."
793
- time ./spkg-check
814
+ export PKG_BASE
815
+ time " $INSTALLED_SCRIPTS_DEST " /spkg-check
794
816
if [ $? -ne 0 ]; then
795
817
TEST_SUITE_RESULT=" failed"
796
818
if [ " $SAGE_CHECK " = " warn" ]; then
@@ -805,8 +827,10 @@ run_test_suite() { ###############################################
805
827
TEST_SUITE_RESULT=" passed"
806
828
echo " Passed the test suite for $PKG_NAME ."
807
829
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."
810
834
exit 1
811
835
else
812
836
echo " Package $PKG_NAME has no test suite."
@@ -899,9 +923,6 @@ if [ $POST_INSTALL = 1 ]; then
899
923
fi
900
924
901
925
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
905
926
run_test_suite
906
927
fi
907
928
0 commit comments