From ed7d3e409e3ecc02372df04bf6dd7d98e9992523 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 18 Sep 2020 00:18:52 +0200 Subject: [PATCH] Place Pkg.build logs in Pkg's scratchspace. (#2022) --- src/Operations.jl | 23 +++++++++++++++++++++-- test/new.jl | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index a46d32254e..fa5ff12e98 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -4,7 +4,7 @@ module Operations using UUIDs using Random: randstring -import LibGit2 +import LibGit2, Dates, TOML import REPL using REPL.TerminalMenus @@ -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)) diff --git a/test/new.jl b/test/new.jl index fb5d887a15..00eed27dd1 100644 --- a/test/new.jl +++ b/test/new.jl @@ -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 #