diff --git a/NEWS.md b/NEWS.md index beba643cd67ee..58346e59eb0ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -288,6 +288,9 @@ Miscellaneous changes * `julia-release-*` executables renamed to `julia-*`, and `libjulia-release` renamed to `libjulia` ([#4177]). + * Packages will now be installed in `.julia/vX.Y`, where + X.Y is the current Julia version. + Bugfixes and performance updates -------------------------------- diff --git a/base/pkg/cache.jl b/base/pkg/cache.jl index ecda6939b5009..576652e71be70 100644 --- a/base/pkg/cache.jl +++ b/base/pkg/cache.jl @@ -1,11 +1,33 @@ module Cache -using Base.Git, ..Types +import Base.Git, ..Dir +using ..Types path(pkg::String) = abspath(".cache", pkg) +function mkcachedir() + cache = joinpath(realpath("."), ".cache") + if isdir(cache) + return + end + + @windows_only mkdir(cache) + @unix_only begin + if Dir.isversioned(pwd()) + rootcache = joinpath(realpath(".."), ".cache") + if !isdir(rootcache) + mkdir(rootcache) + end + run(`ln -s $rootcache $cache`) + return + end + mkdir(cache) + end +end + + function prefetch{S<:String}(pkg::String, url::String, sha1s::Vector{S}) - isdir(".cache") || mkdir(".cache") + isdir(".cache") || mkcachedir() cache = path(pkg) if !isdir(cache) info("Cloning cache of $pkg from $url") diff --git a/base/pkg/dir.jl b/base/pkg/dir.jl index afa3ffe773b4b..4e1a03693f8f0 100644 --- a/base/pkg/dir.jl +++ b/base/pkg/dir.jl @@ -5,13 +5,16 @@ import ..Pkg: DEFAULT_META, META_BRANCH const DIR_NAME = ".julia" +_pkgroot() = abspath(get(ENV,"JULIA_PKGDIR",joinpath(homedir(),DIR_NAME))) +isversioned(p::String) = ((x,y) = (VERSION.major, VERSION.minor); basename(p) == "v$x.$y") + function path() - b = abspath(get(ENV,"JULIA_PKGDIR",joinpath(homedir(),DIR_NAME))) + b = _pkgroot() x, y = VERSION.major, VERSION.minor d = joinpath(b,"v$x.$y") - isdir(d) && return d - d = joinpath(b,"v$x") - isdir(d) && return d + if isdir(d) || !isdir(b) || !isdir(joinpath(b, "METADATA")) + return d + end return b end path(pkg::String...) = normpath(path(),pkg...)