Alien-Xmake
view release on metacpan or search on metacpan
builder/Alien/Xmake/Builder.pm view on Meta::CPAN
# Based on Module::Build::Tiny which is copyright (c) 2011 by Leon Timmermans, David Golden.
# Module::Build::Tiny is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
use v5.40;
use feature 'class';
no warnings 'experimental::class';
class Alien::Xmake::Builder {
use CPAN::Meta;
use ExtUtils::Install qw[pm_to_blib install];
use ExtUtils::InstallPaths;
use JSON::PP;
use Config;
use HTTP::Tiny;
use Path::Tiny qw[path cwd];
use ExtUtils::Helpers qw[make_executable split_like_shell detildefy];
use Data::Dumper;
# Configuration
field $target_version : param : reader //= 'v3.0.6';
field $force : param //= 0;
field $meta : reader //= CPAN::Meta->load_file('META.json');
field $action : param //= 'build';
field $target_config = 'lib/Alien/Xmake/ConfigData.pm';
# Params to Build script
field $install_base : param //= '';
field $installdirs : param //= '';
field $uninst : param //= 0;
field $install_paths : param //= ExtUtils::InstallPaths->new( dist_name => $meta->name );
field $verbose : param(v) //= 0;
field $dry_run : param //= 0;
field $pureperl : param //= 0;
field $jobs : param //= 1;
field $destdir : param //= '';
field $prefix : param //= '';
ADJUST {
-e 'META.json' or die "No META information provided\n";
}
method Build_PL() {
die "Pure perl Affix? Ha! You wish.\n" if $pureperl;
say sprintf 'Creating new Build script for %s %s', $meta->name, $meta->version;
# We must capture the current INC to ensure the builder finds itself
# when running the generated script.
my $inc_str = join( ' ', map {"-I$_"} @INC );
$self->write_file( 'Build', sprintf <<'', $^X, $inc_str, __PACKAGE__, __PACKAGE__ );
#!%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;
( run in 1.024 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )