Skip to content

Commit

Permalink
Merge pull request JuliaLang#13506 from stevengj/buildspawn1
Browse files Browse the repository at this point in the history
eval build.jl files in a separate Julia process for Pkg.build
  • Loading branch information
stevengj committed Oct 9, 2015
2 parents c842e86 + 22e86cb commit 6f3ccdd
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,22 +725,66 @@ function warnbanner(msg...; label="[ WARNING ]", prefix="")
warn(prefix="", "="^cols)
end

function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
function build!(pkgs::Vector, buildstream::IO, seen::Set)
for pkg in pkgs
pkg == "julia" && continue
pkg in seen && continue
build!(Read.requires_list(pkg),errs,push!(seen,pkg))
build!(Read.requires_list(pkg),buildstream,push!(seen,pkg))
Read.isinstalled(pkg) || throw(PkgError("$pkg is not an installed package"))
path = abspath(pkg,"deps","build.jl")
isfile(path) || continue
info("Building $pkg")
cd(dirname(path)) do
try evalfile(path)
catch err
warnbanner(err, label="[ ERROR: $pkg ]")
println(buildstream, path) # send to build process for evalfile
flush(buildstream)
end
end

function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
# To isolate the build from the running Julia process, we
# execute the build.jl files in a separate process that
# is sitting there waiting for paths to evaluate. Errors
# are serialized to errfile for later retrieval into errs[pkg]
errfile = tempname()
close(open(errfile, "w")) # create empty file
code = """
open("$(escape_string(errfile))", "a") do f
for path_ in eachline(STDIN)
path = chomp(path_)
pkg = basename(dirname(dirname(path)))
try
info("Building \$pkg")
cd(dirname(path)) do
evalfile(path)
end
catch err
Base.Pkg.Entry.warnbanner(err, label="[ ERROR: \$pkg ]")
serialize(f, pkg)
serialize(f, err)
end
end
end
"""
io, pobj = open(detach(`$(Base.julia_cmd())
--history-file=no
--color=$(Base.have_color ? "yes" : "no")
--eval $code`), "w", STDOUT)
try
build!(pkgs, io, seen)
close(io)
wait(pobj)
success(pobj) || error("Build process failed.")
open(errfile, "r") do f
while !eof(f)
pkg = deserialize(f)
err = deserialize(f)
errs[pkg] = err
end
end
catch
kill(pobj)
close(io)
rethrow()
finally
isfile(errfile) && Base.rm(errfile)
end
end

Expand Down

0 comments on commit 6f3ccdd

Please sign in to comment.