Skip to content

Commit f30ed3c

Browse files
authored
Allow selection of compilers in the wizard (#553)
* Allow selection of compilers in the wizard * Allow choosing preferred GCC/LLVM versions in the wizard
1 parent 9a6dfcf commit f30ed3c

File tree

6 files changed

+108
-5
lines changed

6 files changed

+108
-5
lines changed

src/Rootfs.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,11 @@ function select_closest_version(preferred::VersionNumber, versions::Vector{Versi
319319
return versions[closest_idx]
320320
end
321321

322+
const available_gcc_builds = [v"4.8.5", v"5.2.0", v"6.1.0", v"7.1.0", v"8.1.0", v"9.1.0"]
323+
const available_llvm_builds = [v"6.0.1", v"7.1.0", v"8.0.1", v"9.0.1"]
324+
322325
function select_gcc_version(p::Platform,
323-
GCC_builds::Vector{VersionNumber} = [v"4.8.5", v"5.2.0", v"6.1.0", v"7.1.0", v"8.1.0", v"9.1.0"],
326+
GCC_builds::Vector{VersionNumber} = available_gcc_builds,
324327
preferred_gcc_version::VersionNumber = GCC_builds[1],
325328
)
326329
# Determine which GCC build we're going to match with this CompilerABI:
@@ -347,8 +350,8 @@ function choose_shards(p::Platform;
347350
compilers::Vector{Symbol} = [:c],
348351
rootfs_build::VersionNumber=v"2020.01.07",
349352
ps_build::VersionNumber=v"2020.01.15",
350-
GCC_builds::Vector{VersionNumber}=[v"4.8.5", v"5.2.0", v"6.1.0", v"7.1.0", v"8.1.0", v"9.1.0"],
351-
LLVM_builds::Vector{VersionNumber}=[v"6.0.1", v"7.1.0", v"8.0.1", v"9.0.1"],
353+
GCC_builds::Vector{VersionNumber}=available_gcc_builds,
354+
LLVM_builds::Vector{VersionNumber}=available_llvm_builds,
352355
Rust_build::VersionNumber=v"1.18.3",
353356
Go_build::VersionNumber=v"1.13",
354357
archive_type::Symbol = (use_squashfs ? :squashfs : :unpacked),

src/wizard/deploy.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ function print_build_tarballs(io::IO, state::WizardState)
3737
psrepr(ps) = "\n PackageSpec(name=\"$(ps.name)\", uuid=\"$(ps.uuid)\")"
3838
dependencies_string = join(map(psrepr, state.dependencies))
3939

40+
# Keyword arguments to `build_tarballs()`
41+
kwargs_vec = String[]
42+
if state.compilers != [:c] && length(state.compilers) >= 1
43+
push!(kwargs_vec, "compilers = [$(join(map(x -> ":$(x)", state.compilers), ", "))]")
44+
end
45+
# Default GCC version is the oldest one
46+
if state.preferred_gcc_version != available_gcc_builds[1]
47+
push!(kwargs_vec, "preferred_gcc_version = v\"$(state.preferred_gcc_version)\"")
48+
end
49+
# Default LLVM version is the latest one
50+
if state.preferred_llvm_version != available_llvm_builds[end]
51+
push!(kwargs_vec, "preferred_llvm_version = v\"$(state.preferred_llvm_version)\"")
52+
end
53+
kwargs = ""
54+
if length(kwargs_vec) >= 1
55+
kwargs = "; " * join(kwargs_vec, ", ")
56+
end
57+
4058
print(io, """
4159
# Note that this script can accept some limited command-line arguments, run
4260
# `julia build_tarballs.jl --help` to see a usage message.
@@ -69,7 +87,7 @@ function print_build_tarballs(io::IO, state::WizardState)
6987
]
7088
7189
# Build the tarballs, and possibly a `build.jl` as well.
72-
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies)
90+
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies$(kwargs))
7391
""")
7492
end
7593

src/wizard/interactive_build.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ function step3_retry(state::WizardState)
221221
cwd="/workspace/srcdir",
222222
platform=platform,
223223
src_name=state.name,
224+
compilers=state.compilers,
225+
preferred_gcc_version=state.preferred_gcc_version,
226+
preferred_llvm_version=state.preferred_llvm_version,
224227
)
225228
with_logfile(joinpath(build_path, "out.log")) do io
226229
run(ur, `/bin/bash -c $(state.history)`, io; verbose=true, tee_stream=state.outs)
@@ -309,6 +312,9 @@ function step34(state::WizardState)
309312
],
310313
platform=platform,
311314
src_name=state.name,
315+
compilers=state.compilers,
316+
preferred_gcc_version=state.preferred_gcc_version,
317+
preferred_llvm_version=state.preferred_llvm_version,
312318
)
313319
return step3_interactive(state, prefix, platform, ur, build_path, artifact_paths)
314320
end
@@ -346,6 +352,9 @@ function step5_internal(state::WizardState, platform::Platform)
346352
cwd="/workspace/srcdir",
347353
platform=platform,
348354
src_name=state.name,
355+
compilers=state.compilers,
356+
preferred_gcc_version=state.preferred_gcc_version,
357+
preferred_llvm_version=state.preferred_llvm_version,
349358
)
350359
with_logfile(joinpath(build_path, "out.log")) do io
351360
run(ur, `/bin/bash -c $(state.history)`, io; verbose=true, tee_stream=state.outs)
@@ -412,6 +421,9 @@ function step5_internal(state::WizardState, platform::Platform)
412421
cwd="/workspace/srcdir",
413422
platform=platform,
414423
src_name=state.name,
424+
compilers=state.compilers,
425+
preferred_gcc_version=state.preferred_gcc_version,
426+
preferred_llvm_version=state.preferred_llvm_version,
415427
)
416428

