Skip to content

Commit

Permalink
make --version printing compatible with juliac
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Nov 19, 2024
1 parent ad205bc commit fcdce59
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/juliac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ function sprint_showerror_juliac(err::Exception)
end
end

# juliac-compatible print(::IO, ::VersionNumber) with explicitly `@inline`d `join` calls...
function print_vnum_juliac(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, '-')
@inline join(io, v.prerelease, '.')

Check warning on line 83 in src/juliac.jl

View check run for this annotation

Codecov / codecov/patch

src/juliac.jl#L74-L83

Added lines #L74 - L83 were not covered by tests
end
if !isempty(v.build)
print(io, '+')
@inline join(io, v.build, '.')

Check warning on line 87 in src/juliac.jl

View check run for this annotation

Codecov / codecov/patch

src/juliac.jl#L85-L87

Added lines #L85 - L87 were not covered by tests
end
return

Check warning on line 89 in src/juliac.jl

View check run for this annotation

Codecov / codecov/patch

src/juliac.jl#L89

Added line #L89 was not covered by tests
end

# juliac-compatible `Base.tempdir` and `Base.mktempdir` without logging and deferred cleanup
function tempdir_juliac()
buf = Base.StringVector(Base.Filesystem.AVG_PATH - 1)
Expand Down
8 changes: 7 additions & 1 deletion src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const juliac = @load_preference("juliac", false)
const printstyled = printstyled_juliac
const mktempdir = mktempdir_juliac
const sprint_showerror = sprint_showerror_juliac
const print_vnum = print_vnum_juliac
else
# const stdin = Base.stdin
# const stdout = Base.stdout
Expand All @@ -24,6 +25,7 @@ else
const printstyled = Base.printstyled
const mktempdir = Base.mktempdir
sprint_showerror(err::Exception) = sprint(showerror, err)
const print_vnum = Base.print
end

supports_color(io) = get(io, :color, false)
Expand Down Expand Up @@ -149,7 +151,11 @@ function print_help()
end

function print_version()
println(stdout, "runic version $(RUNIC_VERSION), julia version $(VERSION)")
print(stdout, "runic version ")
print_vnum(stdout, RUNIC_VERSION)
print(stdout, ", julia version ")
print_vnum(stdout, VERSION)
println(stdout)
return
end

Expand Down

0 comments on commit fcdce59

Please sign in to comment.