Skip to content

Instantly share code, notes, and snippets.

@timsueberkrueb
Created March 3, 2017 11:17
Show Gist options
  • Save timsueberkrueb/15c47f8859cfb0e04496d2d48733a0be to your computer and use it in GitHub Desktop.
Save timsueberkrueb/15c47f8859cfb0e04496d2d48733a0be to your computer and use it in GitHub Desktop.
[Experiment] Script generating snapcraft.yaml for a platform snap including Qt binaries from qt.io
#!/usr/bin/python3
import yaml
from typing import Dict
from collections import OrderedDict
# Add YAML representer to handle OrderedDict
# See http://stackoverflow.com/a/21912744
def represent_ordereddict(dumper, data):
value = []
for item_key, item_value in data.items():
node_key = dumper.represent_data(item_key)
node_value = dumper.represent_data(item_value)
value.append((node_key, node_value))
return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value)
yaml.add_representer(OrderedDict, represent_ordereddict)
# Qt repo url variables
qt_version = '5.8'
qt_sdk_repo_root = 'http://download.qt.io/online/qtsdkrepository/linux_x64/desktop'
qt_sdk_repo_root_version = 'qt5_58'
qt_sdk_repo_dot_version = 'qt.58'
qt_sdk_repo_detail_version = '5.8.0-1'
qt_sdk_repo_compiler_arch = 'gcc_64'
qt_sdk_repo_build_system = 'Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64'
# Qt repo modules
qt_sdk_repo_modules = {
'qtnetworkauth': [
'qtnetworkauth'
],
'qtwebengine': [
'qtwebengine'
],
'': [
'qtxmlpatterns',
'qtx11extras',
'qtwebview',
'qtwebsockets',
'qtwebchannel',
'qttranslations',
'qtsvg',
'qtserialport',
'qtserialbus',
'qtsensors',
'qtscxml',
'qtquickcontrols2',
'qtmultimedia',
'qtlocation',
'qtimageformats',
'qtgraphicaleffects',
'qtdeclarative',
'qtconnectivity',
'qtcanvas3d',
'qtbase',
'qt3d'
]
}
qt_stage_packages = [
'etc1tool',
'fontconfig',
'icu-devtools',
'libc6',
'libcups2',
'libdbus-1-3',
'libdrm2',
'libegl1-mesa',
'libfontconfig1',
'libfreetype6',
'libgbm1',
'libgcc1',
'libgl1-mesa-dev',
'libgl1-mesa-glx',
'libgles2-mesa-dev',
'libglib2.0-0',
'libglu1-mesa-dev',
'libharfbuzz0b',
'libice6',
'libinput10',
'libjpeg8',
'libmtdev1',
'libpcre16-3',
'libproxy1v5',
'libsm6',
'libsqlite3-0',
'libstdc++6',
'libudev1',
'libx11-6',
'libx11-xcb1',
'libxcb1',
'libxcb-glx0',
'libxcb-icccm4',
'libxcb-image0',
'libxcb-keysyms1',
'libxcb-randr0',
'libxcb-render0',
'libxcb-render-util0',
'libxcb-shape0',
'libxcb-shm0',
'libxcb-sync1',
'libxcb-xfixes0',
'libxcb-xkb1',
'libxext-dev',
'libxi6',
'libxkbcommon0',
'libxkbcommon-x11-0',
'libxrender1',
'perl',
'zlib1g',
'libdouble-conversion1v5',
'libpulse0'
]
def get_snapcraft_qt_part_names():
qt_parts = []
for qt_module in qt_sdk_repo_modules:
for qt_submodule in qt_sdk_repo_modules[qt_module]:
qt_parts.append(qt_submodule)
return qt_parts
def build_qt_sdk_repo_module_download_url(qt_module: str, qt_submodule: str) -> str:
url = qt_sdk_repo_root + '/' + \
qt_sdk_repo_root_version + '/' + \
qt_sdk_repo_dot_version + '.' + (qt_module + '.' if qt_module else '') + \
qt_sdk_repo_compiler_arch + '/' + \
qt_sdk_repo_detail_version + qt_submodule + '-' + qt_sdk_repo_build_system + \
'.7z'
return url
def get_snapcraft_qt_parts() -> Dict[str, Dict[str, str]]:
qt_parts = {}
for qt_module in qt_sdk_repo_modules:
for qt_submodule in qt_sdk_repo_modules[qt_module]:
download_url = build_qt_sdk_repo_module_download_url(qt_module, qt_submodule)
qt_parts[qt_submodule] = {
'plugin': 'dump',
'source-type': '7z',
'source': download_url,
'organize': {
qt_version: 'lib/qt/' + qt_version
}
}
qt_parts['qt-dependencies'] = {
'plugin': 'dump',
'stage-packages': qt_stage_packages
}
return qt_parts
def get_snapcraft_other_parts() -> Dict[str, Dict[str, str]]:
other_parts = {
'fluid': {
'plugin': 'cmake',
'source': 'https://github.com/lirios/fluid',
'source-type': 'git',
'source-branch': 'v0.9.0',
'after': get_snapcraft_qt_part_names(),
'configflags': [
'-DCMAKE_PREFIX_PATH={}'.format('$SNAPCRAFT_STAGE/lib/qt/5.8/gcc_64/lib/cmake/'),
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_INSTALL_PREFIX=/',
'-DKDE_INSTALL_QMLDIR={}'.format('lib/qt/5.8/gcc_64/qml'),
'-DECM_DIR={}'.format('/usr/share/ECM/cmake')
],
'build-packages': [
'extra-cmake-modules'
]
}
}
return other_parts
def get_snapcraft_parts() -> Dict[str, Dict[str, str]]:
parts = {}
parts.update(get_snapcraft_qt_parts())
parts.update(get_snapcraft_other_parts())
return parts
def get_snapcraft() -> Dict:
root = OrderedDict([
('name', 'qt-app-platform-example'),
('version', '1'),
('summary', '...'),
('description', '...'),
('grade', 'devel'),
('confinement', 'strict'),
('slots', OrderedDict([
('platform', OrderedDict([
('content', 'qt-app-platform-example1'),
('interface', 'content'),
('read', ['.'])
]))
]),),
('parts', get_snapcraft_parts())
])
return root
def generate_snapcraft():
data = get_snapcraft()
with open('snapcraft.yaml', 'w') as file:
yaml.dump(data, file)
def main():
generate_snapcraft()
if __name__ == '__main__':
main()
name: qt-app-platform-example
version: '1'
summary: '...'
description: '...'
grade: devel
confinement: strict
slots:
platform:
content: qt-app-platform-example1
interface: content
read: [.]
parts:
fluid:
after: [qtxmlpatterns, qtx11extras, qtwebview, qtwebsockets, qtwebchannel, qttranslations,
qtsvg, qtserialport, qtserialbus, qtsensors, qtscxml, qtquickcontrols2, qtmultimedia,
qtlocation, qtimageformats, qtgraphicaleffects, qtdeclarative, qtconnectivity,
qtcanvas3d, qtbase, qt3d, qtnetworkauth, qtwebengine]
build-packages: [extra-cmake-modules]
configflags: [-DCMAKE_PREFIX_PATH=$SNAPCRAFT_STAGE/lib/qt/5.8/gcc_64/lib/cmake/,
-DCMAKE_BUILD_TYPE=Release, -DCMAKE_INSTALL_PREFIX=/, -DKDE_INSTALL_QMLDIR=lib/qt/5.8/gcc_64/qml,
-DECM_DIR=/usr/share/ECM/cmake]
plugin: cmake
source: https://github.com/lirios/fluid
source-branch: v0.9.0
source-type: git
qt-dependencies:
plugin: dump
stage-packages: [etc1tool, fontconfig, icu-devtools, libc6, libcups2, libdbus-1-3,
libdrm2, libegl1-mesa, libfontconfig1, libfreetype6, libgbm1, libgcc1, libgl1-mesa-dev,
libgl1-mesa-glx, libgles2-mesa-dev, libglib2.0-0, libglu1-mesa-dev, libharfbuzz0b,
libice6, libinput10, libjpeg8, libmtdev1, libpcre16-3, libproxy1v5, libsm6,
libsqlite3-0, libstdc++6, libudev1, libx11-6, libx11-xcb1, libxcb1, libxcb-glx0,
libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0, libxcb-render0,
libxcb-render-util0, libxcb-shape0, libxcb-shm0, libxcb-sync1, libxcb-xfixes0,
libxcb-xkb1, libxext-dev, libxi6, libxkbcommon0, libxkbcommon-x11-0, libxrender1,
perl, zlib1g, libdouble-conversion1v5, libpulse0]
qt3d:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qt3d-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtbase:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtbase-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtcanvas3d:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtcanvas3d-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtconnectivity:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtconnectivity-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtdeclarative:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtdeclarative-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtgraphicaleffects:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtgraphicaleffects-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtimageformats:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtimageformats-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtlocation:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtlocation-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtmultimedia:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtmultimedia-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtnetworkauth:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.qtnetworkauth.gcc_64/5.8.0-1qtnetworkauth-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtquickcontrols2:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtquickcontrols2-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtscxml:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtscxml-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtsensors:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtsensors-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtserialbus:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtserialbus-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtserialport:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtserialport-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtsvg:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtsvg-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qttranslations:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qttranslations-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtwebchannel:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtwebchannel-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtwebengine:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.qtwebengine.gcc_64/5.8.0-1qtwebengine-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtwebsockets:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtwebsockets-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtwebview:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtwebview-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtx11extras:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtx11extras-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
qtxmlpatterns:
organize: {'5.8': lib/qt/5.8}
plugin: dump
source: http://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_58/qt.58.gcc_64/5.8.0-1qtxmlpatterns-Linux-RHEL_7_2-GCC-Linux-RHEL_7_2-X86_64.7z
source-type: 7z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment