Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor sage-spkg through sage-package #38271

Merged
merged 7 commits into from
Jul 24, 2024
Merged
119 changes: 60 additions & 59 deletions build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +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
if ! ( cat > /dev/tty ) 2> /dev/null ; then
# Fall back to writing to stdout
cat
return 1
fi
}

# Handle -n, -t, -q options for recursive make
# See Issue #12016.
if echo "$MAKE $MAKEFLAGS -$MAKEFLAGS" |grep '[ ]-[A-Za-z]*[qnt]' >/dev/null; then
Expand Down Expand Up @@ -293,7 +275,7 @@ if echo "$PKG_SRC" | grep / >/dev/null; then
exit 1
fi
PKG_NAME="$PKG_SRC"
PKG_BASE=`echo "$PKG_NAME" | sed 's/-.*//'` # strip version number
export PKG_BASE=`echo "$PKG_NAME" | sed 's/-.*//'` # strip version number

case $# in
1)
Expand All @@ -320,23 +302,20 @@ export SAGE_SPKG_WHEELS="$SAGE_INST_LOCAL/var/lib/sage/wheels"
# PKG_SRC should look like "package-VERSION" or just "package".
# 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"
export PKG_VER="${PKG_VER#-}"
eval $(sage-package properties --format=shell $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
fi
if [ -z "$PKG_VER" ]; then
PKG_NAME="${PKG_BASE}"
export PKG_NAME="${PKG_BASE}"
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"`
export PKG_NAME="${PKG_BASE}-${PKG_VER}"
fi

# Set the $SAGE_DESTDIR variable to be passed to the spkg-install
Expand All @@ -356,20 +335,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 +357,37 @@ 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
;;
none)
echo >&2
echo >&2 "Note: $PKG_BASE is a dummy package that the Sage distribution uses"
echo >&2 "to provide information about equivalent system packages."
echo >&2 "It cannot be installed using the Sage distribution."
echo >&2 "Please install it manually, for example using the system packages"
echo >&2 "recommended at the end of a run of './configure'"
echo >&2 "See below for package-specific information."
echo >&2
sage-spkg-info $PKG_BASE
echo >&2
echo >&2 "Error: $PKG_BASE is a dummy package and "
echo >&2 "cannot be installed using the Sage distribution."
exit 1
;;
esac
} ################################################# ensure_pkg_src

setup_directories() { ############################################
Expand Down Expand Up @@ -438,8 +433,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 +448,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 +472,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 +604,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
21 changes: 1 addition & 20 deletions build/make/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -741,37 +741,18 @@ $(1)-$(4)-no-deps:
echo "Error: The installation tree $(4) has been disabled" 2>&1; \
echo "$$($(4)_DISABLED_MESSAGE)" 2>&1; \
exit 1; \
elif [ -x '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' -o -r '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install.in' ]; then \
else \
rm -rf '$$($(4))/var/lib/sage/scripts/$(1)'; \
cd '$$(SAGE_ROOT)/build/pkgs/$(1)' && \
. '$$(SAGE_ROOT)/src/bin/sage-src-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env' && \
PKG_BASE="$(1)" \
PKG_VER="$(2)" \
PKG_NAME="$(1)-$(2)" \
SAGE_SPKG_WHEELS=$$($(4))/var/lib/sage/wheels \
SAGE_SPKG_SCRIPTS=$$($(4))/var/lib/sage/scripts \
SAGE_INST_LOCAL=$$($(4)) \
SAGE_CHECK=$$(SAGE_CHECK_$(1)) \
sage-logger -p 'SAGE_CHECK=$$(SAGE_CHECK_$(1)) PATH=$$(SAGE_SRC)/bin:$$($(4))/bin:$$$$PATH $$(SAGE_SPKG) $$(SAGE_SPKG_OPTIONS) \
$(if $(filter $(1),$(TOOLCHAIN_DEPS)),--keep-existing) \
$(1)-$(2) $$($(4))' '$$(SAGE_LOGS)/$(1)-$(2).log'; \
else ( \
echo; \
echo "Note: $(1) is a dummy package that the Sage distribution uses"; \
echo "to provide information about equivalent system packages."; \
echo "It cannot be installed using the Sage distribution."; \
echo "Please install it manually, for example using the system packages"; \
echo "recommended at the end of a run of './configure'"; \
echo "See below for package-specific information."; \
echo; \
$$(SAGE_ROOT)/build/bin/sage-spkg-info $(1); \
echo; \
echo "Error: $(1) is a dummy package and "; \
echo "cannot be installed using the Sage distribution." ) | sage-logger -p 'cat; exit 1' '$$(SAGE_LOGS)/$(1)-$(2).log'; \
fi

$(1)-no-deps: $(1)-$(4)-no-deps
Expand Down
17 changes: 4 additions & 13 deletions build/pkgs/python3/spkg-install.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ cd src
sdh_make_install -i -j1

echo "Installing valgrind suppression file..."
if [ "$PKG_BASE" = "python2" ]; then
SUPP_FILENAME="python.supp"
else
SUPP_FILENAME="${PKG_BASE}.supp"
fi
SUPP_FILENAME="python3.supp"
sdh_install -T Misc/valgrind-python.supp "$SAGE_LOCAL/lib/valgrind/$SUPP_FILENAME"

if [ "$UNAME" = "Linux" ]; then
Expand All @@ -42,14 +38,9 @@ else
fi

PYTHON_VERSION=$($PYTHON -c 'import sys; print("%d.%d" % sys.version_info[:2])')
if [ "$PKG_BASE" = "python2" ]; then
PYTHON_LDVERSION="$PYTHON_VERSION"
PYTHON_CONFIG_DIR="$SAGE_LOCAL/lib/python${PYTHON_VERSION}/config"
else
PYTHON_ABIFLAGS=$($PYTHON -c 'import sys; print(sys.abiflags)')
PYTHON_LDVERSION="$PYTHON_VERSION$PYTHON_ABIFLAGS"
PYTHON_CONFIG_DIR="$SAGE_LOCAL/lib/python${PYTHON_VERSION}/config-${PYTHON_LDVERSION}"
fi
PYTHON_ABIFLAGS=$($PYTHON -c 'import sys; print(sys.abiflags)')
PYTHON_LDVERSION="$PYTHON_VERSION$PYTHON_ABIFLAGS"
PYTHON_CONFIG_DIR="$SAGE_LOCAL/lib/python${PYTHON_VERSION}/config-${PYTHON_LDVERSION}"

# On OS X with XCode 4, the presence of
# $SAGE_LOCAL/lib/python3.x/config/libpython3.x.a causes problems with
Expand Down
Loading