Skip to content

Commit e1345f7

Browse files
fix output from runners to IOBuffer (#201)
* fix output from runners to IOBuffer * Update test/runners.jl Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com> * Revert "Revert "simplify `run_interactive`, `pipeline` can now accept an `IOBuffer`" (#199)" This reverts commit 769d8e2. * Add more tests for `run_interactive` Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com> Co-authored-by: Mosè Giordano <mose@gnu.org>
1 parent 769d8e2 commit e1345f7

File tree

5 files changed

+23
-33
lines changed

5 files changed

+23
-33
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BinaryBuilderBase"
22
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
33
authors = ["Elliot Saba <staticfloat@gmail.com>"]
4-
version = "1.2.1"
4+
version = "1.2.2"
55

66
[deps]
77
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"

src/DockerRunner.jl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,7 @@ function run_interactive(dr::DockerRunner, cmd::Cmd; stdin = nothing, stdout = n
212212

213213
try
214214
mount_shards(dr; verbose=verbose)
215-
if stdout isa IOBuffer
216-
if !(stdin isa IOBuffer)
217-
stdin = devnull
218-
end
219-
process = open(docker_cmd, "r", stdin)
220-
@async begin
221-
while !eof(process)
222-
write(stdout, read(process))
223-
end
224-
end
225-
wait(process)
226-
return success(process)
227-
else
228-
return success(run(docker_cmd))
229-
end
215+
return success(run(docker_cmd))
230216
finally
231217
unmount_shards(dr; verbose=verbose)
232218
# Cleanup permissions, if we need to.

src/Runner.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ abstract type Runner; end
33

44
export default_host_platform
55

6+
const AnyRedirectable = Union{Base.AbstractCmd, Base.TTY, IOStream, IOBuffer}
7+
68
# Host platform _must_ match the C++ string ABI of the binaries we get from the
79
# repositories. Note: when preferred_gcc_version=v"4" we can't really build for
810
# that C++ string ABI :-(

src/UserNSRunner.jl

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function UserNSRunner(workspace_root::String;
6262
sandbox_cmd = `$sandbox_cmd --verbose`
6363
end
6464
sandbox_cmd = `$sandbox_cmd --rootfs $(mpath)`
65-
if cwd != nothing
65+
if cwd !== nothing
6666
sandbox_cmd = `$sandbox_cmd --cd $cwd`
6767
end
6868

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

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

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

205204
try
206205
mount_shards(ur; verbose=verbose)
207-
if stdout isa IOBuffer
208-
if !(stdin isa IOBuffer)
209-
stdin = devnull
210-
end
211-
process = open(cmd, "r", stdin)
212-
@async begin
213-
while !eof(process)
214-
write(stdout, read(process))
215-
end
216-
end
217-
wait(process)
218-
return success(process)
219-
else
220-
return success(run(cmd))
221-
end
206+
return success(run(cmd))
222207
finally
223208
unmount_shards(ur)
224209
end

test/runners.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ end
7373
end
7474
end
7575

76+
@testset "run_interactive" begin
77+
platform = default_host_platform
78+
io = IOBuffer()
79+
@test run_interactive(preferred_runner()(mktempdir(); platform), `/bin/bash -c "echo hello world"`, stdout=io)
80+
s = String(take!(io))
81+
@test s == "hello world\n"
82+
# Make sure that `run_interactive` consistently throws an error when the process fails,
83+
# whatever is the type of `stdout`, or it consistently ignores failures if so requested.
84+
# Ref: https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/201#issuecomment-1003192121
85+
cmd = `/bin/bash -c "false"`
86+
@test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd)
87+
@test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer())
88+
cmd = Cmd(`/bin/bash -c "false"`; ignorestatus=true)
89+
@test !run_interactive(preferred_runner()(mktempdir(); platform), cmd)
90+
@test !run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer())
91+
end
92+
7693
if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true"
7794
@info("Beginning full shard test... (this can take a while)")
7895
platforms = supported_platforms()

0 commit comments

Comments
 (0)