Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP/RFC] Conditional dependencies and package features #977

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ keywords = ["package", "management"]
license = "MIT"
name = "Pkg"
version = "1.1.0"
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
8 changes: 7 additions & 1 deletion src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ setprotocol!(proto::Union{Nothing, AbstractString}=nothing) = GitTools.setprotoc
function Package(;name::Union{Nothing,AbstractString} = nothing,
uuid::Union{Nothing,String,UUID} = nothing,
version::Union{VersionNumber, String, VersionSpec, Nothing} = nothing,
features::Union{Nothing, String, Vector{String}} = String[],
url = nothing, rev = nothing, path=nothing, mode::PackageMode = PKGMODE_PROJECT)
path !== nothing && url !== nothing &&
pkgerror("cannot specify both a path and url")
Expand All @@ -555,8 +556,13 @@ function Package(;name::Union{Nothing,AbstractString} = nothing,
nothing :
Types.GitRepo(rev = rev, url = url !== nothing ? url : path)
version = version === nothing ? VersionSpec() : VersionSpec(version)

features = features === nothing ? String[] :
features isa String ? [features] :
features

uuid isa String && (uuid = UUID(uuid))
PackageSpec(name, uuid, version, mode, nothing, PKGSPEC_NOTHING, repo)
PackageSpec(name, uuid, version, features, mode, nothing, PKGSPEC_NOTHING, repo)
end
Package(name::AbstractString) = PackageSpec(name)
Package(name::AbstractString, uuid::UUID) = PackageSpec(name, uuid)
Expand Down
5 changes: 4 additions & 1 deletion src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Base.@kwdef mutable struct PackageSpec
name::Union{Nothing,String} = nothing
uuid::Union{Nothing,UUID} = nothing
version::VersionTypes = VersionSpec()
features::Vector{String} = String[]
mode::PackageMode = PKGMODE_PROJECT
path::Union{Nothing,String} = nothing
special_action::PackageSpecialAction = PKGSPEC_NOTHING # If the package is currently being pinned, freed etc
Expand All @@ -160,7 +161,9 @@ has_uuid(pkg::PackageSpec) = pkg.uuid !== nothing

function Base.show(io::IO, pkg::PackageSpec)
vstr = repr(pkg.version)
f = ["name" => pkg.name, "uuid" => has_uuid(pkg) ? pkg.uuid : "", "v" => (vstr == "VersionSpec(\"*\")" ? "" : vstr)]
f = ["name" => pkg.name, "uuid" => has_uuid(pkg) ? pkg.uuid : "",
"v" => (vstr == "VersionSpec(\"*\")" ? "" : vstr),
"features" => pkg.features]
if pkg.repo !== nothing
if pkg.repo.url !== nothing
push!(f, "url/path" => string("\"", pkg.repo.url, "\""))
Expand Down
6 changes: 6 additions & 0 deletions test/test_packages/CUDA/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
authors = ["Roger-luo <hiroger@qq.com>"]
name = "CUDA"
uuid = "11d27378-0a18-11e9-0a59-4ba122bf6828"
version = "0.1.0"

[deps]
5 changes: 5 additions & 0 deletions test/test_packages/CUDA/src/CUDA.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module CUDA

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

end # module
18 changes: 18 additions & 0 deletions test/test_packages/ConditionalDependency/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
authors = ["Roger-luo <hiroger@qq.com>"]
name = "ConditionalDependency"
uuid = "09c64820-0a14-11e9-376f-03eff1a9e926"
version = "0.1.0"

[extras]
x2 = "52baf49e-96b1-11e8-23dd-2d073a3a6758"

[extras.CUDA]
uuid = "11d27378-0a18-11e9-0a59-4ba122bf6828"
features = ["cuda"]
version = "0.2.0"

[features]
cuda = ["CUDA"]

[targets]
test = ["x2"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ConditionalDependency

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

end # module