Skip to content

Commit 13ed937

Browse files
authored
Merge pull request #2629 from JuliaLang/kc/1.7
Backports for 1.7, take 2.
2 parents 452c367 + 4f2886c commit 13ed937

File tree

8 files changed

+174
-96
lines changed

8 files changed

+174
-96
lines changed

src/API.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,13 +1408,14 @@ end
14081408
instantiate(; kwargs...) = instantiate(Context(); kwargs...)
14091409
function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
14101410
update_registry::Bool=true, verbose::Bool=false,
1411-
platform::AbstractPlatform=HostPlatform(), allow_autoprecomp::Bool=true, kwargs...)
1411+
platform::AbstractPlatform=HostPlatform(), allow_build::Bool=true, allow_autoprecomp::Bool=true, kwargs...)
14121412
Context!(ctx; kwargs...)
14131413
if Registry.download_default_registries(ctx.io)
14141414
copy!(ctx.registries, Registry.reachable_registries())
14151415
end
14161416
if !isfile(ctx.env.project_file) && isfile(ctx.env.manifest_file)
14171417
_manifest = Pkg.Types.read_manifest(ctx.env.manifest_file)
1418+
Types.check_warn_manifest_julia_version_compat(_manifest, ctx.env.manifest_file)
14181419
deps = Dict{String,String}()
14191420
for (uuid, pkg) in _manifest
14201421
if pkg.name in keys(deps)
@@ -1433,6 +1434,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
14331434
if !isfile(ctx.env.manifest_file) && manifest == true
14341435
pkgerror("expected manifest file at `$(ctx.env.manifest_file)` but it does not exist")
14351436
end
1437+
Types.check_warn_manifest_julia_version_compat(ctx.env.manifest, ctx.env.manifest_file)
14361438
Operations.prune_manifest(ctx.env)
14371439
for (name, uuid) in ctx.env.project.deps
14381440
get(ctx.env.manifest, uuid, nothing) === nothing || continue
@@ -1496,7 +1498,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
14961498
# Install all artifacts
14971499
Operations.download_artifacts(ctx.env; platform=platform, verbose=verbose)
14981500
# Run build scripts
1499-
Operations.build_versions(ctx, union(new_apply, new_git); verbose=verbose)
1501+
allow_build && Operations.build_versions(ctx, union(new_apply, new_git); verbose=verbose)
15001502

15011503
allow_autoprecomp && Pkg._auto_precompile(ctx)
15021504
end

