Skip to content

Commit

Permalink
Add versioninfo
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jul 13, 2019
1 parent 1498088 commit 99d4790
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Run.jl
Expand Up @@ -8,6 +8,7 @@ using UUIDs: UUID
import Coverage

include("core.jl")
include("versioninfo.jl")
include("pkg.jl")
include("migratetest.jl")

Expand Down
3 changes: 3 additions & 0 deletions src/core.jl
Expand Up @@ -154,6 +154,9 @@ function script(
precompile = (compiled_modules != false),
kwargs...,
)
if get(ENV, "CI", "false") == "true"
versioninfo()
end
script = checkexisting(script)
projectpath = dirname(script)
julia_options, kwargs = _default_julia_options(;
Expand Down
47 changes: 47 additions & 0 deletions src/versioninfo.jl
@@ -0,0 +1,47 @@
versioninfo() = versioninfo(stdout)
versioninfo(io) = versioninfo(io, Base.PkgId(@__MODULE__))

function versioninfo(io, pkg)
entry = find_pkg_entry(pkg, Base.load_path())
entry === nothing && error("No package information ($pkg not installed?).")

print(io, pkg)
if haskey(entry, "version")
print(io, " version ", entry["version"])
end
println(io)

keys = [
"git-tree-sha1",
"repo-url",
"repo-rev",
]
padn = maximum(length.(keys)) + 1
for key in keys
if haskey(entry, key)
print(io, rpad(key, padn), ": ")
printstyled(io, entry[key], color=:blue)
println(io)
end
end
end

isomething(xs) =
for x in xs
x === nothing || return x
end

tryfind(f, xs) = isomething(f(x) ? x : nothing for x in xs)

find_pkg_entry(pkg, paths) = isomething(find_pkg_entry.(Ref(pkg), paths))

function find_pkg_entry(pkg, path::AbstractString)
isfile(path) || return
manifest = tryfind(
isfile,
joinpath.(dirname(path), ["JuliaManifest.toml", "Manifest.toml"]),
)
return tryfind(get(TOML.parsefile(manifest), pkg.name, ())) do entry
Base.UUID(get(entry, "uuid", 0)) === pkg.uuid
end
end
12 changes: 12 additions & 0 deletions test/runtests.jl
Expand Up @@ -12,4 +12,16 @@ using Test
)
@test Run.test(pkgspec) isa Any
@test Run.test(pkgspec; inline=false) isa Any

pkgid = Base.PkgId(
Base.UUID("22cec73e-a1b8-11e9-2c92-598750a2cf9c"),
"InitialValues",
)

mktempdir() do project
Run.temporaryactivating(project) do
Pkg.add(pkgspec)
Run.versioninfo(stdout, pkgid)
end
end
end

0 comments on commit 99d4790

Please sign in to comment.