Skip to content

Commit

Permalink
fix how entry point to package is computed with path provided in pr…
Browse files Browse the repository at this point in the history
…oject file (#3850)

* fix how entry point to package is computed with `path` provided in project file
  • Loading branch information
KristofferC authored and KristofferC committed May 9, 2024
1 parent 15686ed commit d14dd2e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,14 @@ end
# This has to be done after the packages have been downloaded
# since we need access to the Project file to read the information
# about extensions
function fixup_ext!(env::EnvCache)
function fixups_from_projectfile!(env::EnvCache)
for pkg in values(env.manifest)
v = joinpath(source_path(env.manifest_file, pkg), "Project.toml")
if isfile(v)
p = Types.read_project(v)
pkg.weakdeps = p.weakdeps
pkg.exts = p.exts
pkg.entryfile = p.entryfile
for (name, _) in p.weakdeps
if !haskey(p.deps, name)
delete!(pkg.deps, name)
Expand Down Expand Up @@ -1510,7 +1511,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
man_pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, preserve, ctx.julia_version)
update_manifest!(ctx.env, man_pkgs, deps_map, ctx.julia_version)
new_apply = download_source(ctx)
fixup_ext!(ctx.env)
fixups_from_projectfile!(ctx.env)

# After downloading resolutionary packages, search for (Julia)Artifacts.toml files
# and ensure they are all downloaded and unpacked as well:
Expand Down Expand Up @@ -1554,7 +1555,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Set{UUID};
pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, preserve, ctx.julia_version)
update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
new_apply = download_source(ctx)
fixup_ext!(ctx.env)
fixups_from_projectfile!(ctx.env)
download_artifacts(ctx.env; platform=platform, julia_version=ctx.julia_version, io=ctx.io)
write_env(ctx.env) # write env before building
show_update(ctx.env, ctx.registries; io=ctx.io)
Expand Down Expand Up @@ -1695,7 +1696,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec}, level::UpgradeLevel;
end
update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
new_apply = download_source(ctx)
fixup_ext!(ctx.env)
fixups_from_projectfile!(ctx.env)
download_artifacts(ctx.env, julia_version=ctx.julia_version, io=ctx.io)
write_env(ctx.env; skip_writing_project) # write env before building
show_update(ctx.env, ctx.registries; io=ctx.io, hidden_upgrades_info = true)
Expand Down Expand Up @@ -1741,7 +1742,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec})

update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
new = download_source(ctx)
fixup_ext!(ctx.env)
fixups_from_projectfile!(ctx.env)
download_artifacts(ctx.env; julia_version=ctx.julia_version, io=ctx.io)
write_env(ctx.env) # write env before building
show_update(ctx.env, ctx.registries; io=ctx.io)
Expand Down Expand Up @@ -1789,7 +1790,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; err_if_free=true)

update_manifest!(ctx.env, pkgs, deps_map, ctx.julia_version)
new = download_source(ctx)
fixup_ext!(ctx.env)
fixups_from_projectfile!(ctx.env)
download_artifacts(ctx.env, io=ctx.io)
write_env(ctx.env) # write env before building
show_update(ctx.env, ctx.registries; io=ctx.io)
Expand Down
13 changes: 8 additions & 5 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Base.@kwdef mutable struct Project
uuid::Union{UUID, Nothing} = nothing
version::Union{VersionTypes, Nothing} = nothing
manifest::Union{String, Nothing} = nothing
path::Union{String, Nothing} = nothing
entryfile::Union{String, Nothing} = nothing
# Sections
deps::Dict{String,UUID} = Dict{String,UUID}()
# deps that are also in weakdeps for backwards compat
Expand All @@ -258,6 +258,7 @@ Base.@kwdef mutable struct PackageEntry
name::Union{String,Nothing} = nothing
version::Union{VersionNumber,Nothing} = nothing
path::Union{String,Nothing} = nothing
entryfile::Union{String,Nothing} = nothing
pinned::Bool = false
repo::GitRepo = GitRepo()
tree_hash::Union{Nothing,SHA1} = nothing
Expand All @@ -270,6 +271,7 @@ end
Base.:(==)(t1::PackageEntry, t2::PackageEntry) = t1.name == t2.name &&
t1.version == t2.version &&
t1.path == t2.path &&
t1.entryfile == t2.entryfile &&
t1.pinned == t2.pinned &&
t1.repo == t2.repo &&
t1.tree_hash == t2.tree_hash &&
Expand All @@ -278,7 +280,7 @@ Base.:(==)(t1::PackageEntry, t2::PackageEntry) = t1.name == t2.name &&
t1.exts == t2.exts &&
t1.uuid == t2.uuid
# omits `other`
Base.hash(x::PackageEntry, h::UInt) = foldr(hash, [x.name, x.version, x.path, x.pinned, x.repo, x.tree_hash, x.deps, x.weakdeps, x.exts, x.uuid], init=h) # omits `other`
Base.hash(x::PackageEntry, h::UInt) = foldr(hash, [x.name, x.version, x.path, x.entryfile, x.pinned, x.repo, x.tree_hash, x.deps, x.weakdeps, x.exts, x.uuid], init=h) # omits `other`

