-
Notifications
You must be signed in to change notification settings - Fork 29
/
version.pl
executable file
·59 lines (53 loc) · 1.46 KB
/
version.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
# If you think this is stupid/overkill, blame dormando
use warnings;
use strict;
my $version = `git describe`;
my $changeset = `git rev-parse HEAD`;
if ($ENV{'PRODUCT_VERSION'}) {
$version = $ENV{'PRODUCT_VERSION'}
}
chomp $version;
chomp $changeset;
# Test the various versions.
#my $version = 'foob';
#my $version = '1.4.2-30-gf966dba';
#my $version = '1.4.3-rc1';
#my $version = '1.4.3';
unless ($version =~ m/^\d+\.\d+\.\d+/) {
write_file('m4/version.m4', "m4_define([VERSION_NUMBER], [UNKNOWN])\n");
exit;
}
$version =~ s/-/_/g;
my $version_str = "m4_define([VERSION_NUMBER], [$version])\n";
my $changeset_str = "m4_define([GIT_CHANGESET], [$changeset])\n";
write_file('m4/version.m4', ($version_str . $changeset_str));
my ($VERSION, $FULLVERSION, $RELEASE);
if ($version =~ m/^(\d+\.\d+\.\d+)_rc(\d+)$/) {
$VERSION = $1;
$FULLVERSION = $version;
$RELEASE = '0.1.rc' . $2;
} elsif ($version =~ m/^(\d+\.\d+\.\d+)_(.+)$/) {
$VERSION = $1;
$FULLVERSION = $version;
$RELEASE = '1.' . $2;
} elsif ($version =~ m/^(\d+\.\d+\.\d+)$/) {
$VERSION = $1;
$FULLVERSION = $version;
$RELEASE = '1';
}
sub write_file {
my $file = shift;
my $data = shift;
open(my $fh, "> $file") or die "Can't open $file: $!";
print $fh $data;
close($fh);
}
sub read_file {
my $file = shift;
local $/ = undef;
open(my $fh, "< $file") or die "Can't open $file: $!";
my $data = <$fh>;
close($fh);
return $data;
}