-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
/
compile.jl
68 lines (58 loc) · 2.27 KB
/
compile.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This file is a part of Julia. License is MIT: http:https://julialang.org/license
using Base.Test
dir = mktempdir()
insert!(LOAD_PATH, 1, dir)
insert!(Base.LOAD_CACHE_PATH, 1, dir)
Foo_module = :Foo4b3a94a1a081a8cb
try
Foo_file = joinpath(dir, "$Foo_module.jl")
open(Foo_file, "w") do f
print(f, """
__precompile__(true)
module $Foo_module
@doc "foo function" foo(x) = x + 1
include_dependency("foo.jl")
include_dependency("foo.jl")
module Bar
@doc "bar function" bar(x) = x + 2
include_dependency("bar.jl")
end
end
""")
end
if myid() == 1
@test_throws Base.PrecompilableError __precompile__(true)
@test_throws LoadError include(Foo_file) # from __precompile__(true)
end
Base.require(Foo_module)
cachefile = joinpath(dir, "$Foo_module.ji")
# use _require_from_serialized to ensure that the test fails if
# the module doesn't load from the image:
println(STDERR, "\nNOTE: The following 'replacing module' warning indicates normal operation:")
@test nothing !== Base._require_from_serialized(myid(), Foo_module, true)
let Foo = eval(Main, Foo_module)
@test Foo.foo(17) == 18
@test Foo.Bar.bar(17) == 19
# issue #12284:
@test stringmime("text/plain", Base.Docs.doc(Foo.foo)) == "foo function\n"
@test stringmime("text/plain", Base.Docs.doc(Foo.Bar.bar)) == "bar function\n"
deps = Base.cache_dependencies(cachefile)
@test sort(deps[1]) == map(s -> (s, Base.module_uuid(eval(s))),
[:Base,:Core,:Main])
@test map(x -> x[1], sort(deps[2])) == [Foo_file,joinpath(dir,"bar.jl"),joinpath(dir,"foo.jl")]
end
Baz_file = joinpath(dir, "Baz.jl")
open(Baz_file, "w") do f
print(f, """
__precompile__(false)
module Baz
end
""")
end
println(STDERR, "\nNOTE: The following 'LoadError: __precompile__(false)' indicates normal operation")
@test_throws ErrorException Base.compilecache("Baz") # from __precompile__(false)
finally
splice!(Base.LOAD_CACHE_PATH, 1)
splice!(LOAD_PATH, 1)
rm(dir, recursive=true)
end