diff --git a/Project.toml b/Project.toml index 9edbef2f..90314a68 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BinaryBuilderBase" uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e" authors = ["Elliot Saba "] -version = "1.2.1" +version = "1.2.2" [deps] CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" diff --git a/src/DockerRunner.jl b/src/DockerRunner.jl index 5ce37fc3..3488cd5d 100644 --- a/src/DockerRunner.jl +++ b/src/DockerRunner.jl @@ -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. diff --git a/src/Runner.jl b/src/Runner.jl index 986163e2..14046a31 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -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 :-( diff --git a/src/UserNSRunner.jl b/src/UserNSRunner.jl index 3ea57f44..181404c4 100644 --- a/src/UserNSRunner.jl +++ b/src/UserNSRunner.jl @@ -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 @@ -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() @@ -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 diff --git a/test/runners.jl b/test/runners.jl index 7fd50339..ea2d9971 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -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()