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

snap: prepare override scripts to allow rebuilding #2223

Merged
merged 2 commits into from
Aug 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ apps:
completer: snapcraft-completion

parts:
patches:
source: patches
plugin: dump
prime:
- -*.diff
bash-completion:
source: debian
plugin: dump
Expand Down Expand Up @@ -53,15 +48,34 @@ parts:
override-build: |
snapcraftctl build
TRIPLET_PATH="$SNAPCRAFT_PART_INSTALL/usr/lib/$(gcc -print-multiarch)"
LIBSODIUM=$(readlink -n $TRIPLET_PATH/libsodium.so.18)
ln -s $LIBSODIUM $TRIPLET_PATH/libsodium.so
patch -d $SNAPCRAFT_PART_INSTALL/lib/python3.5/site-packages -p1 < $SNAPCRAFT_STAGE/pyyaml-support-high-codepoints.diff
patch $SNAPCRAFT_PART_INSTALL/usr/lib/python3.5/ctypes/__init__.py $SNAPCRAFT_STAGE/ctypes_init.diff
LIBSODIUM="$(readlink -n "$TRIPLET_PATH/libsodium.so.18")"
# Remove so the link can be recreated on re-builds
rm -f "$TRIPLET_PATH/libsodium.so"
ln -s "$LIBSODIUM" "$TRIPLET_PATH/libsodium.so"

# Restore patched files
PYTHON_PACKAGE_PATH="$SNAPCRAFT_PART_INSTALL/usr/lib/python3.5/"
[ -f "patched/ctypes/__init__.py.orig" ] && mv "patched/ctypes/__init__.py.orig" "$PYTHON_PACKAGE_PATH/ctypes/__init__.py"

SITE_PACKAGES_PATH="$SNAPCRAFT_PART_INSTALL/lib/python3.5/site-packages"
[ -f "patched/yaml/emitter.py.orig" ] && mv "patched/yaml/emitter.py.orig" "$SITE_PACKAGES_PATH/yaml/emitter.py"
[ -f "patched/yaml/reader.py.orig" ] && mv "patched/yaml/reader.py.orig" "$SITE_PACKAGES_PATH/yaml/reader.py"

# Apply patches
patch -b "$PYTHON_PACKAGE_PATH/ctypes/__init__.py" patches/ctypes_init.diff
patch -b -d "$SITE_PACKAGES_PATH/" -p1 < patches/pyyaml-support-high-codepoints.diff

# Save patches to allow rebuilding
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever, took me a second to figure out what you were doing here.

mkdir -p patched/ctypes
[ -f "$PYTHON_PACKAGE_PATH/ctypes/__init__.py.orig" ] && mv "$PYTHON_PACKAGE_PATH/ctypes/__init__.py.orig" patched/ctypes

mkdir -p patched/yaml
[ -f "$SITE_PACKAGES_PATH/yaml/emitter.py.orig" ] && mv "$SITE_PACKAGES_PATH/yaml/emitter.py.orig" patched/yaml
[ -f "$SITE_PACKAGES_PATH/yaml/reader.py.orig" ] && mv "$SITE_PACKAGES_PATH/yaml/reader.py.orig" patched/yaml
override-prime: |
snapcraftctl prime
# Now that everything is built, let's disable user site-packages
# as stated in PEP-0370
sed -i usr/lib/python3.5/site.py -e 's/^ENABLE_USER_SITE = None$/ENABLE_USER_SITE = False/'
# This is the last step, let's now compile all our pyc files.
./usr/bin/python3 -m compileall .
after: [patches]