Alien-Xmake-Project
view release on metacpan or search on metacpan
lib/Alien/Xmake/Project.pm view on Meta::CPAN
use Alien::Xmake;
#
field $file : param //= 'xmake.lua';
field $yes : param //= 0;
field $name;
field $vers = undef;
field $xmakever = undef;
field $root = [];
field $includes = [];
field $requires = [];
field $xpack_included = 0;
field $check_included = 0;
field $domains = []; # option/rule/toolchain/package/xpack, in order
field $xpackdoms = []; # xpack entries (packed last)
field $namespaces = [];
field $targets = [];
field $xmake;
# top level
method set_project ($n) { $name = $n; $self; }
method set_version ($v) { $vers = $v; $self; }
method set_xmakever ($v) { $xmakever = $v; $self; }
method set_config ( $n, $value ) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_config', $n, $value ); $self; }
method set_defaultplat (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_defaultplat', @a ); $self; }
method set_defaultarchs (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_defaultarchs', @a ); $self; }
method set_defaultmode (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_defaultmode', @a ); $self; }
method set_allowedplats (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_allowedplats', @a ); $self; }
method set_allowedarchs (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_allowedarchs', @a ); $self; }
method set_allowedmodes (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_allowedmodes', @a ); $self; }
method add_moduledirs (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'add_moduledirs', @a ); $self; }
method add_plugindirs (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'add_plugindirs', @a ); $self; }
method set_runtimes (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_runtimes', @a ); $self; }
method add_rules (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'add_rules', @a ); $self; }
method add_addons (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'add_addons', @a ); $self; }
# Global scope applies to every target (root scope). These mirror the Target methods but emit
# at the project root so all targets inherit them.
method add_defines (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'add_defines', @a ); $self; }
method set_toolchains (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_toolchains', @a ); $self; }
method set_toolset (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_toolset', @a ); $self; }
method set_plat (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_plat', @a ); $self; }
method set_arch (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_arch', @a ); $self; }
method set_languages (@a) { push @$root, Alien::Xmake::Project::Util::_stmt( 'set_languages', @a ); $self; }
method includes (@a) { push @$includes, Alien::Xmake::Project::Util::_stmt( 'includes', @a ); $self; }
method add_requires (@args) {
push @$requires, Alien::Xmake::Project::Util::_stmt( 'add_requires', @args );
$self;
}
method add_requireconfs (@args) {
push @$root, Alien::Xmake::Project::Util::_stmt( 'add_requireconfs', @args );
$self;
}
method add_repositories (@args) {
push @$root, Alien::Xmake::Project::Util::_stmt( 'add_repositories', @args );
$self;
}
# scope root/global statements behind a Lua condition (see ::Target::when).
method when ( $predicate, $body ) {
my $start = @$root;
if ( ref($body) eq 'ARRAY' ) { push @$root, @$body; }
elsif ( ref($body) eq 'CODE' ) { $body->($self); }
elsif ( defined $body ) { push @$root, $body; }
my @inner = @$root[ $start .. $#$root ];
@$root = @$root[ 0 .. $start - 1 ];
push @$root, "if $predicate then";
push @$root, map {" $_"} @inner;
push @$root, 'end';
$self;
}
# domain entries
method target ($tname) {
my $t = Alien::Xmake::Project::Target->new( _project => $self, _name => $tname );
push @$targets, $t;
return $t;
}
# `option($name)` chains setter statements into an `option(name) ... option_end()`
# block. Calling `option($name, {atts})` instead emits the inline table form:
# option("name", {["default"]=1, ["values"]={"a","b"}})
method option ( $n, @b ) {
if ( @b == 1 && ref( $b[0] ) eq 'HASH' ) {
my $obj = Alien::Xmake::Project::Option->new( _name => $n, _inline => $b[0], _body => [] );
push @$domains, $obj;
return $obj;
}
return $self->_newdomain( 'option', $n, @b );
}
method rule ( $n, @b ) { return $self->_newdomain( 'rule', $n, @b ); }
method toolchain ( $n, @b ) { return $self->_newdomain( 'toolchain', $n, @b ); }
method package ( $n, @b ) { return $self->_newdomain( 'package', $n, @b ); }
method xpack ( $n, @b ) {
unless ($xpack_included) {
push @$root, 'includes("@builtin/xpack")';
$xpack_included = 1;
}
return $self->_newdomain( 'xpack', $n, @b );
}
method _ensure_check {
unless ($check_included) {
unshift @$root, 'includes("@builtin/check")';
$check_included = 1;
}
return $self;
}
method namespace ( $nsname, @body ) {
my $ns = Alien::Xmake::Project::Namespace->new( _project => $self, _name => $nsname, _body => \@body );
push @$namespaces, $ns;
return $ns;
}
#
method save {
my $lua = $self->_render;
my $pfile = Path::Tiny::path($file);
( run in 0.915 second using v1.01-cache-2.11-cpan-1236ad508bc )