Alien-Xmake
view release on metacpan or search on metacpan
builder/Alien/Xmake/Builder.pm view on Meta::CPAN
$dir = $dir->parent;
}
return { version => $ver, bin => $bin, install_dir => $dir };
}
method _find_system_xmake ( ) {
my $sep = ( $^O eq 'MSWin32' ) ? ';' : ':';
for my $dir ( split /$sep/, $ENV{PATH} ) {
my $p = path($dir);
my $exts = ( $^O eq 'MSWin32' ) ? [qw(.exe .cmd .bat)] : [''];
for my $ext (@$exts) {
my $full = $p->child("xmake$ext");
return $full if -x $full;
}
}
return undef;
}
method _get_xmake_version ($cmd) {
my $safe_cmd = ( $^O eq 'MSWin32' ) ? qq{"$cmd"} : "$cmd";
my $out = `$safe_cmd --version`;
if ( $out =~ /xmake\s+v?(\d+\.\d+\.\d+)/i ) {
return "v$1";
}
return 'v0.0.0';
}
method _version_cmp ( $v1, $v2 ) {
require version;
$v1 =~ s/^v//;
$v2 =~ s/^v//;
return version->parse($v1) <=> version->parse($v2);
}
method _write_config_data ($data) {
my $dest = path('blib')->child($target_config);
$dest->parent->mkpath;
my $dumper = Data::Dumper->new( [$data], ['conf'] );
$dumper->Indent(1)->Terse(1)->Sortkeys(1);
my $content = sprintf <<~'PERL', $dumper->Dump;
package Alien::Xmake::ConfigData {
use v5.40;
use File::Spec;
use File::Basename qw[dirname];
my $config = %s;
sub config ($s, $key //= ()) { defined $key ? $config->{$key} : $config }
sub config_names { sort keys %%$config }
#
sub bin {
my $bin = $config->{bin};
return unless defined $bin;
return $bin if $config->{install_type} eq 'system';
File::Spec->rel2abs($bin, dirname(__FILE__))
}
};
1;
PERL
$dest->spew_utf8($content);
say "Generated $dest";
}
method _install_windows ($installdir) {
my $temppath = path('_build_xmake');
$temppath->mkpath;
my $arch_env = $ENV{PROCESSOR_ARCHITECTURE} // '';
my $arch64_env = $ENV{PROCESSOR_ARCHITEW6432} // '';
my $filename;
# Check for ARM64
if ( $arch_env eq 'ARM64' || $arch64_env eq 'ARM64' ) {
# ARM64 releases currently use the 'bundle' naming convention
$filename = "xmake-bundle-$target_version.arm64.exe";
}
# Check for x64 (AMD64/IA64)
elsif ( $arch_env eq 'AMD64' || $arch_env eq 'IA64' || $arch64_env eq 'AMD64' || $arch64_env eq 'IA64' ) {
$filename = "xmake-$target_version.win64.exe";
}
# Fallback to x86
else {
$filename = "xmake-$target_version.win32.exe";
}
my $url = "https://github.com/xmake-io/xmake/releases/download/$target_version/$filename";
my $outfile = $temppath->child('xmake-installer.exe');
if ( !$self->_download_file( $url, $outfile ) ) {
die "Download failed for $url";
}
my $install_str = $installdir->stringify;
$install_str =~ s{/}{\\}g;
my $outfile_str = $outfile->stringify;
$outfile_str =~ s{/}{\\}g;
say "Installing to $install_str...";
# /NOADMIN: Avoid UAC prompt if possible (installs to local user path if allowed)
# /S: Silent
# /D: Destination directory
my $cmd = qq{"$outfile_str" /NOADMIN /S /D=$install_str};
my $ret = system($cmd);
die "Installer failed with code $ret" if $ret != 0;
# Cleanup
path('_build_xmake')->remove_tree;
}
method _install_unix ($installdir) {
my $build_dir = path('_build_xmake');
$build_dir->remove_tree;
$build_dir->mkpath;
my $sudo = '';
if ( $> != 0 && $self->_run_cmd('sudo -n --version >/dev/null 2>&1') ) {
$sudo = 'sudo';
}
unless ( $self->_test_tools() ) {
# Do not auto-install system tools unless requested.
if ( $ENV{ALIEN_INSTALL_SYSTEM_TOOLS} ) {
( run in 0.431 second using v1.01-cache-2.11-cpan-56fb94df46f )