Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add entries to [sources] automatically if package is added by URL or devved #3826

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Pkg v1.12 Release Notes
=======================

- It is now possible to specify "sources" for packages in a `[sources]` section in Project.toml.
This can be used to add non-registered normal or test dependencies. Packages are also automatically added to `[sources]` when they are added by url or devved.
- Pkg now has support for "workspaces" which is a way to resolve multiple project files into a single manifest.
The functions `Pkg.status`, `Pkg.why`, `Pkg.instantiate`, `Pkg.precompile` (and their REPL variants) have been updated
to take a `workspace` option. Read more about this feature in the manual about the TOML-files.
Expand Down
33 changes: 24 additions & 9 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,26 @@ end
function update_source_if_set(project, pkg)
source = get(project.sources, pkg.name, nothing)
source === nothing && return
# This should probably not modify the dicts directly...
if pkg.repo.source !== nothing
source["url"] = pkg.repo.source
end
if pkg.repo.rev !== nothing
source["rev"] = pkg.repo.rev
end
if pkg.path !== nothing
source["path"] = pkg.path
if pkg.repo == GitRepo()
delete!(project.sources, pkg.name)
else
# This should probably not modify the dicts directly...
if pkg.repo.source !== nothing
source["url"] = pkg.repo.source
delete!(source, "path")
end
if pkg.repo.rev !== nothing
source["rev"] = pkg.repo.rev
delete!(source, "path")
end
if pkg.repo.subdir !== nothing
source["subdir"] = pkg.repo.subdir
end
if pkg.path !== nothing
source["path"] = pkg.path
delete!(source, "url")
delete!(source, "rev")
end
end
path, repo = get_path_repo(project, pkg.name)
if path !== nothing
Expand All @@ -205,6 +216,9 @@ function update_source_if_set(project, pkg)
if repo.rev !== nothing
pkg.repo.rev = repo.rev
end
if repo.subdir !== nothing
pkg.repo.subdir = repo.subdir
end
end

function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
Expand Down Expand Up @@ -416,6 +430,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwar
pkgerror("pinning a package requires a single version, not a versionrange")
end
end
update_source_if_set(ctx.env.project, pkg)
end

project_deps_resolve!(ctx.env, pkgs)
Expand Down
8 changes: 8 additions & 0 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,14 @@ function write_env(env::EnvCache; update_undo=true,
@assert entry.repo.subdir == repo.subdir
end
end
if entry.path !== nothing
env.project.sources[pkg] = Dict("path" => entry.path)
elseif entry.repo != GitRepo()
d = Dict("url" => entry.repo.source)
entry.repo.rev !== nothing && (d["rev"] = entry.repo.rev)
entry.repo.subdir !== nothing && (d["subdir"] = entry.repo.subdir)
env.project.sources[pkg] = d
end
end

if (env.project != env.original_project) && (!skip_writing_project)
Expand Down
2 changes: 1 addition & 1 deletion src/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ read_project_compat(raw, project::Project) =

read_project_sources(::Nothing, project::Project) = Dict{String,Any}()
function read_project_sources(raw::Dict{String,Any}, project::Project)
valid_keys = ("path", "url", "rev")
valid_keys = ("path", "url", "rev", "subdir")
sources = Dict{String,Any}()
for (name, source) in raw
if !(source isa AbstractDict)
Expand Down
2 changes: 1 addition & 1 deletion test/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ temp_pkg_dir() do project_path
cp("Project.toml.bak", "Project.toml"; force=true)
cp("BadManifest.toml", "Manifest.toml"; force=true)
Pkg.resolve()
@test Pkg.project().sources["Example"] == Dict("url" => "https://github.com/JuliaLang/Example.jl")
@test Pkg.project().sources["Example"] == Dict("rev" => "master", "url" => "https://github.com/JuliaLang/Example.jl")
@test Pkg.project().sources["LocalPkg"] == Dict("path" => "LocalPkg")
end
end
Expand Down
Loading