blob: 77271269aa345e33e6d1867e20464ccf123d8ba3 (
plain) (
blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#!/usr/bin/perl
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
use POSIX qw(strftime);
$srcdir = ".";
my $generatejava = 0;
my $printdefines = 0;
my $printmap = 0;
my $simple = 0;
my $target = "";
my $pkgname = "";
my $tagtype = "";
while ($opt = shift) {
if ($opt =~ m/^-/) {
if ($opt eq "-M") {
$printmap = 1;
} elsif ($opt eq "-T") {
$tagtype = shift;
} else {
print STDERR "ERROR: unknown option '$opt' for getversion\n";
print "error\n";
exit 1;
}
} else {
$srcdir = $opt;
}
}
if (!defined($srcdir)) {
die "srcdir must be set";
}
# Read current major-minor release
sub read_head_version() {
my $file = "$srcdir/VERSION";
if (! -f $file) {
die "Unable to locate version file";
}
open(my $fd, "< $file") ||
die "Unable to open VERSION: $!";
my $version = <$fd>;
chomp($version);
close($fd);
return $version;
}
if ( ! -d $srcdir ) {
print STDERR "ERROR: bad directory '$srcdir' for getversion\n";
print "error\n";
exit 1;
}
# assume HEAD if all else fails
my $mainver = read_head_version();
# date adding logic
# goal is to end with '$dateadd' set to a value
# starting with dot, date, new dot, wall-clock time
# vbuild/mbuild also has some logic for this:
$dateadd = $ENV{"VBUILD_VERSION_DATE"};
$buildtime = $ENV{"CVSBUILDTIME"};
if ($buildtime && $buildtime =~ m/^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$/ ) {
$dateadd = ".$1$2$3.$4$5$6";
} elsif ($dateadd) {
1;
} else {
$dateadd = (strftime ".%Y%m%d.%H%M%S", gmtime);
}
$tag = "HEAD";
if (defined $ENV{FACTORY_VESPA_VERSION}) {
$version = $ENV{FACTORY_VESPA_VERSION};
} elsif ($tagtype eq 'tag') {
# only for exact tag, do not add date:
$version = $mainver;
} else {
$version = $mainver . $dateadd;
}
if ($printdefines || $generatejava || $printmap) {
# other useful information
chomp($ostype = `uname -s`);
chomp($osver = `uname -r`);
chomp($osarch = `uname -m`);
$vtag_system_rev = $ostype . "-" . $osver;
chomp ($who = `(whoami || logname) 2>/dev/null`);
chomp ($where = `uname -n`);
$where =~ s/\.yahoo\.com$//;
$vtag_date = $dateadd;
$vtag_date =~ s/^\.//;
$mv = $version;
foreach $m ( "major", "minor", "micro" ) {
$mv =~ s/^\D+//;
$cversion{$m} = "0";
if ( $mv =~ s/^(\d+)// ) {
$cversion .= "." . $1;
$cversion{$m} = $1;
}
}
$cversion =~ s/^\.//;
}
if ($printmap) {
print "V_TAG ${tag}\n";
print "V_TAG_DATE ${vtag_date}\n";
print "V_TAG_PKG ${version}\n";
print "V_TAG_ARCH ${osarch}\n";
print "V_TAG_SYSTEM ${ostype}\n";
print "V_TAG_SYSTEM_REV ${vtag_system_rev}\n";
print "V_TAG_BUILDER ${who}\@${where}\n";
print "V_TAG_COMPONENT ${cversion}\n";
exit;
}
print "$version\n";
exit;
|