Skip to content

Commit

Permalink
Add versioninfo function (#77)
Browse files Browse the repository at this point in the history
Move definition of the function from `BinaryBuilder.jl`
  • Loading branch information
giordano committed Nov 14, 2020
1 parent f45ea7c commit 16223e0
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Manifest.toml
Expand Up @@ -20,7 +20,7 @@ deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[Downloads]]
deps = ["ArgTools", "LibCURL"]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[InteractiveUtils]]
Expand Down Expand Up @@ -66,6 +66,9 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[OutputCollectors]]
git-tree-sha1 = "d86c19b7fa8ad6a4dc8ec2c726642cc6291b2941"
uuid = "6c11c7d4-943b-4e2b-80de-f2cfc2930a8c"
Expand All @@ -78,7 +81,7 @@ uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.10"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "UUIDs"]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Expand Up @@ -6,6 +6,7 @@ version = "0.5.0"
[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand Down
98 changes: 97 additions & 1 deletion src/BinaryBuilderBase.jl
@@ -1,6 +1,6 @@
module BinaryBuilderBase

using Pkg, Pkg.Artifacts, Random, Libdl
using Pkg, Pkg.Artifacts, Random, Libdl, InteractiveUtils
using Base.BinaryPlatforms
using Downloads
using JSON, OutputCollectors
Expand Down Expand Up @@ -69,6 +69,102 @@ allow_ecryptfs = false
use_ccache = false
bootstrap_list = Symbol[]

function get_bbb_version(dir=@__DIR__, uuid="7f725544-6523-48cd-82d1-3fa08ff4056e")
# Get BinaryBuilder.jl's version and git sha
version = Pkg.TOML.parsefile(joinpath(dir, "..", "Project.toml"))["version"]
try
# get the gitsha if we can
repo = LibGit2.GitRepo(dirname(@__DIR__))
gitsha = string(LibGit2.GitHash(LibGit2.GitCommit(repo, "HEAD")))
return VersionNumber("$(version)-git-$(gitsha[1:10])")
catch
try
# Settle for the treehash otherwise
env = Pkg.Types.Context().env
bb_uuid = Pkg.Types.UUID(uuid)
treehash = bytes2hex(env.manifest[bb_uuid].tree_hash.bytes)
return VersionNumber("$(version)-tree-$(treehash[1:10])")
catch
# Something went so wrong, we can't get any of that.
return VersionNumber(version)
end
end
end

"""
versioninfo()
Helper function to print out some debugging information
"""
function versioninfo(; name=@__MODULE__, version=get_bbb_version())
@info("Julia versioninfo(): ")
InteractiveUtils.versioninfo()

@info("$(name).jl version: $(version)")

@static if Sys.isunix()
@info("Kernel version: $(readchomp(`uname -r`))")
end

# Dump if some important directories are encrypted:
@static if Sys.islinux()
print_enc(n, path) = begin
is_encrypted, mountpoint = is_ecryptfs(path)
if is_encrypted
@info("$n is encrypted on mountpoint $mountpoint")
else
@info("$n is NOT encrypted on mountpoint $mountpoint")
end
end

print_enc("pkg dir", dirname(@__FILE__))
print_enc("storage dir", storage_dir())
end

# Dump any relevant environment variables:
@info("Relevant environment variables:")
env_var_suffixes = [
"AUTOMATIC_APPLE",
"USE_SQUASHFS",
"STORAGE_DIR",
"RUNNER",
"ALLOW_ECRYPTFS",
"USE_CCACHE",
]
for e in env_var_suffixes
envvar = "BINARYBUILDER_$(e)"
if haskey(ENV, envvar)
@info(" $(envvar): \"$(ENV[envvar])\"")
end
end

# Print out the preferred runner stuff here:
@info("Preferred runner: $(preferred_runner())")

# Try to run 'echo julia' in Linux x86_64 environment
@info("Trying to run `echo hello julia` within a Linux x86_64 environment...")

runner = preferred_runner()(
pwd();
cwd="/workspace/",
platform=Platform("x86_64", "linux"),
verbose=true
)
run_interactive(runner, `/bin/bash -c "echo hello julia"`)

# If we use ccache, dump the ccache stats
if use_ccache
@info("ccache stats:")
runner = preferred_runner()(
pwd();
cwd="/workspace/",
platform=Platform("x86_64", "linux"),
)
run_interactive(runner, `/usr/bin/ccache -s`)
end
return nothing
end

function __init__()
global runner_override, use_squashfs, allow_ecryptfs
global use_ccache, storage_cache
Expand Down

0 comments on commit 16223e0

Please sign in to comment.