Skip to content

Commit

Permalink
add deprecation mechanism for (io,p) = open(cmd)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed May 2, 2017
1 parent 94acb6f commit 505dec5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1324,5 +1324,18 @@ end

# END 0.6 deprecations

# BEGIN 0.7 deprecations

# 12807
start(::Union{Process, ProcessChain}) = 1
done(::Union{Process, ProcessChain}, i::Int) = (i == 3)
next(p::Union{Process, ProcessChain}, i::Int) = (getindex(p, i), i + 1)
@noinline function getindex(p::Union{Process, ProcessChain}, i::Int)
depwarn("open(cmd) now returns only a Process<:IO object", :getindex)
return i == 1 ? getfield(p, p.openstream) : p
end

# END 0.7 deprecations

# BEGIN 1.0 deprecations
# END 1.0 deprecations
13 changes: 13 additions & 0 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ mutable struct Process <: AbstractPipe
termsignal::Int32
exitnotify::Condition
closenotify::Condition
openstream::Symbol # for open(cmd) deprecation
function Process(cmd::Cmd, handle::Ptr{Void},
in::Union{Redirectable, Ptr{Void}},
out::Union{Redirectable, Ptr{Void}},
Expand Down Expand Up @@ -344,7 +345,9 @@ struct ProcessChain <: AbstractPipe
in::Redirectable
out::Redirectable
err::Redirectable
openstream::Symbol # for open(cmd) deprecation
ProcessChain(stdios::StdIOSet) = new(Process[], stdios[1], stdios[2], stdios[3])
ProcessChain(chain::ProcessChain, openstream::Symbol) = new(chain.processes, chain.in, chain.out, chain.err, openstream) # for open(cmd) deprecation
end
pipe_reader(p::ProcessChain) = p.out
pipe_writer(p::ProcessChain) = p.in
Expand Down Expand Up @@ -589,11 +592,21 @@ function open(cmds::AbstractCmd, mode::AbstractString="r", other::Redirectable=D
out = Pipe()
processes = spawn(cmds, (in,out,STDERR))
close(out.in)
if isa(processes, ProcessChain) # for open(cmd) deprecation
processes = ProcessChain(processes, :out)
else
processes.openstream = :out
end
elseif mode == "w"
in = Pipe()
out = other
processes = spawn(cmds, (in,out,STDERR))
close(in.out)
if isa(processes, ProcessChain) # for open(cmd) deprecation
processes = ProcessChain(processes, :in)
else
processes.openstream = :in
end
else
throw(ArgumentError("mode must be \"r\" or \"w\", not \"$mode\""))
end
Expand Down

0 comments on commit 505dec5

Please sign in to comment.