-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdowngrade.jl
79 lines (76 loc) · 2.54 KB
/
downgrade.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
function downgrade(file, ignore_pkgs, strict)
lines = readlines(file)
compat = false
for (i, line) in pairs(lines)
if startswith(line, "[compat]")
compat = true
elseif startswith(line, "[")
compat = false
elseif startswith(strip(line), "#") || isempty(strip(line))
continue
elseif compat
# parse the compat line
m = match(r"^([A-Za-z0-9_]+)( *= *\")([^\"]*)(\".*)", line)
if m === nothing
error("cannot parse compat line: $line")
end
pkg, eq, ver, post = m.captures
# skip julia and any ignored packages
if pkg == "julia" || pkg in ignore_pkgs
println("skipping $pkg: $ver")
continue
end
# just take the first part a list compat
ver2 = strip(split(ver, ",")[1])
if occursin(" - ", ver2)
error("range specifiers not supported")
end
# separate the operator from the version
if ver2[1] in "^~="
op = ver2[1]
ver2 = ver2[2:end]
elseif isnumeric(ver2[1])
op = '^'
else
println("skipping $pkg: $ver")
continue
end
# parse the version
ver2 = VersionNumber(ver2)
# select a new operator
if strict == "true"
op = '='
elseif strict == "v0" && ver2.major == 0
op = '='
elseif op == '^'
op = '~'
end
# output the new compat entry
ver2 = "$op$ver2"
if ver == ver2
println("skipping $pkg: $ver")
continue
end
lines[i] = "$pkg$eq$ver2$post"
println("downgrading $pkg: $ver -> $ver2")
end
end
open(file, "w") do io
for line in lines
println(io, line)
end
end
end
ignore_pkgs = filter(!isempty, map(strip, split(ARGS[1], ",")))
strict = ARGS[2]
dirs = filter(!isempty, map(strip, split(ARGS[3], ",")))
strict in ["true", "false", "v0"] || error("strict must be true, false or v0")
for dir in dirs
files = [joinpath(dir, "Project.toml"), joinpath(dir, "JuliaProject.toml")]
filter!(isfile, files)
isempty(files) && error("could not find Project.toml or JuliaProject.toml in $dir")
for file in files
@info "downgrading $file"
downgrade(file, ignore_pkgs, strict)
end
end