Skip to content

Commit b5f9787

Browse files
Merge pull request #4265 from JuliaLang/backports-release-1.12
2 parents 7802601 + 4d7c901 commit b5f9787

File tree

20 files changed

+514
-259
lines changed

20 files changed

+514
-259
lines changed

src/API.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
389389
manifest_resolve!(ctx.env.manifest, pkgs)
390390
ensure_resolved(ctx, ctx.env.manifest, pkgs)
391391
end
392-
392+
for pkg in pkgs
393+
update_source_if_set(ctx.env.project, pkg)
394+
end
393395
Operations.up(ctx, pkgs, level; skip_writing_project, preserve)
394396
return
395397
end

src/Apps/Apps.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ function _resolve(manifest::Manifest, pkgname=nothing)
7878
end
7979

8080
projectfile = joinpath(app_env_folder(), pkg.name, "Project.toml")
81-
sourcepath = source_path(app_manifest_file(), pkg)
8281

8382
# TODO: Add support for existing manifest
8483
# Create a manifest with the manifest entry
@@ -87,12 +86,8 @@ function _resolve(manifest::Manifest, pkgname=nothing)
8786
if isempty(ctx.env.project.deps)
8887
ctx.env.project.deps[pkg.name] = uuid
8988
end
90-
if isempty(ctx.env.manifest)
91-
ctx.env.manifest.deps[uuid] = pkg
92-
Pkg.resolve(ctx)
93-
else
94-
Pkg.instantiate(ctx)
95-
end
89+
ctx.env.manifest.deps[uuid] = pkg
90+
Pkg.resolve(ctx)
9691
end
9792

9893
# TODO: Julia path

