Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
snapcraft-qt-builder-plugin
import os
import snapcraft
from snapcraft.plugins import make
class QtBuilderPlugin(make.MakePlugin):
@classmethod
def schema(cls):
schema = super().schema()
schema['properties']['configflags'] = {
'type': 'array',
'minitems': 1,
'uniqueItems': False,
'items': {
'type': 'string',
},
'default': [],
}
schema['properties']['qt-source-git'] = {
'type': 'string'
}
schema['properties']['qt-source-depth'] = {
'type': 'integer',
'default': 1
}
schema['properties']['qt-version'] = {
'type': 'string'
}
schema['properties']['qt-patches-base-url'] = {
'type': 'string'
}
schema['properties']['qt-patches-path'] = {
'type': 'string'
}
schema['properties']['qt-submodules'] = {
'type': 'array',
'minitems': 0,
'uniqueItems': True,
'items': {
'type': 'string',
},
'default': [],
}
schema['required'].append('qt-source-git')
schema['build-properties'].append('configflags')
return schema
@classmethod
def get_pull_properties(cls):
return [
'qt-version',
'qt-patches-base-url',
'qt-patches-path',
'qt-submodules',
]
def __init__(self, name, options, project):
super().__init__(name, options, project)
self.build_packages.extend(['g++', 'patch', 'perl', 'wget'])
self.options.source_depth = self.options.qt_source_depth
if self.options.qt_version:
self.options.source_branch = '.'.join(
self.options.qt_version.split('.')[:-1])
def pull(self):
if not os.path.exists(os.path.join(self.sourcedir, '.git')) or \
not os.path.exists(os.path.join(self.sourcedir, 'init-repository')):
self.run('rm -rf {}'.format(self.sourcedir).split())
command = 'git clone {} {}'.format(
self.options.qt_source_git, self.sourcedir).split()
if self.options.source_branch:
command.extend(['--branch', str(self.options.source_branch)])
if self.options.source_depth:
command.extend(['--depth', str(self.options.source_depth)])
self.run(command)
command = 'perl init-repository --branch -f'.split()
if len(self.options.qt_submodules):
command.extend('--module-subset={}'.format(
','.join(self.options.qt_submodules)).split())
self.run(command, cwd=self.sourcedir)
# if self.options.qt_version:
# self.run("git checkout v{}".format(
# self.options.qt_version).split(), cwd=self.sourcedir)
if self.options.qt_version:
self.run("git submodule foreach git checkout v{}".format(
self.options.qt_version).split(), self.sourcedir)
patch_file_template = '${{name}}{}.diff'.format(
'_' + self.options.qt_version.replace('.', '_') \
if self.options.qt_version else '')
if self.options.qt_patches_base_url:
patch_uri_template = '{}/{}'.format(
self.options.qt_patches_base_url, patch_file_template)
patch_cmd = 'git submodule foreach -q'.split() + \
['[ -e {touch_file} ] || ' \
'wget -q -O - {patch_uri_template} | patch -p1 && ' \
'touch {touch_file}'.format(
patch_uri_template=patch_uri_template,
touch_file='.snapcraft-qt-patched')]
self.run(patch_cmd, cwd=self.sourcedir)
if self.options.qt_patches_path:
patch_path_template = os.path.join(
os.getcwd(), self.options.qt_patches_path, patch_file_template)
patch_cmd = 'git submodule foreach -q'.split() + \
['[ -e {patch} ] && git apply {patch} || true'.format(
patch=patch_path_template)]
self.run(patch_cmd, cwd=self.sourcedir)
def build(self):
self.run(['./configure'] + self.options.configflags)
super().build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment