Skip to content

Commit

Permalink
Try building from a versioned archive instead of pulling source from git
Browse files Browse the repository at this point in the history
  • Loading branch information
sanko committed Mar 17, 2024
1 parent d582e77 commit f058987
Showing 1 changed file with 66 additions and 68 deletions.
134 changes: 66 additions & 68 deletions builder/xmake.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ package builder::xmake {
#
#~ use Data::Dump;
#
my $version = 'v2.8.8'; # Target install version
my $version = '2.8.8'; # Target install version
my $branch = 'master';

#~ my $installer_sh = 'https://xmake.io/shget.text';
my $installer_exe
= "https://github.com/xmake-io/xmake/releases/download/${version}/xmake-${version}.win64.exe";
my $share = rel2abs 'share';
my $installer_exe = "https://github.com/xmake-io/xmake/releases/download/v${version}/xmake-v${version}.win64.exe";
my $installer_tar = "https://github.com/xmake-io/xmake/releases/download/v${version}/xmake-v${version}.tar.gz";
my $share = rel2abs 'share';
#
sub http {
CORE::state $http //= HTTP::Tiny->new(
agent => 'Alien::xmake/' .
shift->dist_version() . '; ' # space at the end asks HT to appended default UA
agent => 'Alien::xmake/' . shift->dist_version() . '; ' # space at the end asks HT to appended default UA
);
$http;
}
Expand All @@ -43,10 +42,10 @@ package builder::xmake {
#~ warn File::Spec->rel2abs(
#~ File::Basename::dirname(__FILE__), 'share'
#~ );
sub download_exe {
my ($s) = @_;
my $local = File::Spec->rel2abs( File::Spec->catfile( $s->cwd, 'xmake_installer.exe' ) );
my $response = $s->http->mirror( $installer_exe, $local );
sub download {
my ( $s, $url, $path ) = @_;
my $local = File::Spec->rel2abs( File::Spec->catfile( $s->cwd, $path ) );
my $response = $s->http->mirror( $url, $local );
if ( $response->{success} ) {
$s->log_debug( 'Install executable mirrored at ' . $local );
$s->make_executable($local); # get it ready to run
Expand Down Expand Up @@ -98,16 +97,13 @@ package builder::xmake {
#
my $os = $s->os_type; # based on Perl::OSType
if ( !defined $os ) {
$s->log_warn(
q[Whoa. Perl has no idea what this OS is so... let's try installing with a shell script and hope for the best!]
);
$s->log_warn(q[Whoa. Perl has no idea what this OS is so... let's try installing with a shell script and hope for the best!]);
exit 1;
}
elsif ( $os eq 'Windows' ) {
$s->config_data( xmake_type => 'share' );
my $installer = $s->download_exe();
my $dest = File::Spec->rel2abs(
File::Spec->catdir( $s->base_dir, @{ $s->share_dir->{dist} } ) );
my $installer = $s->download( $installer_exe, 'xmake_installer.exe' );
my $dest = File::Spec->rel2abs( File::Spec->catdir( $s->base_dir, @{ $s->share_dir->{dist} } ) );
$s->log_info(qq[Running installer [$installer]...\n]);
$s->do_system( $installer, '/NOADMIN', '/S', '/D=' . $dest );
$s->log_info(qq[Installed to $dest\n]);
Expand All @@ -128,7 +124,7 @@ package builder::xmake {
$s->config_data( xmake_type => 'system' );
}
else {
build_from_source();
$s->build_from_source();
$xmake = $s->locate_xmake();
#
$s->config_data( xmake_type => 'share' );
Expand Down Expand Up @@ -183,6 +179,7 @@ package builder::xmake {
}

sub build_from_source {
my $s = shift;

# get make
my $make;
Expand All @@ -200,8 +197,7 @@ package builder::xmake {
my ( $fh, $filename ) = tempfile();
syswrite $fh, "#include <stdio.h>\nint main(){return 0;}";
for (qw[gcc cc clang]) {
if ( !system $_, qw'-x c', $filename,
qw'-o /dev/null -I/usr/include -I/usr/local/include' ) {
if ( !system $_, qw'-x c', $filename, qw'-o /dev/null -I/usr/include -I/usr/local/include' ) {
$compiler = $_;
}
}
Expand All @@ -217,27 +213,21 @@ package builder::xmake {
}
$git // warn 'Please install git';
}
if ( !defined $make || !defined $git || !defined $compiler ) {
if ( !defined $make || !defined $compiler ) {
my $sudo = sudo();
my $installer = package_installer();
my %options = (
apt => "$sudo apt install -y git build-essential libreadline-dev ccache"
, # debian, etc.
yum =>
"yum install -y git readline-devel ccache bzip2 && $sudo yum groupinstall -y 'Development Tools'",
apt => "$sudo apt install -y git build-essential libreadline-dev ccache", # debian, etc.
yum => "yum install -y git readline-devel ccache bzip2 && $sudo yum groupinstall -y 'Development Tools'",
zypper =>
"$sudo zypper --non-interactive install git readline-devel ccache && $sudo zypper --non-interactive install -t pattern devel_C_C++",
pacman =>
"$sudo pacman -S --noconfirm --needed git base-devel ncurses readline ccache"
, # arch, etc.
emerge => "$sudo emerge -atv dev-vcs/git ccache", # Gentoo
pkg_termux => "$sudo pkg install -y git getconf build-essential readline ccache"
, # termux (Android)
pkg_bsd => "$sudo pkg install -y git readline ccache ncurses", # freebsd
nixos => "nix-env -i git gcc readline ncurses;",
apk =>
"$sudo apk add git gcc g++ make readline-dev ncurses-dev libc-dev linux-headers",
xbps => "$sudo xbps-install -Sy git base-devel ccache",
pacman => "$sudo pacman -S --noconfirm --needed git base-devel ncurses readline ccache", # arch, etc.
emerge => "$sudo emerge -atv dev-vcs/git ccache", # Gentoo
pkg_termux => "$sudo pkg install -y git getconf build-essential readline ccache", # termux (Android)
pkg_bsd => "$sudo pkg install -y git readline ccache ncurses", # freebsd
nixos => "nix-env -i git gcc readline ncurses;",
apk => "$sudo apk add git gcc g++ make readline-dev ncurses-dev libc-dev linux-headers",
xbps => "$sudo xbps-install -Sy git base-devel ccache",

#scoop => "$sudo ", # Windows
#winget => "$sudo ", # Windows
Expand Down Expand Up @@ -267,32 +257,44 @@ package builder::xmake {
return 'github.com';
}
}
my $mirror = get_fast_host();
CORE::say "Using $mirror mirror...";
my ( $gitrepo, $gitrepo_raw );
if ( $mirror eq 'github.com' ) {
$gitrepo = 'https://github.com/xmake-io/xmake.git';
my $cwd = rel2abs('.');
my $projectdir = tempdir( CLEANUP => 1 );
my $workdir;
undef $git; # Force archive install
if ( defined $git ) {
my $mirror = get_fast_host();
CORE::say "Using $mirror mirror...";
my ( $gitrepo, $gitrepo_raw );
if ( $mirror eq 'github.com' ) {
$gitrepo = 'https://github.com/xmake-io/xmake.git';

#$gitrepo_raw='https://github.com/xmake-io/xmake/raw/master';
$gitrepo_raw = 'https://fastly.jsdelivr.net/gh/xmake-io/xmake@master';
#$gitrepo_raw='https://github.com/xmake-io/xmake/raw/master';
$gitrepo_raw = 'https://fastly.jsdelivr.net/gh/xmake-io/xmake@master';
}
else {
$gitrepo = "https://gitee.com/tboox/xmake.git";
$gitrepo_raw = "https://gitee.com/tboox/xmake/raw/master";
}
#
`git clone --depth=1 -b "v$version" "$gitrepo" --recurse-submodules $projectdir` unless -f $projectdir;
chdir $projectdir;
$workdir = $projectdir;
}
else {
$gitrepo = "https://gitee.com/tboox/xmake.git";
$gitrepo_raw = "https://gitee.com/tboox/xmake/raw/master";
require Archive::Tar;
my $archive = $s->download( $installer_tar, 'xmake.tar.gz' );
my $tar = Archive::Tar->new;
$tar->read($archive);
chdir $projectdir;
$tar->extract();
$workdir = $projectdir . '/xmake-' . $version;
}
#
my $projectdir = tempdir( CLEANUP => 1 );
#
`git clone --depth=1 -b "$branch" "$gitrepo" --recurse-submodules $projectdir`
unless -f $projectdir;
my $cwd = rel2abs('.');
chdir $projectdir;
`./configure` unless -f "$projectdir/makefile";
warn $workdir;

Check failure on line 292 in builder/xmake.pm

View workflow job for this annotation

GitHub Actions / macos/5.38

/var/folders/h1/8hndypj13nsbj5pn4xsnv1tm0000gn/T/JGGX_WQjXz/xmake-2.8.8

Check failure on line 292 in builder/xmake.pm

View workflow job for this annotation

GitHub Actions / ubuntu/5.38

/tmp/fKi777hgtq/xmake-2.8.8

Check failure on line 292 in builder/xmake.pm

View workflow job for this annotation

GitHub Actions / ubuntu/5.36

/tmp/J1U8eZ6xT0/xmake-2.8.8

Check failure on line 292 in builder/xmake.pm

View workflow job for this annotation

GitHub Actions / macos/5.36

/var/folders/h1/8hndypj13nsbj5pn4xsnv1tm0000gn/T/s44yimVrg4/xmake-2.8.8
chdir $workdir;
system './configure' unless -f 'makefile';
system $make;
system $make, qq[install PREFIX=$share];
chdir $cwd; # I really should go to dist base dir

#~ warn 'Building with ' . $make;
`$make -C $projectdir`;
`$make -C $projectdir install PREFIX=$share`;
return $share;
}

Expand All @@ -301,19 +303,15 @@ package builder::xmake {
my $Win32 if $^O eq 'MSWin32';
my $sudo = sudo();
my %options = (
apt =>
"$sudo add-apt-repository ppa:xmake-io/xmake && $sudo apt update && $sudo apt install xmake"
, # debian, etc.
pacman => ( $Win32 ? 'pacman -Sy mingw-w64-x86_64-xmake' : "$sudo pacman -Sy xmake" )
, # arch, etc.
emerge => "$sudo emerge -a --autounmask dev-util/xmake", # Gentoo
pkg_termux => "$sudo pkg install -y xmake", # termux (Android)
apt => "$sudo add-apt-repository ppa:xmake-io/xmake && $sudo apt update && $sudo apt install xmake", # debian, etc.
pacman => ( $Win32 ? 'pacman -Sy mingw-w64-x86_64-xmake' : "$sudo pacman -Sy xmake" ), # arch, etc.
emerge => "$sudo emerge -a --autounmask dev-util/xmake", # Gentoo
pkg_termux => "$sudo pkg install -y xmake", # termux (Android)
xbps => "$sudo xbps-install -Sy git base-devel ccache",
scoop => "scoop install xmake", # Windows
winget => "winget install xmake", # Windows
brew => 'brew install xmake', # MacOS
dnf =>
"$sudo dnf copr enable waruqi/xmake && $sudo dnf install xmake" # Fedora, RHEL, OpenSUSE, CentOS
scoop => "scoop install xmake", # Windows
winget => "winget install xmake", # Windows
brew => 'brew install xmake', # MacOS
dnf => "$sudo dnf copr enable waruqi/xmake && $sudo dnf install xmake" # Fedora, RHEL, OpenSUSE, CentOS
);
return $options{$installer} // ();
}
Expand Down

0 comments on commit f058987

Please sign in to comment.