Skip to content

Commit

Permalink
Place Pkg.build logs in Pkg's scratchspace. (JuliaLang#2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Sep 17, 2020
1 parent c2c9980 commit ed7d3e4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Operations

using UUIDs
using Random: randstring
import LibGit2
import LibGit2, Dates, TOML

import REPL
using REPL.TerminalMenus
Expand Down Expand Up @@ -924,7 +924,26 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve
nothing :
gen_target_project(ctx, pkg, source_path, "build")

log_file = splitext(build_file)[1] * ".log"
# Put log output in Pkg's scratchspace if the package is content adressed
# by tree sha and in the build directory if it is tracked by path etc.
entry = manifest_info(ctx, uuid)
if entry !== nothing && entry.tree_hash !== nothing
key = string(entry.tree_hash)
PkgUUID = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
scratch = joinpath(depots1(), "scratchspaces", PkgUUID, key)
mkpath(scratch)
log_file = joinpath(scratch, "build.log")
# Associate the logfile with the package beeing built
dict = Dict{String,Any}(scratch => [
Dict{String,Any}("time" => Dates.now(), "parent_projects" => [projectfile_path(source_path)])
])
open(joinpath(depots1(), "logs", "scratch_usage.toml"), "a") do io
TOML.print(io, dict)
end
else
log_file = splitext(build_file)[1] * ".log"
end

printpkgstyle(ctx, :Building,
rpad(name * " ", max_name + 1, "") * "" * Types.pathrepr(log_file))

Expand Down
21 changes: 21 additions & 0 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,27 @@ end
Pkg.activate(package_path)
@test_throws PkgError Pkg.build()
end end

# Build log location
isolate(loaded_depot=true) do; mktempdir() do tmp
path = git_init_package(tmp, joinpath(@__DIR__, "test_packages", "FailBuild"))
# Log file in the directory when it is deved
Pkg.develop(path=path; io=devnull)
log_file_dev = joinpath(path, "deps", "build.log")
@test !isfile(log_file_dev)
@test_throws PkgError Pkg.build("FailBuild"; io=devnull)
@test isfile(log_file_dev)
@test occursin("oops", read(log_file_dev, String))
# Log file in scratchspace when added
addpath = dirname(dirname(Base.find_package("FailBuild")))
log_file_add = joinpath(path, "deps", "build.log")
@test_throws PkgError Pkg.add(path=path; io=devnull)
@test !isfile(joinpath(Base.find_package("FailBuild"), "..", "..", "deps", "build.log"))
log_file_add = joinpath(DEPOT_PATH[1], "scratchspaces",
"44cfe95a-1eb2-52ea-b672-e2afdf69b78f", "f99d57aad0e5eb2434491b47bac92bb88d463001", "build.log")
@test isfile(log_file_add)
@test occursin("oops", read(log_file_add, String))
end end
end

#
Expand Down

0 comments on commit ed7d3e4

Please sign in to comment.