Alien-Meson

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

    $binary_release_name_re = qr/meson-.*\.pkg/;
    $binary_release_format = '.pkg';
    return;
  }

  die "No binary packages available for this configuration";
}

sub do_binary {
  plugin 'Download::GitHub' => (
    %github_info,
    asset        => 1,
    asset_name   => $binary_release_name_re,
    asset_format => 'none',
    version      => qr/([0-9\.]+)/,
  );

  if( $binary_release_format eq '.msi' ) {
    extract sub {
      my ($build) = @_;

      my $msi = Path::Tiny::path($build->install_prop->{download})->canonpath;
      my $cwd = Path::Tiny->cwd->canonpath;

      Alien::Build::CommandSequence->new([
        qw(msiexec /a),
        $msi,
        "TARGETDIR=$cwd",
        '/qn'
      ])->execute($build);
    };

    patch sub {
      my $cwd = Path::Tiny->cwd;
      $_->remove for $cwd->children( qr/\.msi$/ );

      my $PFiles = $cwd->child('PFiles64');
      if( -d $PFiles ) {
        File::Copy::Recursive::rmove( "$PFiles/*", $cwd );
        $PFiles->remove_tree;
      }

      my $Meson = $cwd->child('Meson');
      $Meson->child('ninja.exe')->remove;
      File::Copy::Recursive::rmove( "$Meson/*", $cwd );
      $Meson->remove_tree;
    };

    plugin 'Build::Copy';

    after build => sub {
      my($build) = @_;
      $build->runtime_prop->{'style'} = 'binary';
      $build->runtime_prop->{command} = 'meson';
    };
  } elsif( $binary_release_format eq '.pkg' ) {
    extract sub {
      my ($build) = @_;

      Alien::Build::CommandSequence->new([
        qw(pkgutil --expand-full),
        $build->install_prop->{download},
        'meson'
      ])->execute($build);
    };

    patch sub {
      my $cwd = Path::Tiny->cwd;
      my $meson_top = $cwd->child('meson.pkg/Payload/usr/local');
      # remove some small extra files?
      #$_->remove_tree for $cwd->children( qr/^(Distribution|Resources)$/ );
      $meson_top->child('bin', 'ninja')->remove;
      File::Copy::Recursive::rmove( "$meson_top/*", $cwd );
      $meson_top->remove_tree;
    };

    plugin 'Build::Copy';

    after build => sub {
      my($build) = @_;
      $build->runtime_prop->{'style'} = 'binary';
      $build->runtime_prop->{command} = 'meson';
    };
  }
}

share {
  requires 'Path::Tiny';
  requires 'File::Which';
  requires 'Capture::Tiny';
  requires 'Alien::Build::CommandSequence';
  requires 'File::Copy::Recursive';

  $ENV{ALIEN_MESON_SHARE_PREFER} ||= 'auto';

  my $release_types = {
    source => {
      'can' => \&can_source,
      'do'  => \&do_source,
    },
    binary => {
      'can' => \&can_binary,
      'do'  => \&do_binary,
    },
  };

  if( $ENV{ALIEN_MESON_SHARE_PREFER} eq 'auto' ) {
    my $which_type;
    my @types = qw(source binary);
    for my $type (@types) {
      eval { $release_types->{$type}{can}->() };
      my $catch = $@;
      if( $catch ) {
        warn "Unable to install release type $type: $catch";
        next;
      }

      $which_type = $type;
      $release_types->{$type}{do}->();
      last;
    }



( run in 1.644 second using v1.01-cache-2.11-cpan-5b529ec07f3 )