From f6258f5e34ed09640262571062e91554d8b2cec9 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Thu, 30 Dec 2021 15:36:44 +0100 Subject: [PATCH 1/4] fix output from runners to IOBuffer --- src/Runner.jl | 2 ++ src/UserNSRunner.jl | 1 - test/runners.jl | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) 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..93cbfe33 100644 --- a/src/UserNSRunner.jl +++ b/src/UserNSRunner.jl @@ -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() diff --git a/test/runners.jl b/test/runners.jl index 7fd50339..3b921480 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -322,3 +322,10 @@ end end end end + +@testset "outptut runner" begin + io = IOBuffer() + run_interactive(BinaryBuilderBase.preferred_runner()(mktempdir(); platform=Platform("x86_64", "linux"; libc="musl")), `/bin/bash -c "echo \$PATH"`, stdout=io) + s = String(take!(io)) + @test !isempty(s) +end From e93a4fe060070795d57d8d76cbe6ed771dbe2d7e Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 30 Dec 2021 15:43:53 +0100 Subject: [PATCH 2/4] Update test/runners.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mosè Giordano --- test/runners.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runners.jl b/test/runners.jl index 3b921480..da812166 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -325,7 +325,7 @@ end @testset "outptut runner" begin io = IOBuffer() - run_interactive(BinaryBuilderBase.preferred_runner()(mktempdir(); platform=Platform("x86_64", "linux"; libc="musl")), `/bin/bash -c "echo \$PATH"`, stdout=io) + run_interactive(BinaryBuilderBase.preferred_runner()(mktempdir(); platform=Platform("x86_64", "linux"; libc="musl")), `/bin/bash -c "echo hello world"`, stdout=io) s = String(take!(io)) - @test !isempty(s) + @test s == "hello world\n" end From fac19946c207e734f20eee5a2422c671ef2ad1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Thu, 30 Dec 2021 23:50:01 +0100 Subject: [PATCH 3/4] Revert "Revert "simplify `run_interactive`, `pipeline` can now accept an `IOBuffer`" (#199)" This reverts commit 769d8e2f55f48a74728d05355bb9e2c72373aefd. --- src/DockerRunner.jl | 16 +--------------- src/UserNSRunner.jl | 18 ++---------------- 2 files changed, 3 insertions(+), 31 deletions(-) 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/UserNSRunner.jl b/src/UserNSRunner.jl index 93cbfe33..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 @@ -203,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 From a6094a2ee09c675597fe17fefebd58a23576c5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Fri, 31 Dec 2021 00:00:44 +0100 Subject: [PATCH 4/4] Add more tests for `run_interactive` --- Project.toml | 2 +- test/runners.jl | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) 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/test/runners.jl b/test/runners.jl index da812166..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() @@ -322,10 +339,3 @@ end end end end - -@testset "outptut runner" begin - io = IOBuffer() - run_interactive(BinaryBuilderBase.preferred_runner()(mktempdir(); platform=Platform("x86_64", "linux"; libc="musl")), `/bin/bash -c "echo hello world"`, stdout=io) - s = String(take!(io)) - @test s == "hello world\n" -end