270 lines
12 KiB
Perl
Executable File
270 lines
12 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
use Encode 'encode';
|
|
use FindBin;
|
|
use Mojolicious;
|
|
use Mojo::File 'path';
|
|
use Mojo::Log;
|
|
use Mojo::Util;
|
|
|
|
use warnings;
|
|
use strict;
|
|
use utf8;
|
|
|
|
my @vcs_0_variant_suffixes = (qw(git svn hg));
|
|
my @cfg_0_variant_suffixes = (qw(static static-compat));
|
|
my @cfg_1_variant_suffixes = (qw(doc test cli angle dynamic opengl noopengl));
|
|
my @variant_suffixes = (\@vcs_0_variant_suffixes, \@cfg_0_variant_suffixes, \@cfg_1_variant_suffixes);
|
|
|
|
sub is_outdated {
|
|
my ($source_path, $target_path) = @_;
|
|
|
|
my $source_last_modified = (stat($source_path))[9];
|
|
my $target_last_modified = (stat($target_path))[9];
|
|
return !defined $target_last_modified || $source_last_modified > $target_last_modified;
|
|
}
|
|
|
|
my $log = Mojo::Log->new;
|
|
my $mojolicious = Mojolicious->new;
|
|
my $renderer = $mojolicious->renderer;
|
|
my $pkgbuilds_dir = path($FindBin::Bin, '..', '..')->realpath;
|
|
my @template_paths = ("$FindBin::Bin/templates", $pkgbuilds_dir);
|
|
|
|
$log->level($ENV{LOG_LEVEL} // 'info');
|
|
$mojolicious->log($log);
|
|
$renderer->paths(\@template_paths);
|
|
$log->debug("Template paths:\n" . join("\n", @template_paths));
|
|
|
|
my $filter_regex = $ARGV[0];
|
|
my $install_directory = $ARGV[1] // $pkgbuilds_dir;
|
|
unless (-d $install_directory) {
|
|
$log->error("Output directory '$install_directory' does not exist.");
|
|
exit(-1);
|
|
}
|
|
|
|
# add helper to render Qt dependencies
|
|
sub _render_deps {
|
|
my ($package_prefix, $controller, @d) = @_;
|
|
my $prefix = $controller->stash('package_name_prefix');
|
|
my $suffix = $controller->stash('package_name_suffix');
|
|
my $quote = $prefix =~ qr/^(mingw-w64|android)/ ? "'" : '';
|
|
return join(' ', map { "${quote}${prefix}${package_prefix}-${_}${suffix}${quote}" } @d);
|
|
}
|
|
sub _render_optdeps {
|
|
my ($package_prefix, $controller, %d) = @_;
|
|
my $prefix = $controller->stash('package_name_prefix');
|
|
my $suffix = $controller->stash('package_name_suffix');
|
|
return join(' ', map { "'${prefix}${package_prefix}-${_}${suffix}: $d{$_}'" } sort keys %d);
|
|
}
|
|
for my $qt_version (qw(qt5 qt6)) {
|
|
$mojolicious->helper("${qt_version}deps" => sub { _render_deps($qt_version, @_) });
|
|
$mojolicious->helper("${qt_version}optdeps" => sub { _render_optdeps($qt_version, @_) });
|
|
}
|
|
|
|
# add helper to expand pkg-config style libraries into full paths for use with CMake
|
|
# example: "-lfoo -lbar" => "/usr/lib/foo.a;/usr/lib/bar.a"
|
|
$mojolicious->helper(expand_libs => sub {
|
|
my $controller = shift;
|
|
my $prefix = $controller->stash('install_prefix');
|
|
my $extension = $controller->stash('library_extension');
|
|
return join(';', map {
|
|
my $library_name = $_;
|
|
$library_name = $1 if $library_name =~ qr/\w*-l(.*)\w*/;
|
|
"$prefix/lib/lib$library_name.$extension";
|
|
} @_);
|
|
});
|
|
|
|
# define revisions of Qt modules from KDE fork
|
|
my %kde_fork_revisions = (
|
|
# module => [rev, 'commit on KDE fork', 'version bump to be reverted'],
|
|
activeqt => [0, '80b43bfe4109820fb7feddb4a16e227a03bc1c4e'],
|
|
winextras => [0, '2a04b162451460ffc208c2c27acce16a18f763ce'],
|
|
'3d' => [6, '0ff905d194e273e04e95b72dbbfd4e58193ecbaa'],
|
|
base => [168, '08be11284246455bce4455138ebe396d2d8732a1'],
|
|
charts => [0, '055c6d6e49c5ea369990e7078fd534392a0ba6b9'],
|
|
connectivity => [5, '6796953f92a1d3af30d0676e56ec5dfd82199611'],
|
|
datavis3d => [0, '8e1a57efa1ba3eabbf44098ce6ede3d130c57b5d'],
|
|
declarative => [18, '45d43c04088efb8346979f633f72bb1f23183461'],
|
|
gamepad => [0, 'ce0202d67bf1ab2bb887f58122b20eab5b6c1d5d'],
|
|
graphicaleffects => [0, 'a2b1600300cda89804d48ec90e0068a075fecc8b'],
|
|
imageformats => [5, '1b83a9c73d6e5459ec4c2221b2bd7e5396b5e874'],
|
|
location => [3, 'f920a6cc2931402023840c223fce2fed321e28ea'],
|
|
lottie => [0, '8bb9237e4e1462f405d931a8a513ed4c27632d9e'],
|
|
multimedia => [1, 'f3dc18968c437c993886d3bfb668b62344a10860'],
|
|
networkauth => [0, 'f34ac77b5955126be60faa2b801be2d19dff896f'],
|
|
purchasing => [0, '25ead89b0834f669e0a193e6d6cf2da25d33a452'],
|
|
quick3d => [1, '95f52cb212f66e6022661fb7f2eb81a8c21e9f22'],
|
|
quickcontrols => [0, 'c7dae5f6041d6c076311f2d8ed13fcfe3598be70'],
|
|
quickcontrols2 => [5, '9ff77702cc3649cbaf94046742d682d77cdea698'],
|
|
quicktimeline => [0, 'e2438e010a98d731317c10a64c095e0282b51ab0'],
|
|
remoteobjects => [0, '5f2a598a9134167a0da2efcbf1249fc167ae3750'],
|
|
scxml => [0, 'e1faea1db52b91d90ef64dd57eb6529e323b5526'],
|
|
sensors => [0, '5f1f73fdba8906f58c4554cbef9c1a72edcf0230'],
|
|
serialbus => [0, '180cb13048a24510f9a1b20796772d27da762bdd'],
|
|
serialport => [0, '966cf2a2077a8470715894363ad46ea7df0665fa'],
|
|
speech => [1, 'd32f4a479d38a11f547598004b975f4356424a16'],
|
|
svg => [9, '83296f10ebdb9a666b11dc69f3a148c38b9c425c'],
|
|
tools => [1, 'c4750dd02070ce246ff98cc5d137193825043912'],
|
|
translations => [0, 'c38edd3a5501bcd53132e1e4abb7d25a98e0e1a9'],
|
|
virtualkeyboard => [0, '8aebadb96c1e57ba89bba2e5962399f676207a32'],
|
|
wayland => [49, '9c607c771acdb3d820be7f112db99213a6c6d7eb'],
|
|
webchannel => [3, '4e35fe9429920067c17596986b486fb1c1e95db0'],
|
|
webglplugin => [0, '3087cdd0758258163299602550f7d4e72edf2a80'],
|
|
websockets => [2, '594477769ecac4032ba116196493f3ba3db1aaed'],
|
|
webview => [0, 'b1605fea61a6bbb599b720c54282bc8ddb0aacf0'],
|
|
x11extras => [0, '9134cdba9386e408ce2ffe515ca0c3f6f6c66685'],
|
|
xmlpatterns => [0, 'b798a0f0265538a9dd12b5c7e4dad84ba8e1db4e'],
|
|
);
|
|
# $rev := git rev-list --count v5.15.2..$commit_on_kde_fork
|
|
|
|
# find templates; populate "pages" array
|
|
my @pages;
|
|
my $template_file_name = 'PKGBUILD.sh.ep';
|
|
my $top_level_dirs = $pkgbuilds_dir->list({dir => 1});
|
|
for my $top_level_dir (@$top_level_dirs) {
|
|
next unless -d $top_level_dir;
|
|
next unless $top_level_dir ne 'devel';
|
|
|
|
my $default_package_name = $top_level_dir->basename;
|
|
my ($qt_module, $qt_major_version);
|
|
if ($default_package_name =~ qr/qt(5|6)-(.*)/) {
|
|
$qt_major_version = $1;
|
|
$qt_module = $2;
|
|
}
|
|
|
|
my $kde_fork_revision;
|
|
if ($qt_major_version && $qt_major_version eq '5' && $qt_module) {
|
|
$kde_fork_revision = $kde_fork_revisions{$qt_module};
|
|
}
|
|
|
|
my $variant_dirs = $top_level_dir->list({dir => 1});
|
|
for my $variant_dir (@$variant_dirs) {
|
|
next unless -d $variant_dir;
|
|
|
|
my $variant = $variant_dir->basename;
|
|
my $template_file = $variant_dir->child($template_file_name);
|
|
if (!-f $template_file) {
|
|
# print warning; all additional Qt repos for mingw-w64 should be converted to use templates now
|
|
$log->warn("No template $template_file_name present for Qt module $qt_module and variant $variant")
|
|
if defined $qt_module && index($variant, 'mingw-w64') == 0 && $variant !~ qr/.*-test$/;
|
|
next;
|
|
}
|
|
|
|
# determine files
|
|
my $files = $variant_dir->list;
|
|
my $patch_files = $files->grep(qr/.*\.patch/);
|
|
my $qt_module_sha256_file_name = "qt$qt_module-sha256.txt";
|
|
my $qt_module_sha256_file = defined $qt_module
|
|
? $variant_dir->child($qt_module_sha256_file_name)
|
|
: undef;
|
|
my $qt_module_sha256 = defined $qt_module_sha256_file && -f $qt_module_sha256_file
|
|
? Mojo::Util::trim($qt_module_sha256_file->slurp)
|
|
: "$qt_module_sha256_file_name missing";
|
|
|
|
# determine variant parts
|
|
my $variant_prefix_part = $variant;
|
|
my $variant_suffix_part = '';
|
|
if ($variant) {
|
|
for my $variant_suffixes (@variant_suffixes) {
|
|
for my $variant_suffix (@$variant_suffixes) {
|
|
next unless $variant =~ qr/.*-$variant_suffix$/;
|
|
$variant_prefix_part = substr($variant, 0, length($variant) - length($variant_suffix) - 1);
|
|
$variant_suffix_part = $variant_suffix_part ? "$variant_suffix-$variant_suffix_part" : $variant_suffix;
|
|
last;
|
|
}
|
|
}
|
|
}
|
|
my $package_name_prefix = $variant_prefix_part ? "$variant_prefix_part-" : "";
|
|
my $package_name_suffix = $variant_suffix_part ? "-$variant_suffix_part" : "";
|
|
my $is_static_variant = $variant_suffix_part =~ qr/static/;
|
|
my $has_static_variant = $is_static_variant || -d "$default_package_name/$variant-static";
|
|
my $is_mingw = $package_name_prefix eq 'mingw-w64-';
|
|
my $package_name = "$package_name_prefix$default_package_name$package_name_suffix";
|
|
next if defined $filter_regex && $package_name !~ $filter_regex;
|
|
|
|
push(@pages, {
|
|
install_path => "$default_package_name/$variant/PKGBUILD",
|
|
template_params => [
|
|
template => "$default_package_name/$variant/PKGBUILD",
|
|
stash_variables => {
|
|
variant => $variant,
|
|
variant_prefix_part => $variant_prefix_part,
|
|
variant_suffix_part => $variant_suffix_part,
|
|
default_package_name => $default_package_name,
|
|
package_name_prefix => $package_name_prefix,
|
|
package_name_suffix => $package_name_suffix,
|
|
package_name => $package_name,
|
|
files => $files,
|
|
patch_files => $patch_files,
|
|
qt_major_version => $qt_major_version,
|
|
qt_module => $qt_module,
|
|
qt_module_sha256 => $qt_module_sha256,
|
|
kde_fork_revision => $kde_fork_revision,
|
|
static_variant => $is_static_variant,
|
|
static_suffix => $is_static_variant ? '-static' : '',
|
|
static_deps => undef,
|
|
static_makedeps => undef,
|
|
is_mingw => $is_mingw,
|
|
library_extension => $is_static_variant ? 'a' : ($is_mingw ? 'dll.a' : 'so'),
|
|
install_prefix => $is_mingw ? '/usr/$_arch' : '/usr',
|
|
shared_config => !$is_static_variant,
|
|
static_config => $is_static_variant || !$has_static_variant,
|
|
no_libraries => 0,
|
|
},
|
|
]
|
|
});
|
|
}
|
|
}
|
|
|
|
# render "pages"
|
|
for my $page (@pages) {
|
|
# process template params
|
|
my $template_params = $page->{template_params};
|
|
my $template_source_path;
|
|
my $template_target_path;
|
|
my $template_stash_variables;
|
|
if (defined $template_params) {
|
|
my ($template_name, $template_args) = (@$template_params % 2 ? shift @$template_params : undef, {@$template_params});
|
|
my $template_format = ($template_args->{format} //= 'sh');
|
|
my $template_handler = $template_args->{handler} // 'ep';
|
|
$template_name //= $template_args->{template};
|
|
$template_stash_variables = delete $template_args->{stash_variables};
|
|
$template_source_path = "$template_name.$template_format.$template_handler";
|
|
$template_target_path = "$template_name.$template_format";
|
|
$template_params = $template_args;
|
|
$template_params->{template} = $template_name;
|
|
}
|
|
|
|
# determine source path and target path
|
|
my $source_path = $page->{source_path} // $template_source_path;
|
|
if (!$template_params && !$source_path) {
|
|
die 'page needs either template_params or source_path';
|
|
}
|
|
my $output_file = path($install_directory, $page->{install_path} // $template_target_path // $source_path);
|
|
|
|
# ensure output directory exists
|
|
$output_file->dirname->make_path unless -f $output_file;
|
|
|
|
# skip unless the target is outdated
|
|
# note: Can not skip templates that easy because that would require tracking includes.
|
|
if (!defined $template_params && !is_outdated($source_path, $output_file)) {
|
|
$log->info("Skipping '$source_path' -> '$output_file' (target up-to-date)");
|
|
next;
|
|
}
|
|
|
|
# do a simple copy
|
|
if (!defined $template_params) {
|
|
$log->info("Copying '$source_path' -> '$output_file'");
|
|
Mojo::File->new($source_path)->copy_to($output_file);
|
|
next;
|
|
}
|
|
|
|
# render template
|
|
$log->info("Rendering '$source_path' -> '$output_file'");
|
|
my $controller = $mojolicious->build_controller;
|
|
$controller->stash($template_stash_variables) if defined $template_stash_variables;
|
|
my $output = $controller->render_to_string(%$template_params);
|
|
$log->debug($output);
|
|
$output_file->spurt(encode('UTF-8', $output));
|
|
}
|