Alien-Xmake
view release on metacpan or search on metacpan
builder/Alien/Xmake/Builder.pm view on Meta::CPAN
# Stage the bundled xmake into the standard sharedir location so the regular install step ships it and tests
# find it via @INC. This is the Module::Build::Tiny 'dist_shared' model: build copies share/ into
# blib/lib/auto/share/dist/<Name>/ and install just moves blib/lib. A 'system' resolution points at the user's
# own xmake, so there is no bundle to ship: staging it anyway would install a second, unused xmake (and leave
# the runtime free to find the wrong one).
$self->_stage_sharedir if $config_data->{install_type} ne 'system';
# Generate ConfigData.pm
$self->_write_config_data($config_data);
say 'Build complete' if $verbose;
true;
}
method _stage_sharedir () {
my $src = path('share');
return unless $src->is_dir;
my $auto = path('blib/lib/auto/share/dist')->child( $meta->name );
my $iter = $src->iterator( { recurse => 1 } );
while ( my $s = $iter->() ) {
next unless $s->is_file;
my $target = $auto->child( $s->relative($src) );
$target->parent->mkpath;
$s->copy($target) or die "Copy failed: $!";
$target->chmod( $s->stat->mode | 0600 );
}
say 'Staged bundled xmake to ' . $auto if $verbose;
}
method ACTION_install ( ) {
say 'Installing...' if $verbose;
my %install_results;
ExtUtils::Install::install(
[ from_to => { 'blib/lib' => $Config{installprivlib}, 'blib/arch' => $Config{installarchlib} },
verbose => $verbose,
dry_run => 0,
uninstall_shadows => 1,
skip => undef,
always_copy => 1,
result => \%install_results
]
);
# XXX: Should I bother with the $install_results{install_fail}?
true;
}
method ACTION_clean () {
say 'Cleaning...' if $verbose;
path('blib')->remove_tree;
path('_build_xmake')->remove_tree;
path('config.log')->remove;
path('Build')->remove;
path('_build_params')->remove;
true;
}
method ACTION_test ( ) {
die "Run `./Build build` first.\n" unless -d 'blib';
say 'Running tests...' if $verbose;
require Test::Harness;
my @tests = glob('t/*.t');
return Test::Harness::runtests(@tests) if @tests;
true;
}
method _copy_libs ( ) {
my $src_root = path('lib');
return unless $src_root->exists;
my $iter = $src_root->iterator( { recurse => 1 } );
while ( my $file = $iter->() ) {
next unless $file->is_file;
# Skip hidden files/dirs
my $rel = $file->relative($src_root);
next if $rel =~ m{(^|/)\.};
my $dest = path('blib/lib')->child($rel);
$dest->parent->mkpath;
$file->copy($dest) or die "Copy failed: $!";
}
}
method _copy_directory ( $src, $dest ) {
my $src_path = path($src)->absolute;
my $dest_path = path($dest)->absolute;
return unless $src_path->is_dir;
$dest_path->mkpath;
my $iter = $src_path->iterator( { recurse => 1 } );
while ( my $p = $iter->() ) {
next if $p eq $src_path; # Skip root
# Skip if we are inside the destination directory
# (prevents infinite loop if dest is inside src)
if ( $p eq $dest_path || $dest_path->subsumes($p) ) {
next;
}
my $rel = $p->relative($src_path);
my $target = $dest_path->child($rel);
$p = $p->realpath if -l $p;
if ( $p->is_dir ) {
$target->mkpath;
}
else {
$p->copy($target) or die "Failed to copy $p to $target: $!";
$target->chmod( $p->stat->mode | 0600 );
}
}
}
method _run_cmd (@args) { system(@args) == 0 }
method _cmd_exists (@cmd) {
my ( undef, undef, $exit ) = capture { system @cmd };
return $exit == 0;
}
# Query the GitHub releases API for the target release (latest unless a
# --target_version was pinned).
method _github_release () {
return $gh_release if defined $gh_release;
my $tag = $self->target_version;
my $url = $tag ? "https://api.github.com/repos/$owner/$repo/releases/tags/$tag" : "https://api.github.com/repos/$owner/$repo/releases/latest";
say 'Resolving Xmake release info from the GitHub API...' if $verbose;
( run in 1.650 second using v1.01-cache-2.11-cpan-1236ad508bc )