forked from marbl/canu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canu_version_update.pl
executable file
·76 lines (59 loc) · 1.89 KB
/
canu_version_update.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env perl
use strict;
use File::Compare;
# If not a git repo, do nothing.
exit(0) if (! -d "../.git");
my $firstRev = undef;
my $revCount = 0;
open(F, "git rev-list HEAD |") or die "Failed to run 'git rev-list'.\n";
while (<F>) {
chomp;
$firstRev = $_ if (!defined($firstRev));
$revCount++;
}
close(F);
my $major = "M";
my $minor = "n";
my $commits = "d";
my $hash = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
my $dirty = "";
open(F, "git describe --tags --long --dirty --always --abbrev=40 |") or die "Failed to run 'git describe'.\n";
while (<F>) {
chomp;
if (m/^v(\d+)\.(\d+.*)-(\d+)-g(.{40})-*(.*)$/) {
$major = $1;
$minor = $2;
$commits = $3;
$hash = $4;
$dirty = $5;
} else {
die "Failed to parse describe string '$_'.\n";
}
}
close(F);
if ($dirty eq "dirty") {
$dirty = "ahead of github";
} else {
$dirty = "sync'd with guthub";
}
# Report what we found. This is really for the gmake output.
print STDERR "Building v$major.$minor (+$commits commits) r$revCount $hash ($dirty)\n";
print STDERR "\n";
# Dump a new file, but don't overwrite the original.
open(F, "> canu_version.H.new") or die "Failed to open 'canu-version.H.new' for writing: $!\n";
print F "// Automagically generated by canu_version_update.pl! Do not commit!\n";
print F "#define CANU_VERSION_MAJOR \"$major\"\n";
print F "#define CANU_VERSION_MINOR \"$minor\"\n";
print F "#define CANU_VERSION_COMMITS \"$commits\"\n";
print F "#define CANU_VERSION_REVISION \"$revCount\"\n";
print F "#define CANU_VERSION_HASH \"$firstRev\"\n";
close(F);
# If they're the same, don't replace the original.
if (compare("canu_version.H", "canu_version.H.new") == 0) {
unlink "canu_version.H.new";
} else {
unlink "canu_version.H";
rename "canu_version.H.new", "canu_version.H";
}
# That's all, folks!
exit(0);