Pkg.jl
Pkg.jl copied to clipboard
`Pkg.add` operates in-place on the arguments without notice
julia> using Pkg
julia> Pkg.activate(; temp=true, io=devnull)
julia> spec = Pkg.PackageSpec(; name = "Example", version = Pkg.Types.VersionSpec("0.5.3"));
julia> Pkg.add(Pkg.Types.Context(), [spec]; io=devnull)
julia> spec
PackageSpec(
name = Example
uuid = 7876af07-990d-54b4-ab0e-23690620f79a
tree_hash = 46e44e869b4d90b96bd8ed1fdcf32244fddfb6cc
version = v"0.5.3"
)
spec
changed after the call to Pkg.add
, it acquired the tree hash and the UUID. One could claim this method is internal, but this still violates the convention of appending !
to a function name when arguments are modified in-place.
https://github.com/JuliaLang/Pkg.jl/blob/423343402943074825392faa8b04a6d353204689/src/API.jl#L154
That's not the same method I used above.
The rub again is that the first arg Context()
methods aren't part of the public API. And adding them was rejected https://github.com/JuliaLang/Pkg.jl/pull/2952
So seems like you need to deepcopy
before passing the arg in to use this internal method
The rub again is that the first arg Context() methods aren't part of the public API.
In fact I said
One could claim this method is internal, but this still violates the convention of appending
!
to a function name when arguments are modified in-place.
So seems like you need to
deepcopy
before passing the arg in to use this internal method
Which is what I had done before opening the issue: https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/250. But discovering that a method not following the naming convention was modifying my specs, just to make me run into another Pkg bug #3113, wasn't exactly fun