Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add source version token #34

Merged
merged 5 commits into from

2 participants

@MidLifeXis

A use case exists where an archive is of the form:

    foo-x.y.z.zip

and contains a file (among others) of

   foo-x.y.z.wmi

The use case is to be able to use a string of

   %n-%v.wmi

as a parameter in a command line.

@MidLifeXis

There is still an issue of being able to access the version information from within the first execution of

    build alien_code

(or build, etc).

It appears to me that there are 4 sections in the ACTION_alien_code routine:

  1. get possible files and download best candidate
  2. extract files
  3. build library (optional)
  4. store version information

It seems to me that there are two types of potential version information - one from the downloaded candidate and the other from the build information. It seems like the version needs to be set prior to running the build commands for this use case to be effective.

I am not familiar (yet) with the effect of moving the version-setting code around impacts. Is there anything that you know of that immediately will break something? Does the pkgconfig configuration depend on having already built the package (if needed)?

Perhaps it would make sense to break that into a couple of steps (download + extract + set downloaded version state) and (build + set package state),

I guess the real question is, do you know if the test cases handle all of the needed use cases?

@MidLifeXis

I added the final commit after running the tests. It passes all included tests.

@jberger jberger merged commit 436f161 into from
@MidLifeXis MidLifeXis deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
12 lib/Alien/Base/ModuleBuild.pm
@@ -232,6 +232,7 @@ sub ACTION_alien_code {
my $file = $cabinet->files->[0];
$version = $file->version;
+ $self->config_data( version => $version ); # Temporary setting, may be overridden later
print "Downloading File: " . $file->filename . " ... ";
my $filename = $file->get;
@@ -529,6 +530,17 @@ sub alien_interpolate {
my $perl = $self->perl;
$string =~ s/(?<!\%)\%x/$perl/g;
+ # Version, but only if needed. Complain if needed and not yet
+ # stored.
+ if ($string =~ /(?<!\%)\%v/) {
+ my $version = $self->config_data( 'version' );
+ if ( ! defined( $version ) ) {
+ carp "Version substution requested but unable to identify";
+ } else {
+ $string =~ s/(?<!\%)\%v/$version/g;
+ }
+ }
+
#remove escapes (%%)
$string =~ s/\%(?=\%)//g;
View
4 lib/Alien/Base/ModuleBuild/API.pod
@@ -206,6 +206,10 @@ Shortcut for the name stored in C<alien_name>
pkg-config --modversion %n
+=item %v
+
+Captured version of the original archive.
+
=item %x
The current Perl interpreter (aka $^X)
View
19 t/interpolate.t
@@ -20,5 +20,24 @@ is( $builder->alien_interpolate('thing other=%%s'), 'thing other=%s', 'no share_
my $perl = $builder->perl;
is( $builder->alien_interpolate('%x'), $perl, '%x is current interpreter' );
+# Prior to loading the version information
+{
+ my @warn = ();
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+
+ is ( $builder->alien_interpolate('version=%v'), 'version=%v', 'version prior to setting it' );
+ isnt( join( "\n", @warn ), '', 'version warning prior to setting it' );
+}
+
+# After loading the version information
+{
+ my @warn = ();
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+
+ $builder->config_data( 'version', '1.2.3' );
+ is( $builder->alien_interpolate('version=%v'), "version=1.2.3", 'version after setting it' );
+ is( join( "\n", @warn ), '', 'version warning after setting it' );
+}
+
done_testing;
Something went wrong with that request. Please try again.