Skip to content

Commit b3375c5

Browse files
KristofferCKristofferC
andcommitted
collect paths for input packages that are in a workspace (#4229)
Co-authored-by: KristofferC <[email protected]> (cherry picked from commit 2097cdb)
1 parent f4e4b50 commit b3375c5

File tree

7 files changed

+68
-29
lines changed

7 files changed

+68
-29
lines changed

src/API.jl

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -187,35 +187,30 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status, :why, :
187187
end
188188
end
189189

190-
function update_source_if_set(project, pkg)
190+
function update_source_if_set(env, pkg)
191+
project = env.project
191192
source = get(project.sources, pkg.name, nothing)
192-
source === nothing && return
193-
# This should probably not modify the dicts directly...
194-
if pkg.repo.source !== nothing
195-
source["url"] = pkg.repo.source
196-
end
197-
if pkg.repo.rev !== nothing
198-
source["rev"] = pkg.repo.rev
199-
end
200-
if pkg.path !== nothing
201-
source["path"] = pkg.path
202-
end
203-
if pkg.subdir !== nothing
204-
source["subdir"] = pkg.subdir
205-
end
206-
path, repo = get_path_repo(project, pkg.name)
207-
if path !== nothing
208-
pkg.path = path
209-
end
210-
if repo.source !== nothing
211-
pkg.repo.source = repo.source
212-
end
213-
if repo.rev !== nothing
214-
pkg.repo.rev = repo.rev
193+
if source !== nothing
194+
# This should probably not modify the dicts directly...
195+
if pkg.repo.source !== nothing
196+
source["url"] = pkg.repo.source
197+
end
198+
if pkg.repo.rev !== nothing
199+
source["rev"] = pkg.repo.rev
200+
end
201+
if pkg.path !== nothing
202+
source["path"] = pkg.path
203+
end
215204
end
216-
if repo.subdir !== nothing
217-
pkg.repo.subdir = repo.subdir
205+
206+
# Packages in manifest should have their paths set to the path in the manifest
207+
for (path, wproj) in env.workspace
208+
if wproj.uuid == pkg.uuid
209+
pkg.path = Types.relative_project_path(env.manifest_file, dirname(path))
210+
break
211+
end
218212
end
213+
return
219214
end
220215

221216
function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
@@ -257,7 +252,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
257252
if length(findall(x -> x.uuid == pkg.uuid, pkgs)) > 1
258253
pkgerror("it is invalid to specify multiple packages with the same UUID: $(err_rep(pkg))")
259254
end
260-
update_source_if_set(ctx.env.project, pkg)
255+
update_source_if_set(ctx.env, pkg)
261256
end
262257

263258
Operations.develop(ctx, pkgs, new_git; preserve=preserve, platform=platform)
@@ -311,7 +306,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; preserve::PreserveLevel=Op
311306
if length(findall(x -> x.uuid == pkg.uuid, pkgs)) > 1
312307
pkgerror("it is invalid to specify multiple packages with the same UUID: $(err_rep(pkg))")
313308
end
314-
update_source_if_set(ctx.env.project, pkg)
309+
update_source_if_set(ctx.env, pkg)
315310
end
316311

317312
Operations.add(ctx, pkgs, new_git; allow_autoprecomp, preserve, platform, target)
@@ -390,7 +385,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
390385
ensure_resolved(ctx, ctx.env.manifest, pkgs)
391386
end
392387
for pkg in pkgs
393-
update_source_if_set(ctx.env.project, pkg)
388+
update_source_if_set(ctx.env, pkg)
394389
end
395390
Operations.up(ctx, pkgs, level; skip_writing_project, preserve)
396391
return
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[workspace]
2+
projects = [
3+
"SubProjectA",
4+
"SubProjectB",
5+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "SubProjectA"
2+
uuid = "87654321-4321-4321-4321-210987654321"
3+
version = "0.1.0"
4+
5+
[deps]
6+
SubProjectB = "12345678-1234-1234-1234-123456789012"
7+
8+
[sources]
9+
SubProjectB = {path = "SubProjectB"}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module SubProjectA
2+
3+
using SubProjectB
4+
5+
greet() = "Hello from SubProjectA! " * SubProjectB.greet()
6+
7+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "SubProjectB"
2+
uuid = "12345678-1234-1234-1234-123456789012"
3+
version = "0.1.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module SubProjectB
2+
3+
greet() = "Hello from SubProjectB!"
4+
5+
end

test/workspaces.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,19 @@ end
163163
end
164164
end
165165

166+
@testset "workspace path resolution issue #4222" begin
167+
mktempdir() do dir
168+
path = copy_test_package(dir, "WorkspacePathResolution")
169+
cd(path) do
170+
with_current_env() do
171+
# First resolve SubProjectB (non-root project) without existing Manifest
172+
Pkg.activate("SubProjectB")
173+
@test !isfile("Manifest.toml")
174+
# Should be able to find SubProjectA and succeed
175+
Pkg.update()
176+
end
177+
end
178+
end
179+
end
180+
166181
end # module

0 commit comments

Comments
 (0)