diff --git a/CHANGELOG.md b/CHANGELOG.md index e33ed4b248..cab85f27d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/API.jl b/src/API.jl index d8853d02dd..c28750f569 100644 --- a/src/API.jl +++ b/src/API.jl @@ -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 @@ -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, @@ -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) diff --git a/src/Types.jl b/src/Types.jl index 859b93221a..8bda0065e8 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -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) diff --git a/src/project.jl b/src/project.jl index f7a7e83757..1b559898c2 100644 --- a/src/project.jl +++ b/src/project.jl @@ -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) diff --git a/test/sources.jl b/test/sources.jl index 311b203f00..3f319c4b3f 100644 --- a/test/sources.jl +++ b/test/sources.jl @@ -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