-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_languages_version.pl
executable file
·145 lines (125 loc) · 4.13 KB
/
get_languages_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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/perl
use strict;
use warnings;
use v5.14;
my $version_re = qr/\d+\.\d+\.\d+/;
my %version_subs = (
'Bash' => \&get_bash_version,
'GCC' => \&get_gcc_version,
'Go' => \&get_go_version,
'Java' => \&get_java_version,
'Node.js' => \&get_node_version,
'Perl' => \&get_perl_version,
'PHP' => \&get_php_version,
'PyPy' => \&get_pypy_version,
'Python' => \&get_python_version,
'OCaml' => \&get_ocaml_version,
'R' => \&get_R_version,
'Racket' => \&get_racket_version,
'Ruby' => \&get_ruby_version,
'Rust' => \&get_rust_version,
'SBCL' => \&get_sbcl_version,
'Scala' => \&get_scala_version
);
for my $lang (sort keys %version_subs) {
# Note that there is no error checking: if the sub fails to find
# the version number, then "say" will emit a warning saying that
# the version is unitialized; this should be enough for whoever
# runs this script to investiguate.
# If on the other hand, the subs finds a wrong version
# number... well, tough luck :p
say " - $lang ", $version_subs{$lang}->();
}
sub get_bash_version {
my $version_string = `bash --version`;
my ($version) = $version_string =~ /version ($version_re)/;
return $version;
}
sub get_gcc_version {
my $version_string = `gcc --version`;
my ($version) = $version_string =~ /^gcc.*($version_re)/;
return $version;
}
sub get_go_version {
my $version_string = `go version`;
my ($version) = $version_string =~ /^go version go($version_re)/;
return $version;
}
sub get_java_version {
# Note: this doesn't seem to be standard at all: we might need to
# run instead `java -version`, and the output can vary even when
# running `java --version`.
my $version_string = `java --version`;
my ($version) = $version_string =~ /^java ($version_re)/;
return $version;
}
sub get_node_version {
my $version_string = `node -v`;
my ($version) = $version_string =~ /^v($version_re)/;
return $version;
}
sub get_ocaml_version {
my $version_string = `ocamlopt --version`;
my $version_string2 = `ocamlc --version`;
if ($version_string ne $version_string2) {
die "Different version for ocamltop and ocamlc: " .
"$version_string vs $version_string2. ".
"Exiting.";
}
my ($version) = $version_string =~ /($version_re)/;
return $version;
}
sub get_perl_version {
# Note: could use directly $^V, but to be more consistent with
# other languages, doing a "system" call.
# (meaning, if at any point this script needs to be ported to any
# other language, nobody will wonder "hmm, how to do it in Perl?")
my $version_string = `perl -e 'print \$^V'`;
my ($version) = $version_string =~ /v($version_re)/;
return $version;
}
sub get_php_version {
my $version_string = `php -v`;
my ($version) = $version_string =~ /^PHP ($version_re)/;
return $version;
}
sub get_pypy_version {
my $version_string = `pypy --version 2>&1`;
my ($version) = $version_string =~ /PyPy ($version_re)/;
return $version;
}
sub get_python_version {
my $version_string = `python3 --version`;
my ($version) = $version_string =~ /Python ($version_re)/;
return $version;
}
sub get_R_version {
my $version_string = `Rscript --version 2>&1`;
my ($version) = $version_string =~ /version ($version_re)/;
return $version;
}
sub get_racket_version {
my $version_string = `racket -v`;
my ($version) = $version_string =~ /Racket v(\d+\.\d+)/;
return $version;
}
sub get_ruby_version {
my $version_string = `ruby -v`;
my ($version) = $version_string =~ /ruby ($version_re)/;
return $version;
}
sub get_rust_version {
my $version_string = `rustc --version`;
my ($version) = $version_string =~ /rustc ($version_re)/;
return $version;
}
sub get_sbcl_version {
my $version_string = `sbcl --version`;
my ($version) = $version_string =~ /SBCL ($version_re)/;
return $version;
}
sub get_scala_version {
my $version_string = `scala -version 2>&1`;
my ($version) = $version_string =~ /version ($version_re)/;
return $version
}