Skip to content

Commit b444f5a

Browse files
authored
Tool to bump JuliaSyntax version in Base (#485)
It turns out that this is basically a local version of BumpStdlibs.jl...
1 parent d8796c6 commit b444f5a

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

tools/bump_in_Base.jl

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function find_checksum_files(checksum_dir)
2+
filter(readdir(checksum_dir, join=true)) do path
3+
occursin(r"^JuliaSyntax-", basename(path))
4+
end
5+
end
6+
7+
function bump_in_Base(julia_dir, juliasyntax_dir, juliasyntax_branch_or_commit)
8+
julia_git_dir = joinpath(julia_dir, ".git")
9+
JuliaSyntax_git_dir = joinpath(juliasyntax_dir, ".git")
10+
if !isdir(julia_git_dir)
11+
@error "Julia .git directory not found" julia_git_dir
12+
return 1
13+
end
14+
if !isdir(JuliaSyntax_git_dir)
15+
@error "JuliaSyntax .git directory not found" JuliaSyntax_git_dir
16+
return 1
17+
end
18+
19+
@info "Vendoring JuliaSyntax into Base" julia_dir juliasyntax_branch_or_commit
20+
21+
remote_containing_branches = filter(b->occursin(r"^origin/(main|release-.*)$", b),
22+
strip.(split(
23+
read(`git --git-dir=$JuliaSyntax_git_dir branch -r --contains $juliasyntax_branch_or_commit`, String),
24+
'\n', keepempty=false)))
25+
if isempty(remote_containing_branches)
26+
@warn "No remote main or release branches contain the given commit. This is ok for testing, but is otherwise an error." juliasyntax_branch_or_commit
27+
else
28+
@info "Given commit is accessible on remote branch" remote_containing_branches
29+
end
30+
31+
commit_sha = strip(String(read(`git --git-dir=$JuliaSyntax_git_dir show -s --pretty=tformat:%H $juliasyntax_branch_or_commit`)))
32+
33+
cd(julia_dir) do
34+
status = read(`git status --porcelain --untracked-files=no`, String)
35+
if status != ""
36+
@error "Julia git directory contains uncommitted changes" status=Text(status)
37+
return 1
38+
end
39+
40+
verfile_path = joinpath("deps", "JuliaSyntax.version")
41+
@info "Updating JuliaSyntax.version" verfile_path
42+
write(verfile_path, replace(read(verfile_path, String), r"JULIASYNTAX_SHA1.*"=>"JULIASYNTAX_SHA1 = "*commit_sha))
43+
run(`git add $verfile_path`)
44+
45+
@info "Updating JuliaSyntax checksums"
46+
deps_dir = "deps"
47+
checksum_dir = joinpath(deps_dir, "checksums")
48+
old_checksum_paths = find_checksum_files(checksum_dir)
49+
if !isempty(old_checksum_paths)
50+
run(`git rm -rf $old_checksum_paths`)
51+
end
52+
run(`make -C $deps_dir`)
53+
run(`git add $(find_checksum_files(checksum_dir))`)
54+
55+
# Force rebuild of Base to include the newly vendored JuliaSyntax next time Julia is built.
56+
# (TODO: fix the Makefile instead?)
57+
touch("base/Base.jl")
58+
59+
@info "JuliaSyntax version updated. You can now test or commit the following changes"
60+
run(`git diff --cached`)
61+
end
62+
63+
return 0
64+
end
65+
66+
if !isinteractive()
67+
if length(ARGS) != 2
68+
println("Usage: bump_in_Base.jl \$julia_dir \$juliasyntax_branch_or_commit")
69+
exit(1)
70+
else
71+
juliasyntax_dir = dirname(@__DIR__)
72+
exit(bump_in_Base(ARGS[1], juliasyntax_dir, ARGS[2]))
73+
end
74+
end
75+

0 commit comments

Comments
 (0)