Refactoring the Peace::Model::Release generate_build method.
This commit is contained in:
parent
5eb44406a9
commit
3e331d7b1a
@ -6,7 +6,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Params::ValidationCompiler qw/validation_for/;
|
use Params::ValidationCompiler qw/validation_for/;
|
||||||
use Types::Standard qw/InstanceOf Str HasMethods/;
|
use Types::Standard qw/InstanceOf Str HasMethods HashRef/;
|
||||||
use Path::Tiny;
|
use Path::Tiny;
|
||||||
use File::pushd;
|
use File::pushd;
|
||||||
use YAML;
|
use YAML;
|
||||||
@ -74,29 +74,21 @@ use List::AllUtils qw/any/;
|
|||||||
say "CLONE_DIR: $clone_dir";
|
say "CLONE_DIR: $clone_dir";
|
||||||
my $current_dir = pushd $clone_dir;
|
my $current_dir = pushd $clone_dir;
|
||||||
my $flatpak_data = $self->_parse_flatpak_builder_file;
|
my $flatpak_data = $self->_parse_flatpak_builder_file;
|
||||||
my $app_id = $flatpak_data->{"app-id"};
|
|
||||||
say "$app_id is not the provided app_id ($application->app_id)",
|
|
||||||
return 1
|
|
||||||
if $app_id ne $application->app_id;
|
|
||||||
say "APP_ID: $app_id";
|
|
||||||
my $sdk = $flatpak_data->{sdk};
|
|
||||||
say "SDK: $sdk";
|
|
||||||
my $runtime = $flatpak_data->{runtime};
|
|
||||||
say "RUNTIME: $runtime";
|
|
||||||
my %installed_apps = map { (join(',',[split "\t"]->@[1,4]) => 1) } split "\n", `flatpak list`;
|
|
||||||
|
|
||||||
system 'flatpak', '--user', 'list' and return 1;
|
if ( !defined $flatpak_data ) {
|
||||||
system 'flatpak', '--user', 'remote-add', '--if-not-exists',
|
return 1;
|
||||||
'remote', $application->flatpak_repo
|
}
|
||||||
and return 1;
|
my $app_id = $application->app_id;
|
||||||
say $sdk;
|
my ( $sdk, $runtime ) = $flatpak_data->@{qw/sdk runtime/};
|
||||||
exists $installed_apps{"$sdk,$arch"} or system 'flatpak', '--user', 'install', '--arch', $arch, '-y',
|
say "APP_ID: $app_id";
|
||||||
"$sdk"
|
say "SDK: $sdk";
|
||||||
and return 1;
|
say "RUNTIME: $runtime";
|
||||||
say $runtime;
|
return 1
|
||||||
exists $installed_apps{"$runtime,$arch"} or system 'flatpak', '--user', 'install', '--arch', $arch, '-y',
|
if $self->_install_dependencies(
|
||||||
"$runtime"
|
arch => $arch,
|
||||||
and return 1;
|
runtime => $runtime,
|
||||||
|
sdk => $sdk
|
||||||
|
);
|
||||||
system 'flatpak-builder', '--arch', $arch, '--install', '--user',
|
system 'flatpak-builder', '--arch', $arch, '--install', '--user',
|
||||||
'build', $application->flatpak_builder_file, $app_id
|
'build', $application->flatpak_builder_file, $app_id
|
||||||
and return 1;
|
and return 1;
|
||||||
@ -104,7 +96,7 @@ use List::AllUtils qw/any/;
|
|||||||
$output_dir->mkpath;
|
$output_dir->mkpath;
|
||||||
return system 'flatpak', 'build-bundle', '--arch', $arch,
|
return system 'flatpak', 'build-bundle', '--arch', $arch,
|
||||||
$dir->child('.local/share/flatpak/repo/'),
|
$dir->child('.local/share/flatpak/repo/'),
|
||||||
$output_dir->child($arch), $app_id;
|
$output_dir->child("$arch.flatpak"), $app_id;
|
||||||
};
|
};
|
||||||
my $success = 1;
|
my $success = 1;
|
||||||
if ($exit) {
|
if ($exit) {
|
||||||
@ -118,6 +110,69 @@ use List::AllUtils qw/any/;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $validator = validation_for(
|
||||||
|
params => {
|
||||||
|
arch => { type => Str },
|
||||||
|
runtime => { type => Str },
|
||||||
|
sdk => { type => Str },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
sub _install_dependencies {
|
||||||
|
my $self = shift;
|
||||||
|
my %params = $validator->(@_);
|
||||||
|
my $application = $self->application;
|
||||||
|
my ( $arch, $runtime, $sdk ) = @params{qw/arch runtime sdk/};
|
||||||
|
return 1
|
||||||
|
if system 'flatpak', '--user', 'remote-add', '--if-not-exists',
|
||||||
|
'remote', $application->flatpak_repo;
|
||||||
|
my $installed_apps = $self->_get_installed_flatpak_packages;
|
||||||
|
return 1
|
||||||
|
unless $self->_install_flatpak_package_if_not_exists(
|
||||||
|
arch => $arch,
|
||||||
|
package => $sdk,
|
||||||
|
installed_apps => $installed_apps,
|
||||||
|
);
|
||||||
|
return 1
|
||||||
|
unless $self->_install_flatpak_package_if_not_exists(
|
||||||
|
arch => $arch,
|
||||||
|
package => $runtime,
|
||||||
|
installed_apps => $installed_apps,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _get_installed_flatpak_packages {
|
||||||
|
return {
|
||||||
|
map { ( join( ',', [ split "\t" ]->@[ 1, 4 ] ) => 1 ) }
|
||||||
|
split "\n",
|
||||||
|
`flatpak list`
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $validator = validation_for(
|
||||||
|
params => {
|
||||||
|
arch => { type => Str },
|
||||||
|
package => { type => Str },
|
||||||
|
installed_apps => { type => HashRef },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
sub _install_flatpak_package_if_not_exists {
|
||||||
|
my $self = shift;
|
||||||
|
my %params = $validator->(@_);
|
||||||
|
my ( $arch, $package, $installed_apps ) =
|
||||||
|
@params{ 'arch', 'package', 'installed_apps' };
|
||||||
|
return 1 if exists $installed_apps->{"$package,$arch"};
|
||||||
|
return !system qw/flatpak --user install --arch/, $arch, '-y',
|
||||||
|
"$package";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub _parse_flatpak_builder_file {
|
sub _parse_flatpak_builder_file {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $application = $self->application;
|
my $application = $self->application;
|
||||||
@ -130,7 +185,13 @@ sub _parse_flatpak_builder_file {
|
|||||||
eval { ($structure) = Load($payload); };
|
eval { ($structure) = Load($payload); };
|
||||||
}
|
}
|
||||||
if ( !defined $structure ) {
|
if ( !defined $structure ) {
|
||||||
die "Unable to parse flatpak builder file.";
|
say "Unable to parse flatpak builder file.";
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
my $app_id = $structure->{"app-id"};
|
||||||
|
if ( $app_id ne $application->app_id ) {
|
||||||
|
say "$app_id is not the provided app_id ($application->app_id)";
|
||||||
|
return undef;
|
||||||
}
|
}
|
||||||
return $structure;
|
return $structure;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user