Alien-Base-ModuleBuild
view release on metacpan or search on metacpan
lib/Alien/Base/ModuleBuild.pm view on Meta::CPAN
my $cabinet = Alien::Base::ModuleBuild::Cabinet->new;
foreach my $repo (@repos) {
$cabinet->add_files( $repo->probe );
}
$cabinet->sort_files;
{
local $CWD = $self->alien_temp_dir;
my $file = $cabinet->files->[0];
unless (defined $file) {
die "no files found in repository";
}
$version = $file->version;
$self->config_data( alien_version => $version ); # Temporary setting, may be overridden later
print "Downloading File: " . $file->filename . " ... ";
my $filename = $file->get;
croak "Error downloading file" unless $filename;
print "Done\n";
my $extract_path = _catdir(File::Spec->rel2abs($self->alien_extract_archive($filename)));
$self->config_data( working_directory => $extract_path );
$CWD = $extract_path;
if ( $file->platform eq 'src' ) {
print "Building library ... ";
unless ($self->alien_do_commands('build')) {
print "Failed\n";
croak "Build not completed";
}
}
print "Done\n";
}
$self->config_data( install_type => 'share' );
$self->config_data( original_prefix => $self->alien_library_destination );
my $pc = $self->alien_load_pkgconfig;
my $pc_version = (
$pc->{$self->alien_name} || $pc->{_manual}
)->keyword('Version');
unless (defined $version) {
local $CWD = $self->config_data( 'working_directory' );
$version = $self->alien_check_built_version
}
if (! $version && ! $pc_version) {
print STDERR "If you are the author of this Alien dist, you may need to provide a an\n";
print STDERR "alien_check_built_version method for your Alien::Base::ModuleBuild\n";
print STDERR "class. See:\n";
print STDERR "https://metacpan.org/pod/Alien::Base::ModuleBuild#alien_check_built_version\n";
carp "Library looks like it installed, but no version was determined";
$self->config_data( version => 0 );
return
}
if ( $version and $pc_version and versioncmp($version, $pc_version)) {
carp "Version information extracted from the file name and pkgconfig data disagree";
}
$self->config_data( version => $pc_version || $version );
# prevent building multiple times (on M::B::dispatch)
$self->notes( 'ACTION_alien_completed' => 1 );
return;
}
sub ACTION_alien_test {
my $self = shift;
print "Testing library (if applicable) ... ";
if ($self->config_data( 'install_type' ) eq 'share') {
if (defined (my $wdir = $self->config_data( 'working_directory' ))) {
local $CWD = $wdir;
$self->alien_do_commands('test') or die "Failed\n";
}
}
print "Done\n";
}
sub ACTION_test {
my $self = shift;
$self->depends_on('alien_test');
$self->SUPER::ACTION_test;
}
sub ACTION_install {
my $self = shift;
$self->SUPER::ACTION_install;
if($self->alien_stage_install) {
$self->alien_relocation_fixup;
} else {
$self->depends_on('alien_install');
}
}
sub ACTION_alien_install {
my $self = shift;
local $| = 1; # don't buffer stdout
return if $self->config_data( 'install_type' ) eq 'system';
my $destdir = $self->destdir;
my $target = $self->alien_library_destination;
if(defined $destdir && !$self->alien_stage_install)
{
# Note: no longer necessary when doing a staged install
# prefix the target directory with $destdir so that package builds
# can install into a fake root
$target = File::Spec->catdir($destdir, $target);
lib/Alien/Base/ModuleBuild.pm view on Meta::CPAN
(we will continue to fix bugs where appropriate), we aren't adding any
new features to this module.
This is a subclass of L<Module::Build>, that with L<Alien::Base> allows
for easy creation of Alien distributions. This module is used during the
build step of your distribution. When properly configured it will
=over 4
=item use pkg-config to find and use the system version of the library
=item download, build and install the library if the system does not provide it
=back
=head1 METHODS
=head2 alien_check_installed_version
[version 0.001]
my $version = $abmb->alien_check_installed_version;
This function determines if the library is already installed as part of
the operating system, and returns the version as a string. If it can't
be detected then it should return empty list.
The default implementation relies on C<pkg-config>, but you will probably
want to override this with your own implementation if the package you are
building does not use C<pkg-config>.
=head2 alien_check_built_version
[version 0.006]
my $version = $amb->alien_check_built_version;
This function determines the version of the library after it has been
built from source. This function only gets called if the operating
system version can not be found and the package is successfully built.
The version is returned on success. If the version can't be detected
then it should return empty list. Note that failing to detect a version
is considered a failure and the corresponding C<./Build> action will
fail!
Any string is valid as a version as far as L<Alien::Base> is concerned.
The most useful value would be a number or dotted decimal that most
software developers recognize and that software tools can differentiate.
In some cases packages will not have a clear version number, in which
case the string C<unknown> would be a reasonable choice.
The default implementation relies on C<pkg-config>, and other heuristics,
but you will probably want to override this with your own implementation
if the package you are building does not use C<pkg-config>.
When this method is called, the current working directory will be the
build root.
If you see an error message like this:
Library looks like it installed, but no version was determined
After the package is built from source code then you probably need to
provide an implementation for this method.
=head2 alien_extract_archive
[version 0.024]
my $dir = $amb->alien_extract_archive($filename);
This function unpacks the given archive and returns the directory
containing the unpacked files.
The default implementation relies on L<Archive::Extract> that is able
to handle most common formats. In order to handle other formats or
archives requiring some special treatment you may want to override
this method.
=head2 alien_do_system
[version 0.024]
my %result = $amb->alien_do_system($cmd)
Similar to
L<Module::Build's do_system|Module::Build::API/"do_system($cmd, @args)">,
also sets the path and several environment variables in accordance
to the object configuration (i.e. C<alien_bin_requires>) and
performs the interpolation of the patterns described in
L<Alien::Base::ModuleBuild::API/"COMMAND INTERPOLATION">.
Returns a set of key value pairs including C<stdout>, C<stderr>,
C<success> and C<command>.
=head2 alien_do_commands
$amb->alien_do_commands($phase);
Executes the commands for the given phase.
=head2 alien_interpolate
my $string = $amb->alien_interpolate($string);
Takes the input string and interpolates the results.
=head2 alien_install_network
[version 1.16]
my $bool = $amb->alien_install_network;
Returns true if downloading source from the internet is allowed. This
is true unless C<ALIEN_INSTALL_NETWORK> is defined and false.
=head2 alien_download_rule
[version 1.16]
my $rule = $amb->alien_download_rule;
( run in 0.561 second using v1.01-cache-2.11-cpan-fa01517f264 )