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, 'ccc9a61d10404a4999dec61fdb513aa50f265cc3'],
|
|
winextras => [0, 'a2ef397d1833c7417138a14ae23c880ae434d8a6'],
|
|
'3d' => [6, 'fe5fca853c09c7e03a2ff66dac21584e3307984d'],
|
|
base => [165, 'eeadc036d77b75bec5b7c41869688c7db9a2e221'],
|
|
charts => [0, '841083c263f16f8acb81e4915bf24bbed0461c9a'],
|
|
connectivity => [5, '01e8b04b121712ea0a2b2793ce13f4dd5e9cfcf8'],
|
|
datavis3d => [0, '502612c72a2cd3b3b0c4cff926e7764d74106d33'],
|
|
declarative => [19, 'e1ecf1c4e09b2f1d04f94971771019e59a50679f'],
|
|
gamepad => [0, '0a2d4651362810600d2ff7272772d5908bb8714b'],
|
|
graphicaleffects => [0, 'e6e1e58ec28fd0f2e6426e6962cc4ccddb493349'],
|
|
imageformats => [4, '9044695f4b1acdd7ec24e7b01f6a6ca61f982a75'],
|
|
location => [3, 'ebdf5b38da6e3fe0a183702bcca395c589c459ed'],
|
|
lottie => [0, 'd40b67401afe7156b03c62c9a4d517b07555fe64'],
|
|
multimedia => [1, '76f84c545429a1b988b79f971734ef4bc3e6643f'],
|
|
networkauth => [0, '01315e31c5164c896a524175854c4b6df17fe166'],
|
|
purchasing => [0, 'fa07915d5b7c5ba16f2e8ba32a9066fe7eed0cb1'],
|
|
quick3d => [1, '5cf67a0a93026ffd41d2ea5a11b289f46a518376'],
|
|
quickcontrols => [0, 'e62b8b6d2f45a79652238b33f4bbe23023004ae7'],
|
|
quickcontrols2 => [5, '74e8db97fdb9b55c4b4614b83f4bf17e00df55e9'],
|
|
quicktimeline => [0, '87ad61716a7cba5a070d8a7b1756c8b2b48d5d53'],
|
|
remoteobjects => [0, 'aa705010da0f658b78c1155babce7091ae44529a'],
|
|
scxml => [0, '631fd7bcc34802b7650c2b1dc73691463954d982'],
|
|
sensors => [0, '35eb5ac7eaef4745a38958c3ca780d7baa2e4f30'],
|
|
serialbus => [0, 'f9f7eee60adac72fcf6617d164e3bf61222bb5c5'],
|
|
serialport => [0, 'c9abfcd5d88cb43c2a7c1d5ddecbff4cdd320694'],
|
|
speech => [1, 'd1273416f25a15a6edf6ea56a07602cd7d99fe48'],
|
|
svg => [9, 'a9752b00a03438de8e5b080073816e12409404b7'],
|
|
tools => [1, '32912a06aadfc3dcbc34e0a668ce2c78351eee6e'],
|
|
translations => [2, 'd4db9d8a4893a70e7ba3a6d5fe62f24f9ce745ca'],
|
|
virtualkeyboard => [1, '9fbb837b55887bec5d73fad142c853ef68db35b3'],
|
|
wayland => [43, '489a0a1fc1db61f46e2b232ae4523723a05304b7'],
|
|
webchannel => [3, 'fb1ca87aa1a12048199d2aabe9015b7222d2b773'],
|
|
webglplugin => [0, '68a322c391c2eb92876fce42b9fc23ad2f3a1ecb'],
|
|
websockets => [2, 'a066371747a7eb9de9b1ae38fbc41b2059080802'],
|
|
webview => [0, '87577dde04ed219bda776dabca86176149736331'],
|
|
x11extras => [0, '982f20eb585d77e5b5c721e05a466d7161f7f2d1'],
|
|
xmlpatterns => [0, '30e6c84fe2752cde8b53aff9d38c2095cd7c8761'],
|
|
);
|
|
# $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));
|
|
}
|