Skip to content

Commit 01690b5

Browse files
authored
make .path field consistently be relative manifest and convert to project relative upon writing to a project file (#4427)
1 parent 3306ed5 commit 01690b5

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

src/API.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function update_source_if_set(env, pkg)
225225
if pkg.subdir !== nothing
226226
source["subdir"] = pkg.subdir
227227
end
228-
path, repo = get_path_repo(project, pkg.name)
228+
path, repo = get_path_repo(project, env.project_file, env.manifest_file, pkg.name)
229229
if path !== nothing
230230
pkg.path = path
231231
end
@@ -397,13 +397,13 @@ end
397397
function append_all_pkgs!(pkgs, ctx, mode)
398398
if mode == PKGMODE_PROJECT || mode == PKGMODE_COMBINED
399399
for (name::String, uuid::UUID) in ctx.env.project.deps
400-
path, repo = get_path_repo(ctx.env.project, name)
400+
path, repo = get_path_repo(ctx.env.project, ctx.env.project_file, ctx.env.manifest_file, name)
401401
push!(pkgs, PackageSpec(name = name, uuid = uuid, path = path, repo = repo))
402402
end
403403
end
404404
if mode == PKGMODE_MANIFEST || mode == PKGMODE_COMBINED
405405
for (uuid, entry) in ctx.env.manifest
406-
path, repo = get_path_repo(ctx.env.project, entry.name)
406+
path, repo = get_path_repo(ctx.env.project, ctx.env.project_file, ctx.env.manifest_file, entry.name)
407407
push!(pkgs, PackageSpec(name = entry.name, uuid = uuid, path = path, repo = repo))
408408
end
409409
end

src/Operations.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function load_project_deps(
148148

149149
for (name::String, uuid::UUID) in project.deps
150150
findfirst(pkg -> pkg.uuid == uuid, pkgs) === nothing || continue # do not duplicate packages
151-
path, repo = get_path_repo(project, name)
151+
path, repo = get_path_repo(project, project_file, manifest_file, name)
152152
entry = manifest_info(manifest, uuid)
153153
push!(
154154
pkgs_direct, entry === nothing ?
@@ -197,7 +197,7 @@ function load_all_deps(
197197
pkgs = load_manifest_deps(env.manifest, pkgs; preserve = preserve)
198198
# Sources takes presedence over the manifest...
199199
for pkg in pkgs
200-
path, repo = get_path_repo(env.project, pkg.name)
200+
path, repo = get_path_repo(env.project, env.project_file, env.manifest_file, pkg.name)
201201
if path !== nothing
202202
pkg.path = path
203203
end
@@ -363,7 +363,7 @@ function reset_all_compat!(proj::Project)
363363
return nothing
364364
end
365365

366-
function collect_project(pkg::Union{PackageSpec, Nothing}, path::String, julia_version)
366+
function collect_project(pkg::Union{PackageSpec, Nothing}, path::String, manifest_file::String, julia_version)
367367
deps = PackageSpec[]
368368
weakdeps = Set{UUID}()
369369
project_file = projectfile_path(path; strict = true)
@@ -373,9 +373,9 @@ function collect_project(pkg::Union{PackageSpec, Nothing}, path::String, julia_v
373373
pkgerror("julia version requirement for package at `$path` not satisfied: compat entry \"julia = $(get_compat_str(project, "julia"))\" does not include Julia version $julia_version")
374374
end
375375
for (name, uuid) in project.deps
376-
path, repo = get_path_repo(project, name)
376+
dep_path, repo = get_path_repo(project, project_file, manifest_file, name)
377377
vspec = get_compat(project, name)
378-
push!(deps, PackageSpec(name = name, uuid = uuid, version = vspec, path = path, repo = repo))
378+
push!(deps, PackageSpec(name = name, uuid = uuid, version = vspec, path = dep_path, repo = repo))
379379
end
380380
for (name, uuid) in project.weakdeps
381381
vspec = get_compat(project, name)
@@ -439,15 +439,15 @@ function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UU
439439
weak_map = Dict{UUID, Set{UUID}}()
440440

441441
uuid = Types.project_uuid(env)
442-
deps, weakdeps = collect_project(env.pkg, dirname(env.project_file), julia_version)
442+
deps, weakdeps = collect_project(env.pkg, dirname(env.project_file), env.manifest_file, julia_version)
443443
deps_map[uuid] = deps
444444
weak_map[uuid] = weakdeps
445445
names[uuid] = env.pkg === nothing ? "project" : env.pkg.name
446446

447447
for (path, project) in env.workspace
448448
uuid = Types.project_uuid(project, path)
449449
pkg = project.name === nothing ? nothing : PackageSpec(name = project.name, uuid = uuid)
450-
deps, weakdeps = collect_project(pkg, path, julia_version)
450+
deps, weakdeps = collect_project(pkg, path, env.manifest_file, julia_version)
451451
deps_map[Types.project_uuid(env)] = deps
452452
weak_map[Types.project_uuid(env)] = weakdeps
453453
names[uuid] = project.name === nothing ? "project" : project.name
@@ -485,7 +485,7 @@ function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UU
485485
end
486486
pkgerror(error_msg)
487487
end
488-
deps, weakdeps = collect_project(pkg, path, julia_version)
488+
deps, weakdeps = collect_project(pkg, path, env.manifest_file, julia_version)
489489
deps_map[pkg.uuid] = deps
490490
weak_map[pkg.uuid] = weakdeps
491491
end
@@ -2081,7 +2081,7 @@ function up(
20812081
# TODO check all pkg.version == VersionSpec()
20822082
# set version constraints according to `level`
20832083
for pkg in pkgs
2084-
source_path, source_repo = get_path_repo(ctx.env.project, pkg.name)
2084+
source_path, source_repo = get_path_repo(ctx.env.project, ctx.env.project_file, ctx.env.manifest_file, pkg.name)
20852085
entry = manifest_info(ctx.env.manifest, pkg.uuid)
20862086
new = up_load_versions!(ctx, pkg, entry, source_path, source_repo, level)
20872087
new && push!(new_git, pkg.uuid) #TODO put download + push! in utility function
@@ -2333,7 +2333,8 @@ end
23332333
function abspath!(env::EnvCache, project::Project)
23342334
for (key, entry) in project.sources
23352335
if haskey(entry, "path")
2336-
entry["path"] = project_rel_path(env, entry["path"])
2336+
# Paths in project sources are project-relative, so join with project_file dir, not manifest_file dir
2337+
entry["path"] = normpath(joinpath(dirname(env.project_file), entry["path"]))
23372338
end
23382339
end
23392340
return project

src/Types.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,22 @@ function EnvCache(env::Union{Nothing, String} = nothing)
442442
return env′
443443
end
444444

445+
# Convert a path from project-relative to manifest-relative
446+
# If path is absolute, returns it as-is
447+
function project_path_to_manifest_path(project_file::String, manifest_file::String, path::String)
448+
isabspath(path) && return path
449+
abs_path = Pkg.safe_realpath(joinpath(dirname(project_file), path))
450+
return relpath(abs_path, Pkg.safe_realpath(dirname(manifest_file)))
451+
end
452+
453+
# Convert a path from manifest-relative to project-relative
454+
# If path is absolute, returns it as-is
455+
function manifest_path_to_project_path(project_file::String, manifest_file::String, path::String)
456+
isabspath(path) && return path
457+
abs_path = Pkg.safe_realpath(joinpath(dirname(manifest_file), path))
458+
return relpath(abs_path, Pkg.safe_realpath(dirname(project_file)))
459+
end
460+
445461
include("project.jl")
446462
include("manifest.jl")
447463

@@ -1281,7 +1297,7 @@ function write_env(
12811297
)
12821298
# Verify that the generated manifest is consistent with `sources`
12831299
for (pkg, uuid) in env.project.deps
1284-
path, repo = get_path_repo(env.project, pkg)
1300+
path, repo = get_path_repo(env.project, env.project_file, env.manifest_file, pkg)
12851301
entry = manifest_info(env.manifest, uuid)
12861302
if path !== nothing
12871303
@assert normpath(entry.path) == normpath(path)
@@ -1296,7 +1312,9 @@ function write_env(
12961312
end
12971313
if entry !== nothing
12981314
if entry.path !== nothing
1299-
env.project.sources[pkg] = Dict("path" => entry.path)
1315+
# Convert path from manifest-relative to project-relative before writing
1316+
project_relative_path = manifest_path_to_project_path(env.project_file, env.manifest_file, entry.path)
1317+
env.project.sources[pkg] = Dict("path" => project_relative_path)
13001318
elseif entry.repo != GitRepo()
13011319
d = Dict{String, String}()
13021320
entry.repo.source !== nothing && (d["url"] = entry.repo.source)

src/project.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
listed_deps(project::Project; include_weak::Bool) =
55
vcat(collect(keys(project.deps)), collect(keys(project.extras)), include_weak ? collect(keys(project.weakdeps)) : String[])
66

7-
function get_path_repo(project::Project, name::String)
7+
function get_path_repo(project::Project, project_file::String, manifest_file::String, name::String)
88
source = get(project.sources, name, nothing)
99
if source === nothing
1010
return nothing, GitRepo()
@@ -17,6 +17,10 @@ function get_path_repo(project::Project, name::String)
1717
pkgerror("`path` and `url` are conflicting specifications")
1818
end
1919
repo = GitRepo(url, rev, subdir)
20+
# Convert path from project-relative to manifest-relative
21+
if path !== nothing
22+
path = project_path_to_manifest_path(project_file, manifest_file, path)
23+
end
2024
return path, repo
2125
end
2226

test/workspaces.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ temp_pkg_dir() do project_path
2626
Pkg.develop(path = "PrivatePackage")
2727
d = TOML.parsefile("Project.toml")
2828
d["workspace"] = Dict("projects" => ["test", "docs", "benchmarks", "PrivatePackage"])
29-
abs_path = abspath("PrivatePackage") # TODO: Make relative after #3842 is fixed
30-
d["sources"] = Dict("PrivatePackage" => Dict("path" => abs_path))
29+
d["sources"] = Dict("PrivatePackage" => Dict("path" => "PrivatePackage"))
3130
Pkg.Types.write_project(d, "Project.toml")
3231
write(
3332
"src/MonorepoSub.jl", """
@@ -105,8 +104,7 @@ temp_pkg_dir() do project_path
105104
Pkg.generate("TestSpecificPackage")
106105
Pkg.develop(path = "TestSpecificPackage")
107106
d = TOML.parsefile("test/Project.toml")
108-
abs_pkg = abspath("TestSpecificPackage") # TODO: Make relative after #3842 is fixed
109-
d["sources"] = Dict("TestSpecificPackage" => Dict("path" => abs_pkg))
107+
d["sources"] = Dict("TestSpecificPackage" => Dict("path" => "../TestSpecificPackage"))
110108
Pkg.Types.write_project(d, "test/Project.toml")
111109

112110
@test !isfile("test/Manifest.toml")

0 commit comments

Comments
 (0)