| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# Copyright: 2017 Dmitry Shachnev <[email protected]> |
| 4 |
# |
| 5 |
# Permission is hereby granted, free of charge, to any person obtaining |
| 6 |
# a copy of this software and associated documentation files (the |
| 7 |
# "Software"), to deal in the Software without restriction, including |
| 8 |
# without limitation the rights to use, copy, modify, merge, publish, |
| 9 |
# distribute, sublicense, and/or sell copies of the Software, and to |
| 10 |
# permit persons to whom the Software is furnished to do so, subject to |
| 11 |
# the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included |
| 14 |
# in all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 20 |
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 |
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
|
| 24 |
=head1 NAME |
| 25 |
|
| 26 |
dh_qmlcdeps - generate proper dependencies for QML cache files |
| 27 |
|
| 28 |
=head1 SYNOPSIS |
| 29 |
|
| 30 |
B<dh_qmlcdeps> [S<I<debhelper options>>] |
| 31 |
|
| 32 |
=head1 DESCRIPTION |
| 33 |
|
| 34 |
B<dh_qmlcdeps> is a debhelper program that looks for F<*.qmlc> files |
| 35 |
(generated by B<qmlcachegen>) in the package temporary locations, performs |
| 36 |
sanity check on them, and adds a dependency on B<libqt5qml5> package to |
| 37 |
B<${qmlc:Depends}> substitution variable to make sure its version matches |
| 38 |
the Qt version in these files. |
| 39 |
|
| 40 |
You can pass B<--with qmlcdeps> to L<dh(1)> to make it automatically call |
| 41 |
B<dh_qmlcdeps> after B<dh_install>. |
| 42 |
|
| 43 |
=cut |
| 44 |
|
| 45 |
use strict; |
| 46 |
use warnings; |
| 47 |
use File::Find; |
| 48 |
use Debian::Debhelper::Dh_Lib; |
| 49 |
|
| 50 |
init(options => {}); |
| 51 |
|
| 52 |
foreach my $package (@{$dh{DOPACKAGES}}) { |
| 53 |
my $tmpdir = tmpdir($package); |
| 54 |
next unless -d $tmpdir; |
| 55 |
my $qt_version_bin; |
| 56 |
|
| 57 |
find({ |
| 58 |
wanted => sub { |
| 59 |
my $filename = $_; |
| 60 |
return unless ($filename =~ m/\.qmlc$/); |
| 61 |
open (my $fh, "<", $filename); |
| 62 |
binmode $fh; |
| 63 |
read ($fh, my $magic, 8); |
| 64 |
if ($magic ne "qv4cdata") { |
| 65 |
close $fh; |
| 66 |
error("Unknown .qmlc file: $File::Find::name"); |
| 67 |
} |
| 68 |
read ($fh, my $struct_version, 4); |
| 69 |
read ($fh, my $file_qt_version_bin, 4); |
| 70 |
close $fh; |
| 71 |
if ($qt_version_bin and $file_qt_version_bin ne $qt_version_bin) { |
| 72 |
error("Package $package contains .qmlc files built for different Qt versions"); |
| 73 |
} |
| 74 |
$qt_version_bin = $file_qt_version_bin; |
| 75 |
} |
| 76 |
}, $tmpdir); |
| 77 |
|
| 78 |
$qt_version_bin or next; |
| 79 |
my @qt_version = unpack("C4", $qt_version_bin); |
| 80 |
my $qt_version_str = "$qt_version[2].$qt_version[1].$qt_version[0]"; |
| 81 |
$qt_version[2] == 5 or error("Qt version $qt_version_str is not supported"); |
| 82 |
my $qt_next_version_str = "$qt_version[2].$qt_version[1]." . ($qt_version[0] + 1); |
| 83 |
|
| 84 |
addsubstvar($package, "qmlc:Depends", "libqt5qml5 (>= $qt_version_str~)"); |
| 85 |
addsubstvar($package, "qmlc:Depends", "libqt5qml5 (<< $qt_next_version_str~)"); |
| 86 |
} |
| 87 |
|
| 88 |
=head1 SEE ALSO |
| 89 |
|
| 90 |
L<debhelper(7)> |
| 91 |
|
| 92 |
=head1 AUTHOR |
| 93 |
|
| 94 |
Dmitry Shachnev <[email protected]> |
| 95 |
|
| 96 |
=cut |