Skip to content

Commit

Permalink
Add DESTDIR prefix hack
Browse files Browse the repository at this point in the history
See issue <PerlAlien/Alien-Build#407> for more information.
  • Loading branch information
zmughal committed Nov 9, 2023
1 parent aaae539 commit f58237e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Add DESTDIR prefix hack. See issue <https://github.com/PerlAlien/Alien-Build/issues/407>
for more information.

0.05 2023-10-29 15:08:30-04:00 America/New_York
- Deprecate interpolation of `%{meson}`.
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ for the use of other modules.

Returns the command name for running meson.

## \_apply\_destdir\_prefix\_hack

use alienfile;

eval {
require Alien::Meson;
Alien::Meson->_apply_destdir_prefix_hack;
};

share { ... }

Applies a hack to fix how the `DESTDIR` and prefix are joined to follow the
approach that Meson takes. See issue at [https://github.com/PerlAlien/Alien-Build/issues/407](https://github.com/PerlAlien/Alien-Build/issues/407)
for more information.

**WARNING**: This is a hack. It is not expected to work long-term and if a
better solution is possible, it will be deprecated then removed.

# HELPERS

## meson
Expand Down
36 changes: 36 additions & 0 deletions lib/Alien/Meson.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use base qw( Alien::Base );
use 5.008004;

use Path::Tiny;
use Alien::Build::Util qw( _destdir_prefix );

=head1 NAME
Expand Down Expand Up @@ -89,6 +90,41 @@ sub bin_dir {
}
}

=head2 _apply_destdir_prefix_hack
use alienfile;
eval {
require Alien::Meson;
Alien::Meson->_apply_destdir_prefix_hack;
};
share { ... }
Applies a hack to fix how the C<DESTDIR> and prefix are joined to follow the
approach that Meson takes. See issue at L<https://github.com/PerlAlien/Alien-Build/issues/407>
for more information.
B<WARNING>: This is a hack. It is not expected to work long-term and if a
better solution is possible, it will be deprecated then removed.
=cut

sub _apply_destdir_prefix_hack {
my ($class) = @_;
no warnings "redefine";
# Work around for Meson's `destdir_join` which drops the first part of
# the path when joining (this is the drive letter).
# See <https://github.com/mesonbuild/meson/blob/1.2.3/mesonbuild/scripts/__init__.py>.
*Alien::Build::Util::_destdir_prefix = \&_meson_destdir_prefix;
}

sub _meson_destdir_prefix {
my($destdir, $prefix) = @_;
$prefix =~ s{^/?([a-z]):}{}i if $^O eq 'MSWin32';
path($destdir)->child($prefix)->stringify;
}

=head1 HELPERS
=head2 meson
Expand Down

0 comments on commit f58237e

Please sign in to comment.