julia icon indicating copy to clipboard operation
julia copied to clipboard

Coverage isn't generated if tracked path is in a symlink

Open IanButterworth opened this issue 2 years ago • 6 comments

testing: Test Failed at /Users/runner/work/Pkg.jl/Pkg.jl/test/pkg.jl:244
  Expression: any(endswith(".cov"), readdir(pkgdir))

https://github.com/JuliaLang/Pkg.jl/actions/runs/7071386764/job/19249051912

Probably related to https://github.com/JuliaLang/julia/pull/52123

IanButterworth avatar Dec 08 '23 20:12 IanButterworth

This was introduced by https://github.com/JuliaLang/julia/pull/52140

It seems to be that on macos calling our c function abspath on /var/folders paths converts them to /private/var/folders So the tracking path gets mutated, but the function location doesn't seem to go through abspath.

% ./julia --code-coverage=@/var/folders
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.0-DEV.1104 (2023-12-15)
 _/ |\__'_|_|_|\__'_|  |  Commit d0efc5cd29 (3 days old master)
|__/                   |

julia> unsafe_string(Base.JLOptions().tracked_path)
"/private/var/folders"

julia> include("/var/folders/test/test.jl")
foo (generic function with 1 method)

julia> @functionloc foo()
("/var/folders/test/test.jl", 1)
julia> include("/private/var/folders/test/test.jl")
foo (generic function with 1 method)

julia> @functionloc foo()
("/private/var/folders/test/test.jl", 1)

IanButterworth avatar Dec 18 '23 18:12 IanButterworth

It's not clear to me why Pkg CI isn't failing in the same way on macos on buildkite here.

IanButterworth avatar Dec 18 '23 18:12 IanButterworth

The julia function abspath doesn't add /private

julia> abspath(mktempdir())
"/var/folders/1z/jf841bdj73bdj3vk7kc7f_3w0000gn/T/jl_bFNXp8"

Perhaps the fix is to stop the c function abspath calling realpath?

https://github.com/JuliaLang/julia/blob/67c7843d8ca8e4cc1a3565e36b4e5b7339f6e4b2/src/init.c#L546


It also affects the way to specify the current dir with a lone @

ian@Ians-MBP test % pwd
/var/folders/test
ian@Ians-MBP test % /Users/ian/Documents/GitHub/julia/julia --code-coverage=@ -E "unsafe_string((Base.JLOptions()).tracked_path)"
"/private/var/folders/test/"

IanButterworth avatar Dec 18 '23 18:12 IanButterworth

The fix for this seems to be

  • rename the init.c func abspath -> absrealpath
  • make a new abspath that doesn't call realpath and use that for tracked_path

In the meantime we can work around it in Pkg by using realpath for tempdirs in the test harnesses https://github.com/JuliaLang/Pkg.jl/pull/3734

IanButterworth avatar Dec 19 '23 21:12 IanButterworth

@IanButterworth, https://github.com/JuliaLang/julia/pull/52574 is now merged, are we ready for "step 2" in the previous comment?

KristofferC avatar Apr 22 '24 13:04 KristofferC

I think it can be dropped off the 1.11 milestone. It's worked around in Pkg and otherwise a bit of an edge case as I can't imagine many people store their packages in symlinked dirs and run code coverage locally

IanButterworth avatar May 13 '24 20:05 IanButterworth