forked from scharch/SONAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.pm
executable file
·69 lines (48 loc) · 1.54 KB
/
version.pm
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
#!/usr/bin/env perl
package version;
use strict;
use vars '@ISA', '@EXPORT', '$NAME', '$VERSION', '$DATE', '$AUTHOR';
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(logCmdLine);
BEGIN {
$SIG{__DIE__} = sub {
my $message = shift;
print STDERR "$message";
open LOG, ">>$version::LOGFILE";
print LOG localtime() . " -- DIED WITH ERROR:\n$message\n";
close LOG;
exit("179");
}
}
sub logCmdLine() {
my $command = shift;
foreach(@_) { $command .= /(\s|\*)/ ? " \'$_\'" : " $_"; }
my $VERSION = `git --git-dir $FindBin::Bin/../.git --work-tree=$FindBin::Bin/../ describe --always --dirty --tags`;
chomp $VERSION;
our $LOGFILE = "SONAR_command_history.log";
if (-d "output/logs") {
$LOGFILE = "output/logs/command_history.log";
}
my $LOGMESSAGE = "\n" . localtime() . " -- SONAR $VERSION run with command:\n\t$command\n";
print STDERR $LOGMESSAGE;
my $check = open LOG, ">>$LOGFILE";
if ($check) {
print LOG $LOGMESSAGE;
close LOG;
our $PRINT_LOGS = 1;
} else {
warn("Directory appears to be read-only; command line and output will not be saved\n");
}
}
END {
if ( -defined $version::PRINT_LOGS ) {
if ($? != 179) { #error code 179 indicates a die command which was already logged by $SIG{__DIE__} above
open LOG, ">>$version::LOGFILE";
my $status = $? == 0 ? "finished successfully" : "exited unexpectedly with error code $?";
print LOG localtime() . " -- Program $status\n";
close LOG;
}
}
}
1;