Debian Codegraph @

snap/plugins/x-qbs.py

raw symbols SCIP
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 # Qt version must be specified
36 schema['required'].append('qt-version')
37
38 # Inform Snapcraft of the properties associated with building and
39 # pulling so it can mark those steps dirty if they change in the YAML.
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 # TODO: is this already defined in snapcraft somewhere?
64 arch = subprocess.getoutput("dpkg-architecture -qDEB_HOST_MULTIARCH")
65
66 # a unique'ish name for snap builds. Hopefully this shouldn't clash with
67 # any other local profiles.
68 buildProfile = 'snapcraft'+self.options.qt_version
69
70 # Setup the toolchains, there will only be gcc or clang by default
71 self.run(['qbs', 'setup-toolchains', '--detect'], env=env)
72
73 # Setup a qt4 or qt5 profile. It will auto set gcc as it's build profile
74 self.run(['qbs', 'setup-qt', '/usr/bin/qmake', buildProfile], env=env)
75
76 # Switch buildprofile to clang if required
77 if self.options.profile == 'clang':
78 self.run(['qbs', 'config',
79 'profiles.'+ buildProfile + '.baseProfile',
80 self.options.profile],
81 env=env)
82 # Run the build.
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