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

build/bin/sage-spkg: Add support for installing script packages #36747

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ EOF
if test -f "$DIR/requirements.txt"; then
SPKG_SOURCE=pip
elif test ! -f "$DIR/checksums.ini"; then
if test -f "$DIR/spkg-install"; then
if test -f "$DIR/spkg-install" -o -f "$DIR/spkg-install.in"; then
SPKG_SOURCE=script
else
# a dummy package
Expand Down
88 changes: 54 additions & 34 deletions build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,30 @@ export SAGE_SPKG_SCRIPTS="$SAGE_INST_LOCAL/var/lib/sage/scripts"
export SAGE_SPKG_WHEELS="$SAGE_INST_LOCAL/var/lib/sage/wheels"

# PKG_SRC should look like "package-VERSION" or just "package".
# If VERSION matches the version in build/pkgs or there is no version
# specified, use the local scripts; otherwise we try to find a package
# in upstream.
# 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`
LOCAL_PKG_VER=`cat $PKG_SCRIPTS/package-version.txt 2>/dev/null || echo none`
PKG_VER="$LOCAL_PKG_VER"
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}"
else
PKG_NAME="${PKG_BASE}-${PKG_VER}"
fi
PKG_BASE_VER=`echo $PKG_VER | sed 's/\.p[0-9][0-9]*$//'`
PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini" | sed "s/VERSION/$PKG_BASE_VER/"`
if [ -f "$PKG_SCRIPTS/checksums.ini" ]; then
# Normal/wheel package
PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini" | sed "s/VERSION/$PKG_BASE_VER/"`
fi

# Warning for experimental packages
if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" -a $INFO = 0 ]; then
if [ $YES != 1 ]; then
if [ $YES != 1 -a -n "$PKG_NAME_UPSTREAM" ]; then
# We use /dev/tty here because our output may be redirected
# to a logfile, or line-buffered.
write_to_tty <<EOF
Expand Down Expand Up @@ -349,27 +354,21 @@ if [ $INFO -ne 0 ]; then
exec sage-spkg-info $PKG_BASE
fi

# If we haven't found the package yet, we must download it
if [ ! -f "$PKG_SRC" ]; then
if [ -n "$PKG_NAME_UPSTREAM" ]; then
# This is the new-style package way of downloading the tarball
if ! sage-download-file $SAGE_DOWNLOAD_FILE_OPTIONS "$PKG_NAME_UPSTREAM"; then
error_msg "Error downloading $PKG_NAME_UPSTREAM"
exit 1
fi
PKG_SRC="$SAGE_DISTFILES/$PKG_NAME_UPSTREAM"
else
echo >&2 "Error: Installing old-style SPKGs is no longer supported"
if [ -n "$PKG_NAME_UPSTREAM" ]; then
# Normal or wheel package
if ! sage-download-file $SAGE_DOWNLOAD_FILE_OPTIONS "$PKG_NAME_UPSTREAM"; then
error_msg "Error downloading $PKG_NAME_UPSTREAM"
exit 1
fi
fi
PKG_SRC="$SAGE_DISTFILES/$PKG_NAME_UPSTREAM"

# Do a final check that PKG_SRC is a file with an absolute path
cd /
if [ ! -f "$PKG_SRC" ]; then
echo >&2 "Error: spkg file '$PKG_SRC' not found."
echo >&2 "This shouldn't happen, it is a bug in the sage-spkg script."
exit 1
# Do a final check that PKG_SRC is a file with an absolute path
cd /
if [ ! -f "$PKG_SRC" ]; then
echo >&2 "Error: spkg file '$PKG_SRC' not found."
echo >&2 "This shouldn't happen, it is a bug in the sage-spkg script."
exit 1
fi
fi

# Go back to SAGE_ROOT where we have less chance of completely messing
Expand All @@ -378,7 +377,7 @@ 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
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
error_msg "Error copying upstream tarball to directory '$SAGE_SPKG_COPY_UPSTREAM'"
Expand Down Expand Up @@ -448,10 +447,26 @@ fi
##################################################################

echo "Setting up build directory for $PKG_NAME"
cp -RLp "$PKG_SCRIPTS" "$PKG_NAME"
cd "$PKG_NAME" || exit $?

