-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatomize-debs.rb
489 lines (441 loc) · 13.8 KB
/
atomize-debs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
require 'json'
require 'tmpdir'
require 'yaml'
class Source
attr_reader :upstream_name
attr_reader :upstream_version
def initialize(upstream_name)
@upstream_name = upstream_name
end
def all_qml_depends
@all_qml_depends ||= controls.collect do |control|
control.binaries.collect do |binary|
next nil unless runtime_binaries.include?(binary['package'])
deps = binary.fetch('depends', []) + binary.fetch('recommends', [])
deps.collect do |dep|
dep = [dep[0]] if dep.size > 1
next nil unless dep[0].name.start_with?('qml-module')
dep = dep.each { |y| y.architectures = nil; y.version = nil; y.operator = nil }
# puts "---> #{dep} ---> #{dep[0].substvar?}"
dep = dep.reject(&:substvar?)
dep.collect(&:to_s)
end.compact
end.flatten
end.flatten
end
def dev_binaries
dev_only(all_packages)
end
def runtime_binaries
runtime_only(all_packages)
end
def all_build_depends
@all_build_depends ||= controls.collect do |control|
bdeps = control.source.fetch('build-depends', []) +
control.source.fetch('build-depends-indep', [])
bdeps.collect do |x|
# TODO: this makes a bunch of assumptions as we have no proper
# resolver for dependencies. in alternates the first always wins
# architecture restrictions are entirely ignored
x = [x[0]] if x.size > 1
x = x.each { |y| y.architectures = nil; y.version = nil; y.operator = nil }
x.collect(&:to_s)
end.compact
end.flatten
end
private
def read_upstream_version(dir)
version = `dpkg-parsechangelog -S version -l #{dir}/debian/changelog`.strip
unless $?.success?
warn 'Got error during dpkg-parsechangelog!'
warn version
return nil
end
version = version.split(':', 2)[-1] # ditch epoch
version.split('-', 2)[0] # ditch rev
end
def parse_control(src)
system("apt-get --download-only source #{src}") || raise
FileUtils.mkpath('source/')
files = 'debian/control debian/changelog'
system("tar -xvf *debian.tar.* -C source #{files}") || raise
@upstream_version = read_upstream_version('source')
require_relative 'debian/control'
control = Debian::Control.new('source')
control.parse!
control
end
def controls
@controls ||= sources.collect do |src|
Dir.mktmpdir do |tmpdir|
Dir.chdir(tmpdir) do
parse_control(src)
end
end
end
end
def all_packages
@all_packages ||= controls.collect do |control|
control.binaries.collect { |x| x.fetch('package') }
end.flatten
end
def dev_only(packages)
packages.select do |pkg|
pkg.include?('-dev') && !(pkg == 'qt5-qmake-arm-linux-gnueabihf')
end
end
def runtime_only(packages)
packages.delete_if do |pkg|
pkg.include?('-dev') || pkg.include?('-doc') || pkg.include?('-dbg') ||
pkg.include?('-examples') || pkg == 'qt5-qmake-arm-linux-gnueabihf'
end
end
MAP = {
'qt5' => %w(qtbase-opensource-src
qtscript-opensource-src
qtdeclarative-opensource-src
qttools-opensource-src
qtsvg-opensource-src
qtx11extras-opensource-src),
'kwallet' => %w(kwallet-kf5),
'kdnssd' => [],
'baloo' => %w(baloo-kf5),
'kdoctools' => %w(kdoctools5),
'kfilemetadata' => %w(kfilemetadata-kf5),
'attica' => %w(attica-kf5),
'kactivities' => %w(kactivities-kf5)
}.freeze
def sources
MAP.fetch(@upstream_name, [@upstream_name])
end
end
class SnapcraftConfig
module AttrRecorder
def attr_accessor(*args)
record_readable(*args)
super
end
def attr_reader(*args)
record_readable(*args)
super
end
def record_readable(*args)
@readable_attrs ||= []
@readable_attrs += args
end
def readable_attrs
@readable_attrs
end
end
module YamlAttributer
def encode_with(c)
c.tag = nil # Unset the tag to prevent clutter
self.class.readable_attrs.each do |readable_attrs|
next unless data = method(readable_attrs).call
c[readable_attrs.to_s.tr('_', '-')] = data
end
super(c) if defined?(super)
end
end
class Part
extend AttrRecorder
prepend YamlAttributer
# Array<String>
attr_accessor :after
# String
attr_accessor :plugin
# Array<String>
attr_accessor :build_packages
# Array<String>
attr_accessor :stage_packages
# Hash
attr_accessor :filesets
# Array<String>
attr_accessor :snap
# Array<String>
attr_accessor :stage
# Hash<String, String>
attr_accessor :organize
attr_writer :source
attr_writer :configflags
def initialize
@after = []
@plugin = 'nil'
@build_packages = []
@stage_packages = []
@filesets = {
'exclusion' => %w(
-usr/lib/*/cmake/*
-usr/lib/*/qt5/bin/moc
-usr/lib/*/qt5/bin/qmake
-usr/lib/*/qt5/bin/rcc
-usr/lib/*/qt5/bin/*cpp*
-usr/lib/qt5/bin/assistant
-usr/lib/qt5/bin/designer
-usr/lib/qt5/bin/lconvert
-usr/lib/qt5/bin/linguist
-usr/lib/qt5/bin/lupdate
-usr/lib/qt5/bin/lrelease
-usr/lib/qt5/bin/moc
-usr/lib/qt5/bin/pixeltool
-usr/lib/qt5/bin/qcollectiongenerator
-usr/lib/qt5/bin/qdbuscpp2xml
-usr/lib/qt5/bin/qdbusxml2cpp
-usr/lib/qt5/bin/qdoc
-usr/lib/qt5/bin/qhelpconverter
-usr/lib/qt5/bin/qlalr
-usr/lib/qt5/bin/qmake
-usr/lib/qt5/bin/rcc
-usr/lib/qt5/bin/syncqt.pl
-usr/lib/vlc/plugins/gui/libqt4_plugin.so
-usr/include/*
-usr/share/ECM/*
-usr/share/xml/docbook/*
-usr/share/doc/*
-usr/share/locale/*/LC_MESSAGES/vlc.mo
-usr/share/man/*
-usr/share/icons/breeze/*.rcc
-usr/share/icons/breeze-dark/*.rcc
-usr/share/wallpapers/*
-usr/share/fonts/*
-usr/share/pkgconfig
-usr/lib/*/pkgconfig
-usr/share/QtCurve
-usr/share/kde4
-usr/share/bug
-usr/share/debhelper
-usr/share/lintian
-usr/share/menu
-usr/bin/*vlc
-usr/bin/dh_*
-usr/lib/*/*.a
-usr/lib/*/*.pri
)
}
@stage = %w[
-usr/share/doc/*
-usr/share/man/*
-usr/share/icons/breeze/*.rcc
-usr/share/wallpapers/*
-usr/share/fonts/*
]
@snap = %w($exclusion)
# @organize = {
# 'etc/*' => 'slash/etc/',
# 'usr/*' => 'slash/usr/'
# }
end
def encode_with(c)
if @plugin != 'nil'
c['configflags'] = @configflags
c['source'] = @source
end
super if defined?(super)
end
end
class Slot
extend AttrRecorder
prepend YamlAttributer
attr_accessor :content
attr_accessor :interface
attr_accessor :read
end
extend AttrRecorder
prepend YamlAttributer
attr_accessor :name
attr_accessor :version
attr_accessor :summary
attr_accessor :description
attr_accessor :confinement
attr_accessor :grade
attr_accessor :slots
attr_accessor :parts
def initialize
@parts = {}
@slots = {}
end
end
config = SnapcraftConfig.new
config.name = 'kde-frameworks-5'
config.version = 'unknown'
config.summary = 'KDE Frameworks 5'
config.description = 'KDE Frameworks are addons and useful extensions to Qt'
config.confinement = 'strict'
config.grade = 'stable'
slot = SnapcraftConfig::Slot.new
slot.content = 'kde-frameworks-5-all'
slot.interface = 'content'
slot.read = %w[.]
config.slots['kde-frameworks-5-slot'] = slot
# These are only old versions! The new version is created later after we know
# the current versions of the content.
content_versions = JSON.parse(File.read('versions.json')).uniq
content_versions.each do |content_version|
slot = SnapcraftConfig::Slot.new
slot.content = content_version
slot.interface = 'content'
slot.read = %w[.]
config.slots[content_version] = slot
end
# This list is generated by resolving and sorting the dep tree from
# kde-build-metadata. Commented out bits we don't presently want to build.
parts = %w(extra-cmake-modules kcoreaddons) + # kdesupport/polkit-qt-1
%w(kauth kconfig kwidgetsaddons kcompletion
kwindowsystem kcrash karchive ki18n kfilemetadata
kjobwidgets kpty kunitconversion kcodecs) + # kdesupport/phonon/phonon
%w(knotifications kpackage kguiaddons kconfigwidgets kitemviews
kiconthemes attica kdbusaddons kservice kglobalaccel sonnet
ktextwidgets breeze-icons kxmlgui kbookmarks solid kwallet kio
kdeclarative kcmutils kplotting kparts kdewebkit
kemoticons knewstuff kinit knotifyconfig kded
kdesu ktexteditor kactivities kactivities-stats
kdnssd kidletime kitemmodels threadweaver
plasma-framework kxmlrpcclient kpeople frameworkintegration
kdoctools
kdesignerplugin
krunner kwayland baloo)
# plasma-integration) # extra integration pulls in breeze pulls in kde4/qt4
parts += %w(qtwebkit qtbase qtdeclarative qtgraphicaleffects qtlocation
qtmultimedia qtquickcontrols qtquickcontrols2 qtscript qtsensors qtserialport
qtsvg qttools qttranslations qtvirtualkeyboard qtwayland qtwebchannel
qtwebengine qtwebsockets qtx11extras qtxmlpatterns).collect { |x| x += '-opensource-src' }
#
# oxygen-icons5 only one icon set
# Not Runtime Relevant! FIXME: need to seperate these out to only end up in -dev but not content!
# extra-cmake-modules
# kdesignerplugin
# kdoctools
# No Porting Aids!
# kdelibs4support
# khtml
# kjs
# kjsembed
# kmediaplayer
# kross
# padding
parts = [nil] + parts
# parts += [nil]
devs = []
# mesa-utils-extra - es2_info useful to debug GL problems.
runs = %w[mesa-utils-extra]
# GStreamer plugins
runs += %w[gstreamer1.0-fluendo-mp3 gstreamer1.0-x gstreamer1.0-plugins-base
gstreamer1.0-pulseaudio gstreamer1.0-plugins-good]
# For on-demand locale generation we need the raw data to generate locales from.
runs += %w[locales libc-bin]
kf5_version = nil
qt5_version = nil
parts.each_cons(2) do |first_name, second_name|
# puts "#{second_name} AFTER #{first_name}"
next unless second_name # first item is nil
source = Source.new(second_name)
devs += source.dev_binaries
runs += source.runtime_binaries
if source.upstream_name == 'extra-cmake-modules' && config.version
kf5_version = source.upstream_version
config.version = source.upstream_version
end
if source.upstream_name == 'qtbase-opensource-src'
qt5_version = source.upstream_version
end
end
# Construct a new interface name with up to date versions.
# This is the only way we can version a content snap.
kf5_version = 'kde-frameworks-' + kf5_version.split('.')[0..1].join('-')
qt5_version = 'qt-' + qt5_version.split('.')[0..1].join('-')
platform_version = 'ubuntu-1604'
latest_version = [kf5_version, qt5_version, platform_version].join('-')
# Dump the latest interface. The application builds will pick this up and
# set it as their content provider, this way we should be able to prevent
# Qt version mismatches.
File.write('content.json',
JSON.generate(latest_version))
unless config.slots.include?(latest_version)
slot = SnapcraftConfig::Slot.new
slot.content = latest_version
slot.interface = 'content'
slot.read = %w[.]
config.slots[latest_version] = slot
content_versions << latest_version
File.write('versions.json', JSON.generate(content_versions.uniq))
end
# Do not pull in the GTK stack.
runs.delete('qt5-gtk-platformtheme')
devs.delete('qt5-gtk-platformtheme')
part = SnapcraftConfig::Part.new
part.stage_packages = runs.flatten
config.parts['kf5'] = part
dev = SnapcraftConfig::Part.new
dev.stage_packages = devs.flatten
dev.stage = (dev.stage + %w[
-usr/share/emoticons
-usr/share/icons/*
-usr/share/locale/*/LC_*/*
-usr/share/qt5/translations/*
-usr/lib/*/dri/*
]).uniq
dev.snap = ['-*']
dev.after = %w(kf5)
config.parts['kf5-dev'] = dev
breeze = SnapcraftConfig::Part.new
breeze.after = %w(kf5-dev)
breeze.build_packages = %w(
pkg-config
libx11-dev
extra-cmake-modules
qtbase5-dev
libkf5config-dev
libkf5configwidgets-dev
libkf5windowsystem-dev
libkf5i18n-dev
libkf5coreaddons-dev
libkf5guiaddons-dev
libqt5x11extras5-dev
libkf5style-dev
libkf5kcmutils-dev
kwayland-dev
libkf5package-dev
)
breeze.configflags = %w(
-DKDE_INSTALL_USE_QT_SYS_PATHS=ON
-DCMAKE_INSTALL_PREFIX=/usr
-DCMAKE_BUILD_TYPE=Release
-DENABLE_TESTING=OFF
-DBUILD_TESTING=OFF
-DKDE_SKIP_TEST_SETTINGS=ON
-DWITH_DECORATIONS=OFF
)
breeze.plugin = 'cmake'
breeze.source = 'http://download.kde.org/stable/plasma/5.10.5/breeze-5.10.5.tar.xz'
config.parts['breeze'] = breeze
integration = SnapcraftConfig::Part.new
integration.after = %w(kf5-dev breeze)
integration.build_packages = %w(
extra-cmake-modules
kio-dev
kwayland-dev
libkf5config-dev
libkf5configwidgets-dev
libkf5i18n-dev
libkf5iconthemes-dev
libkf5notifications-dev
libkf5widgetsaddons-dev
libqt5x11extras5-dev
libxcursor-dev
qtbase5-dev
qtbase5-private-dev
)
integration.configflags = %w(
-DKDE_INSTALL_USE_QT_SYS_PATHS=ON
-DCMAKE_INSTALL_PREFIX=/usr
-DCMAKE_BUILD_TYPE=Release
-DENABLE_TESTING=OFF
-DBUILD_TESTING=OFF
-DKDE_SKIP_TEST_SETTINGS=ON
)
integration.plugin = 'cmake'
integration.source = 'http://download.kde.org/stable/plasma/5.10.5/plasma-integration-5.10.5.tar.xz'
config.parts['plasma-integration'] = integration
puts File.write('snapcraft.yaml', YAML.dump(config, indentation: 4))
puts File.write('stage-content.json', JSON.generate(runs))
puts File.write('stage-dev.json', JSON.generate(runs + devs))