-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from canonical/add-snaps
Add checkbox snaps code
- Loading branch information
Showing
22 changed files
with
1,085 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[bumpversion] | ||
current_version = 1.30.dev | ||
parse = (?P<major>\d+)\.(?P<minor>\d+)((?P<release>\.?[a-z]+))? | ||
serialize = | ||
{major}.{minor}{release} | ||
{major}.{minor} | ||
|
||
[bumpversion:file:snap/snapcraft.yaml] | ||
search = version: '{current_version}' | ||
replace = version: '{new_version}' | ||
|
||
[bumpversion:part:release] | ||
optional_value = RELEASE | ||
values = | ||
.dev | ||
RELEASE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.pyc | ||
*.snap | ||
__pycache__ | ||
build/mo/* | ||
dist/*.tar.gz | ||
parts/ | ||
snap/.snapcraft | ||
snap/gui/ | ||
stage/ | ||
prime/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
function append_path() { | ||
local var="$1" | ||
local dir="$2" | ||
if [ -e "$dir" ]; then | ||
eval "export $var=\"\${$var:+\$$var:}\$dir\"" | ||
fi | ||
} | ||
|
||
if [ -z "$RUNTIME" ]; then | ||
RUNTIME=$SNAP | ||
else | ||
# add general paths not added by snapcraft due to runtime snap | ||
append_path PERL5LIB $RUNTIME/usr/lib/$ARCH/perl/$PERL_VERSION | ||
append_path PERL5LIB $RUNTIME/usr/lib/$ARCH/perl5/$PERL_VERSION | ||
append_path PERL5LIB $RUNTIME/usr/share/perl/$PERL_VERSION | ||
append_path PERL5LIB $RUNTIME/usr/share/perl5 | ||
append_path LD_LIBRARY_PATH $RUNTIME/lib | ||
append_path LD_LIBRARY_PATH $RUNTIME/lib/$ARCH | ||
append_path LD_LIBRARY_PATH $RUNTIME/usr/lib/$ARCH | ||
append_path LD_LIBRARY_PATH $RUNTIME/lib/fwts | ||
append_path GI_TYPELIB_PATH $RUNTIME/usr/lib/girepository-1.0 | ||
append_path GI_TYPELIB_PATH $RUNTIME/usr/lib/$ARCH/girepository-1.0 | ||
append_path PATH $RUNTIME/bin | ||
append_path PATH $RUNTIME/usr/bin | ||
append_path PATH $RUNTIME/sbin | ||
append_path PATH $RUNTIME/usr/sbin | ||
append_path ALSA_CONFIG_PATH $RUNTIME/usr/share/alsa/alsa.conf | ||
append_path ALSA_CONFIG_PATH $RUNTIME/usr/share/alsa/pcm/default.conf | ||
append_path PYTHONUSERBASE $RUNTIME | ||
append_path PYTHONHOME $RUNTIME/usr | ||
append_path PYTHONPATH $RUNTIME/usr/lib/python3/dist-packages | ||
append_path PYTHONPATH $RUNTIME/lib/python3*/site-packages | ||
fi | ||
|
||
# make sure we always know where the content snap is especially for classic | ||
# checkbox snaps where the checkbox-runtime bind mount does not exist | ||
export CHECKBOX_RUNTIME=$(findmnt -oTARGET -n $(findmnt -oSOURCE -n $RUNTIME) | grep -P "^\/snap\/checkbox(|\d{2})\/") | ||
|
||
# Tell GStreamer where to find its plugins | ||
export GST_PLUGIN_PATH=$RUNTIME/usr/lib/$ARCH/gstreamer-1.0 | ||
export GST_PLUGIN_SYSTEM_PATH=$RUNTIME/usr/lib/$ARCH/gstreamer-1.0 | ||
# gst plugin scanner doesn't install in the correct path: https://github.com/ubuntu/snapcraft-desktop-helpers/issues/43 | ||
export GST_PLUGIN_SCANNER=$RUNTIME/usr/lib/$ARCH/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
function append_path() { | ||
local var="$1" | ||
local dir="$2" | ||
if [ -e "$dir" ]; then | ||
eval "export $var=\"\${$var:+\$$var:}\$dir\"" | ||
fi | ||
} | ||
|
||
function prepend_dir() { | ||
local var="$1" | ||
local dir="$2" | ||
if [ -d "$dir" ]; then | ||
eval "export $var=\"\$dir\${$var:+:\$$var}\"" | ||
fi | ||
} | ||
|
||
if [ -z "$RUNTIME" ]; then | ||
RUNTIME=$SNAP | ||
else | ||
# add general paths not added by snapcraft due to runtime snap | ||
append_path PERL5LIB $RUNTIME/usr/lib/$ARCH/perl/$PERL_VERSION | ||
append_path PERL5LIB $RUNTIME/usr/lib/$ARCH/perl5/$PERL_VERSION | ||
append_path PERL5LIB $RUNTIME/usr/share/perl/$PERL_VERSION | ||
append_path PERL5LIB $RUNTIME/usr/share/perl5 | ||
append_path LD_LIBRARY_PATH $RUNTIME/lib | ||
append_path LD_LIBRARY_PATH $RUNTIME/lib/$ARCH | ||
append_path LD_LIBRARY_PATH $RUNTIME/usr/lib/$ARCH | ||
append_path LD_LIBRARY_PATH $RUNTIME/lib/fwts | ||
append_path GI_TYPELIB_PATH $RUNTIME/usr/lib/girepository-1.0 | ||
append_path GI_TYPELIB_PATH $RUNTIME/usr/lib/$ARCH/girepository-1.0 | ||
prepend_dir PATH $RUNTIME/bin | ||
prepend_dir PATH $RUNTIME/usr/bin | ||
prepend_dir PATH $RUNTIME/sbin | ||
prepend_dir PATH $RUNTIME/usr/sbin | ||
prepend_dir PATH $RUNTIME/usr/lib/qt5/bin | ||
append_path ALSA_CONFIG_PATH $RUNTIME/usr/share/alsa/alsa.conf | ||
append_path ALSA_CONFIG_PATH $RUNTIME/usr/share/alsa/pcm/default.conf | ||
append_path PYTHONUSERBASE $RUNTIME | ||
append_path PYTHONHOME $RUNTIME/usr | ||
append_path PYTHONPATH $RUNTIME/usr/lib/python3/dist-packages | ||
append_path PYTHONPATH $RUNTIME/lib/python3*/site-packages | ||
fi | ||
|
||
# make sure we always know where the content snap is especially for classic | ||
# checkbox snaps where the checkbox-runtime bind mount does not exist | ||
export CHECKBOX_RUNTIME=$RUNTIME | ||
|
||
# Use a modules directory which doesn't exist so we don't load random things | ||
# which may then get deleted (or their dependencies) and potentially segfault | ||
export GIO_MODULE_DIR=$SNAP/gio/modules-dummy | ||
|
||
export QML2_IMPORT_PATH="$RUNTIME/usr/lib/$ARCH/qt5/qml:$QML2_IMPORT_PATH" | ||
export QT_PLUGIN_PATH=$RUNTIME/usr/lib/$ARCH/qt5/plugins | ||
export QT_QPA_PLATFORM=xcb | ||
export QT_QPA_PLATFORMTHEME=appmenu-qt5 | ||
|
||
# Tell GStreamer where to find its plugins | ||
export GST_PLUGIN_PATH=$RUNTIME/usr/lib/$ARCH/gstreamer-1.0 | ||
export GST_PLUGIN_SYSTEM_PATH=$RUNTIME/usr/lib/$ARCH/gstreamer-1.0 | ||
# gst plugin scanner doesn't install in the correct path: https://github.com/ubuntu/snapcraft-desktop-helpers/issues/43 | ||
export GST_PLUGIN_SCANNER=$RUNTIME/usr/lib/$ARCH/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner | ||
|
||
# Make PulseAudio socket available inside the snap-specific $XDG_RUNTIME_DIR | ||
if [ -n "$XDG_RUNTIME_DIR" ]; then | ||
export PULSE_RUNTIME_PATH="$XDG_RUNTIME_DIR/../pulse" | ||
export PULSE_SYSTEM=1 | ||
fi | ||
|
||
# Method for making providers available from the checkbox core snap without the | ||
# content interface | ||
BASE_PROVIDERS=($RUNTIME/providers/*) | ||
BASE_PROVIDERS_PATH=$(IFS=:; echo "${BASE_PROVIDERS[*]}") | ||
PROVIDERS=($SNAP/providers/*) | ||
export PROVIDERPATH=$(IFS=:; echo "${PROVIDERS[*]}"):$BASE_PROVIDERS_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright (C) 2016-2021 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from textwrap import dedent | ||
from typing import Any, Dict, List, Set | ||
|
||
from snapcraft.plugins.v2 import PluginV2 | ||
from snapcraft.project import Project, get_snapcraft_yaml | ||
|
||
|
||
class PluginImpl(PluginV2): | ||
@classmethod | ||
def get_schema(cls) -> Dict[str, Any]: | ||
return {} | ||
|
||
def __init__(self, *, part_name: str, options) -> None: | ||
super().__init__(part_name=part_name, options=options) | ||
self.project = Project(snapcraft_yaml_file_path=get_snapcraft_yaml()) | ||
|
||
def get_build_snaps(self) -> Set[str]: | ||
return set() | ||
|
||
def get_build_packages(self) -> Set[str]: | ||
return set() | ||
|
||
def get_build_environment(self) -> Dict[str, str]: | ||
if self.project._get_build_base() == "core22": | ||
site_pkg_path = "$SNAPCRAFT_STAGE/lib/python3.10/site-packages:$SNAPCRAFT_STAGE/usr/lib/python3/dist-packages" | ||
else: | ||
site_pkg_path = "$SNAPCRAFT_STAGE/lib/python3.8/site-packages" | ||
return {"PYTHONPATH": site_pkg_path} | ||
|
||
def get_build_commands(self) -> List[str]: | ||
build_commands = [ | ||
'for path in $(find "$SNAPCRAFT_STAGE/providers/" -mindepth 1 -maxdepth 1 -type d); do export PROVIDERPATH=$path${PROVIDERPATH:+:$PROVIDERPATH}; done', | ||
'python3 manage.py validate', | ||
'python3 manage.py build', | ||
'python3 manage.py install ' | ||
'--layout=relocatable ' | ||
'--prefix=/providers/{} ' | ||
'--root="${{SNAPCRAFT_PART_INSTALL}}"'.format(self.name) | ||
] | ||
# See https://github.com/snapcore/snapcraft/blob/master/snapcraft/plugins/v2/python.py | ||
# Now fix shebangs. | ||
# TODO: replace with snapcraftctl once the two scripts are consolidated | ||
# and use mangling.rewrite_python_shebangs. | ||
build_commands.append( | ||
dedent( | ||
"""\ | ||
for e in $(find "${SNAPCRAFT_PART_INSTALL}" -type f -executable) | ||
do | ||
if head -1 "${e}" | grep -q "python" ; then | ||
sed \\ | ||
-r '1 s|#\\!.*python3?$|#\\!/usr/bin/env python3|' \\ | ||
-i "${e}" | ||
fi | ||
done | ||
""" | ||
) | ||
) | ||
return build_commands |
Oops, something went wrong.