src/Operations.jl

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,42 @@ end
222222
# This has to be done after the packages have been downloaded
223223
# since we need access to the Project file to read the information
224224
# about extensions
225-
function fixups_from_projectfile!(env::EnvCache)
225+
function fixups_from_projectfile!(ctx::Context)
226+
env = ctx.env
226227
for pkg in values(env.manifest)
227-
# isfile_casesenstive within locate_project_file used to error on Windows if given a
228-
# relative path so abspath it to be extra safe https://github.com/JuliaLang/julia/pull/55220
229-
project_file = Base.locate_project_file(abspath(source_path(env.manifest_file, pkg)))
230-
if project_file isa String && isfile(project_file)
231-
p = Types.read_project(project_file)
232-
pkg.weakdeps = p.weakdeps
233-
pkg.exts = p.exts
234-
pkg.entryfile = p.entryfile
235-
for (name, _) in p.weakdeps
228+
if ctx.julia_version !== VERSION && is_stdlib(pkg.uuid, ctx.julia_version)
229+
# Special handling for non-current julia_version resolving given the source for historical stdlibs
230+
# isn't available at this stage as Pkg thinks it should not be needed, so rely on STDLIBS_BY_VERSION
231+
stdlibs = Types.get_last_stdlibs(ctx.julia_version)
232+
p = stdlibs[pkg.uuid]
233+
pkg.weakdeps = Dict{String, Base.UUID}(stdlibs[uuid].name => uuid for uuid in p.weakdeps)
234+
# pkg.exts = p.exts # TODO: STDLIBS_BY_VERSION doesn't record this
235+
# pkg.entryfile = p.entryfile # TODO: STDLIBS_BY_VERSION doesn't record this
236+
for (name, _) in pkg.weakdeps
236237
if !haskey(p.deps, name)
237238
delete!(pkg.deps, name)
238239
end
239240
end
241+
else
242+
# normal mode based on project files.
243+
# isfile_casesenstive within locate_project_file used to error on Windows if given a
244+
# relative path so abspath it to be extra safe https://github.com/JuliaLang/julia/pull/55220
245+
sourcepath = source_path(env.manifest_file, pkg)
246+
if sourcepath === nothing
247+
pkgerror("could not find source path for package $(pkg.name) based on manifest $(env.manifest_file)")
248+
end
249+
project_file = Base.locate_project_file(abspath(sourcepath))
250+
if project_file isa String && isfile(project_file)
251+
p = Types.read_project(project_file)
252+
pkg.weakdeps = p.weakdeps
253+
pkg.exts = p.exts
254+
pkg.entryfile = p.entryfile
255+
for (name, _) in p.weakdeps
256+
if !haskey(p.deps, name)
257+
delete!(pkg.deps, name)
258+
end
259+
end
260+
end
240261
end
241262
end
242263
prune_manifest(env)
@@ -337,18 +358,22 @@ function collect_developed!(env::EnvCache, pkg::PackageSpec, developed::Vector{P
337358
source = project_rel_path(env, source_path(env.manifest_file, pkg))
338359
source_env = EnvCache(projectfile_path(source))
339360
pkgs = load_project_deps(source_env.project, source_env.project_file, source_env.manifest, source_env.manifest_file)
340-
for pkg in filter(is_tracking_path, pkgs)
361+
for pkg in pkgs
341362
if any(x -> x.uuid == pkg.uuid, developed)
342363
continue
343364
end
344-
# normalize path
345-
# TODO: If path is collected from project, it is relative to the project file
346-
# otherwise relative to manifest file....
347-
pkg.path = Types.relative_project_path(env.manifest_file,
348-
project_rel_path(source_env,
349-
source_path(source_env.manifest_file, pkg)))
350-
push!(developed, pkg)
351-
collect_developed!(env, pkg, developed)
365+
if is_tracking_path(pkg)
366+
# normalize path
367+
# TODO: If path is collected from project, it is relative to the project file
368+
# otherwise relative to manifest file....
369+
pkg.path = Types.relative_project_path(env.manifest_file,
370+
project_rel_path(source_env,
371+
source_path(source_env.manifest_file, pkg)))
372+
push!(developed, pkg)
373+
collect_developed!(env, pkg, developed)
374+
elseif is_tracking_repo(pkg)
375+
push!(developed, pkg)
376+
end
352377
end
353378
end
354379

@@ -1537,6 +1562,12 @@ function is_all_registered(registries::Vector{Registry.RegistryInstance}, pkgs::
15371562
end
15381563

15391564
function check_registered(registries::Vector{Registry.RegistryInstance}, pkgs::Vector{PackageSpec})
1565+
if isempty(registries) && !isempty(pkgs)
1566+
registry_pkgs = filter(tracking_registered_version, pkgs)
1567+
if !isempty(registry_pkgs)
1568+
pkgerror("no registries have been installed. Cannot resolve the following packages:\n$(join(map(pkg -> " " * err_rep(pkg), registry_pkgs), "\n"))")
1569+
end
1570+
end
15401571
pkg = is_all_registered(registries, pkgs)
15411572
if pkg isa PackageSpec
15421573
pkgerror("expected package $(err_rep(pkg)) to be registered")
@@ -1658,7 +1689,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
16581689
man_pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, preserve, ctx.julia_version)
16591690
update_manifest!(ctx.env, man_pkgs, deps_map, ctx.julia_version)
16601691
new_apply = download_source(ctx)
1661-
fixups_from_projectfile!(ctx.env)
1692+
fixups_from_projectfile!(ctx)
16621693

16631694
# After downloading resolutionary packages, search for (Julia)Artifacts.toml files
16641695
# and ensure they are all downloaded and unpacked as well:
@@ -1705,7 +1736,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Set{UUID};
17051736
pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, preserve, ctx.julia_version)
17061737
update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
17071738
new_apply = download_source(ctx)
1708-
fixups_from_projectfile!(ctx.env)
1739+
fixups_from_projectfile!(ctx)
17091740
download_artifacts(ctx; platform=platform, julia_version=ctx.julia_version)
17101741
write_env(ctx.env) # write env before building
17111742
show_update(ctx.env, ctx.registries; io=ctx.io)
@@ -1720,7 +1751,9 @@ function up_load_versions!(ctx::Context, pkg::PackageSpec, entry::PackageEntry,
17201751
entry.version !== nothing || return false # no version to set
17211752
if entry.pinned || level == UPLEVEL_FIXED
17221753
pkg.version = entry.version
1723-
pkg.tree_hash = entry.tree_hash
1754+
if pkg.path === nothing
1755+
pkg.tree_hash = entry.tree_hash
1756+
end
17241757
elseif entry.repo.source !== nothing || source_repo.source !== nothing # repo packages have a version but are treated specially
17251758
if source_repo.source !== nothing
17261759
pkg.repo = source_repo
@@ -1846,7 +1879,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec}, level::UpgradeLevel;
18461879
end
18471880
update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
18481881
new_apply = download_source(ctx)
1849-
fixups_from_projectfile!(ctx.env)
1882+
fixups_from_projectfile!(ctx)
18501883
download_artifacts(ctx, julia_version=ctx.julia_version)
18511884
write_env(ctx.env; skip_writing_project) # write env before building
18521885
show_update(ctx.env, ctx.registries; io=ctx.io, hidden_upgrades_info = true)
@@ -1892,7 +1925,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec})
18921925

