Skip to content

fix output from runners to IOBuffer #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BinaryBuilderBase"
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
authors = ["Elliot Saba <[email protected]>"]
version = "1.2.1"
version = "1.2.2"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
16 changes: 1 addition & 15 deletions src/DockerRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,7 @@ function run_interactive(dr::DockerRunner, cmd::Cmd; stdin = nothing, stdout = n

try
mount_shards(dr; verbose=verbose)
if stdout isa IOBuffer
if !(stdin isa IOBuffer)
stdin = devnull
end
process = open(docker_cmd, "r", stdin)
@async begin
while !eof(process)
write(stdout, read(process))
end
end
wait(process)
return success(process)
else
return success(run(docker_cmd))
end
return success(run(docker_cmd))
finally
unmount_shards(dr; verbose=verbose)
# Cleanup permissions, if we need to.
Expand Down
2 changes: 2 additions & 0 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ abstract type Runner; end

export default_host_platform

const AnyRedirectable = Union{Base.AbstractCmd, Base.TTY, IOStream, IOBuffer}

# Host platform _must_ match the C++ string ABI of the binaries we get from the
# repositories. Note: when preferred_gcc_version=v"4" we can't really build for
# that C++ string ABI :-(
Expand Down
19 changes: 2 additions & 17 deletions src/UserNSRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function UserNSRunner(workspace_root::String;
sandbox_cmd = `$sandbox_cmd --verbose`
end
sandbox_cmd = `$sandbox_cmd --rootfs $(mpath)`
if cwd != nothing
if cwd !== nothing
sandbox_cmd = `$sandbox_cmd --cd $cwd`
end

Expand Down Expand Up @@ -182,7 +182,6 @@ function Base.read(ur::UserNSRunner, cmd; verbose=false)
return collect_stdout(oc)
end

const AnyRedirectable = Union{Base.AbstractCmd, Base.TTY, IOStream}
function run_interactive(ur::UserNSRunner, user_cmd::Cmd; stdin = nothing, stdout = nothing, stderr = nothing, verbose::Bool = false)
warn_priviledged()

Expand All @@ -204,21 +203,7 @@ function run_interactive(ur::UserNSRunner, user_cmd::Cmd; stdin = nothing, stdou

try
mount_shards(ur; verbose=verbose)
if stdout isa IOBuffer
if !(stdin isa IOBuffer)
stdin = devnull
end
process = open(cmd, "r", stdin)
@async begin
while !eof(process)
write(stdout, read(process))
end
end
wait(process)
return success(process)
else
return success(run(cmd))
end
return success(run(cmd))
finally
unmount_shards(ur)
end
Expand Down
17 changes: 17 additions & 0 deletions test/runners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ end
end
end

@testset "run_interactive" begin
platform = default_host_platform
io = IOBuffer()
@test run_interactive(preferred_runner()(mktempdir(); platform), `/bin/bash -c "echo hello world"`, stdout=io)
s = String(take!(io))
@test s == "hello world\n"
# Make sure that `run_interactive` consistently throws an error when the process fails,
# whatever is the type of `stdout`, or it consistently ignores failures if so requested.
# Ref: https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/201#issuecomment-1003192121
cmd = `/bin/bash -c "false"`
@test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd)
@test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer())
cmd = Cmd(`/bin/bash -c "false"`; ignorestatus=true)
@test !run_interactive(preferred_runner()(mktempdir(); platform), cmd)
@test !run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer())
end

if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true"
@info("Beginning full shard test... (this can take a while)")
platforms = supported_platforms()
Expand Down