261 lines
12 KiB
Perl
Executable File
261 lines
12 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
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, '2ed4be9e852d2533b982493a26bf061b245dc106'],
|
|
winextras => [0, '1bf19cc6a7972d8543485786418b6631459d3469'],
|
|
'3d' => [0, 'c1f8fa2578d99e07f5e581f26bd532695b9534f9'],
|
|
base => [135, 'b6867eef3dd3ac7e825e22b4ad4d2fc182cf20ff'],
|
|
charts => [0, 'e17308d5ce83a8b66aeeaaaf16ce16d4ee6b2826'],
|
|
connectivity => [6, 'e33b82889625b6a72e0be91c5023a30d53136a80'],
|
|
datavis3d => [0, 'd7af24d26b9fbb83bf57b2b7245d280eb78e8b22'],
|
|
declarative => [30, '1b0e366092bcfae0392592c3b7891f0e47af1018'],
|
|
gamepad => [0, '4b52913503e3713200265cd6bc19b301792dbf96'],
|
|
graphicaleffects => [0, 'cce7d784237cd2dd4af1abe2757d048e34e02685'],
|
|
imageformats => [12, 'b22bf4d0d77c7dafe8b4622f8bb45ac0b9cc9bdd'],
|
|
location => [4, 'b4c42e255ee0f04eec4cf5cde35398f3c303ddb9'],
|
|
multimedia => [2, 'f587b18db4abd68cb6d4d77fbcec1b94c38d2a51'],
|
|
networkauth => [0, '1e3f2196bd45a5ee272b08b1d82cef29aaa89b61'],
|
|
quickcontrols => [0, 'dcc90558d9c0cba41eec7df290943994289b0e87'],
|
|
quickcontrols2 => [5, 'a2d56960dd76c94a5115b5415be5ee174d377718'],
|
|
remoteobjects => [0, 'bdc316aca82769b43cb7821c10d80a1ca02b846e'],
|
|
scxml => [0, 'e8727aabe55526956295407d27317ec15e12b283'],
|
|
sensors => [0, 'a41492b23cde20d1e00427d31e4637d06aea3638'],
|
|
serialport => [0, '3380465d5d4977326616c5e57789a81681be650e'],
|
|
speech => [1, '3b163bfd46d96bc9ee848dcee49e9cabe6699287'],
|
|
svg => [6, '7d6e373c7db9c05ef586db0eb50c87cd894229ad'],
|
|
tools => [3, '38ae810be3fb4984f75b55a16d3413e35d701af1'],
|
|
translations => [0, '56065158ffc4cd0fd78f9edf4b21b77b969f8dbb'],
|
|
virtualkeyboard => [0, '817378aa10176fd26eed36542bc657e48d9dd42e'],
|
|
webchannel => [3, 'f84887c1aee4ab04af375e639ae965c9ea2186a5'],
|
|
webglplugin => [0, 'ddcff45e8f2ca9f229017b3ded62327d2fb50af2'],
|
|
websockets => [2, 'd41bb9f4f7ab9d5ff184ef94cf2f6ff7cf01de00'],
|
|
xmlpatterns => [0, '5a1948ddc05bf44017ac12bd5c2b9bc79fbcb9a2'],
|
|
);
|
|
# $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->spew($output, 'UTF-8');
|
|
}
|