case "$PKG_SRC" in
if [ -z "$PKG_NAME_UPSTREAM" ]; then
# Not a normal or wheel package.
# Transplant the 'src' symlink, copy scripts.
mkdir -p "$PKG_NAME"
if [ -d "$PKG_SCRIPTS"/src ]; then
ln -s $(cd "$PKG_SCRIPTS"/src && pwd -P) "$PKG_NAME"/src
fi
for a in build install check preinst postinst; do # replace by use of $WRAPPED_SCRIPTS later
if [ -r "$PKG_SCRIPTS"/spkg-$a.in ]; then
cp "$PKG_SCRIPTS"/spkg-$a.in "$PKG_NAME"/
elif [ -x "$PKG_SCRIPTS"/spkg-$a ]; then
cp "$PKG_SCRIPTS"/spkg-$a "$PKG_NAME"/
fi
done
cd "$PKG_NAME" || exit $?
else
# Normal or wheel package, copy whole directory, resolving symlinks
cp -RLp "$PKG_SCRIPTS" "$PKG_NAME"
cd "$PKG_NAME" || exit $?
case "$PKG_SRC" in
*.whl)
# (Platform-independent) wheel
# Do not extract, do not create a src directory,
Expand All @@ -475,7 +490,8 @@ case "$PKG_SRC" in
fi
cd ..
;;
esac
esac
fi

##################################################################
# The package has been extracted, prepare for installation
Expand Down Expand Up @@ -578,11 +594,15 @@ echo "****************************************************"

##################################################################
# Poison the proxy variable to forbid downloads in spkg-install
# for normal packages
##################################################################
export http_proxy=http://192.0.2.0:5187/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
if [ -n "$PKG_NAME_UPSTREAM" ]; then
# Normal/wheel package
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

