Skip to content

Commit

Permalink
build/bin/sage-spkg: Use sage-package
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jun 24, 2024
1 parent ab24dac commit b79fd73
Showing 1 changed file with 40 additions and 45 deletions.
85 changes: 40 additions & 45 deletions build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ exit_with_error_msg()
exit 1
}

lookup_param()
{
local param=$1
local file=$2
# Ignore errors if the file does not exist
sed -n "s/^${param} *= *//p" $file 2>/dev/null
}

write_to_tty()
{
# Try writing to terminal. Suppress the possible error message
Expand Down Expand Up @@ -321,9 +313,11 @@ export SAGE_SPKG_WHEELS="$SAGE_INST_LOCAL/var/lib/sage/wheels"
# VERSION, if provided, must match the version in build/pkgs.
PKG_VER="${PKG_NAME#${PKG_BASE}}"
PKG_VER="${PKG_VER#-}"
PKG_SCRIPTS="$SAGE_ROOT/build/pkgs/$PKG_BASE"
LOCAL_PKG_VER=`cat $PKG_SCRIPTS/package-version.txt 2>/dev/null || echo none`
PKG_VER="$LOCAL_PKG_VER"
eval $(sage-package properties $PKG_BASE)
eval PKG_SCRIPTS=\$path_$PKG_BASE \
PKG_TYPE=\$type_$PKG_BASE \
PKG_SRC_TYPE=\$source_$PKG_BASE \
LOCAL_PKG_VER=\$version_with_patchlevel_$PKG_BASE
if [ -n "$PKG_VER" -a "$PKG_VER" != "$LOCAL_PKG_VER" ]; then
echo >&2 "Error: Selecting a different version of a package is no longer supported"
exit 1
Expand All @@ -333,11 +327,6 @@ if [ -z "$PKG_VER" ]; then
else
PKG_NAME="${PKG_BASE}-${PKG_VER}"
fi
PKG_BASE_VER=`echo $PKG_VER | sed 's/\.p[0-9][0-9]*$//'`
if [ -f "$PKG_SCRIPTS/checksums.ini" ]; then
# Normal/wheel package
PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini"`
fi

# Set the $SAGE_DESTDIR variable to be passed to the spkg-install
# script (the script itself could set this, but better to standardize
Expand All @@ -356,20 +345,20 @@ WRAPPED_SCRIPTS="build install preinst pipinst postinst $INSTALLED_SCRIPTS"


warning_for_experimental_packages() { ############################
if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" ]; then
if [ $YES != 1 -a -n "$PKG_NAME_UPSTREAM" ]; then
case "$PKG_TYPE:$PKG_SRC_TYPE" in
experimental:normal|experimental:wheel)
if [ $YES != 1 ]; then
echo "Error: The package $PKG_NAME is marked as experimental."
echo "Use 'sage -i -y $PKG_BASE' to force installation of this package"
echo "or use the configure option --enable-experimental-packages"
exit 1
fi
fi
fi;;
esac
} ############################## warning_for_experimental_packages

ensure_pkg_src() { ###############################################
if [ ! -f "$PKG_SRC" ]; then
if [ -n "$PKG_NAME_UPSTREAM" ]; then
# Normal or wheel package
case "$PKG_SRC_TYPE" in
normal|wheel)
PKG_SRC=$(sage-package download $SAGE_DOWNLOAD_FILE_OPTIONS $PKG_BASE) || exit_with_error_msg "Error downloading tarball of $PKG_BASE"
# Do a final check that PKG_SRC is a file with an absolute path
cd /
Expand All @@ -378,21 +367,21 @@ if [ ! -f "$PKG_SRC" ]; then
echo >&2 "This shouldn't happen, it is a bug in the sage-spkg script."
exit 1
fi
fi
fi

# Go back to SAGE_ROOT where we have less chance of completely messing
# up the system if we do something wrong.
cd "$SAGE_ROOT" || exit $?

# If SAGE_SPKG_COPY_UPSTREAM is set, it should be the name of a directory
# to which all upstream files are copied. This is used in sage-sdist.
if [ -n "$SAGE_SPKG_COPY_UPSTREAM" -a -n "$PKG_NAME_UPSTREAM" ]; then
mkdir -p "$SAGE_SPKG_COPY_UPSTREAM" && cp -p "$PKG_SRC" "$SAGE_SPKG_COPY_UPSTREAM"
if [ $? -ne 0 ]; then
exit_with_error_msg "Error copying upstream tarball to directory '$SAGE_SPKG_COPY_UPSTREAM'"
fi
fi
# Go back to SAGE_ROOT where we have less chance of completely messing
# up the system if we do something wrong.
cd "$SAGE_ROOT" || exit $?

# If SAGE_SPKG_COPY_UPSTREAM is set, it should be the name of a directory
# to which all upstream files are copied. This is used in sage-sdist.
if [ -n "$SAGE_SPKG_COPY_UPSTREAM" ]; then
mkdir -p "$SAGE_SPKG_COPY_UPSTREAM" && cp -p "$PKG_SRC" "$SAGE_SPKG_COPY_UPSTREAM"
if [ $? -ne 0 ]; then
error_msg "Error copying upstream tarball to directory '$SAGE_SPKG_COPY_UPSTREAM'"
exit 1
fi
fi;;
esac
} ################################################# ensure_pkg_src

setup_directories() { ############################################
Expand Down Expand Up @@ -438,8 +427,8 @@ extract_the_package() { ##########################################

cd "$SAGE_BUILD_DIR" || exit $?
echo "Setting up build directory $SAGE_BUILD_DIR/$PKG_NAME"
if [ -z "$PKG_NAME_UPSTREAM" ]; then
# Not a normal or wheel package.
case "$PKG_SRC_TYPE" in
script)
# Transplant the 'src' symlink, copy scripts.
mkdir -p "$PKG_NAME"
if [ -d "$PKG_SCRIPTS"/src ]; then
Expand All @@ -453,8 +442,9 @@ if [ -z "$PKG_NAME_UPSTREAM" ]; then
fi
done
cd "$PKG_NAME" || exit $?
else
# Normal or wheel package, copy whole directory, resolving symlinks
;;
normal|wheel)
# Copy whole directory, resolving symlinks
cp -RLp "$PKG_SCRIPTS" "$PKG_NAME"
cd "$PKG_NAME" || exit $?
case "$PKG_SRC" in
Expand All @@ -476,7 +466,11 @@ else
cd ..
;;
esac
fi
;;
*)
error_msg "Unhandled source type $PKG_SRC_TYPE"
;;
esac
if [ "$SAGE_KEEP_BUILT_SPKGS" = "yes" ]; then
touch .keep
fi
Expand Down Expand Up @@ -604,13 +598,14 @@ esac
# Poison the proxy variable to forbid downloads in spkg-install
# for normal packages
if [ -n "$PKG_NAME_UPSTREAM" ]; then
# Normal/wheel package
case $PKG_SRC_TYPE in
normal|wheel)
export http_proxy=http://192.0.2.0:5187/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
fi
;;
esac
# Make sage-logger show the full logs
unset SAGE_SILENT_BUILD
Expand Down

0 comments on commit b79fd73

Please sign in to comment.