Skip to content

Commit ad8188c

Browse files
authored
In bb add, unlink artifacts, but move rm to BBBase (#1119)
* In `bb add`, unlink artifacts, but move rm to BBBase BBBase changed the layout of the $prefix/artifacts directory, such that the fix in #931 was no longer effective. Instead of closely coupling BB to BBBase just move the rm part to BBBase[1] and do a proper cleanup/setup cycle here. [1] JuliaPackaging/BinaryBuilderBase.jl#183 * Add test for bb add
1 parent ab9f0cb commit ad8188c

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

src/wizard/interactive_build.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,24 @@ function diff_srcdir(state::WizardState, prefix::Prefix, ur::Runner)
212212
return false
213213
end
214214

215-
function bb_add(client, state::WizardState, prefix::Prefix, platform::AbstractPlatform, jll::AbstractString)
215+
function bb_add(client, state::WizardState, prefix::Prefix, prefix_artifacts::Union{Dict{Prefix,Vector{String}}, Nothing}, platform::AbstractPlatform, jll::AbstractString)
216216
if any(dep->getpkg(dep).name == jll, state.dependencies)
217217
println(client, "ERROR: Package was already added")
218218
return
219219
end
220+
if prefix_artifacts === nothing
221+
println(client, "ERROR: `bb add` not available in this context (if you think it should be, file an issue)!")
222+
return
223+
end
220224
new_dep = Dependency(jll)
221225
try
222226
# This will redo some work, but that may be ok
223227
concrete_platform = get_concrete_platform(platform, state)
224228
# Clear out the prefix artifacts directory in case this change caused
225229
# any previous dependencies to change
226-
let artifacts_dir = joinpath(prefix, "artifacts")
227-
isdir(artifacts_dir) && rm(artifacts_dir; recursive=true)
228-
end
229-
setup_dependencies(prefix, getpkg.([state.dependencies; new_dep]), concrete_platform)
230+
cleanup_dependencies(prefix, get(prefix_artifacts, prefix, String[]), concrete_platform)
231+
pkgs = getpkg.([state.dependencies; new_dep])
232+
prefix_artifacts[prefix] = setup_dependencies(prefix, pkgs, concrete_platform)
230233
push!(state.dependencies, new_dep)
231234
catch e
232235
showerror(client, e)
@@ -253,7 +256,7 @@ function bb_parser()
253256
s
254257
end
255258

256-
function setup_bb_service(state::WizardState, prefix, platform)
259+
function setup_bb_service(state::WizardState, prefix, platform, prefix_artifacts::Union{Dict{Prefix,Vector{String}}, Nothing})
257260
fpath = joinpath(prefix, "metadir", "bb_service")
258261
server = listen(fpath)
259262
@async begin
@@ -273,7 +276,7 @@ function setup_bb_service(state::WizardState, prefix, platform)
273276
parsed = parse_args(ARGS, s)
274277
if parsed == nothing
275278
elseif parsed["%COMMAND%"] == "add"
276-
bb_add(client, state, prefix, platform, parsed["add"]["jll"])
279+
bb_add(client, state, prefix, prefix_artifacts, platform, parsed["add"]["jll"])
277280
end
278281
close(client)
279282
catch e
@@ -305,6 +308,7 @@ end
305308
function interactive_build(state::WizardState, prefix::Prefix,
306309
ur::Runner, build_path::AbstractString,
307310
platform::AbstractPlatform;
311+
prefix_artifacts::Union{Dict{Prefix,Vector{String}}, Nothing} = nothing,
308312
hist_modify = string, srcdir_overlay = true)
309313
histfile = joinpath(prefix, "metadir", ".bash_history")
310314
cmd = `/bin/bash -l`
@@ -325,7 +329,7 @@ function interactive_build(state::WizardState, prefix::Prefix,
325329
cmd = `/bin/bash -c $cmd`
326330
end
327331

328-
(fpath, server) = setup_bb_service(state, prefix, platform)
332+
(fpath, server) = setup_bb_service(state, prefix, platform, prefix_artifacts)
329333

330334
script_successful = run_interactive(ur, ignorestatus(cmd), stdin=state.ins, stdout=state.outs, stderr=state.outs)
331335

@@ -407,7 +411,7 @@ function step3_interactive(state::WizardState, prefix::Prefix,
407411
ur::Runner, build_path::AbstractString, artifact_paths::Vector{String})
408412

409413
concrete_platform = get_concrete_platform(platform, state)
410-
if interactive_build(state, prefix, ur, build_path, platform)
414+
if interactive_build(state, prefix, ur, build_path, platform; prefix_artifacts=Dict(prefix=>artifact_paths))
411415
# Unsymlink all the deps from the dest_prefix before moving to the next step
412416
cleanup_dependencies(prefix, artifact_paths, concrete_platform)
413417
state.step = :step3_retry
@@ -617,6 +621,7 @@ function step5_internal(state::WizardState, platform::AbstractPlatform)
617621

618622
if choice == 1
619623
if interactive_build(state, prefix, ur, build_path, platform;
624+
prefix_artifacts = prefix_artifacts,
620625
hist_modify = function(olds, s)
621626
"""
622627
$olds
@@ -658,6 +663,7 @@ function step5_internal(state::WizardState, platform::AbstractPlatform)
658663
)
659664

660665
if interactive_build(state, prefix, ur, build_path, platform;
666+
prefix_artifacts = prefix_artifacts,
661667
hist_modify = function(olds, s)
662668
"""
663669
if [ \$target != "$(triplet(platform))" ]; then

test/wizard.jl

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function with_wizard_output(f::Function, state, step_func::Function)
1717
z = String(readavailable(pty.master))
1818

1919
# Un-comment this to figure out what on earth is going wrong
20-
#print(z)
20+
# print(z)
2121
write(out_buff, z)
2222
end
2323
end
@@ -83,10 +83,14 @@ for i in available_ports
8383
end
8484

8585
function readuntil_sift(io::IO, needle)
86+
# N.B.: This is a terrible way to do this and works around the fact that our `IOBuffer`
87+
# does not block. It works fine here, but do not copy this to other places.
8688
needle = codeunits(needle)
8789
buffer = zeros(UInt8, length(needle))
90+
all_buffer = UInt8[]
8891
while isopen(io)
8992
new_c = read(io, 1)
93+
append!(all_buffer, new_c)
9094
if isempty(new_c)
9195
# We need to wait for more data, sleep for a bit
9296
sleep(0.01)
@@ -95,14 +99,14 @@ function readuntil_sift(io::IO, needle)
9599

96100
buffer = [buffer[2:end]; new_c]
97101
if !any(buffer .!= needle)
98-
return true
102+
return all_buffer
99103
end
100104
end
101-
return false
105+
return nothing
102106
end
103107

104108
function call_response(ins, outs, question, answer; newline=true)
105-
@assert readuntil_sift(outs, question)
109+
@assert readuntil_sift(outs, question) !== nothing
106110
# Because we occasionally are dealing with things that do strange
107111
# stdin tricks like reading raw stdin buffers, we sleep here for safety.
108112
sleep(0.1)
@@ -284,10 +288,16 @@ end
284288

285289
@testset "Wizard - Building" begin
286290
function succcess_path_call_response(ins, outs)
291+
output = readuntil_sift(outs, "Build complete")
292+
if contains(String(output), "Warning:")
293+
close(ins)
294+
return false
295+
end
287296
call_response(ins, outs, "Would you like to edit this script now?", "N")
288297
call_response(ins, outs, "d=done, a=all", "ad"; newline=false)
289298
call_response(ins, outs, "lib/libfoo.so", "libfoo")
290299
call_response(ins, outs, "bin/fooifier", "fooifier")
300+
return true
291301
end
292302

293303
# Test step3 success path
@@ -298,7 +308,7 @@ end
298308
make install
299309
exit
300310
""")
301-
succcess_path_call_response(ins, outs)
311+
@test succcess_path_call_response(ins, outs)
302312
end
303313
@test state.history == """
304314
cd \$WORKSPACE/srcdir
@@ -323,7 +333,7 @@ end
323333
exit
324334
""")
325335

326-
succcess_path_call_response(ins, outs)
336+
@test succcess_path_call_response(ins, outs)
327337
end
328338
@test state.history == """
329339
cd \$WORKSPACE/srcdir
@@ -357,9 +367,9 @@ end
357367
exit 1
358368
""")
359369

360-
@test readuntil_sift(outs, "Warning:")
370+
@test readuntil_sift(outs, "Warning:") !== nothing
361371

362-
succcess_path_call_response(ins, outs)
372+
@test succcess_path_call_response(ins, outs)
363373
end
364374
step3_test(state)
365375

@@ -376,7 +386,29 @@ end
376386
make install
377387
exit
378388
""")
379-
succcess_path_call_response(ins, outs)
389+
@test succcess_path_call_response(ins, outs)
390+
end
391+
392+
# Step 3 - `bb add`
393+
state = step3_state()
394+
state.dependencies = [Dependency(PackageSpec(name="Zlib_jll", uuid="83775a58-1f1d-513f-b197-d71354ab007a"))]
395+
with_wizard_output(state, Wizard.step34) do ins, outs
396+
call_response(ins, outs, "\${WORKSPACE}/srcdir", """
397+
if [[ ! -f \${libdir}/libz.\${dlext} ]]; then
398+
echo "ERROR: Could not find libz.\${dlext}" >&2
399+
exit 1
400+
fi
401+
bb add Xorg_xorgproto_jll
402+
if [[ ! -d \${includedir}/X11 ]]; then
403+
echo "ERROR: Could not find include/X11" >&2
404+
exit 1
405+
fi
406+
bb add Zlib_jll
407+
cd libfoo
408+
make install
409+
exit
410+
""")
411+
@test succcess_path_call_response(ins, outs)
380412
end
381413
end
382414

@@ -431,12 +463,12 @@ end
431463
state = step7_state()
432464
with_wizard_output(state, state->Wizard._deploy(state)) do ins, outs
433465
call_response(ins, outs, "How should we deploy this build recipe?", "\e[B\e[B\r")
434-
@test readuntil_sift(outs, "Your generated build_tarballs.jl:")
435-
@test readuntil_sift(outs, "name = \"libfoo\"")
436-
@test readuntil_sift(outs, "make install")
437-
@test readuntil_sift(outs, "LibraryProduct(\"libfoo\", :libfoo)")
438-
@test readuntil_sift(outs, "ExecutableProduct(\"fooifier\", :fooifier)")
439-
@test readuntil_sift(outs, "dependencies = Dependency[")
466+
@test readuntil_sift(outs, "Your generated build_tarballs.jl:") !== nothing
467+
@test readuntil_sift(outs, "name = \"libfoo\"") !== nothing
468+
@test readuntil_sift(outs, "make install") !== nothing
469+
@test readuntil_sift(outs, "LibraryProduct(\"libfoo\", :libfoo)") !== nothing
470+
@test readuntil_sift(outs, "ExecutableProduct(\"fooifier\", :fooifier)") !== nothing
471+
@test readuntil_sift(outs, "dependencies = Dependency[") !== nothing
440472
end
441473
end
442474

0 commit comments

Comments
 (0)