417429
if interactive_build(state, prefix, ur, build_path;
@@ -538,6 +550,9 @@ function step5c(state::WizardState)
538550
cwd="/workspace/srcdir",
539551
platform=platform,
540552
src_name=state.name,
553+
compilers=state.compilers,
554+
preferred_gcc_version=state.preferred_gcc_version,
555+
preferred_llvm_version=state.preferred_llvm_version,
541556
)
542557
with_logfile(joinpath(build_path, "out.log")) do io
543558
run(ur, `/bin/bash -c $(state.history)`, io; verbose=false, tee_stream=state.outs)

src/wizard/obtain_source.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,42 @@ function get_name_and_version(state::WizardState)
357357
end
358358
end
359359

360+
@enum Compilers C=1 Go Rust
361+
function get_compilers(state::WizardState)
362+
while state.compilers === nothing
363+
compiler_descriptions = Dict(C => "C/C++/Fortran", Go => "Go", Rust => "Rust")
364+
compiler_symbols = Dict(Int(C) => :c, Int(Go) => :go, Int(Rust) => :rust)
365+
terminal = TTYTerminal("xterm", state.ins, state.outs, state.outs)
366+
result = nothing
367+
while true
368+
select_menu = MultiSelectMenu([compiler_descriptions[i] for i in instances(Compilers)])
369+
select_menu.selected = Set([Int(C)])
370+
result = request(terminal,
371+
"Select compilers for the project",
372+
select_menu
373+
)
374+
if isempty(result)
375+
println("Must select at least one platform")
376+
else
377+
break
378+
end
379+
end
380+
state.compilers = map(c -> compiler_symbols[c], collect(result))
381+
end
382+
end
383+
384+
function get_preferred_version(state::WizardState, compiler::AbstractString,
385+
available_versions=Vector{Integer})
386+
terminal = TTYTerminal("xterm", state.ins, state.outs, state.outs)
387+
version_selected = request(terminal, "Select the preferred $(compiler) version",
388+
RadioMenu(string.(available_versions)))
389+
if compiler == "GCC"
390+
state.preferred_gcc_version = available_versions[version_selected]
391+
elseif compiler == "LLVM"
392+
state.preferred_llvm_version = available_versions[version_selected]
393+
end
394+
end
395+
360396
"""
361397
step2(state::WizardState)
362398
@@ -366,4 +402,15 @@ function step2(state::WizardState)
366402
obtain_source(state)
367403
obtain_binary_deps(state)
368404
get_name_and_version(state)
405+
if yn_prompt(state, "Do you want to customize the set of compilers?", :n) == :y
406+
get_compilers(state)
407+
get_preferred_version(state, "GCC", available_gcc_builds)
408+
get_preferred_version(state, "LLVM", available_llvm_builds)
409+
else
410+
state.compilers = [:c]
411+
# Default GCC version is the oldest one
412+
state.preferred_gcc_version = available_gcc_builds[1]
413+
# Default LLVM version is the latest one
414+
state.preferred_llvm_version = available_llvm_builds[end]
415+
end
369416
end

src/wizard/state.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ necessary. It also holds all necessary metadata such as input/output streams.
3535
source_files::Union{Nothing, Vector{String}} = nothing
3636
source_hashes::Union{Nothing, Vector{String}} = nothing
3737
dependencies::Union{Nothing, Vector} = nothing
38+
compilers::Union{Nothing, Vector{Symbol}} = nothing
39+
preferred_gcc_version::Union{Nothing, VersionNumber} = nothing
40+
preferred_llvm_version::Union{Nothing, VersionNumber} = nothing
3841

3942
# Filled in by step 3
4043
history::Union{Nothing, String} = nothing

test/wizard.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,19 @@ end
105105
# Test bad version number detection
106106
call_response(ins, outs, "Enter a version number", "parse me, I dare you")
107107
call_response(ins, outs, "Enter a version number", "1.0.0")
108+
109+
# Compiler
110+
call_response(ins, outs, "Do you want to customize the set of compilers?", "Y")
111+
call_response(ins, outs, "Select compilers for the project", "ad")
112+
call_response(ins, outs, "Select the preferred GCC version", "\r")
113+
call_response(ins, outs, "Select the preferred LLVM version", "\e[B\e[B\e[B\r")
108114
end
109115
# Check that the state is modified appropriately
110116
@test state.source_urls == ["http://127.0.0.1:14444/a/source.tar.gz"]
111117
@test state.source_hashes == [libfoo_tarball_hash]
112-
118+
@test Set(state.compilers) == Set([:c, :rust, :go])
119+
@test state.preferred_gcc_version == BinaryBuilder.available_gcc_builds[1]
120+
@test state.preferred_llvm_version == BinaryBuilder.available_llvm_builds[4]
113121

114122
# Test two tar.gz download
115123
state = step2_state()
@@ -122,6 +130,8 @@ end
122130

123131
call_response(ins, outs, "Enter a name for this project", "libfoo")
124132
call_response(ins, outs, "Enter a version number", "1.0.0")
133+
134+
call_response(ins, outs, "Do you want to customize the set of compilers?", "N")
125135
end
126136
# Check that the state is modified appropriately
127137
@test state.source_urls == [
@@ -143,6 +153,8 @@ end
143153

144154
call_response(ins, outs, "Enter a name for this project", "broken_symlink")
145155
call_response(ins, outs, "Enter a version number", "1.0.0")
156+
157+
call_response(ins, outs, "Do you want to customize the set of compilers?", "N")
146158
end
147159

148160
# Test failure to resolve a dependency
@@ -164,6 +176,8 @@ end
164176

165177
call_response(ins, outs, "Enter a name for this project", "check_deps")
166178
call_response(ins, outs, "Enter a version number", "1.0.0")
179+
180+
call_response(ins, outs, "Do you want to customize the set of compilers?", "N")
167181
end
168182
@test length(state.dependencies) == 2
169183
@test any([d.name == "ghr_jll" for d in state.dependencies])
@@ -190,6 +204,9 @@ function step3_state()
190204
state.name = "libfoo"
191205
state.version = v"1.0.0"
192206
state.dependencies = typeof(Pkg.PackageSpec(name="dummy"))[]
207+
state.compilers = [:c]
208+
state.preferred_gcc_version = BinaryBuilder.available_gcc_builds[1]
209+
state.preferred_llvm_version = BinaryBuilder.available_llvm_builds[end]
193210

194211
return state
195212
end

0 commit comments

Comments
 (0)