This repository was archived by the owner on Dec 16, 2022. It is now read-only.
forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversion.jl
271 lines (245 loc) · 10 KB
/
version.jl
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
## semantic version numbers (http://semver.org)
immutable VersionNumber
major::Int
minor::Int
patch::Int
prerelease::(Union(Int,ASCIIString)...)
build::(Union(Int,ASCIIString)...)
function VersionNumber(major::Integer, minor::Integer, patch::Integer, pre::(Union(Int,ASCIIString)...), bld::(Union(Int,ASCIIString)...))
major >= 0 || error("invalid negative major version: $major")
minor >= 0 || error("invalid negative minor version: $minor")
patch >= 0 || error("invalid negative patch version: $patch")
for ident in pre
if isa(ident,Int)
ident >= 0 || error("invalid negative pre-release identifier: $ident")
else
if !ismatch(r"^(?:|[0-9a-z-]*[a-z-][0-9a-z-]*)$"i, ident) ||
isempty(ident) && !(length(pre)==1 && isempty(bld))
error("invalid pre-release identifier: ", repr(ident))
end
end
end
for ident in bld
if isa(ident,Int)
ident >= 0 || error("invalid negative build identifier: $ident")
else
if !ismatch(r"^(?:|[0-9a-z-]*[a-z-][0-9a-z-]*)$"i, ident) ||
isempty(ident) && length(bld)!=1
error("invalid build identifier: ", repr(ident))
end
end
end
new(major, minor, patch, pre, bld)
end
end
VersionNumber(x::Integer, y::Integer, z::Integer) = VersionNumber(x, y, z, (), ())
VersionNumber(x::Integer, y::Integer) = VersionNumber(x, y, 0, (), ())
VersionNumber(x::Integer) = VersionNumber(x, 0, 0, (), ())
function print(io::IO, v::VersionNumber)
v == typemax(VersionNumber) && return print(io, "∞")
print(io, v.major)
print(io, '.')
print(io, v.minor)
print(io, '.')
print(io, v.patch)
if !isempty(v.prerelease)
print(io, '-')
print_joined(io, v.prerelease,'.')
end
if !isempty(v.build)
print(io, '+')
print_joined(io, v.build,'.')
end
end
show(io::IO, v::VersionNumber) = print(io, "v\"", v, "\"")
convert(::Type{VersionNumber}, v::Integer) = VersionNumber(v)
convert(::Type{VersionNumber}, v::Tuple) = VersionNumber(v...)
const VERSION_REGEX = r"^
v? # prefix (optional)
(\d+) # major (required)
(?:\.(\d+))? # minor (optional)
(?:\.(\d+))? # patch (optional)
(?:(-)|
(?:-((?:[0-9a-z-]+\.)*[0-9a-z-]+))? # pre-release (optional)
(?:(\+)|
(?:\+((?:[0-9a-z-]+\.)*[0-9a-z-]+))? # build (optional)
))
$"ix
function split_idents(s::String)
idents = split(s, '.')
ntuple(length(idents)) do i
ident = idents[i]
ismatch(r"^\d+$", ident) ? parseint(ident) : ident
end
end
function convert(::Type{VersionNumber}, v::String)
m = match(VERSION_REGEX, v)
if m == nothing error("invalid version string: $v") end
major, minor, patch, minus, prerl, plus, build = m.captures
major = int(major)
minor = minor != nothing ? int(minor) : 0
patch = patch != nothing ? int(patch) : 0
prerl = prerl != nothing ? split_idents(prerl) : minus == "-" ? ("",) : ()
build = build != nothing ? split_idents(build) : plus == "+" ? ("",) : ()
VersionNumber(major, minor, patch, prerl, build)
end
macro v_str(v); convert(VersionNumber, v); end
typemin(::Type{VersionNumber}) = v"0-"
typemax(::Type{VersionNumber}) = VersionNumber(typemax(Int),typemax(Int),typemax(Int),(),("",))
ident_cmp(a::Int, b::Int) = cmp(a,b)
ident_cmp(a::Int, b::ASCIIString) = isempty(b) ? +1 : -1
ident_cmp(a::ASCIIString, b::Int) = isempty(a) ? -1 : +1
ident_cmp(a::ASCIIString, b::ASCIIString) = cmp(a,b)
function ident_cmp(A::(Union(Int,ASCIIString)...),
B::(Union(Int,ASCIIString)...))
i = start(A)
j = start(B)
while !done(A,i) && !done(B,i)
a,i = next(A,i)
b,j = next(B,j)
c = ident_cmp(a,b)
(c != 0) && return c
end
done(A,i) && !done(B,j) ? -1 :
!done(A,i) && done(B,j) ? +1 : 0
end
function isequal(a::VersionNumber, b::VersionNumber)
(a.major != b.major) && return false
(a.minor != b.minor) && return false
(a.patch != b.patch) && return false
(ident_cmp(a.prerelease,b.prerelease) != 0) && return false
(ident_cmp(a.build,b.build) != 0) && return false
return true
end
issupbuild(v::VersionNumber) = length(v.build)==1 && isempty(v.build[1])
function isless(a::VersionNumber, b::VersionNumber)
(a.major < b.major) && return true
(a.major > b.major) && return false
(a.minor < b.minor) && return true
(a.minor > b.minor) && return false
(a.patch < b.patch) && return true
(a.patch > b.patch) && return false
(!isempty(a.prerelease) && isempty(b.prerelease)) && return true
(isempty(a.prerelease) && !isempty(b.prerelease)) && return false
c = ident_cmp(a.prerelease,b.prerelease)
(c < 0) && return true
(c > 0) && return false
(!issupbuild(a) && issupbuild(b)) && return true
(issupbuild(a) && !issupbuild(b)) && return false
c = ident_cmp(a.build,b.build)
(c < 0) && return true
return false
end
hash(v::VersionNumber) = hash([v.(n) for n in VersionNumber.names])
## julia version info
let
local version::VersionNumber
if isfile("$JULIA_HOME/../../VERSION")
version = readchomp("$JULIA_HOME/../../VERSION")
elseif isfile("$JULIA_HOME/../share/julia/VERSION")
version = readchomp("$JULIA_HOME/../share/julia/VERSION")
else
println("ERROR: VERSION file not found")
error()
end
expected = ErrorException("don't copy this code, for breaking out of uv_run during boot-strapping only")
acceptable = ErrorException(expected.msg) # we would like to update the error msg for this later, but at
# this point in the bootstrapping, conflicts between old and new
# defintions for write, TTY, ASCIIString, and STDOUT make it fail
outctim,ps = readsfrom(`git log -1 --pretty=format:%ct`)
ps.closecb = function(proc)
if !success(proc)
#acceptable.msg = string("failed process: ",proc," [",proc.exit_code,"]")
error(acceptable)
end
ctim = int(readall(proc.out.buffer))
outdesc,ps = readsfrom(`git describe --tags --dirty --long --abbrev=10`)
ps.closecb = function(proc)
if !success(proc)
#acceptable.msg = string("failed process: ",proc," [",proc.exit_code,"]")
error(acceptable)
end
description = readchomp(proc.out.buffer)
m = match(r"^(v\d+(?:\.\d+)+)-(\d+)-g([0-9a-f]{10})(-dirty)?$", description)
if m == nothing
error(acceptable)
end
tag = convert(VersionNumber, m.captures[1])
commits_after_tag = int(m.captures[2])
commit = m.captures[3]
dirty = m.captures[4] != nothing
if commits_after_tag > 0
field = tag < version ? version.prerelease : version.build
field = tuple(field..., commits_after_tag, "r$(commit[1:8])")
if dirty
field = tuple(field..., "dirty")
end
tag = VersionNumber(
version.major,
version.minor,
version.patch,
tag < version ? field : version.prerelease,
tag < version ? version.build : field,
)
end
isotime = strftime("%Y-%m-%d %H:%M:%S", ctim)
global const commit_string = "Commit $commit $isotime" * (dirty ? "*" : "")
global const VERSION = tag
global const VERSION_COMMIT = commit
error(expected)
end
end
try
run_event_loop() # equivalent to wait_exit() on a more sane version of the previous
# block of code, but Scheduler doesn't exist during bootstrapping
# so we do what we must, but don't do this in user-land code or you'll regret it
catch err
if err != expected
if isfile("$JULIA_HOME/../../COMMIT")
global const commit_string = readchomp("$JULIA_HOME/../../COMMIT")
elseif isfile("$JULIA_HOME/../share/julia/COMMIT")
global const commit_string = readchomp("$JULIA_HOME/../share/julia/COMMIT")
else
global const commit_string = ""
end
global const VERSION = version
global const VERSION_COMMIT = ""
if err == acceptable
println("Warning: git failed in version.jl")
#println(err) # not a useful error msg currently
else
rethrow(err)
end
end
end
end
begin
const version_string = "Version $VERSION"
const banner_plain =
"""
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" to list help topics
| | | | | | |/ _` | |
| | |_| | | | (_| | | $version_string
_/ |\\__'_|_|_|\\__'_| | $commit_string
|__/ |
"""
local tx = "\033[0m\033[1m" # text
local jl = "\033[0m\033[1m" # julia
local d1 = "\033[34m" # first dot
local d2 = "\033[31m" # second dot
local d3 = "\033[32m" # third dot
local d4 = "\033[35m" # fourth dot
const banner_color =
"\033[1m $(d3)_
$(d1)_ $(jl)_$(tx) $(d2)_$(d3)(_)$(d4)_$(tx) | A fresh approach to technical computing
$(d1)(_)$(jl) | $(d2)(_)$(tx) $(d4)(_)$(tx) | Documentation: http://docs.julialang.org
$(jl)_ _ _| |_ __ _$(tx) | Type \"help()\" to list help topics
$(jl)| | | | | | |/ _` |$(tx) |
$(jl)| | |_| | | | (_| |$(tx) | $version_string
$(jl)_/ |\\__'_|_|_|\\__'_|$(tx) | $commit_string
$(jl)|__/$(tx) |
\033[0m"
end # begin