Skip to content

Commit

Permalink
Merge pull request #25920 from JuliaLang/sk/uuid-all-the-things
Browse files Browse the repository at this point in the history
stdlib: add project files with UUIDs and deps
  • Loading branch information
StefanKarpinski authored Feb 8, 2018
2 parents 4603496 + 895b8c5 commit 2017524
Show file tree
Hide file tree
Showing 32 changed files with 162 additions and 23 deletions.
35 changes: 16 additions & 19 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ end

const ns_dummy_uuid = UUID("fe0723d6-3a44-4c41-8065-ee0f42c8ceab")

dummy_uuid(project_file::String) = uuid5(ns_dummy_uuid, project_file)
dummy_uuid(project_file::String) = isfile_casesensitive(project_file) ?
uuid5(ns_dummy_uuid, realpath(project_file)) : nothing

## package path slugs: turning UUID + SHA1 into a pair of 4-byte "slugs" ##

Expand Down Expand Up @@ -220,11 +221,9 @@ struct PkgId
end
PkgId(name::AbstractString) = PkgId(nothing, name)

function PkgId(m::Module)
function PkgId(m::Module, name::String = String(nameof(moduleroot(m))))
uuid = UUID(ccall(:jl_module_uuid, NTuple{2, UInt64}, (Any,), m))
name = String(nameof(m))
UInt128(uuid) == 0 && return PkgId(name)
return PkgId(uuid, name)
UInt128(uuid) == 0 ? PkgId(name) : PkgId(uuid, name)
end

==(a::PkgId, b::PkgId) = a.uuid == b.uuid && a.name == b.name
Expand Down Expand Up @@ -865,6 +864,7 @@ Windows.
"""
function require(into::Module, mod::Symbol)
uuidkey = identify_package(into, String(mod))
# Core.println("require($(PkgId(into)), $mod) -> $uuidkey")
uuidkey === nothing &&
throw(ArgumentError("Module $mod not found in current path.\nRun `Pkg.add(\"$mod\")` to install the $mod package."))
if _track_dependencies[]
Expand All @@ -883,8 +883,11 @@ end
const loaded_modules = Dict{PkgId,Module}()
const module_keys = IdDict{Module,PkgId}() # the reverse

is_root_module(m::Module) = haskey(module_keys, m)
root_module_key(m::Module) = module_keys[m]

function register_root_module(m::Module)
key = PkgId(m)
key = PkgId(m, String(nameof(m)))
if haskey(loaded_modules, key)
oldm = loaded_modules[key]
if oldm !== m
Expand All @@ -900,9 +903,6 @@ register_root_module(Core)
register_root_module(Base)
register_root_module(Main)

is_root_module(m::Module) = haskey(module_keys, m)
root_module_key(m::Module) = module_keys[m]

# This is used as the current module when loading top-level modules.
# It has the special behavior that modules evaluated in it get added
# to the loaded_modules table instead of getting bindings.
Expand Down Expand Up @@ -1008,9 +1008,10 @@ function _require(pkg::PkgId)
# TODO: disable __precompile__(true) error and do normal include instead of error
error("Module $name declares __precompile__(true) but require failed to create a usable precompiled cache file.")
end
end
if uuid !== old_uuid
ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), __toplevel__, old_uuid)
finally
if uuid !== old_uuid
ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), __toplevel__, old_uuid)
end
end
finally
toplevel_load[] = last
Expand Down Expand Up @@ -1141,10 +1142,8 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
write(in, "push!(Base._concrete_dependencies, $pkg_str => $(repr(build_id)))\n")
end
write(io, "end\0")
if uuid !== nothing
uuid_tuple = convert(NTuple{2, UInt64}, uuid)
write(in, "ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Base.__toplevel__, $uuid_tuple)\0")
end
uuid_tuple = uuid === nothing ? (0, 0) : convert(NTuple{2, UInt64}, uuid)
write(in, "ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Base.__toplevel__, $uuid_tuple)\0")
source = source_path(nothing)
if source !== nothing
write(in, "task_local_storage()[:SOURCE_PATH] = $(repr(source))\0")
Expand All @@ -1154,9 +1153,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
if source !== nothing
write(in, "delete!(task_local_storage(), :SOURCE_PATH)\0")
end
if uuid !== nothing
write(in, "ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Base.__toplevel__, (0, 0))\0")
end
write(in, "ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Base.__toplevel__, (0, 0))\0")
close(in)
catch ex
close(in)
Expand Down
5 changes: 3 additions & 2 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ function url(m::Method)
line = m.line
line <= 0 || contains(file, r"In\[[0-9]+\]") && return ""
Sys.iswindows() && (file = replace(file, '\\' => '/'))
libgit2_id = PkgId(UUID((0x76f85450_5226_5b5a,0x8eaa_529ad045b433)), "LibGit2")
if inbase(M)
if isempty(Base.GIT_VERSION_INFO.commit)
# this url will only work if we're on a tagged release
return "https://github.com/JuliaLang/julia/tree/v$VERSION/base/$file#L$line"
else
return "https://github.com/JuliaLang/julia/tree/$(Base.GIT_VERSION_INFO.commit)/base/$file#L$line"
end
elseif root_module_exists(PkgId(nothing, "LibGit2"))
LibGit2 = Base.root_module(Main, :LibGit2)
elseif root_module_exists(libgit2_id)
LibGit2 = root_module(libgit2_id)
try
d = dirname(file)
return LibGit2.with(LibGit2.GitRepoExt(d)) do repo
Expand Down
16 changes: 16 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ Base
"""
parentmodule(m::Module) = ccall(:jl_module_parent, Ref{Module}, (Any,), m)

