Skip to content

Commit

Permalink
make reading packages a bit more robust (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jul 9, 2018
1 parent 9f61bbb commit c1b4816
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions stdlib/Pkg/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function collect_project!(ctx::Context, pkg::PackageSpec, path::String, fix_deps
project_file = projectfile_path(path)
fix_deps_map[pkg.uuid] = valtype(fix_deps_map)()
(project_file === nothing) && return false
project = read_project(project_file)
project = read_package(project_file)
compat = get(project, "compat", Dict())
if haskey(compat, "julia")
if !(VERSION in Types.semver_spec(compat["julia"]))
Expand Down Expand Up @@ -839,7 +839,7 @@ function collect_target_deps!(ctx::Context, pkgs::Vector{PackageSpec}, pkg::Pack
end
project = nothing
if project_path !== nothing
project = read_project(project_path)
project = read_package(project_path)
end

# Pkg2 compatibiity with test/REQUIRE
Expand Down
21 changes: 17 additions & 4 deletions stdlib/Pkg/src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export UUID, pkgID, SHA1, VersionRange, VersionSpec, empty_versionspec,
CommandError, cmderror, has_name, has_uuid, write_env, parse_toml, find_registered!,
project_resolve!, project_deps_resolve!, manifest_resolve!, registry_resolve!, stdlib_resolve!, handle_repos_develop!, handle_repos_add!, ensure_resolved,
manifest_info, registered_uuids, registered_paths, registered_uuid, registered_name,
read_project, read_manifest, pathrepr, registries,
read_project, read_package, read_manifest, pathrepr, registries,
PackageMode, PKGMODE_MANIFEST, PKGMODE_PROJECT, PKGMODE_COMBINED,
UpgradeLevel, UPLEVEL_FIXED, UPLEVEL_PATCH, UPLEVEL_MINOR, UPLEVEL_MAJOR,
PackageSpecialAction, PKGSPEC_NOTHING, PKGSPEC_PINNED, PKGSPEC_FREED, PKGSPEC_DEVELOPED, PKGSPEC_TESTED, PKGSPEC_REPO_ADDED,
Expand Down Expand Up @@ -371,6 +371,19 @@ function read_project(file::String)
isfile(file) ? open(read_project, file) : read_project(devnull)
end

_throw_package_err(x, f) = cmderror("expected a `$x` entry in project file at $(abspath(f))")
function read_package(f::String)
project = read_project(f)
haskey(project, "name") || _throw_package_err("name", f)
haskey(project, "uuid") || _throw_package_err("uuid", f)
name = project["name"]
entry = joinpath(dirname(f), "src", "$name.jl")
if !isfile(entry)
cmderror("expected the file `src/$name.jl` to exist for package $name at $(dirname(f))")
end
return project
end

function read_manifest(io::IO)
manifest = TOML.parse(io)
for (name, infos) in manifest, info in infos
Expand Down Expand Up @@ -590,17 +603,17 @@ function parse_package!(ctx, pkg, project_path)
env = ctx.env
project_file = projectfile_path(project_path)
if project_file !== nothing
project_data = parse_toml(project_file)
project_data = read_package(project_file)
pkg.uuid = UUID(project_data["uuid"])
pkg.name = project_data["name"]
if haskey(project_data, "version")
pkg.version = VersionNumber(project_data["version"])
else
@warn "project file for $(pkg.name) is missing a `version` entry"
@warn "project file for $(pkg.name) at $(project_path) is missing a `version` entry"
Pkg.Operations.set_maximum_version_registry!(env, pkg)
end
else
@warn "packages will need to have a [Julia]Project.toml file in the future"
@warn "package $(pkg.name) at $(project_path) will need to have a [Julia]Project.toml file in the future"
if !isempty(ctx.old_pkg2_clone_name) # remove when legacy CI script support is removed
pkg.name = ctx.old_pkg2_clone_name
else
Expand Down
18 changes: 18 additions & 0 deletions stdlib/Pkg/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ temp_pkg_dir() do project_path
LibGit2.with(LibGit2.GitRepo(devdir)) do repo
@test LibGit2.branch(repo) == "DO_NOT_REMOVE"
end

withenv("USER" => "Test User") do
pkg"generate Foo"
end
pkg"dev Foo"
mv(joinpath("Foo", "src", "Foo.jl"), joinpath("Foo", "src", "Foo2.jl"))
@test_throws CommandError pkg"dev Foo"
mv(joinpath("Foo", "src", "Foo2.jl"), joinpath("Foo", "src", "Foo.jl"))
write(joinpath("Foo", "Project.toml"), """
name = "Foo"
"""
)
@test_throws CommandError pkg"dev Foo"
write(joinpath("Foo", "Project.toml"), """
uuid = "b7b78b08-812d-11e8-33cd-11188e330cbe"
"""
)
@test_throws CommandError pkg"dev Foo"
end
end

Expand Down

0 comments on commit c1b4816

Please sign in to comment.