@@ -5,7 +5,7 @@ using Pkg
55
66ENV [" JULIA_DEBUG" ] = " PackageCompiler"
77
8- # Make a new depot
8+ # Make a new depot to test stuff in
99new_depot = mktempdir ()
1010mkpath (joinpath (new_depot, " registries" ))
1111cp (joinpath (DEPOT_PATH [1 ], " registries" , " General" ), joinpath (new_depot, " registries" , " General" ))
@@ -18,29 +18,49 @@ if haskey(ENV, "CI")
1818 @show Sys. ARCH
1919end
2020
21- @testset " PackageCompiler.jl" begin
22- new_project = mktempdir ()
23- old_project = Base. ACTIVE_PROJECT[]
24- Base. ACTIVE_PROJECT[] = new_project
25- try
26- Pkg. add (" Example" )
27- finally
28- Base. ACTIVE_PROJECT[] = old_project
21+
22+ @testset " Sysimage" begin
23+
24+ new_project = mktempdir ()
25+ old_project = Base. ACTIVE_PROJECT[]
26+ Base. ACTIVE_PROJECT[] = new_project
27+ try
28+ Pkg. add (" Example" )
29+ finally
30+ Base. ACTIVE_PROJECT[] = old_project
31+ end
32+ tmp = mktempdir ()
33+ sysimage_path = joinpath (tmp, " sys." * Libdl. dlext)
34+ script = tempname ()
35+ write (script, " script_func() = println(\" I am a script\" )" )
36+
37+ create_sysimage (:Example ; sysimage_path= sysimage_path,
38+ project= new_project,
39+ precompile_execution_file= " precompile_execution.jl" ,
40+ precompile_statements_file= [" precompile_statements.jl" ,
41+ " precompile_statements2.jl" ],
42+ script= script)
43+ # Check we can load sysimage and that Example is available in Main
44+ str = read (` $(Base. julia_cmd ()) -J $(sysimage_path) -e 'println(Example.hello("foo")); script_func()'` , String)
45+ @test occursin (" Hello, foo" , str)
46+ @test occursin (" I am a script" , str)
47+
48+ end # sysimage
49+
50+
51+ @testset " App" begin
52+
53+ tmp = mktempdir ()
54+ app_source_dir = joinpath (@__DIR__ , " .." , " examples/MyApp/" )
55+ # TODO : Also test something that actually gives audit warnings
56+ @test_logs PackageCompiler. audit_app (app_source_dir)
57+ app_compiled_dir = joinpath (tmp, " MyAppCompiled" )
58+ for incremental in (is_slow_ci ? (false ,) : (true , false ))
59+ if incremental == false
60+ filter_stdlibs = (is_slow_ci ? (true , ) : (true , false ))
61+ else
62+ filter_stdlibs = (false ,)
2963 end
30- tmp = mktempdir ()
31- sysimage_path = joinpath (tmp, " sys." * Libdl. dlext)
32- script = tempname ()
33- write (script, " script_func() = println(\" I am a script\" )" )
34- create_sysimage (:Example ; sysimage_path= sysimage_path,
35- project= new_project,
36- precompile_execution_file= joinpath (@__DIR__ , " precompile_execution.jl" ),
37- precompile_statements_file= joinpath .(@__DIR__ , [" precompile_statements.jl" ,
38- " precompile_statements2.jl" ]),
39- script= script)
40- # Check we can load sysimage and that Example is available in Main
41- str = read (` $(Base. julia_cmd ()) -J $(sysimage_path) -e 'println(Example.hello("foo")); script_func()'` , String)
42- @test occursin (" Hello, foo" , str)
43- @test occursin (" I am a script" , str)
4464
4565 # Test creating an app
4666 app_source_dir = joinpath (@__DIR__ , " .." , " examples/MyApp/" )
84104 @test occursin (" HelloWorld artifact at $(realpath (app_compiled_dir)) " , app_output)
85105 end
86106 end
87- # Test creating an empty sysimage
88- if ! is_slow_ci
89- tmp = mktempdir ()
90- sysimage_path = joinpath (tmp, " empty." * Libdl. dlext)
91- foreach (x -> touch (joinpath (tmp, x)), [" Project.toml" , " Manifest.toml" ])
92- create_sysimage (; sysimage_path= sysimage_path, incremental= false , filter_stdlibs= true , project= tmp)
93- hello = read (` $(Base. julia_cmd ()) -J $(sysimage_path) -e 'print("hello, world")'` , String)
94- @test hello == " hello, world"
107+ end
108+
109+ end # testset
110+
111+
112+ @testset " empty sysimage" begin
113+
114+ if ! is_slow_ci
115+ tmp = mktempdir ()
116+ sysimage_path = joinpath (tmp, " empty." * Libdl. dlext)
117+ foreach (x -> touch (joinpath (tmp, x)), [" Project.toml" , " Manifest.toml" ])
118+ create_sysimage (; sysimage_path= sysimage_path, incremental= false , filter_stdlibs= true , project= tmp)
119+ hello = read (` $(Base. julia_cmd ()) -J $(sysimage_path) -e 'print("hello, world")'` , String)
120+ @test hello == " hello, world"
121+ end
122+
123+ end # testset
124+
125+
126+ # Test for https://github.com/JuliaLang/julia/issues/34680
127+ @testset " ccall absolute path" begin
128+
129+ tmpdir = mktempdir ()
130+ open (joinpath (tmpdir, " libfoo.c" ), " w" ) do io
131+ write (io, """
132+ #include <stdio.h>
133+
134+ void foo() {
135+ printf("Hello, Foo!\\ n");
136+ }
137+ """ )
138+ end
139+ libfoo_libname = string (" libfoo" , " ." , Libdl. dlext)
140+ cd (tmpdir) do
141+ compiler = PackageCompiler. get_compiler ()
142+ cmd = ` $compiler -o $libfoo_libname libfoo.c -shared -fPIC $(PackageCompiler. bitflag ()) `
143+ PackageCompiler. run_with_env (cmd, compiler)
144+
145+ Pkg. generate (" LibFoo" )
146+ open (joinpath (" LibFoo" , " src" , " LibFoo.jl" ), " w" ) do io
147+ write (io, """
148+ module LibFoo
149+ const libfoo = $(repr (joinpath (tmpdir, libfoo_libname)))
150+ f() = ccall((:foo, libfoo), Cvoid, ())
151+ function __init__()
152+ f()
153+ end
154+ end
155+ """ )
95156 end
96157end
158+
159+ prev = Base. ACTIVE_PROJECT[]
160+ Base. ACTIVE_PROJECT[] = joinpath (tmpdir, " LibFoo" )
161+
162+ try
163+ sysimage_path = tempname ()
164+ create_sysimage (:LibFoo ; sysimage_path= sysimage_path)
165+ content = " using .LibFoo; LibFoo.f()"
166+ str = read (` $(Base. julia_cmd ()) -J $(sysimage_path) -e $content ` , String)
167+ @test occursin (" Hello, Foo" , str)
168+ finally
169+ Base. ACTIVE_PROJECT[] = prev
170+ end
171+
172+ end # testset
0 commit comments