"""
moduleroot(m::Module) -> Module
Find the root module of a given module. This is the first module in the chain of
parent modules of `m` which is either a registered root module or which is its
own parent module.
"""
function moduleroot(m::Module)
while true
is_root_module(m) && return m
p = parentmodule(m)
p == m && return m
m = p
end
end

"""
@__MODULE__ -> Module
Expand Down
3 changes: 2 additions & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ function __init__()
Csrand()
# Base library init
reinit_stdio()
global_logger(root_module(PkgId("Logging")).ConsoleLogger(STDERR))
Logging = root_module(PkgId(UUID(0x56ddb016_857b_54e1_b83d_db4d58db5568), "Logging"))
global_logger(Logging.ConsoleLogger(STDERR))
Multimedia.reinit_displays() # since Multimedia.displays uses STDOUT as fallback
early_init()
init_depot_path()
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Base64/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "Base64"
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
2 changes: 2 additions & 0 deletions stdlib/CRC32c/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "CRC32c"
uuid = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
5 changes: 5 additions & 0 deletions stdlib/Dates/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "Dates"
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[deps]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
5 changes: 5 additions & 0 deletions stdlib/DelimitedFiles/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "DelimitedFiles"
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[deps]
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
7 changes: 7 additions & 0 deletions stdlib/Distributed/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "Distributed"
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2 changes: 2 additions & 0 deletions stdlib/FileWatching/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "FileWatching"
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
5 changes: 5 additions & 0 deletions stdlib/Future/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "Future"
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
6 changes: 6 additions & 0 deletions stdlib/InteractiveUtils/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "InteractiveUtils"
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[deps]
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pkg = "fe1c5a76-5840-53d2-82f9-288dd83ce2ce"
5 changes: 5 additions & 0 deletions stdlib/IterativeEigensolvers/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "IterativeEigensolvers"
uuid = "de555fa4-b82f-55e7-8b71-53f60bbc027d"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2 changes: 2 additions & 0 deletions stdlib/LibGit2/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "LibGit2"
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
2 changes: 2 additions & 0 deletions stdlib/Libdl/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "Libdl"
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
5 changes: 5 additions & 0 deletions stdlib/LinearAlgebra/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "LinearAlgebra"
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
2 changes: 2 additions & 0 deletions stdlib/Logging/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "Logging"
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
5 changes: 5 additions & 0 deletions stdlib/Markdown/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "Markdown"
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[deps]
Pkg = "fe1c5a76-5840-53d2-82f9-288dd83ce2ce"
2 changes: 2 additions & 0 deletions stdlib/Mmap/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "Mmap"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
5 changes: 5 additions & 0 deletions stdlib/Pkg/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "Pkg"
uuid = "fe1c5a76-5840-53d2-82f9-288dd83ce2ce"

[deps]
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
5 changes: 5 additions & 0 deletions stdlib/Printf/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "Printf"
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[deps]
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
5 changes: 5 additions & 0 deletions stdlib/Profile/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "Profile"
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"

[deps]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
7 changes: 7 additions & 0 deletions stdlib/REPL/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "REPL"
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pkg = "fe1c5a76-5840-53d2-82f9-288dd83ce2ce"
5 changes: 5 additions & 0 deletions stdlib/Random/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "Random"
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[deps]
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
2 changes: 2 additions & 0 deletions stdlib/Serialization/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "Serialization"
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
9 changes: 9 additions & 0 deletions stdlib/SharedArrays/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "SharedArrays"
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
6 changes: 6 additions & 0 deletions stdlib/SparseArrays/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "SparseArrays"
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
8 changes: 8 additions & 0 deletions stdlib/SuiteSparse/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name = "SuiteSparse"
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
8 changes: 8 additions & 0 deletions stdlib/Test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name = "Test"
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
5 changes: 5 additions & 0 deletions stdlib/UUIDs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "UUIDs"
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2 changes: 2 additions & 0 deletions stdlib/Unicode/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "Unicode"
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
2 changes: 1 addition & 1 deletion test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ try
@test map(x -> x[2], deps) == [ Foo_file, joinpath(dir, "foo.jl"), joinpath(dir, "bar.jl") ]
@test requires == [ Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)),
Base.PkgId(Foo) => Base.PkgId(Foo2),
Base.PkgId(Foo) => Base.PkgId("Test"),
Base.PkgId(Foo) => Base.PkgId(Test),
Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)) ]
srctxt = Base.read_dependency_src(cachefile, Foo_file)
@test !isempty(srctxt) && srctxt == read(Foo_file, String)
Expand Down

0 comments on commit 2017524

Please sign in to comment.