Skip to content

Commit 0d1023b

Browse files
authored
Some fixes suggested by JET (#196)
1 parent 18cc881 commit 0d1023b

File tree

11 files changed

+88
-91
lines changed

11 files changed

+88
-91
lines changed

src/BinaryBuilderBase.jl

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ include("utils.jl")
4545
# downloads, unpacked .tar.gz shards, mounted shards, ccache cache, etc....
4646
function storage_dir(args::AbstractString...)
4747
global storage_cache
48-
dir = joinpath(storage_cache, args...)
48+
dir = joinpath(storage_cache[], args...)
4949
mkpath(dirname(dir))
5050
return dir
5151
end
@@ -64,11 +64,11 @@ enable_apple_file() = storage_dir("enable_apple")
6464
# These globals store important information such as where we're downloading
6565
# the rootfs to, and where we're unpacking it. These constants are initialized
6666
# by `__init__()` to allow for environment variable overrides from the user.
67-
storage_cache = ""
68-
use_squashfs = false
69-
allow_ecryptfs = false
70-
use_ccache = false
71-
bootstrap_list = Symbol[]
67+
const storage_cache = Ref("")
68+
const use_squashfs = Ref(false)
69+
const allow_ecryptfs = Ref(false)
70+
const use_ccache = Ref(false)
71+
const bootstrap_list = Symbol[]
7272

7373
function get_bbb_version(dir=@__DIR__, uuid="7f725544-6523-48cd-82d1-3fa08ff4056e")
7474
# Get BinaryBuilder.jl's version and git sha
@@ -154,7 +154,7 @@ function versioninfo(; name=@__MODULE__, version=get_bbb_version())
154154
run_interactive(runner, `/bin/bash -c "echo hello julia"`)
155155

156156
# If we use ccache, dump the ccache stats
157-
if use_ccache
157+
if use_ccache[]
158158
@info("ccache stats:")
159159
runner = preferred_runner()(
160160
pwd();
@@ -171,8 +171,8 @@ function __init__()
171171
global use_ccache, storage_cache
172172

173173
# Allow the user to override the default value for `storage_dir`
174-
storage_cache = get(ENV, "BINARYBUILDER_STORAGE_DIR",
175-
abspath(joinpath(@__DIR__, "..", "deps")))
174+
storage_cache[] = get(ENV, "BINARYBUILDER_STORAGE_DIR",
175+
abspath(joinpath(@__DIR__, "..", "deps")))
176176

177177
# If the user has signalled that they really want us to automatically
178178
# accept apple EULAs, do that.
@@ -181,13 +181,13 @@ function __init__()
181181
end
182182

183183
# If the user has overridden our runner selection algorithms, honor that
184-
runner_override = lowercase(get(ENV, "BINARYBUILDER_RUNNER", ""))
185-
if runner_override == "unprivileged"
186-
runner_override = "userns"
184+
runner_override[] = lowercase(get(ENV, "BINARYBUILDER_RUNNER", ""))
185+
if runner_override[] == "unprivileged"
186+
runner_override[] = "userns"
187187
end
188-
if !(runner_override in ["", "userns", "privileged", "docker"])
189-
@warn("Invalid runner value $runner_override, ignoring...")
190-
runner_override = ""
188+
if !(runner_override[] in ("", "userns", "privileged", "docker"))
189+
@warn("Invalid runner value $(runner_override[]), ignoring...")
190+
runner_override[] = ""
191191
end
192192

193193
# If the user has asked for squashfs mounting instead of tarball mounting,
@@ -196,35 +196,30 @@ function __init__()
196196
# default. If we are not on Travis, we default to using tarballs and not
197197
# squashfs images as using them requires `sudo` access.
198198
if get(ENV, "BINARYBUILDER_USE_SQUASHFS", "") == "false"
199-
use_squashfs = false
199+
use_squashfs[] = false
200200
elseif get(ENV, "BINARYBUILDER_USE_SQUASHFS", "") == "true"
201-
use_squashfs = true
201+
use_squashfs[] = true
202202
else
203-
# If it hasn't been specified, but we're on Travis, default to "on"
204-
if get(ENV, "TRAVIS", "") == "true"
205-
use_squashfs = true
206-
end
207-
208203
# If it hasn't been specified but we're going to use the docker runner,
209204
# then set `use_squashfs` to `true` here.
210205
if preferred_runner() == DockerRunner
211206
# Conversely, if we're dock'ing it up, don't use it.
212-
use_squashfs = false
207+
use_squashfs[] = false
213208
elseif runner_override == "privileged"
214209
# If we're forcing a privileged runner, go ahead and default to squashfs
215-
use_squashfs = true
210+
use_squashfs[] = true
216211
end
217212
end
218213

219214
# If the user has signified that they want to allow mounting of ecryptfs
220215
# paths, then let them do so at their own peril.
221216
if get(ENV, "BINARYBUILDER_ALLOW_ECRYPTFS", "") == "true"
222-
allow_ecryptfs = true
217+
allow_ecryptfs[] = true
223218
end
224219

225220
# If the user has enabled `ccache` support, use it!
226221
if get(ENV, "BINARYBUILDER_USE_CCACHE", "false") == "true"
227-
use_ccache = true
222+
use_ccache[] = true
228223
end
229224
end
230225

src/BuildToolchains.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function cmake_os(p::AbstractPlatform)
2626
return "Darwin"
2727
elseif Sys.iswindows(p)
2828
return "Windows"
29+
else
30+
return "Unknown"
2931
end
3032
end
3133

@@ -162,7 +164,7 @@ function meson_cpu_family(p::AbstractPlatform)
162164
return "x86_64"
163165
elseif arch(p) == "aarch64"
164166
return "aarch64"
165-
elseif startswith(arch(p), "arm")
167+
elseif startswith(arch(p)::String, "arm")
166168
return "arm"
167169
end
168170
end

src/DockerRunner.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function DockerRunner(workspace_root::String;
9191
# Construct docker command
9292
docker_cmd = `docker run --rm --privileged `#--cap-add SYS_ADMIN`
9393

94-
if cwd != nothing
94+
if cwd !== nothing
9595
docker_cmd = `$docker_cmd -w /$(abspath(cwd))`
9696
end
9797

src/Platforms.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Strip out any tags that are not the basic annotations like `libc` and `call_abi`
2525
"""
2626
function abi_agnostic(p::Platform)
2727
keeps = ("libc", "call_abi", "os_version")
28-
filtered_tags = Dict(Symbol(k) => v for (k, v) in tags(p) if k keeps)
29-
return Platform(arch(p), os(p); filtered_tags...)
28+
filtered_tags = Dict{Symbol,String}(Symbol(k) => v for (k, v) in tags(p) if k keeps)
29+
return Platform(arch(p)::String, os(p)::String; filtered_tags...)
3030
end
3131
abi_agnostic(p::AnyPlatform) = p
3232

src/Products.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ If `isolate` is set to `true`, will isolate all checks from the main Julia
5151
process in the event that `dlopen()`'ing a library might cause issues.
5252
"""
5353
function satisfied(p::Product, prefix::Prefix; kwargs...)
54-
return locate(p, prefix; kwargs...) != nothing
54+
return locate(p, prefix; kwargs...) !== nothing
5555
end
5656

5757

@@ -357,7 +357,7 @@ struct ExecutableProduct <: Product
357357
error("`$(varname)` is already defined in Base")
358358
end
359359
# If some other kind of AbstractString is passed in, convert it
360-
if dir_path != nothing
360+
if dir_path !== nothing
361361
dir_path = string(dir_path)
362362
end
363363
return new(binnames, varname, dir_path)
@@ -378,7 +378,7 @@ end
378378
function repr(p::ExecutableProduct)
379379
varname = repr(p.variable_name)
380380
binnames = repr(p.binnames)
381-
if p.dir_path != nothing
381+
if p.dir_path !== nothing
382382
return "ExecutableProduct($(binnames), $(varname), $(repr(p.dir_path)))"
383383
else
384384
return "ExecutableProduct($(binnames), $(varname))"
@@ -410,10 +410,10 @@ function locate(ep::ExecutableProduct, prefix::Prefix; platform::AbstractPlatfor
410410
end
411411

412412
# Join into the `dir_path` given by the executable product
413-
if ep.dir_path != nothing
414-
path = joinpath(prefix.path, template(joinpath(ep.dir_path, binname), platform))
413+
path = if ep.dir_path !== nothing
414+
joinpath(prefix.path, template(joinpath(ep.dir_path, binname), platform))
415415
else
416-
path = joinpath(bindir(prefix), template(binname, platform))
416+
joinpath(bindir(prefix), template(binname, platform))
417417
end
418418

419419
if isfile(path)

src/Rootfs.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct CompilerShard
3939
# by higher-level things to choose e.g. which version of GCC
4040
# to use, but once we're at this level we only care about the
4141
# larger-scale things, not the ABI).
42-
host = abi_agnostic(host)
43-
if target != nothing
42+
host = abi_agnostic(host::AbstractPlatform)
43+
if target !== nothing
4444
target = abi_agnostic(target)
4545
end
4646

@@ -64,8 +64,8 @@ Return the bound artifact name for a particular shard.
6464
"""
6565
function artifact_name(cs::CompilerShard)
6666
target_str = ""
67-
if cs.target != nothing
68-
target_str = "-$(triplet(cs.target))"
67+
if cs.target !== nothing
68+
target_str = "-$(triplet(cs.target::Platform))"
6969

7070
if cs.name in ("GCCBootstrap", "PlatformSupport")
7171
# armv6l uses the same GCC shards as armv7l, so we just rename here.
@@ -84,15 +84,15 @@ function CompilerShard(art_name::String)
8484
end
8585
return CompilerShard(
8686
m.captures[1],
87-
VersionNumber(m.captures[3]),
87+
VersionNumber(m.captures[3]::AbstractString),
8888
m.captures[4],
8989
Symbol(m.captures[5]);
9090
target=m.captures[2]
9191
)
9292
end
9393

9494
const ALL_SHARDS = Ref{Union{Vector{CompilerShard},Nothing}}(nothing)
95-
function all_compiler_shards()
95+
function all_compiler_shards()::Vector{CompilerShard}
9696
if ALL_SHARDS[] === nothing
9797
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
9898
artifact_dict = load_artifacts_toml(artifacts_toml)
@@ -114,13 +114,13 @@ function all_compiler_shards()
114114
end
115115

116116
# If this compiler shard has an os_version, that should be interpreted as the bound it is.
117-
if cs.target !== nothing && os_version(cs.target) !== nothing
118-
set_compare_strategy!(cs.target, "os_version", compare_version_cap)
117+
if cs.target !== nothing && os_version(cs.target::Platform) !== nothing
118+
set_compare_strategy!(cs.target::Platform, "os_version", compare_version_cap)
119119
end
120-
push!(ALL_SHARDS[], cs)
120+
push!(ALL_SHARDS[]::Vector{CompilerShard}, cs)
121121
end
122122
end
123-
return ALL_SHARDS[]
123+
return ALL_SHARDS[]::Vector{CompilerShard}
124124
end
125125

126126
function shard_source_artifact_hash(cs::CompilerShard)
@@ -168,7 +168,7 @@ function map_target(cs::CompilerShard)
168168
return "/"
169169
elseif lowercase(cs.name) == "rusttoolchain"
170170
# We override RustToolchain because they all have to sit in the same location
171-
return "/opt/$(aatriplet(cs.host))/$(cs.name)-$(cs.version)-$(aatriplet(cs.target)))"
171+
return "/opt/$(aatriplet(cs.host))/$(cs.name)-$(cs.version)-$(aatriplet(cs.target::Platform)))"
172172
else
173173
return joinpath("/opt", aatriplet(something(cs.target, cs.host)), "$(cs.name)-$(cs.version)")
174174
end
@@ -231,7 +231,7 @@ function mount(cs::CompilerShard, build_prefix::AbstractString; verbose::Bool =
231231
# they must accept the Xcode EULA. This will be skipped if either the
232232
# environment variable BINARYBUILDER_AUTOMATIC_APPLE has been set to `true`
233233
# or if the SDK has been downloaded in the past.
234-
if cs.target !== nothing && Sys.isapple(cs.target) && !isfile(enable_apple_file()) && !macos_sdk_already_installed()
234+
if cs.target !== nothing && Sys.isapple(cs.target::Platform) && !isfile(enable_apple_file()) && !macos_sdk_already_installed()
235235
if !isinteractive()
236236
msg = strip("""
237237
This is not an interactive Julia session, so we will not prompt you
@@ -343,7 +343,7 @@ Returns `true` if any piece of the MacOS SDK is already installed.
343343
function macos_sdk_already_installed()
344344
# Get all compiler shards we know about
345345
css = all_compiler_shards()
346-
macos_artifact_names = artifact_name.(filter(cs -> cs.target !== nothing && Sys.isapple(cs.target), css))
346+
macos_artifact_names = artifact_name.(filter(cs -> cs.target !== nothing && Sys.isapple(cs.target::Platform), css))
347347

348348
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
349349
macos_artifact_hashes = artifact_hash.(macos_artifact_names, artifacts_toml; platform=default_host_platform)
@@ -481,7 +481,7 @@ end
481481

482482
function llvm_version(p::AbstractPlatform, LLVM_builds::Vector{LLVMBuild})
483483
if march(p) in ("armv8_2_crypto", "armv8_4_crypto_sve")
484-
LLVM_builds = filter(b -> getversion(b) >= v"9.0")
484+
LLVM_builds = filter(b -> getversion(b) >= v"9.0", LLVM_builds)
485485
end
486486
return getversion.(LLVM_builds)
487487
end
@@ -527,7 +527,7 @@ function choose_shards(p::AbstractPlatform;
527527
LLVM_builds::Vector{LLVMBuild}=available_llvm_builds,
528528
Rust_build::VersionNumber=v"1.57.0",
529529
Go_build::VersionNumber=v"1.16.3",
530-
archive_type::Symbol = (use_squashfs ? :squashfs : :unpacked),
530+
archive_type::Symbol = (use_squashfs[] ? :squashfs : :unpacked),
531531
bootstrap_list::Vector{Symbol} = bootstrap_list,
532532
# Because GCC has lots of compatibility issues, we always default to
533533
# the earliest version possible.
@@ -714,7 +714,7 @@ matching. If the given `Platform` already specifies a `libgfortran_version`
714714
"""
715715
function expand_gfortran_versions(platform::AbstractPlatform)
716716
# If this platform is already explicitly libgfortran-versioned, exit out fast here.
717-
if libgfortran_version(platform) != nothing
717+
if libgfortran_version(platform) !== nothing
718718
return [platform]
719719
end
720720

@@ -857,11 +857,11 @@ function preferred_libgfortran_version(platform::AbstractPlatform, shard::Compil
857857
if shard.name != "GCCBootstrap"
858858
error("Shard must be `GCCBootstrap`")
859859
end
860-
if arch(shard.target) != arch(platform) || libc(shard.target) != libc(platform)
860+
if arch(shard.target::Platform) != arch(platform) || libc(shard.target::Platform) != libc(platform)
861861
error("Incompatible platform and shard target")
862862
end
863863

864-
if libgfortran_version(platform) != nothing
864+
if libgfortran_version(platform) !== nothing
865865
# Here we can't use `shard.target` because the shard always has the
866866
# target as ABI-agnostic, thus we have also to ask for the platform.
867867
return libgfortran_version(platform)
@@ -887,11 +887,11 @@ function preferred_cxxstring_abi(platform::AbstractPlatform, shard::CompilerShar
887887
if shard.name != "GCCBootstrap"
888888
error("Shard must be `GCCBootstrap`")
889889
end
890-
if arch(shard.target) != arch(platform) || libc(shard.target) != libc(platform)
890+
if arch(shard.target::Platform) != arch(platform) || libc(shard.target::Platform) != libc(platform)
891891
error("Incompatible platform and shard target")
892892
end
893893

894-
if cxxstring_abi(platform) != nothing
894+
if cxxstring_abi(platform) !== nothing
895895
# Here we can't use `shard.target` because the shard always has the
896896
# target as ABI-agnostic, thus we have also to ask for the platform.
897897
return cxxstring_abi(platform)
@@ -922,26 +922,26 @@ function download_all_artifacts(; verbose::Bool = false)
922922
)
923923
end
924924

925-
_sudo_cmd = nothing
926-
function sudo_cmd()
925+
const _sudo_cmd = Ref{Union{Cmd,Nothing}}(nothing)
926+
function sudo_cmd()::Cmd
927927
global _sudo_cmd
928928

929929
# Use cached value if we've already run this
930-
if _sudo_cmd != nothing
931-
return _sudo_cmd
930+
if _sudo_cmd[] !== nothing
931+
return _sudo_cmd[]::Cmd
932932
end
933933

934-
if getuid() == 0
934+
_sudo_cmd[] = if getuid() == 0
935935
# If we're already root, don't use any kind of sudo program
936-
_sudo_cmd = ``
936+
``
937937
elseif success(`sudo -V`)
938938
# If `sudo` is available, use that
939-
_sudo_cmd = `sudo`
939+
`sudo`
940940
else
941941
# Fall back to `su` if all else fails
942-
_sudo_cmd = `su root -c`
942+
`su root -c`
943943
end
944-
return _sudo_cmd
944+
return _sudo_cmd[]::Cmd
945945
end
946946

947947
"""

0 commit comments

Comments
 (0)