Base.@kwdef mutable struct Manifest
julia_version::Union{Nothing,VersionNumber} = nothing # only set to VERSION when resolving
Expand Down Expand Up @@ -629,9 +631,10 @@ function read_package(path::String)
pkgerror("expected a `uuid` entry in project file at `$(abspath(path))`")
end
name = project.name
pkgpath = joinpath(dirname(path), something(project.path, ""))
if !isfile(joinpath(pkgpath, "src", "$name.jl"))
pkgerror("expected the file `src/$name.jl` to exist for package `$name` at `$(dirname(path))`")
entry_point = something(project.entryfile, joinpath("src", "$(name).jl"))
pkgpath = joinpath(dirname(path), entry_point)
if !isfile(pkgpath)
pkgerror("expected the file `$pkgpath` to exist for package `$name` at `$(dirname(path))`")
end
return project
end
Expand Down
1 change: 1 addition & 0 deletions src/manifest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ function destructure(manifest::Manifest)::Dict
path = join(splitpath(path), "/")
end
entry!(new_entry, "path", path)
entry!(new_entry, "entryfile", entry.entryfile)
repo_source = entry.repo.source
if repo_source !== nothing && Sys.iswindows() && !isabspath(repo_source) && !isurl(repo_source)
repo_source = join(splitpath(repo_source), "/")
Expand Down
7 changes: 5 additions & 2 deletions src/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ function Project(raw::Dict; file=nothing)
project.other = raw
project.name = get(raw, "name", nothing)::Union{String, Nothing}
project.manifest = get(raw, "manifest", nothing)::Union{String, Nothing}
project.path = get(raw, "path", nothing)::Union{String, Nothing}
project.entryfile = get(raw, "path", nothing)::Union{String, Nothing}
if project.entryfile === nothing
project.entryfile = get(raw, "entryfile", nothing)::Union{String, Nothing}
end
project.uuid = read_project_uuid(get(raw, "uuid", nothing))
project.version = read_project_version(get(raw, "version", nothing))
project.deps = read_project_deps(get(raw, "deps", nothing), "deps")
Expand Down Expand Up @@ -243,7 +246,7 @@ function destructure(project::Project)::Dict
entry!("version", project.version)
entry!("workspace", project.workspace)
entry!("manifest", project.manifest)
entry!("path", project.path)
entry!("entryfile", project.entryfile)
entry!("deps", merge(project.deps, project._deps_weak))
entry!("weakdeps", project.weakdeps)
entry!("sources", project.sources)
Expand Down
16 changes: 16 additions & 0 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3198,4 +3198,20 @@ if :version in fieldnames(Base.PkgOrigin)
end
end

temp_pkg_dir() do project_path
@testset "test entryfile entries" begin
mktempdir() do dir
path = abspath(joinpath(dirname(pathof(Pkg)), "../test", "test_packages", "ProjectPath"))
cp(path, joinpath(dir, "ProjectPath"))
cd(joinpath(dir, "ProjectPath")) do
with_current_env() do
Pkg.resolve()
@test success(run(`$(Base.julia_cmd()) --startup-file=no --project -e 'using ProjectPath'`))
@test success(run(`$(Base.julia_cmd()) --startup-file=no --project -e 'using ProjectPathDep'`))
end
end
end
end
end

end #module
7 changes: 7 additions & 0 deletions test/test_packages/ProjectPath/CustomPath.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ProjectPath

using ProjectPathDep

greet() = print("Hello World!")

end # module ProjectPath
10 changes: 10 additions & 0 deletions test/test_packages/ProjectPath/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "ProjectPath"
uuid = "32833bde-7fc1-4d28-8365-9d01e1bcbc1b"
entryfile = "CustomPath.jl"
version = "0.1.0"

[deps]
ProjectPathDep = "f18633fc-8799-43ff-aa06-99ed830dc572"

[sources]
ProjectPathDep = {path = "ProjectPathDep"}
5 changes: 5 additions & 0 deletions test/test_packages/ProjectPath/ProjectPathDep/CustomPath.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ProjectPathDep

greet() = print("Hello World!")

end # module ProjectPathDep
4 changes: 4 additions & 0 deletions test/test_packages/ProjectPath/ProjectPathDep/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "ProjectPathDep"
uuid = "f18633fc-8799-43ff-aa06-99ed830dc572"
version = "0.1.0"
entryfile = "CustomPath.jl"

0 comments on commit d14dd2e

Please sign in to comment.