| 1 |
import os |
| 2 |
import snapcraft |
| 3 |
import subprocess |
| 4 |
from snapcraft import common |
| 5 |
|
| 6 |
class QbsPlugin(snapcraft.BasePlugin): |
| 7 |
|
| 8 |
@classmethod |
| 9 |
def schema(cls): |
| 10 |
schema = super().schema() |
| 11 |
schema['properties']['options'] = { |
| 12 |
'type': 'array', |
| 13 |
'minitems': 1, |
| 14 |
'uniqueItems': True, |
| 15 |
'items': { |
| 16 |
'type': 'string', |
| 17 |
}, |
| 18 |
'default': [], |
| 19 |
} |
| 20 |
|
| 21 |
schema['properties']['profile'] = { |
| 22 |
'enum': ['gcc', 'clang'], |
| 23 |
'default': 'gcc', |
| 24 |
} |
| 25 |
|
| 26 |
schema['properties']['build-variant'] = { |
| 27 |
'enum': ['debug', 'release'], |
| 28 |
'default': 'release', |
| 29 |
} |
| 30 |
|
| 31 |
schema['properties']['qt-version'] = { |
| 32 |
'enum': ['qt4', 'qt5'], |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
schema['required'].append('qt-version') |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
schema['build-properties'].append('options') |
| 41 |
schema['pull-properties'].append('qt-version') |
| 42 |
|
| 43 |
return schema |
| 44 |
|
| 45 |
def __init__(self, name, options, project): |
| 46 |
super().__init__(name, options, project) |
| 47 |
|
| 48 |
self.build_packages.append('qbs') |
| 49 |
self.build_packages.append('gcc') |
| 50 |
self.build_packages.append('clang') |
| 51 |
if self.options.qt_version == 'qt5': |
| 52 |
self.build_packages.extend(['qt5-qmake', 'qtbase5-dev']) |
| 53 |
elif self.options.qt_version == 'qt4': |
| 54 |
self.build_packages.extend(['qt4-qmake', 'libqt4-dev']) |
| 55 |
else: |
| 56 |
raise RuntimeError('Unsupported Qt version: {!r}'.format( |
| 57 |
self.options.qt_version)) |
| 58 |
|
| 59 |
def build(self): |
| 60 |
super().build() |
| 61 |
|
| 62 |
env = self._build_environment() |
| 63 |
|
| 64 |
arch = subprocess.getoutput("dpkg-architecture -qDEB_HOST_MULTIARCH") |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
buildProfile = 'snapcraft'+self.options.qt_version |
| 69 |
|
| 70 |
|
| 71 |
self.run(['qbs', 'setup-toolchains', '--detect'], env=env) |
| 72 |
|
| 73 |
|
| 74 |
self.run(['qbs', 'setup-qt', '/usr/bin/qmake', buildProfile], env=env) |
| 75 |
|
| 76 |
|
| 77 |
if self.options.profile == 'clang': |
| 78 |
self.run(['qbs', 'config', |
| 79 |
'profiles.'+ buildProfile + '.baseProfile', |
| 80 |
self.options.profile], |
| 81 |
env=env) |
| 82 |
|
| 83 |
self.run(['qbs', 'build', |
| 84 |
'-d', self.builddir, |
| 85 |
'-f', self.sourcedir, |
| 86 |
'-j', '4', |
| 87 |
self.options.build_variant, |
| 88 |
'qbs.installRoot:' + self.installdir, |
| 89 |
'project.binDir:/usr/bin', |
| 90 |
'project.libDir:/usr/lib/' + arch, |
| 91 |
'project.qmlDir:/usr/lib/' + arch + '/qt5/qml', |
| 92 |
'project.dataDir:/usr/share/dekko', |
| 93 |
'profile:' + buildProfile] + self.options.options, |
| 94 |
env=env) |
| 95 |
|
| 96 |
def _build_environment(self): |
| 97 |
env = os.environ.copy() |
| 98 |
env['QT_SELECT'] = self.options.qt_version |
| 99 |
return env |
| 100 |
|
| 101 |
|