##################################################################
# We need to run sage-rebase.sh for each package installed, but it
Expand Down
20 changes: 8 additions & 12 deletions build/make/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ $(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' ]; then \
elif [ -x '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' -o -r '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install.in' ]; then \
rm -rf '$$($(4))/var/lib/sage/scripts/$(1)'; \
cd '$$(SAGE_ROOT)/build/pkgs/$(1)' && \
. '$$(SAGE_ROOT)/src/bin/sage-src-env-config' && \
Expand All @@ -740,9 +740,9 @@ $(1)-$(4)-no-deps:
SAGE_SPKG_SCRIPTS=$$($(4))/var/lib/sage/scripts \
SAGE_INST_LOCAL=$$($(4)) \
SAGE_CHECK=$$(SAGE_CHECK_$(1)) \
sage-logger -p '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install && if [ $$$$SAGE_CHECK != no -a -x $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-check ]; then $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-check; fi' '$$(SAGE_LOGS)/$(1)-$(2).log' && \
rm -f "$$($(4))/$(SPKG_INST_RELDIR)/$(1)"-* && \
touch "$$($(4))/$(SPKG_INST_RELDIR)/$(1)-$(2)"; \
sage-logger -p 'SAGE_CHECK=$$(SAGE_CHECK_$(1)) PATH=$$(SAGE_SRC)/bin:$$($(4))/bin:$$$$PATH $$(SAGE_SPKG) $$(SAGE_SPKG_OPTIONS) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$$$$PATH 💪

$(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"; \
Expand Down Expand Up @@ -781,14 +781,10 @@ $(1)-$(4)-check:
$(1)-check: $(1)-$(4)-check

$(1)-$(4)-uninstall:
-$(AM_V_at)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' && \
'$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-uninstall'
-rm -f "$$($(4))/$(SPKG_INST_RELDIR)/$(1)"-*
if [ -d '$$($(4))' ]; then \
sage-spkg-uninstall $(if $(filter $(1),$(TOOLCHAIN_DEPS)),--keep-files) \
$(1) '$$($(4))'; \
fi

$(1)-uninstall: $(1)-$(4)-uninstall

Expand Down
7 changes: 0 additions & 7 deletions build/pkgs/r/spkg-uninstall

This file was deleted.

20 changes: 0 additions & 20 deletions build/pkgs/sage_conf/spkg-install

This file was deleted.

9 changes: 9 additions & 0 deletions build/pkgs/sage_conf/spkg-install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cd src
if [ "$SAGE_EDITABLE" = yes ]; then
sdh_pip_editable_install .
if [ "$SAGE_WHEELS" = yes ]; then
sdh_setup_bdist_wheel && sdh_store_wheel .
fi
else
sdh_pip_install .
fi
20 changes: 0 additions & 20 deletions build/pkgs/sage_docbuild/spkg-install

This file was deleted.

9 changes: 9 additions & 0 deletions build/pkgs/sage_docbuild/spkg-install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cd src
if [ "$SAGE_EDITABLE" = yes ]; then
sdh_pip_editable_install .
if [ "$SAGE_WHEELS" = yes ]; then
sdh_setup_bdist_wheel && sdh_store_wheel .
fi
else
sdh_pip_install .
fi
20 changes: 0 additions & 20 deletions build/pkgs/sage_setup/spkg-install

This file was deleted.

9 changes: 9 additions & 0 deletions build/pkgs/sage_setup/spkg-install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cd src
if [ "$SAGE_EDITABLE" = yes ]; then
sdh_pip_editable_install .
if [ "$SAGE_WHEELS" = yes ]; then
sdh_setup_bdist_wheel && sdh_store_wheel .
fi
else
sdh_pip_install .
fi
20 changes: 0 additions & 20 deletions build/pkgs/sage_sws2rst/spkg-install

This file was deleted.

9 changes: 9 additions & 0 deletions build/pkgs/sage_sws2rst/spkg-install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cd src
if [ "$SAGE_EDITABLE" = yes ]; then
sdh_pip_editable_install .
if [ "$SAGE_WHEELS" = yes ]; then
sdh_setup_bdist_wheel && sdh_store_wheel .
fi
else
sdh_pip_install .
fi
12 changes: 0 additions & 12 deletions build/pkgs/sagelib/spkg-install → build/pkgs/sagelib/spkg-install.in
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#!/usr/bin/env bash
# From sage-spkg.
# For type=script packages, the build rule in build/make/Makefile sources
# sage-env but not sage-dist-helpers.
lib="$SAGE_ROOT/build/bin/sage-dist-helpers"
source "$lib"
if [ $? -ne 0 ]; then
echo >&2 "Error: failed to source $lib"
echo >&2 "Is $SAGE_ROOT the correct SAGE_ROOT?"
exit 1
fi

if [ "$SAGE_EDITABLE" = yes ]; then
cd "$SAGE_SRC"
else
Expand Down
11 changes: 0 additions & 11 deletions build/pkgs/sagemath_bliss/spkg-install → build/pkgs/sagemath_bliss/spkg-install.in
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
#!/usr/bin/env bash
# From sage-spkg.
# For type=script packages, the build rule in build/make/Makefile sources
# sage-env but not sage-dist-helpers.
lib="$SAGE_ROOT/build/bin/sage-dist-helpers"
source "$lib"
if [ $? -ne 0 ]; then
echo >&2 "Error: failed to source $lib"
echo >&2 "Is $SAGE_ROOT the correct SAGE_ROOT?"
exit 1
fi
cd src

export PIP_NO_INDEX=true
Expand Down
1 change: 0 additions & 1 deletion build/pkgs/sagemath_categories/spkg-install

This file was deleted.

1 change: 1 addition & 0 deletions build/pkgs/sagemath_categories/spkg-install.in
11 changes: 0 additions & 11 deletions build/pkgs/sagemath_coxeter3/spkg-install → build/pkgs/sagemath_coxeter3/spkg-install.in
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
#!/usr/bin/env bash
# From sage-spkg.
# For type=script packages, the build rule in build/make/Makefile sources
# sage-env but not sage-dist-helpers.
lib="$SAGE_ROOT/build/bin/sage-dist-helpers"
source "$lib"
if [ $? -ne 0 ]; then
echo >&2 "Error: failed to source $lib"
echo >&2 "Is $SAGE_ROOT the correct SAGE_ROOT?"
exit 1
fi
cd src

export PIP_NO_INDEX=true
Expand Down
1 change: 0 additions & 1 deletion build/pkgs/sagemath_environment/spkg-install

This file was deleted.

1 change: 1 addition & 0 deletions build/pkgs/sagemath_environment/spkg-install.in