use v5.30.0; use strict; use warnings; use Data::Dumper; use Const::Fast; use Path::Tiny; use File::pushd qw/pushd/; use JSON qw/encode_json/; sub build; sub build_packages; sub generate_jni_libs; sub generate_deb_iteration_jni; const my $TERMUX_PACKAGES_URL => 'https://gitea.sergiotarxz.freemyip.com/sergiotarxz/termux-packages'; build; sub build { #### For the release. ## my $tmpdir = Path::Tiny->tempdir; my $tmpdir = path('tmpdir'); build_packages $tmpdir; generate_jni_libs $tmpdir; } sub generate_deb_iteration_jni { my $source_file = path(__FILE__)->absolute; my $current_file = 0; my %mappings; return ( sub { my $deb = shift->absolute; my $tmpdir_extract_deb = Path::Tiny->tempdir; my $tmpdir_extract_data = Path::Tiny->tempdir; my $out_of_scope_deb = pushd $tmpdir_extract_deb; system qw/ar x/, $deb; undef $out_of_scope_deb; system qw/tar -xf/, $tmpdir_extract_deb->child('data.tar.xz'), '-C', $tmpdir_extract_data; $tmpdir_extract_data->visit( sub { my ( $path, $state ) = @_; return if $path->is_dir; my $stripped_path = $path =~ s{/.*?/.*?(?=/)}{}r; if ($path->basename eq 'libwayland-server.so') { system qw/cp -v/, $path, path(__FILE__)->parent->child('./app/src/main/jni/prebuilt/x86_64/libwayland-server.so'); } if ( -l $path || lstat $path && !stat $path ) { $mappings{$stripped_path} = readlink($path); return; } my $result_file = $source_file->parent->child( "./app/src/main/jni/prebuilt/x86_64/lib$current_file.so" ); system 'cp', $path, $result_file and die "$path not copied."; $mappings{$stripped_path} = '@' . $result_file->basename . ''; $current_file++; }, { recurse => 1 } ); }, sub { return \%mappings } ); } sub generate_jni_libs { my $tmpdir = shift; my %mappings; my $current_file = 0; my @debs = $tmpdir->child('output')->children; @debs = grep { /(?:x86_64|all)\.deb$/ } @debs; my ( $iterator, $result_func ) = generate_deb_iteration_jni(); for my $deb (@debs) { $iterator->($deb); } my $mapping_so_content = encode_json $result_func->(); my $mapping_so = path('app/src/main/jni/prebuilt/x86_64/libmappings.so'); $mapping_so->spew($mapping_so_content); } sub build_packages { my $tmpdir = shift; ## my $fake_home = Path::Tiny->tempdir; #### To avoid conflicting with real termux packages. my $fake_home = path('fake_home')->absolute; local $ENV{HOME} = $fake_home; local $ENV{TERMUX_ARCH} = 'x86_64'; #### TODO: Avoid this to be needed to avoid conflicting with real termux packages. # path('/data/data/.built-packages/')->remove_tree; say "CLONING $TERMUX_PACKAGES_URL."; say "-----------------------------"; say ''; say ''; system qw/git clone/, $TERMUX_PACKAGES_URL, $tmpdir; my $out_of_scope_remove_tempdir = pushd $tmpdir; say "PULLING $TERMUX_PACKAGES_URL."; say "-----------------------------"; say ''; say ''; system qw/git pull/; say "Building i3."; say "-----------------------------"; say ''; say ''; system qw{./build-package.sh i3}; say "Building xwayland."; say "-----------------------------"; say ''; say ''; system qw{./build-package.sh xwayland}; say "Building openmg."; say "-----------------------------"; say ''; say ''; system qw{./build-package.sh openmg}; }