src/Operations.jl

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ function update_manifest!(env::EnvCache, pkgs::Vector{PackageSpec}, deps_map, ju
131131
entry = PackageEntry(;name = pkg.name, version = pkg.version, pinned = pkg.pinned,
132132
tree_hash = pkg.tree_hash, path = pkg.path, repo = pkg.repo, uuid=pkg.uuid)
133133
if is_stdlib(pkg.uuid, julia_version)
134-
# do not set version for stdlibs
135-
entry.version = nothing
134+
# Only set stdlib versions for versioned (external) stdlibs
135+
entry.version = stdlib_version(pkg.uuid, julia_version)
136136
end
137137
if Types.is_project(env, pkg)
138138
entry.deps = env.project.deps
@@ -288,10 +288,13 @@ end
288288
function resolve_versions!(env::EnvCache, registries::Vector{Registry.RegistryInstance}, pkgs::Vector{PackageSpec}, julia_version)
289289
# compatibility
290290
if julia_version !== nothing
291+
env.manifest.julia_version = julia_version
291292
v = intersect(julia_version, get_compat(env.project, "julia"))
292293
if isempty(v)
293294
@warn "julia version requirement for project not satisfied" _module=nothing _file=nothing
294295
end
296+
else
297+
env.manifest.julia_version = VERSION
295298
end
296299
names = Dict{UUID, String}(uuid => stdlib for (uuid, stdlib) in stdlibs())
297300
# recursive search for packages which are tracking a path
@@ -381,6 +384,7 @@ function deps_graph(env::EnvCache, registries::Vector{Registry.RegistryInstance}
381384
union!(uuids, fixed_uuids)
382385
end
383386

387+
stdlibs_for_julia_version = Types.get_last_stdlibs(julia_version)
384388
seen = Set{UUID}()
385389

386390
# pkg -> version -> (dependency => compat):
@@ -396,13 +400,21 @@ function deps_graph(env::EnvCache, registries::Vector{Registry.RegistryInstance}
396400
for uuid in unseen
397401
push!(seen, uuid)
398402
uuid in keys(fixed) && continue
399-
all_compat_u = get_or_make!(all_compat, uuid)
403+
all_compat_u = get_or_make!(all_compat, uuid)
404+
405+
uuid_is_stdlib = false
406+
stdlib_name = ""
407+
stdlib_version = nothing
408+
if haskey(stdlibs_for_julia_version, uuid)
409+
uuid_is_stdlib = true
410+
stdlib_name, stdlib_version = stdlibs_for_julia_version[uuid]
411+
end
400412

401-
# If we're requesting resolution of a package that is an stdlib and is not registered,
402-
# we must special-case it here. This is further complicated by the fact that we can
403-
# ask this question relative to a particular Julia version.
404-
if is_unregistered_stdlib(uuid) || is_stdlib(uuid, julia_version)
405-
path = Types.stdlib_path(stdlibs()[uuid])
413+
# If we're requesting resolution of a package that is an unregistered stdlib (or one
414+
# that tracks no version information) we must special-case it here. This is further
415+
# complicated by the fact that we can ask this question relative to a Julia version.
416+
if is_unregistered_stdlib(uuid) || (uuid_is_stdlib && stdlib_version === nothing)
417+
path = Types.stdlib_path(stdlibs_for_julia_version[uuid][1])
406418
proj_file = projectfile_path(path; strict=true)
407419
@assert proj_file !== nothing
408420
proj = read_package(proj_file)
@@ -813,7 +825,7 @@ end
813825

814826
function build(ctx::Context, uuids::Set{UUID}, verbose::Bool)
815827
if any_package_not_installed(ctx.env.manifest) || !isfile(ctx.env.manifest_file)
816-
Pkg.instantiate(ctx)
828+
Pkg.instantiate(ctx, allow_build = false, allow_autoprecomp = false)
817829
end
818830
all_uuids = get_deps(ctx.env, uuids)
819831
build_versions(ctx, all_uuids; verbose)
@@ -1398,11 +1410,11 @@ function sandbox_preserve(env::EnvCache, target::PackageSpec, test_project::Stri
13981410
if env.pkg !== nothing
13991411
env.manifest[env.pkg.uuid] = PackageEntry(;name=env.pkg.name, path=dirname(env.project_file),
14001412
deps=env.project.deps)
1401-
# if the source manifest is an old format, upgrade the manifest_format so
1402-
# that warnings aren't thrown for the temp sandbox manifest
1403-
if env.manifest.manifest_format < v"2.0"
1404-
env.manifest.manifest_format = v"2.0"
1405-
end
1413+
end
1414+
# if the source manifest is an old format, upgrade the manifest_format so
1415+
# that warnings aren't thrown for the temp sandbox manifest
1416+
if env.manifest.manifest_format < v"2.0"
1417+
env.manifest.manifest_format = v"2.0"
14061418
end
14071419
# preserve important nodes
14081420
keep = [target.uuid]

src/Types.jl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using SHA
2222

2323
export UUID, SHA1, VersionRange, VersionSpec,
2424
PackageSpec, PackageEntry, EnvCache, Context, GitRepo, Context!, Manifest, Project, err_rep,
25-
PkgError, pkgerror, has_name, has_uuid, is_stdlib, is_unregistered_stdlib, stdlibs, write_env, write_env_usage, parse_toml, find_registered!,
25+
PkgError, pkgerror, has_name, has_uuid, is_stdlib, stdlib_version, is_unregistered_stdlib, stdlibs, write_env, write_env_usage, parse_toml, find_registered!,
2626
project_resolve!, project_deps_resolve!, manifest_resolve!, registry_resolve!, stdlib_resolve!, handle_repos_develop!, handle_repos_add!, ensure_resolved,
2727
registered_name,
2828
manifest_info,
@@ -261,7 +261,7 @@ Base.:(==)(t1::PackageEntry, t2::PackageEntry) = t1.name == t2.name &&
261261
Base.hash(x::PackageEntry, h::UInt) = foldr(hash, [x.name, x.version, x.path, x.pinned, x.repo, x.tree_hash, x.deps, x.uuid], init=h) # omits `other`
262262

263263
Base.@kwdef mutable struct Manifest
264-
julia_version::Union{Nothing,VersionNumber} = Base.VERSION
264+
julia_version::Union{Nothing,VersionNumber} = nothing # only set to VERSION when resolving
265265
manifest_format::VersionNumber = v"2.0.0"
266266
deps::Dict{UUID,PackageEntry} = Dict{UUID,PackageEntry}()
267267
other::Dict{String,Any} = Dict{String,Any}()
@@ -411,8 +411,9 @@ is_stdlib(uuid::UUID) = uuid in keys(stdlibs())
411411

412412
# Find the entry in `STDLIBS_BY_VERSION`
413413
# that corresponds to the requested version, and use that.
414+
# If we can't find one, defaults to `UNREGISTERED_STDLIBS`
414415
function get_last_stdlibs(julia_version::VersionNumber)
415-
last_stdlibs = Dict{UUID,String}()
416+
last_stdlibs = UNREGISTERED_STDLIBS
416417
for (version, stdlibs) in STDLIBS_BY_VERSION
417418
if VersionNumber(julia_version.major, julia_version.minor, julia_version.patch) < version
418419
break
@@ -421,6 +422,10 @@ function get_last_stdlibs(julia_version::VersionNumber)
421422
end
422423
return last_stdlibs
423424
end
425+
# If `julia_version` is set to `nothing`, that means (essentially) treat all registered
426+
# stdlibs as normal packages so that we get the latest versions of everything, ignoring
427+
# julia compat. So we set the list of stdlibs to that of only the unregistered stdlibs.
428+
get_last_stdlibs(::Nothing) = UNREGISTERED_STDLIBS
424429

425430
# Allow asking if something is an stdlib for a particular version of Julia
426431
function is_stdlib(uuid::UUID, julia_version::Union{VersionNumber, Nothing})
@@ -429,23 +434,24 @@ function is_stdlib(uuid::UUID, julia_version::Union{VersionNumber, Nothing})
429434
return is_stdlib(uuid)
430435
end
431436

432-
# If this UUID is known to be unregistered, always return `true`
433-
if haskey(UNREGISTERED_STDLIBS, uuid)
434-
return true
435-
end
436-
437-
# Otherwise, if the `julia_version` is `nothing`, all registered stdlibs
438-
# will be treated like normal packages.
439-
if julia_version === nothing
440-
return false
441-
end
442-
443437
last_stdlibs = get_last_stdlibs(julia_version)
444438
# Note that if the user asks for something like `julia_version = 0.7.0`, we'll
445439
# fall through with an empty `last_stdlibs`, which will always return `false`.
446440
return uuid in keys(last_stdlibs)
447441
end
448442

443+
# Return the version of a stdlib with respect to a particular Julia version, or
444+
# `nothing` if that stdlib is not versioned. We only store version numbers for
445+
# stdlibs that are external and thus could be installed from their repositories,
446+
# e.g. things like `GMP_jll`, `Tar`, etc...
447+
function stdlib_version(uuid::UUID, julia_version::Union{VersionNumber,Nothing})
448+
last_stdlibs = get_last_stdlibs(julia_version)
449+
if !(uuid in keys(last_stdlibs))
450+
return nothing
451+
end
452+
return last_stdlibs[uuid][2]
453+
end
454+
449455
is_unregistered_stdlib(uuid::UUID) = haskey(UNREGISTERED_STDLIBS, uuid)
450456

451457
Context!(kw_context::Vector{Pair{Symbol,Any}})::Context =

src/manifest.jl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ function Manifest(raw::Dict, f_or_io::Union{String, IO})::Manifest
135135
manifest_format = VersionNumber(raw["manifest_format"])
136136
if !in(manifest_format.major, 1:2)
137137
if f_or_io isa IO
138-
@warn "Unknown Manifest.toml format version detected in streamed manifest. Unexpected behavior may occur" manifest_format maxlog = 1
138+
@warn "Unknown Manifest.toml format version detected in streamed manifest. Unexpected behavior may occur" manifest_format
139139
else
140-
@warn "Unknown Manifest.toml format version detected in file `$(f_or_io)`. Unexpected behavior may occur" manifest_format maxlog = 1
140+
@warn "Unknown Manifest.toml format version detected in file `$(f_or_io)`. Unexpected behavior may occur" manifest_format maxlog = 1 _id = Symbol(f_or_io)
141141
end
142142
end
143143
stage1 = Dict{String,Vector{Stage1}}()
@@ -160,7 +160,7 @@ function Manifest(raw::Dict, f_or_io::Union{String, IO})::Manifest
160160
deps = read_deps(get(info::Dict, "deps", nothing))
161161
catch
162162
# TODO: Should probably not unconditionally log something
163-
@error "Could not parse entry for `$name`"
163+
@error "Could not parse entry for `$name`" f_or_io
164164
rethrow()
165165
end
166166
entry.other = info::Union{Dict,Nothing}
@@ -285,7 +285,7 @@ end
285285
function write_manifest(manifest::Manifest, manifest_file::AbstractString)
286286
if manifest.manifest_format.major == 1
287287
@warn """The active manifest file at `$(manifest_file)` has an old format that is being maintained.
288-
To update to the new format run `Pkg.upgrade_manifest()` which will upgrade the format without re-resolving.""" maxlog = 1
288+
To update to the new format run `Pkg.upgrade_manifest()` which will upgrade the format without re-resolving.""" maxlog = 1 _id = Symbol(manifest_file)
289289
end
290290
return write_manifest(destructure(manifest), manifest_file)
291291
end
@@ -304,3 +304,27 @@ function write_manifest(raw_manifest::Dict, manifest_file::AbstractString)
304304
str = sprint(write_manifest, raw_manifest)
305305
write(manifest_file, str)
306306
end
307+
308+
############
309+
# METADATA #
310+
############
311+
312+
function check_warn_manifest_julia_version_compat(manifest::Manifest, manifest_file::String)
313+
isempty(manifest.deps) && return
314+
if manifest.manifest_format < v"2"
315+
@warn """The active manifest file is an older format with no julia version entry. Dependencies may have \
316+
been resolved with a different julia version.""" maxlog = 1 _file = manifest_file _line = 0 _module = nothing
317+
return
318+
end
319+
v = manifest.julia_version
320+
if v === nothing
321+
@warn """The active manifest file is missing a julia version entry. Dependencies may have \
322+
been resolved with a different julia version.""" maxlog = 1 _file = manifest_file _line = 0 _module = nothing
323+
return
324+
end
325+
if v.major != VERSION.major && v.minor != VERSION.minor
326+
ver_str = something(manifest.julia_version, "pre-1.7")
327+
@warn """The active manifest file has dependencies that were resolved with a different julia \
328+
version ($(manifest.julia_version)). Unexpected behavior may occur.""" maxlog = 1 _file = manifest_file _line = 0 _module = nothing
329+
end
330+
end

0 commit comments

Comments
 (0)