Skip to content

Commit 6f3ccdd

Browse files
committed
Merge pull request #13506 from stevengj/buildspawn1
eval build.jl files in a separate Julia process for Pkg.build
2 parents c842e86 + 22e86cb commit 6f3ccdd

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

base/pkg/entry.jl

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,22 +725,66 @@ function warnbanner(msg...; label="[ WARNING ]", prefix="")
725725
warn(prefix="", "="^cols)
726726
end
727727

728-
function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
728+
function build!(pkgs::Vector, buildstream::IO, seen::Set)
729729
for pkg in pkgs
730730
pkg == "julia" && continue
731731
pkg in seen && continue
732-
build!(Read.requires_list(pkg),errs,push!(seen,pkg))
732+
build!(Read.requires_list(pkg),buildstream,push!(seen,pkg))
733733
Read.isinstalled(pkg) || throw(PkgError("$pkg is not an installed package"))
734734
path = abspath(pkg,"deps","build.jl")
735735
isfile(path) || continue
736-
info("Building $pkg")
737-
cd(dirname(path)) do
738-
try evalfile(path)
739-
catch err
740-
warnbanner(err, label="[ ERROR: $pkg ]")
736+
println(buildstream, path) # send to build process for evalfile
737+
flush(buildstream)
738+
end
739+
end
740+
741+
function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
742+
# To isolate the build from the running Julia process, we
743+
# execute the build.jl files in a separate process that
744+
# is sitting there waiting for paths to evaluate. Errors
745+
# are serialized to errfile for later retrieval into errs[pkg]
746+
errfile = tempname()
747+
close(open(errfile, "w")) # create empty file
748+
code = """
749+
open("$(escape_string(errfile))", "a") do f
750+
for path_ in eachline(STDIN)
751+
path = chomp(path_)
752+
pkg = basename(dirname(dirname(path)))
753+
try
754+
info("Building \$pkg")
755+
cd(dirname(path)) do
756+
evalfile(path)
757+
end
758+
catch err
759+
Base.Pkg.Entry.warnbanner(err, label="[ ERROR: \$pkg ]")
760+
serialize(f, pkg)
761+
serialize(f, err)
762+
end
763+
end
764+
end
765+
"""
766+
io, pobj = open(detach(`$(Base.julia_cmd())
767+
--history-file=no
768+
--color=$(Base.have_color ? "yes" : "no")
769+
--eval $code`), "w", STDOUT)
770+
try
771+
build!(pkgs, io, seen)
772+
close(io)
773+
wait(pobj)
774+
success(pobj) || error("Build process failed.")
775+
open(errfile, "r") do f
776+
while !eof(f)
777+
pkg = deserialize(f)
778+
err = deserialize(f)
741779
errs[pkg] = err
742780
end
743781
end
782+
catch
783+
kill(pobj)
784+
close(io)
785+
rethrow()
786+
finally
787+
isfile(errfile) && Base.rm(errfile)
744788
end
745789
end
746790

0 commit comments

Comments
 (0)