diff --git a/packaging/linux/snap/build.sh b/packaging/linux/snap/build.sh new file mode 100755 --- /dev/null +++ b/packaging/linux/snap/build.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -ex + +IMAGE=ubuntu:18.04 +CONTAINER=container-krita-snap + +function at_exit { + lxc stop $CONTAINER +} + +lxc stop $CONTAINER || true + +lxc launch --ephemeral "$IMAGE" $CONTAINER +sleep 4 # so network is up + +trap at_exit INT TERM EXIT + +lxc file push --recursive . $CONTAINER/workspace +lxc exec $CONTAINER -- /workspace/build_in_container.sh +lxc file pull --recursive $CONTAINER/workspace/result . diff --git a/packaging/linux/snap/build_in_container.sh b/packaging/linux/snap/build_in_container.sh new file mode 100755 --- /dev/null +++ b/packaging/linux/snap/build_in_container.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -ex + +cd /workspace + +ping -c1 networkcheck.kde.org + +apt-key adv --keyserver keyserver.ubuntu.com --recv E6D4736255751E5D +echo 'deb http://archive.neon.kde.org/unstable bionic main' > /etc/apt/sources.list.d/neon.list +apt update + +snap install --edge --classic snapcraft + +snapcraft --version +snapcraft --destructive-mode + +mkdir -p result +mv *.snap result/ diff --git a/packaging/linux/snap/kf5-locale-gen b/packaging/linux/snap/kf5-locale-gen new file mode 100755 --- /dev/null +++ b/packaging/linux/snap/kf5-locale-gen @@ -0,0 +1,115 @@ +#!/usr/bin/perl +# +# Copyright 2019 Harald Sitter +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of +# the License or any later version accepted by the membership of +# KDE e.V. (or its successor approved by the membership of KDE +# e.V.), which shall act as a proxy defined in Section 14 of +# version 3 of the license. +# +# 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 . + +use strict; + +my $debug = 0; +if (defined $ENV{'LOCALE_DEBUG'}) { + $debug = 1; +} + +my $config_dir = ($ENV{'XDG_CONFIG_HOME'} or "$ENV{'HOME'}/.config"); +my $conf="$config_dir/klanguageoverridesrc"; + +my @languages = ('C.UTF-8'); + +sub debug { + print(@_) if $debug; +} + +# Grab langs from languageoverrides file (in-app language switch feature). +if (-e $conf) { + my $group; + open my $ini, '<', $conf or die "Can't open $conf: $!\n"; + while (<$ini>) { # loops in $_ + chomp; + my $keyword; + my $value; + if (/^\s*\[(.+)\].*/) { + $group = $1; + } elsif (/^([^=]+?)\s*=\s*(.*?)\s*$/) { # https://code-maven.com/slides/perl-programming/solution-parse-ini-file + if ($group ne 'Language') { + next; + } + $keyword = $1; + $value = $2; + my $pattern = '@ByteArray\((.+)\)'; + (my $langs = $value) =~ s/$pattern/$1/g; + push @languages, split(/:/, $langs); + # print("-- keyword: $1 -- value: $2\n"); + } + } + close($ini); +} + +# Grab values from ENV. +push @languages, ($ENV{'LANG'} or 'C.UTF-8'); +foreach my $key (sort keys %ENV) { + my $needle = 'LC_'; + if (substr($key, 0, length($needle)) eq $needle) { + push @languages, $ENV{$key}; + } +} +if (my $language = $ENV{'LANGUAGE'}) { + push @languages, split(':', $language); +} +push @languages, ($ENV{'LANG'} or 'C.UTF-8'); + +# Uniqify; can't really use any perl modules as the base requirements of KF5 are +# mostly perl core only. +@languages = do { my %seen; grep { !$seen{$_}++ } @languages }; + +# Generate as necessary. +# Note: this actually generates invalid stuff as well (e.g. fr.UTF-8) while we +# apparently do not need these there isn't much of a downside to generate them +# lest something in glibc falls over if the language is entirely unknown in +# the locpath. I should point out that we can't actually get from +# language-only settings (as seen in klanguageoverrides) to full locales, so +# there is no other option here anyway. +my $env_locpath = $ENV{'LOCPATH'} or die "LOCPATH not set"; +my @locpaths = split(/:/, $env_locpath); +my $master_locpath = $locpaths[0]; +foreach my $lang (@languages) { + my ($locale, $encoding) = split(/\./, $lang); + $encoding //= 'UTF-8'; + debug("lang: $lang loc: $locale, char: $encoding\n"); + + my $found = 0; + foreach my $locpath (@locpaths) { + my $loc_target = "$locpath/$locale.$encoding"; + debug("checking $loc_target\n"); + if (-e $loc_target) { + debug("exists! skipping\n"); + $found = 1; + last; + } + } + next if $found; + my $target = "$master_locpath/$locale.$encoding"; + + debug("generating $target\n"); + # localedef will exit !0 for unknown reasons, even when everything was + # generated fine. + # may be: /snap/krita/32/usr/share/i18n/locales/iso14651_t1_common:7120: LC_COLLATE: symbol `pure-ta-zh' not known + system('localedef', '-i', $locale, '-f', $encoding, $target); +} + +# use Data::Dumper; +# print Dumper(@languages); diff --git a/packaging/linux/snap/qt5-launch b/packaging/linux/snap/qt5-launch --- a/packaging/linux/snap/qt5-launch +++ b/packaging/linux/snap/qt5-launch @@ -8,47 +8,92 @@ ARCH="$SNAP_ARCH-linux-gnu" fi -export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=$SNAP/lib:$SNAP/lib/$ARCH:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=$SNAP/usr/lib:$SNAP/usr/lib/$ARCH:$LD_LIBRARY_PATH # XKB config export XKB_CONFIG_ROOT=$SNAP/usr/share/X11/xkb # Mesa Libs export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH/mesa:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH/mesa-egl:$LD_LIBRARY_PATH -# XDG Config -export XDG_CONFIG_DIRS=$SNAP/etc:$XDG_CONFIG_DIRS +# libGL Drivers +export LIBGL_DRIVERS_PATH=$SNAP/usr/lib/$ARCH/dri +export LD_LIBRARY_PATH=$LIBGL_DRIVERS_PATH:$LD_LIBRARY_PATH -# Note: this doesn't seem to work, QML's LocalStorage either ignores -# or fails to use $SNAP_USER_DATA if defined here -export XDG_DATA_DIRS=$SNAP/usr/share:$XDG_DATA_DIRS +# Grab proprietary nvidia mount when possible. +# https://bugs.launchpad.net/snappy/+bug/1588192 +export LD_LIBRARY_PATH=/var/lib/snapd/lib/gl:$LD_LIBRARY_PATH -# Font Config -export FONTCONFIG_PATH=$SNAP/etc/fonts/config.d -export FONTCONFIG_FILE=$SNAP/etc/fonts/fonts.conf +# Pulseaudio plugins +export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH/pulseaudio:$LD_LIBRARY_PATH -# Tell libGL where to find the drivers -export LIBGL_DRIVERS_PATH=$SNAP/usr/lib/$ARCH/dri +# XDG Config +export XDG_CONFIG_DIRS=$SNAP/etc:${XDG_CONFIG_DIRS:-/etc/xdg} -# Necessary for the SDK to find the translations directory -export APP_DIR=$SNAP +# Note: this doesn't seem to work, QML's LocalStorage either ignores +# or fails to use $SNAP_USER_DATA if defined here +export XDG_DATA_DIRS=$SNAP/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share} # Set XDG_DATA_HOME to local path, dependent on snap version -export XDG_DATA_HOME=$SNAP_USER_DATA/.local-$SNAP_VERSION/share -export XDG_DATA_DIRS=$XDG_DATA_HOME:$XDG_DATA_DIRS +export XDG_DATA_HOME=$SNAP_USER_DATA/.local/share mkdir -p $XDG_DATA_HOME -# Set cache folder to local path, dependent on snap version -export XDG_CACHE_HOME=$SNAP_USER_DATA/.cache-$SNAP_VERSION +export XDG_CONFIG_HOME=$SNAP_USER_DATA/.config +mkdir -p $XDG_CONFIG_HOME + +if [ -e $SNAP_USER_DATA/.local/config/kdeglobals ]; then + # Migrate legacy path previously (incorrectly) used for configs. + # The current var $HOME/.config is in line with the XDG default. + cp -rv $SNAP_USER_DATA/.local/config/. $XDG_CONFIG_HOME + rm -rv $SNAP_USER_DATA/.local/config/ +fi + +export XDG_CACHE_HOME=$SNAP_USER_DATA/.cache mkdir -p $XDG_CACHE_HOME -# Not good, needed for fontconfig and themes -ln -sf $SNAP/usr/share/{fontconfig,fonts,fonts-*,themes} $XDG_DATA_HOME +export XDG_RUNTIME_DIR=$SNAP_USER_DATA/.local/var/run/$UID +mkdir -p $XDG_RUNTIME_DIR -# Qt Platform to Mir -export QTCHOOSER_NO_GLOBAL_DIR=1 -export QT_SELECT=snappy-qt5 +# Font Config +export FONTCONFIG_PATH=$SNAP/etc/fonts/config.d +export FONTCONFIG_FILE=$XDG_CONFIG_HOME/fontconfig/fonts.conf + +REALHOME=`getent passwd $UID | cut -d ':' -f 6` +# Keep an array of data dirs, for looping through them +IFS=':' read -r -a data_dirs_array <<< "$XDG_DATA_DIRS" + +function make_user_fontconfig { + echo "" + if [ -d $REALHOME/.local/share/fonts ]; then + echo " $REALHOME/.local/share/fonts" + fi + if [ -d $REALHOME/.fonts ]; then + echo " $REALHOME/.fonts" + fi + for d in "${data_dirs_array[@]}"; do + if [ -d "$d/fonts" ]; then + echo " $d/fonts" + fi + done + echo ' conf.d' + # We need to include this default cachedir first so that caching + # works: without it, fontconfig will try to write to the real user home + # cachedir and be blocked by AppArmor. + echo ' fontconfig' + if [ -d $REALHOME/.cache/fontconfig ]; then + echo " $REALHOME/.cache/fontconfig" + fi + echo "" +} + +# This relies on the desktop, x11, or unity7 interface from what I can tell. +# We'll configure the in-snap fontconfig to look in the outside resoruces, +# the outside resources are made readable by the aforementioned interfaces. +rm -rf $XDG_DATA_HOME/{fontconfig,fonts,fonts-*,themes,.themes} +mkdir -p $XDG_CONFIG_HOME/fontconfig +make_user_fontconfig > $FONTCONFIG_FILE # Qt Libs export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH/qt5/libs:$LD_LIBRARY_PATH @@ -62,16 +107,61 @@ # Removes Qt warning: Could not find a location # of the system Compose files export QTCOMPOSE=$SNAP/usr/share/X11/locale - -export DESKTOP_SESSION=ubuntu -export XDG_SESSION_DESKTOP=ubuntu -export XDG_CURRENT_DESKTOP=kde -export QT_QPA_PLATFORMTHEME=appmenu-qt5 export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb +# FIXME: it's unclear if we actually need to force plasma theming, even without +# gtk integration theme Qt should probably figure out a sane style. Needs +# testing though. +export KDE_FULL_SESSION=true +export DESKTOP_SESSION=${DESKTOP_SESSION:-/usr/share/xsessions/plasma} +export XDG_SESSION_DESKTOP=${XDG_SESSION_DESKTOP:-KDE} +export XDG_CURRENT_DESKTOP=${XDG_CURRENT_DESKTOP:-KDE} +export QT_QPA_PLATFORMTHEME=${QT_QPA_PLATFORMTHEME:-kde} + # ensure that our HW/opengl libs are before the snap specific libs export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH +# KDE specific +## Do not start slaves through klauncher but fork them directly. +export KDE_FORK_SLAVES=1 +## Neon PATCH! make KIO look for slaves in a dynamic location depending on $SNAP +## FIXME: should be made a : separated list so we can look in $SNAP and $KF5! +export KF5_LIBEXEC_DIR=$SNAP/usr/lib/$ARCH/libexec/kf5 + +# Link icons into home so (xcursor) can find its cursor theme. +mkdir -p $HOME/.icons +ln -fs $SNAP/usr/share/icons/* $HOME/.icons + +# Make sure QtChooser isn't being terrible to us +export QTCHOOSER_NO_GLOBAL_DIR=1 +export QT_SELECT=5 +# qtchooser hardcodes reference paths, we'll need to rewrite them properly +[ -d $XDG_CONFIG_HOME/qtchooser ] || mkdir -p $XDG_CONFIG_HOME/qtchooser +echo "$SNAP/usr/lib/qt5/bin" > $XDG_CONFIG_HOME/qtchooser/5.conf +echo "$SNAP/usr/lib/$ARCH" >> $XDG_CONFIG_HOME/qtchooser/5.conf +echo "$SNAP/usr/lib/qt5/bin" > $XDG_CONFIG_HOME/qtchooser/default.conf +echo "$SNAP/usr/lib/$ARCH" >> $XDG_CONFIG_HOME/qtchooser/default.conf + +# This relies on qtbase patch +# 0001-let-qlibraryinfo-fall-back-to-locate-qt.conf-via-XDG.patch +# to make QLibraryInfo look in XDG_* locations for qt.conf. The paths configured +# here are applied to everything that uses QLibraryInfo as final fallback and +# has no XDG_* fallback before that. Currently the most interesting offender +# is QtWebEngine which will not work unless the Data path is correctly set. +cat << EOF > $XDG_CONFIG_HOME/qt.conf +[Paths] +Data = $SNAP/usr/share/qt5/ +Translations = $SNAP/usr/share/qt5/translations +EOF + +# requires `locales, libc-bin` being stage-packages +if [ -e $SNAP/usr/share/i18n ]; then + export I18NPATH=$SNAP/usr/share/i18n + locpath=$XDG_DATA_HOME/locale + mkdir -p $locpath + export LOCPATH=$locpath:/usr/lib/locale # core snap contains C.UTF-8 already + LC_ALL=C.UTF-8 $SNAP/bin/kf5-locale-gen || exit 1 +fi + cd $SNAP exec "$@" - diff --git a/packaging/linux/snap/setup/gui/calligrakrita.png b/packaging/linux/snap/snap/gui/calligrakrita.png rename from packaging/linux/snap/setup/gui/calligrakrita.png rename to packaging/linux/snap/snap/gui/calligrakrita.png diff --git a/packaging/linux/snap/setup/gui/krita.desktop b/packaging/linux/snap/snap/gui/krita.desktop rename from packaging/linux/snap/setup/gui/krita.desktop rename to packaging/linux/snap/snap/gui/krita.desktop diff --git a/packaging/linux/snap/snapcraft.yaml b/packaging/linux/snap/snapcraft.yaml --- a/packaging/linux/snap/snapcraft.yaml +++ b/packaging/linux/snap/snapcraft.yaml @@ -1,59 +1,33 @@ name: krita -version: 3.0.91-snap15 +version: 4.1.7.101 summary: Krita is the digital painting studio for artists description: Krita is a creative application for raster images. Whether you want to create from scratch or work with existing images, Krita is for you. You can work with photos or scanned images, or start with a blank slate. Krita supports most graphics tablets out of the box. - +base: core18 apps: krita: command: qt5-launch usr/bin/krita - plugs: [x11, unity7, home, opengl, network, network-bind, removable-media] + plugs: [x11, unity7, home, opengl, network, network-bind, removable-media, desktop, desktop-legacy] parts: - qt: - plugin: nil - stage-packages: - - libqt5concurrent5 - - libqt5core5a - - libqt5dbus5 - - libqt5gui5 - - libqt5network5 - - libqt5printsupport5 - - libqt5svg5 - - libqt5widgets5 - - libqt5x11extras5 - - libqt5xml5 - - kdeframeworks: - plugin: nil - stage-packages: - - libkf5archive5 - - libkf5completion5 - - libkf5configcore5 - - libkf5configgui5 - - libkf5coreaddons5 - - libkf5guiaddons5 - - libkf5i18n5 - - libkf5itemviews5 - - libkf5widgetsaddons5 - - libkf5windowsystem5 - - libkf5crash5 - after: [qt] - krita: plugin: cmake -# Using -DKDE_NO_DEBUG_OUTPUT was causing compilation failure for some reason -# configflags: [-DCMAKE_INSTALL_PREFIX=/usr, -DQT_NO_DEBUG=1, -DCMAKE_CXX_FLAGS="-DKDE_NO_DEBUG_OUTPUT"] - configflags: [-DCMAKE_INSTALL_PREFIX=/usr, -DQT_NO_DEBUG=1] - source: http://download.kde.org/unstable/krita/3.0.91/krita-3.0.91.tar.gz + configflags: + - "-DCMAKE_INSTALL_PREFIX=/usr" + - "-DCMAKE_BUILD_TYPE=Release" + - "-DENABLE_TESTING=OFF" + - "-DBUILD_TESTING=OFF" + - "-DKDE_SKIP_TEST_SETTINGS=ON" + source: https://download.kde.org/stable/krita/4.1.7/krita-4.1.7.101.tar.gz # Use these instead to build from the git source -# source: git://anongit.kde.org/krita.git +# source: https://anongit.kde.org/krita.git # source-type: git -# source-branch: krita/3.0 +# source-branch: master build-packages: + - gettext - build-essential - cmake - libboost-dev @@ -72,20 +46,19 @@ - libjpeg-dev - liblcms2-dev - libopenexr-dev - - libpng12-dev - - libpoppler-qt4-dev + - libpng-dev + - libpoppler-qt5-dev - libtiff5-dev - libvc-dev - libopencolorio-dev - libx11-dev - libxml2-dev - libxslt1-dev - libxi-dev - pkg-config - - pkg-kde-tools - vc-dev - zlib1g-dev - - libkdcraw-dev + - libkf5kdcraw-dev - shared-mime-info - libopenimageio-dev - extra-cmake-modules @@ -103,39 +76,73 @@ - libqt5svg5-dev - libqt5x11extras5-dev - libqt5opengl5-dev - stage-packages: - - libboost-system1.58.0 - - libexiv2-14 + + runtime: + plugin: nil + stage-packages: + - libexiv2-26 - libfftw3-double3 - libgomp1 - - libgsl2 + - libgsl23 - libilmbase12 - libjpeg8 - liblcms2-2 - libopencolorio1v5 - libopenexr22 - - libpng12-0 + - libpng16-16 - libstdc++6 - libtiff5 - libx11-6 - libxcb1 - libxi6 - zlib1g - - libraw15 - - libkf5crash5 - libpoppler-qt5-1 - after: [qt, kdeframeworks] - - integration: + - shared-mime-info + - libboost-system1.65.1 + - librtmp1 + - libqt5multimedia5 + - libqt5quickwidgets5 + - libkf5archive5 + - libkf5completion5 + - libkf5configcore5 + - libkf5configgui5 + - libkf5coreaddons5 + - libkf5guiaddons5 + - libkf5i18n5 + - libkf5itemviews5 + - libkf5widgetsaddons5 + - libkf5windowsystem5 + - libkf5crash5 + - libqt5concurrent5 + - libqt5core5a + - libqt5dbus5 + - libqt5gui5 + - libqt5network5 + - libqt5printsupport5 + - libqt5svg5 + - libqt5widgets5 + - libqt5x11extras5 + - libqt5xml5 + - locales + - libc-bin + prime: + - "-usr/share/wallpapers/*" + - "-usr/share/fonts/*" + + plasma-integration: plugin: nil stage-packages: - - ttf-ubuntu-font-family - snap: - - usr/share - - -usr/share/doc + - plasma-integration + - kde-style-breeze + - breeze-icon-theme + - kio # runtime slaves for kio + prime: + - "-usr/share/wallpapers/*" + - "-usr/share/fonts/*" launcher: - plugin: copy - files: + plugin: dump + source: . + organize: qt5-launch: bin/qt5-launch - + kf5-locale-gen: bin/kf5-locale-gen