Ticket #9960: trac_9960-additional_fixes_to_sage-spkg_rebased_to_4.6.1.rc0-scripts-repo.patch

File trac_9960-additional_fixes_to_sage-spkg_rebased_to_4.6.1.rc0-scripts-repo.patch, 14.3 KB (added by leif, 10 years ago)

SCRIPTS REPO. My previous patch rebased to Sage 4.6.1.rc0, with some more changes. Apply on top of John's (rebased one).

  • sage-spkg

    # HG changeset patch
    # User Leif Leonhardy <not.really@online.de>
    # Date 1293766945 -3600
    # Node ID 564756deee126dc6c1d8f7690fdabec5d831cdf4
    # Parent  9e4f7775bc7035e1fc90c1102264ea1f534642f2
    #9960 Additional fixes to sage-spkg, some comments added. (Rebased to 4.6.1.rc0.)
    
    Besides cosmetic changes (formatting, tabs, some messages), I've only
    
     * added lots of comments (including TODOs/notes on future changes),
     * quoted all necessary environment variables,
     * fixed a bug which caused a successful test suite run never getting
       logged (to 'spkg/installed/<package-name>').
    
    So there are (still) lots of things to do, but on another ticket.
    
    (The rebased patch also contains some more changes than the previous
    one.)
    
    diff -r 9e4f7775bc70 -r 564756deee12 sage-spkg
    a b  
    3030#
    3131#######################################################
    3232
    33 mymkdir()
     33mymkdir()       # XXX: This function is superfluous since we have 'mkdir -p'
    3434{
    35     if [ ! -d $1 ]; then
    36             mkdir $1
     35    if [ ! -d "$1" ]; then
     36        mkdir "$1"
    3737    fi
    3838}
    3939
    4040no_version()
    4141{
    42     if [ -z "`echo "$1" | grep -`" ]; then
     42    if [ -z "`echo "$1" | grep -`" ]; then      # XXX: too complicated
    4343        echo "no version"
    4444    fi
    4545}
     46
    4647# The following sets environment variables for building
    4748# packages.  (Using dot suggested by W. Cheung.)
    4849
    49 . "$SAGE_ROOT/local/bin/sage-env"
     50. "$SAGE_ROOT/local/bin/sage-env" # *returns* non-zero value on errors rather than exiting
    5051
    51 cd "$SAGE_PACKAGES"
     52if [ $? -ne 0 ]; then
     53    echo "Error setting environment variables by running \"$SAGE_ROOT/local/bin/sage-env\";"
     54    echo "possibly contact sage-devel (see http://groups.google.com/group/sage-devel)."
     55    exit 1
     56fi
     57
     58
     59cd "$SAGE_PACKAGES"     # SAGE_PACKAGES is set in sage-env
    5260
    5361if [ $# -eq 0 ]; then
    5462    echo "Currently installed packages:"
     
    5866
    5967
    6068cd "$SAGE_PACKAGES"
    61 mymkdir "$BUILD"
     69mymkdir "$BUILD"        # BUILD is also set in sage-env, but not to an absolute path
    6270mymkdir installed
    6371cd "$BUILD"
    6472mymkdir old
    6573
    66 # the following two options are mutually exclusive -- i.e., you
     74# The following two options are mutually exclusive -- i.e., you
    6775# can give only one.
    6876
    6977INFO=0
    70 if [ $1 = '-info' ]; then
     78if [ "$1" = '-info' ]; then
    7179    INFO=1
    7280    shift
    7381fi
    7482
    7583FORCE=0
    76 if [ $1 = '-f' ]; then
     84if [ "$1" = '-f' ]; then
    7785    FORCE=1
    7886    shift
    7987fi
    8088export FORCE
    8189
    8290DELETE_TMP=1
    83 if [ $1 = '-s' -o $1 = '-m' ]; then
     91if [ "$1" = '-s' -o "$1" = '-m' ]; then
    8492    DELETE_TMP=0
    8593    shift
    8694fi
     
    9199PKG_SRC="$1"
    92100PKG_BASE=`echo "$PKG_NAME" | sed -e "s/-.*//"`
    93101
    94 # check if noclobber is set and warn about it
    95 if [ $PKG_SRC == "noclobber" ]; then
     102# Check if noclobber is set and warn about it:
     103if [ "$PKG_SRC" = "noclobber" ]; then
    96104    echo "***********************************************************"
    97105    echo "* WARNING WARNING WARNING WARNING WARNING WARNING WARNING *"
    98106    echo "*                                                         *"
     
    136144fi
    137145
    138146if [ $INFO -ne 0 ]; then
     147    # XXX FIXME: The following is totally buggy.
     148    #            Also, we should perhaps (try to) extract some info from
     149    #            'SPKG.txt', not 'SAGE.txt' which at most rarely exists.
    139150    if [ ! -f "$PKG_SRC" ]; then
    140151        echo "Package $PKG_NAME not found"
    141152    fi
    142     bunzip2 -c "$PKG_SRC" 2>/dev/null | tar Ofx${UNTAR_VERBOSE} - $PKG_NAME/SAGE.txt 2>/dev/null
     153    bunzip2 -c "$PKG_SRC" 2>/dev/null | tar Ofx${UNTAR_VERBOSE} - "$PKG_NAME/SAGE.txt" 2>/dev/null
    143154    if [ $? -ne 0 ]; then
    144155        tar Ofx${UNTAR_VERBOSE} "$PKG_SRC" "$PKG_NAME/SAGE.txt" 2>/dev/null
    145156    fi
     
    158169
    159170if [ -f "$INSTALLED/$PKG_NAME" -a $FORCE -eq 0 ]; then
    160171    echo "sage: $1 is already installed"
    161     touch "$INSTALLED/$PKG_NAME"
     172    touch "$INSTALLED/$PKG_NAME" # XXX Why touch it?
    162173    exit 0
    163174fi
    164175
    165 cd "$SAGE_PACKAGES/build"
     176cd "$SAGE_PACKAGES/build"       # FIXME: Above, we use $BUILD instead of "build"
    166177
    167178if [ $DELETE_TMP -eq 1 ]; then
    168179    echo "Deleting directories from past builds of previous/current versions of $PKG_NAME"
    169180    # Make triply sure that we are in the build directory before doing
    170181    # a scary "rm -rf".
    171     cd "$SAGE_PACKAGES/build"
     182    cd "$SAGE_PACKAGES/build"   # FIXME: see above (use $BUILD).
    172183    if [ $? -ne 0 ]; then
    173184        echo "Unable to find build directory."
    174185    else
     
    192203   
    193204    FOUND_VERSION=''
    194205    if [ -n "`no_version "$PKG_NAME"`" ]; then
     206        # No version was given on the command line.
    195207        echo "Searching for latest version of $PKG_NAME"
    196208        PKG_NAME=`sage-latest-online-package "$PKG_NAME"`
    197209        if [ $? -eq 0 ]; then
    198210            echo "Found package $PKG_NAME"
    199             FOUND_VERSION='1'
     211            FOUND_VERSION='1'
    200212        else
     213            # XXX I guess (hope) 'sage-latest-online-package' already spit out
     214            #     an appropriate error message...
    201215            echo "$PKG_NAME"
    202216            exit 1
    203217        fi
     
    223237    # download the package specified by $1, since it either already
    224238    # contains the version number or is a URL.
    225239    if [ "x$FOUND_VERSION" = "x" ]; then
    226         sage-download_package "$1"
     240        sage-download_package "$1"
    227241    else
    228         sage-download_package "$PKG_NAME"
     242        sage-download_package "$PKG_NAME"
    229243    fi
    230244    if [ ! -f "$PKG_NAME.spkg" ]; then
    231             echo "sage: Failed to download package $PKG_NAME from $SAGE_SERVER"
    232             exit 1
     245        echo "sage: Failed to download package $PKG_NAME from $SAGE_SERVER"
     246        exit 1
    233247    fi
    234248    PKG_SRC="`pwd`/$PKG_NAME.spkg"
    235249    cd "$CUR"
    236250fi
    237251
    238 # * The -i option below to ignore checksum errors, since
     252# * The -i option below is to ignore checksum errors, since
    239253#   I've had problems with this on Solaris.
    240 # * The m option avoids clock skew problems.   
     254# * The m option avoids clock skew problems.
    241255
    242256echo "Extracting package $PKG_SRC ..."
    243257ls -l "$PKG_SRC"
     
    247261    rm -rf "$PKG_NAME"
    248262fi
    249263
    250 bunzip2 -c "$PKG_SRC" 2>/dev/null | tar fx${UNTAR_VERBOSE} -  2>/dev/null
     264bunzip2 -c "$PKG_SRC" 2>/dev/null | tar fx${UNTAR_VERBOSE} - 2>/dev/null
    251265if [ ! -d "$PKG_NAME" ]; then
     266    # Maybe the spkg wasn't compressed, so retry with plain 'tar':
    252267    tar fx${UNTAR_VERBOSE} "$PKG_SRC"
    253268fi
    254269echo "Finished extraction"
    255270
     271# XXX The following only works as expected if $PKG_NAME really
     272#     contains the version number (which isn't always the case):
    256273if [ ! -d "$PKG_NAME" ]; then
    257274    echo "sage: After decompressing the directory $PKG_NAME does not exist"
    258275    echo "This means that the corresponding .spkg needs to be downloaded"
     
    263280        if [ $? -eq 0 ]; then
    264281            echo "Found package $PKG_NAME"
    265282        else
     283            # XXX Again, I guess (hope) 'sage-latest-online-package' already
     284            #     spit out an appropriate error message...
    266285            echo "$PKG_NAME"
    267286            exit 1
    268287        fi
    269288    fi
    270289    sage-download_package "$PKG_NAME"
    271290    echo `pwd`
    272     bunzip2 -c "$PKG_NAME.spkg"  | tar fx${UNTAR_VERBOSE} -
     291    bunzip2 -c "$PKG_NAME.spkg" | tar fx${UNTAR_VERBOSE} -
    273292    if [ ! -d "$PKG_NAME.spkg" ]; then
     293        # Maybe the spkg wasn't compressed, so retry with plain 'tar':
    274294        tar fx${UNTAR_VERBOSE} "$PKG_NAME.spkg"
    275295    fi
    276296    if [ ! -d "$PKG_NAME" ]; then
     
    287307        echo "python setup.py install" >> spkg-install
    288308    else
    289309        if [ -f configure ]; then
    290             echo "./configure --prefix=\$SAGE_ROOT/local/" >> spkg-install
     310            echo "./configure --prefix=\"\$SAGE_ROOT/local/\"" >> spkg-install
     311            # XXX Should use '$MAKE' here, perhaps '$MAKE -j1' to be safe:
    291312            echo "make" >> spkg-install
    292             echo "make install" >> spkg-install 
     313            echo "make install" >> spkg-install
    293314        else
    294315            echo "There is no spkg-install script, no setup.py, and no configure script,"
    295316            echo "so I do not know how to install $PKG_SRC."
     
    298319    fi
    299320fi
    300321
    301 chmod +x spkg-install
     322chmod +x spkg-install # We may issue a warning if it isn't already nor was
     323                      # just created above.
    302324
    303325# this is just wrong... (so don't do it)
    304326#echo "TOUCHING"
    305327#touch * */* */*/* */*/*/* 1>/dev/null 2>/dev/null
    306328
    307 echo "****************************************************"
     329echo "*****************************************************"
    308330echo "Host system"
    309331echo "uname -a:"
    310332uname -a
    311333if [ $? -ne 0 ]; then
    312     echo "Unable to determine host system information."
     334    echo "Warning: Unable to determine host system information."
    313335fi
    314 echo "****************************************************"
     336echo "*****************************************************"
    315337
    316 echo "****************************************************"
     338echo "*****************************************************"
    317339echo "CC Version"
    318 echo "$CC -v"
     340echo "$CC -v:"
    319341$CC -v
    320342if [ $? -ne 0 ]; then
    321     echo "Unable to determine C compiler version."
     343    echo "Warning: Unable to determine C compiler version."
    322344fi
    323 echo "****************************************************"
     345echo "*****************************************************"
    324346
    325347
    326348##################################################################
    327349# If spkg-install is a Python script, verify that the Sage Python
    328350# has already been installed.
    329351##################################################################
    330 # Check the first line of the file for the string "python".
     352# Check the first line of the file for the string "python":
    331353head -1 spkg-install | grep python > /dev/null
    332 if [ $? -eq 0 ]; then   # if it is found, then the exit code will be 0
    333     if [ ! -f "$SAGE_LOCAL"/bin/python ]; then   # now check if the python program is in local/bin/
    334          # if so, exit with an error. 
    335          echo "The spkg-install script depends on the Sage Python package,"
     354if [ $? -eq 0 ]; then   # If it is found, then the exit code will be 0.
     355    # Now check if Sage's python program is already installed:
     356    if [ ! -f "$SAGE_LOCAL"/bin/python ]; then
     357         # If not, exit with an error:
     358         echo "Error: The spkg-install script depends on the Sage Python package,"
    336359         echo "but the Sage Python package is not yet installed.  This may be"
    337360         echo "a bug in the Sage build system dependency file.  Please"
    338          echo "update the $SAGE_ROOT/spkg/standard/deps makefile."
     361         echo "update the '$SAGE_ROOT/spkg/standard/deps' makefile."
    339362         exit 1
    340     fi 
     363    fi
    341364fi
    342365
    343366BASEDIR=`pwd`
    344367if [ -n "$DEBIAN_RELEASE" ]; then
    345368    SAGE_CHECK=''
    346369    if [ -e ./spkg-debian ]; then
    347             time ./spkg-debian
     370        time ./spkg-debian
    348371    else
    349             time sage-build-debian $BASEDIR
     372        time sage-build-debian "$BASEDIR"
    350373    fi
    351374else
    352375    time ./spkg-install
    353376fi
    354377
    355378if [ $? -eq 0 ]; then
    356     cd $INSTALLED
     379    cd "$INSTALLED"
    357380    # TURNED OFF: Remove all old packages with the same name up to the first "-":
    358381    # rm -f $PKG_BASE-*
    359382
     
    362385    echo "PACKAGE NAME: $PKG_NAME" > "$PKG_NAME"
    363386    echo "INSTALL DATE: `date`" >> "$PKG_NAME"
    364387    echo "UNAME: `uname -a`" >> "$PKG_NAME"
     388    # Don't grep it from '$SAGE_LOCAL/bin/sage-banner' here since that might
     389    # not yet exist (cf. #9434):
    365390    if [ -f "$SAGE_ROOT"/VERSION.txt ]; then
    366         cat "$SAGE_ROOT"/VERSION.txt >> "$PKG_NAME"
     391        cat "$SAGE_ROOT"/VERSION.txt >> "$PKG_NAME"
    367392    fi
    368393    echo "Successfully installed $PKG_NAME"
    369394
    370     cd $BASEDIR
     395    cd "$BASEDIR"
    371396    if [ "x$SAGE_CHECK" = "xyes" -a -f spkg-check ]; then
     397        # TODO: Allow e.g. also SAGE_CHECK="ignore" to run the test suites
     398        #       without making errors fatal, which would be convenient for
     399        #       the Python package (whose test suite fails on almost all
     400        #       Linux systems and some others) and also porting.
    372401        echo "Running the test suite."
    373         chmod +x spkg-check
     402        chmod +x spkg-check # We may issue a warning if it isn't already.
    374403        ./spkg-check
    375404        if [ $? -ne 0 ]; then
    376             echo "*************************************"
    377             echo "Error testing package ** $PKG_NAME **"
    378             echo "*************************************"
    379             rm -f $SAGE_ROOT/spkg/installed/$PKG_NAME
     405            # TODO: Allow test suite failures to be non-fatal (see above).
     406            echo "*************************************************************"
     407            echo "Error testing package $PKG_NAME."
     408            echo "*************************************************************"
     409            rm -f "$SAGE_ROOT/spkg/installed/$PKG_NAME"
    380410            echo "sage: An error occurred while testing $PKG_NAME"
    381411            echo "Please email sage-devel http://groups.google.com/group/sage-devel"
    382412            echo "explaining the problem and send the relevant part of"
     
    390420            echo "subshell."
    391421            exit 1
    392422        else
    393             echo "TEST SUITE: passed" >> "$PKG_NAME"
     423            echo "TEST SUITE: passed" >> "$INSTALLED/$PKG_NAME"
    394424        fi
    395425    fi
    396426
    397427
    398428    # Delete the temporary build directory if required.
    399429    if [ $DELETE_TMP -eq 1 ]; then
    400         echo "Now cleaning up tmp files."
     430        echo "Now cleaning up temporary files."
    401431        if [ -d "$SAGE_PACKAGES/build/$PKG_NAME" ]; then
    402            # the if is there only to avoid the possibility of a weird bug.
    403             cd "$SAGE_PACKAGES/build/"
     432            # The 'if' is there only to avoid the possibility of a weird bug.
     433            cd "$SAGE_PACKAGES/build/" # XXX useless?!
    404434            rm -rf "$SAGE_PACKAGES/build/$PKG_NAME"
    405435        fi
    406436    else
    407437        echo "You can safely delete the temporary build directory"
    408         echo "$SAGE_PACKAGES/build/$PKG_NAME"
     438        echo "'$SAGE_PACKAGES/build/$PKG_NAME'"
    409439    fi
    410440
    411441else
     442    # 'spkg-install' returned non-zero exit code:
     443    echo "*************************************************************"
     444    echo "Error installing package $PKG_NAME."
     445    echo "*************************************************************"
    412446    echo "sage: An error occurred while installing $PKG_NAME"
    413447    echo "Please email sage-devel http://groups.google.com/group/sage-devel"
    414448    echo "explaining the problem and send the relevant part of"
     
    429463cd "$SAGE_LOCAL"/bin
    430464./sage-make_relative
    431465
    432 echo "Finished installing $PKG_NAME.spkg" 
     466echo "Finished installing $PKG_NAME.spkg"
    433467
    434468# It's OK if the above fails -- in fact it will until Python
    435 # itself gets installed. That's fine. 
    436 exit 0   
     469# itself gets installed. That's fine.
     470exit 0