18931926
update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
18941927
new = download_source(ctx)
1895-
fixups_from_projectfile!(ctx.env)
1928+
fixups_from_projectfile!(ctx)
18961929
download_artifacts(ctx; julia_version=ctx.julia_version)
18971930
write_env(ctx.env) # write env before building
18981931
show_update(ctx.env, ctx.registries; io=ctx.io)
@@ -1940,7 +1973,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; err_if_free=true)
19401973

19411974
update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
19421975
new = download_source(ctx)
1943-
fixups_from_projectfile!(ctx.env)
1976+
fixups_from_projectfile!(ctx)
19441977
download_artifacts(ctx)
19451978
write_env(ctx.env) # write env before building
19461979
show_update(ctx.env, ctx.registries; io=ctx.io)
@@ -2553,8 +2586,7 @@ end
25532586

25542587
function is_package_downloaded(manifest_file::String, pkg::PackageSpec; platform=HostPlatform())
25552588
sourcepath = source_path(manifest_file, pkg)
2556-
identifier = pkg.name !== nothing ? pkg.name : pkg.uuid
2557-
(sourcepath === nothing) && pkgerror("Could not locate the source code for the $(identifier) package. Are you trying to use a manifest generated by a different version of Julia?")
2589+
sourcepath === nothing && return false
25582590
isdir(sourcepath) || return false
25592591
check_artifacts_downloaded(sourcepath; platform) || return false
25602592
return true

src/REPLMode/argument_parsers.jl

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ let url = raw"((git|ssh|http(s)?)|(git@[\w\-\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git
5757
name_uuid = raw"[^@\#\s:]+\s*=\s*[^@\#\s:]+",
5858

5959
# Match a `#BRANCH` branch or tag specifier.
60-
branch = raw"\#\s*[^@\#\s]*",
60+
branch = raw"\#\s*[^@^:\s]+",
6161

