Skip to content

Commit 8b477db

Browse files
committed
Isolate each build.jl in a seperate Julia process
1 parent 7584ad5 commit 8b477db

File tree

1 file changed

+37
-51
lines changed

1 file changed

+37
-51
lines changed

base/pkg/entry.jl

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -580,26 +580,9 @@ function warnbanner(msg...; label="[ WARNING ]", prefix="")
580580
warn(prefix="", "="^cols)
581581
end
582582

583-
function build!(pkgs::Vector, buildstream::IO, seen::Set)
584-
for pkg in pkgs
585-
pkg == "julia" && continue
586-
pkg in seen ? continue : push!(seen,pkg)
587-
Read.isinstalled(pkg) || throw(PkgError("$pkg is not an installed package"))
588-
build!(Read.requires_list(pkg),buildstream,seen)
589-
path = abspath(pkg,"deps","build.jl")
590-
isfile(path) || continue
591-
println(buildstream, path) # send to build process for evalfile
592-
flush(buildstream)
593-
end
594-
end
595-
596-
function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
597-
# To isolate the build from the running Julia process, we
598-
# execute the build.jl files in a separate process that
599-
# is sitting there waiting for paths to evaluate. Errors
600-
# are serialized to errfile for later retrieval into errs[pkg]
601-
errfile = tempname()
602-
close(open(errfile, "w")) # create empty file
583+
function build(pkg::AbstractString, build_file::AbstractString, errfile::AbstractString)
584+
# To isolate the build from the running Julia process, we execute each build.jl file in
585+
# a separate process. Errors are serialized to errfile for later reporting.
603586
code = """
604587
empty!(Base.LOAD_PATH)
605588
append!(Base.LOAD_PATH, $(repr(Base.LOAD_PATH)))
@@ -608,49 +591,52 @@ function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
608591
empty!(Base.DL_LOAD_PATH)
609592
append!(Base.DL_LOAD_PATH, $(repr(Base.DL_LOAD_PATH)))
610593
open("$(escape_string(errfile))", "a") do f
611-
pkg = ""
612-
atexit(() -> !isempty(pkg) && run_build())
613-
function run_build()
614-
for path_ in eachline(STDIN)
615-
path = chomp(path_)
616-
pkg = basename(dirname(dirname(path)))
617-
try
618-
info("Building \$pkg")
619-
cd(dirname(path)) do
620-
evalfile(path)
621-
end
622-
catch err
623-
Base.Pkg.Entry.warnbanner(err, label="[ ERROR: \$pkg ]")
624-
serialize(f, pkg)
625-
serialize(f, err)
626-
end
594+
pkg, build_file = "$pkg", "$(escape_string(build_file))"
595+
try
596+
info("Building \$pkg")
597+
cd(dirname(build_file)) do
598+
evalfile(build_file)
627599
end
600+
catch err
601+
Base.Pkg.Entry.warnbanner(err, label="[ ERROR: \$pkg ]")
602+
serialize(f, pkg)
603+
serialize(f, err)
628604
end
629-
run_build()
630-
pkg = ""
631605
end
632606
"""
633-
io, pobj = open(pipeline(detach(`$(Base.julia_cmd()) -O0
634-
--compilecache=$(Bool(Base.JLOptions().use_compilecache) ? "yes" : "no")
635-
--history-file=no
636-
--color=$(Base.have_color ? "yes" : "no")
637-
--eval $code`), stderr=STDERR), "w", STDOUT)
607+
cmd = `$(Base.julia_cmd()) -O0
608+
--compilecache=$(Bool(Base.JLOptions().use_compilecache) ? "yes" : "no")
609+
--history-file=no
610+
--color=$(Base.have_color ? "yes" : "no")
611+
--eval $code`
612+
613+
success(pipeline(cmd, stderr=STDERR))
614+
end
615+
616+
function build!(pkgs::Vector, seen::Set, errfile::AbstractString)
617+
for pkg in pkgs
618+
pkg == "julia" && continue
619+
pkg in seen ? continue : push!(seen,pkg)
620+
Read.isinstalled(pkg) || throw(PkgError("$pkg is not an installed package"))
621+
build!(Read.requires_list(pkg), seen, errfile)
622+
path = abspath(pkg,"deps","build.jl")
623+
isfile(path) || continue
624+
build(pkg, path, errfile) || error("Build process failed.")
625+
end
626+
end
627+
628+
function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
629+
errfile = tempname()
630+
touch(errfile) # create empty file
638631
try
639-
build!(pkgs, io, seen)
640-
close(io)
641-
wait(pobj)
642-
success(pobj) || error("Build process failed.")
632+
build!(pkgs, seen, errfile)
643633
open(errfile, "r") do f
644634
while !eof(f)
645635
pkg = deserialize(f)
646636
err = deserialize(f)
647637
errs[pkg] = err
648638
end
649639
end
650-
catch err
651-
close(io)
652-
isa(err, PkgError) ? wait(pobj) : kill(pobj)
653-
rethrow(err)
654640
finally
655641
isfile(errfile) && Base.rm(errfile)
656642
end

0 commit comments

Comments
 (0)