From 16223e035a1b316f3d6e15a2a63733bd36f3935f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Sat, 14 Nov 2020 15:34:49 +0000 Subject: [PATCH] Add `versioninfo` function (#77) Move definition of the function from `BinaryBuilder.jl` --- Manifest.toml | 7 ++- Project.toml | 1 + src/BinaryBuilderBase.jl | 98 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 3 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index ef0905f8..511de64f 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -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]] @@ -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" @@ -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]] diff --git a/Project.toml b/Project.toml index 93a24218..69dceecb 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/BinaryBuilderBase.jl b/src/BinaryBuilderBase.jl index 8312b589..f129a2e7 100644 --- a/src/BinaryBuilderBase.jl +++ b/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 @@ -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