Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4f55203

Browse files
committedMay 29, 2018
make sure we error on build if a package fails to build (#298)
1 parent 2edd482 commit 4f55203

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed
 

‎stdlib/Pkg/src/Operations.jl

+12-3
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve
843843
sort!(builds, by = build -> order[first(build)])
844844
max_name = isempty(builds) ? 0 : maximum(textwidth.([build[2] for build in builds]))
845845
# build each package verions in a child process
846+
build_succeeded = true
846847
for (uuid, name, hash_or_path, build_file) in builds
847848
log_file = splitext(build_file)[1] * ".log"
848849
printpkgstyle(ctx, :Building,
@@ -861,16 +862,24 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve
861862
--compiled-modules=$(Bool(Base.JLOptions().use_compiled_modules) ? "yes" : "no")
862863
--eval $code
863864
```
864-
run_build = () -> begin
865-
open(log_file, "w") do log
865+
run_build = () ->begin
866+
ok = open(log_file, "w") do log
866867
success(pipeline(cmd, stdout=log, stderr=log))
867-
end ? Base.rm(log_file, force=true) :
868+
end
869+
if ok
870+
Base.rm(log_file, force=true)
871+
else
868872
@error("Error building `$name`; see log file for further info")
873+
build_succeeded = false
874+
end
869875
end
870876
with_dependencies_loadable_at_toplevel(ctx, PackageSpec(name, uuid); might_need_to_resolve=might_need_to_resolve) do
871877
run_build()
872878
end
873879
end
880+
if !build_succeeded
881+
cmderror("at least one package failed to build")
882+
end
874883
return
875884
end
876885

‎stdlib/Pkg/test/pkg.jl

+17
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ temp_pkg_dir() do project_path
180180
end
181181
end
182182
end
183+
184+
@testset "failing building a package should throw" begin
185+
mktempdir() do path
186+
try
187+
cd(path) do
188+
pushfirst!(LOAD_PATH, Base.parse_load_path("@"))
189+
Pkg.generate("FailBuildPkg")
190+
cd("FailBuildPkg") do
191+
write_build(pwd(), "error()")
192+
@test_throws CommandError Pkg.build()
193+
end
194+
end
195+
finally
196+
popfirst!(LOAD_PATH)
197+
end
198+
end
199+
end
183200
end
184201

185202
temp_pkg_dir() do project_path

‎stdlib/Pkg/test/utils.jl

+6
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ function cd_tempdir(f)
3434
end
3535

3636
isinstalled(pkg) = Base.locate_package(Base.PkgId(pkg.uuid, pkg.name)) !== nothing
37+
38+
function write_build(path, content)
39+
build_filename = joinpath(path, "deps", "build.jl")
40+
mkpath(dirname(build_filename))
41+
write(build_filename, content)
42+
end

0 commit comments

Comments
 (0)
Please sign in to comment.