6262
# Match an `@VERSION` version specifier.
6363
version = raw"@\s*[^@\#\s]*",
@@ -94,19 +94,34 @@ function parse_package_args(args::Vector{PackageToken}; add_or_dev=false)::Vecto
9494
# check for and apply PackageSpec modifier (e.g. `#foo` or `@v1.0.2`)
9595
function apply_modifier!(pkg::PackageSpec, args::Vector{PackageToken})
9696
(isempty(args) || args[1] isa PackageIdentifier) && return
97-
modifier = popfirst!(args)
98-
if modifier isa Subdir
99-
pkg.subdir = modifier.dir
100-
(isempty(args) || args[1] isa PackageIdentifier) && return
97+
parsed_subdir = false
98+
parsed_version = false
99+
parsed_rev = false
100+
while !isempty(args)
101101
modifier = popfirst!(args)
102-
end
103-
104-
if modifier isa VersionToken
105-
pkg.version = modifier.version
106-
elseif modifier isa Rev
107-
pkg.rev = modifier.rev
108-
else
109-
pkgerror("Package name/uuid must precede subdir specifier `$args`.")
102+
if modifier isa Subdir
103+
if parsed_subdir
104+
pkgerror("Multiple subdir specifiers `$args` found.")
105+
end
106+
pkg.subdir = modifier.dir
107+
(isempty(args) || args[1] isa PackageIdentifier) && return
108+
modifier = popfirst!(args)
109+
parsed_subdir = true
110+
elseif modifier isa VersionToken
111+
if parsed_version
112+
pkgerror("Multiple version specifiers `$args` found.")
113+
end
114+
pkg.version = modifier.version
115+
parsed_version = true
116+
elseif modifier isa Rev
117+
if parsed_rev
118+
pkgerror("Multiple revision specifiers `$args` found.")
119+
end
120+
pkg.rev = modifier.rev
121+
parsed_rev = true
122+
else
123+
pkgerror("Package name/uuid must precede subdir specifier `$args`.")
124+
end
110125
end
111126
end
112127

src/Types.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ end
8585

8686
Base.:(==)(r1::GitRepo, r2::GitRepo) =
8787
r1.source == r2.source && r1.rev == r2.rev && r1.subdir == r2.subdir
88-
88+
Base.hash(r::GitRepo, h::UInt) =
89+
foldr(hash, [r.source, r.rev, r.subdir], init=h)
8990

9091
mutable struct PackageSpec
9192
name::Union{Nothing,String}
@@ -119,11 +120,15 @@ PackageSpec(name::AbstractString, uuid::UUID) = PackageSpec(;name=name, uuid=uui
119120
PackageSpec(name::AbstractString, version::VersionTypes) = PackageSpec(;name=name, version=version)::PackageSpec
120121
PackageSpec(n::AbstractString, u::UUID, v::VersionTypes) = PackageSpec(;name=n, uuid=u, version=v)::PackageSpec
121122

123+
# XXX: These definitions are a bit fishy. It seems to be used in an `==` call in status printing
122124
function Base.:(==)(a::PackageSpec, b::PackageSpec)
123125
return a.name == b.name && a.uuid == b.uuid && a.version == b.version &&
124126
a.tree_hash == b.tree_hash && a.repo == b.repo && a.path == b.path &&
125127
a.pinned == b.pinned
126128
end
129+
function Base.hash(a::PackageSpec, h::UInt)
130+
return foldr(hash, [a.name, a.uuid, a.version, a.tree_hash, a.repo, a.path, a.pinned], init=h)
131+
end
127132

128133
function err_rep(pkg::PackageSpec)
129134
x = pkg.name !== nothing && pkg.uuid !== nothing ? x = "$(pkg.name) [$(string(pkg.uuid)[1:8])]" :

src/manifest.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ function destructure(manifest::Manifest)::Dict
288288
end
289289

290290
for (uuid, entry) in manifest
291+
# https://github.com/JuliaLang/Pkg.jl/issues/4086
292+
@assert !(entry.tree_hash !== nothing && entry.path !== nothing)
293+
291294
new_entry = something(entry.other, Dict{String,Any}())
292295
new_entry["uuid"] = string(uuid)
293296
entry!(new_entry, "version", entry.version)

test/apps.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ isolate(loaded_depot=true) do
3333
Pkg.Apps.rm("Rot13")
3434
@test Sys.which(exename) == nothing
3535
end
36+
37+
# https://github.com/JuliaLang/Pkg.jl/issues/4258
38+
Pkg.Apps.add(path=path)
39+
Pkg.Apps.develop(path=path)
40+
mv(joinpath(path, "src", "Rot13_edited.jl"), joinpath(path, "src", "Rot13.jl"); force=true)
41+
withenv("PATH" => string(joinpath(first(DEPOT_PATH), "bin"), sep, current_path)) do
42+
@test read(`$exename test`, String) == "Updated!\n"
43+
end
3644
end
3745
end
3846

0 commit comments

Comments
 (0)