Alien-Xmake
view release on metacpan or search on metacpan
builder/Alien/Xmake/Builder.pm view on Meta::CPAN
#!%s %s
use lib 'builder';
use %s;
%s->new( @ARGV && $ARGV[0] =~ /\A\w+\z/ ? ( action => shift @ARGV ) : (),
map { /^--/ ? ( shift(@ARGV) =~ s[^--][]r => 1 ) : /^-/ ? ( shift(@ARGV) =~ s[^-][]r => shift @ARGV ) : () } @ARGV )->Build();
make_executable('Build');
my @env = defined $ENV{PERL_MB_OPT} ? split_like_shell( $ENV{PERL_MB_OPT} ) : ();
$self->write_file( '_build_params', encode_json( [ \@env, \@ARGV ] ) );
if ( my $dynamic = $meta->custom('x_dynamic_prereqs') ) {
my %meta_struct = ( %{ $meta->as_struct }, dynamic_config => 1 );
require CPAN::Requirements::Dynamic;
my $dynamic_parser = CPAN::Requirements::Dynamic->new();
my $prereq = $dynamic_parser->evaluate($dynamic);
$meta_struct{prereqs} = $meta->effective_prereqs->with_merged_prereqs($prereq)->as_string_hash;
$meta = CPAN::Meta->new( \%meta_struct );
}
$meta->save(@$_) for ['MYMETA.json'];
}
# Actions
method ACTION_build ( ) {
say 'Building Alien-Xmake...';
# Prepare blib
path('blib/lib')->mkpath;
path('blib/arch')->mkpath;
path('blib/script')->mkpath;
path('blib/bin')->mkpath;
# Copy Libs
$self->_copy_libs();
# Alien Logic: Check or Install Xmake
my $config_data = $self->_resolve_xmake();
# Generate ConfigData.pm
$self->_write_config_data($config_data);
say 'Build complete';
}
method ACTION_install ( ) {
say 'Installing...';
require ExtUtils::Install;
ExtUtils::Install::install( { 'blib/lib' => $Config{installprivlib}, 'blib/arch' => $Config{installarchlib} }, 1, 0, 0 );
}
method ACTION_clean () {
say 'Cleaning...';
path('blib')->remove_tree;
path('_build_xmake')->remove_tree;
path('config.log')->remove;
path('Build')->remove;
path('_build_params')->remove;
}
method ACTION_test ( ) {
$self->ACTION_build();
say 'Running tests...';
use Test::Harness;
my @tests = glob('t/*.t');
runtests(@tests) if @tests;
}
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);
if ( $p->is_dir ) {
$target->mkpath;
}
else {
$p->copy($target) or die "Failed to copy $p to $target: $!";
$target->chmod( $p->stat->mode );
}
}
}
method _run_cmd (@args) {
system(@args) == 0;
}
method _resolve_xmake ( ) {
# Check for system install
unless ($force) {
my $sys_path = $self->_find_system_xmake();
if ($sys_path) {
my $ver = $self->_get_xmake_version($sys_path);
if ( $self->_version_cmp( $ver, $target_version ) >= 0 ) {
say "Found suitable system Xmake: $sys_path ($ver)";
return { install_type => 'system', version => $ver, bin => "$sys_path" };
}
( run in 1.431 second using v1.01-cache-2.11-cpan-e1769b4cff6 )