Skip to content

Commit 5b4d192

Browse files
committed
make snoop reusable
1 parent 540496a commit 5b4d192

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.jl.*.cov
33
*.jl.mem
44
deps.jl
5+
*.csv
6+
snoopy.jl

src/PackageCompiler.jl

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,63 @@ using SnoopCompile
55

66
include("build_sysimg.jl")
77

8-
function snoop(path, compilationfile)
8+
function snoop(path, compilationfile, reuse)
99
cd(@__DIR__)
10-
mktempdir() do tmpfolder
11-
csv = joinpath(homedir(), "test.csv") #joinpath(tmpfolder, "precompile.csv")
12-
# Snoop compiler can't handle the path as a variable, so we just create a file
13-
open(joinpath(tmpfolder, "snoopy.jl"), "w") do io
10+
csv = "precompile.csv"
11+
# Snoop compiler can't handle the path as a variable, so we just create a file
12+
if !reuse
13+
open(joinpath("snoopy.jl"), "w") do io
1414
println(io, "include(\"$(escape_string(path))\")")
1515
end
16-
cd(tmpfolder)
1716
SnoopCompile.@snoop csv begin
1817
include("snoopy.jl")
1918
end
20-
data = SnoopCompile.read(csv)
21-
pc = SnoopCompile.parcel(reverse!(data[2]))
22-
delims = r"([\{\} \n\(\),])_([\{\} \n\(\),])"
23-
tmp_mod = eval(:(module $(gensym()) end))
24-
open(compilationfile, "w") do io
25-
for (k, v) in pc
26-
k == :unknown && continue
27-
println(k)
19+
end
20+
data = SnoopCompile.read(csv)
21+
pc = SnoopCompile.parcel(reverse!(data[2]))
22+
delims = r"([\{\} \n\(\),])_([\{\} \n\(\),])"
23+
tmp_mod = eval(:(module $(gensym()) end))
24+
open(compilationfile, "w") do io
25+
for (k, v) in pc
26+
k == :unknown && continue
27+
try
28+
eval(tmp_mod, :(using $k))
29+
println(io, "using $k")
30+
info("using $k")
31+
catch e
32+
println("Module not found: $k")
33+
end
34+
end
35+
for (k, v) in pc
36+
for ln in v
37+
# replace `_` for free parameters, which print out a warning otherwise
38+
ln = replace(ln, delims, s"\1XXX\2")
39+
# only print out valid lines
40+
# TODO figure out why some precompile statements have undefined free variables in there
2841
try
29-
eval(tmp_mod, :(using $k))
30-
println(io, "using $k")
42+
eval(tmp_mod, parse(ln))
43+
println(io, ln)
3144
catch e
32-
warn(e)
33-
end
34-
end
35-
for (k, v) in pc
36-
for ln in v
37-
# replace `_` for free parameters, which print out a warning otherwise
38-
ln = replace(ln, delims, s"\1XXX\2")
39-
# only print out valid lines
40-
# TODO figure out why some precompile statements have undefined free variables in there
41-
try
42-
eval(tmp_mod, parse(ln))
43-
println(io, ln)
44-
catch e
45-
warn(e)
46-
end
45+
warn("Not emitted: ", ln)
4746
end
4847
end
4948
end
5049
end
51-
cd(@__DIR__)
52-
end
53-
54-
55-
function compile(file; force = false)
56-
build_sysimg(default_sysimg_path(), "native", file, force = force)
5750
end
5851

59-
function revert(file; force = false)
52+
function revert()
6053
build_sysimg(force = true)
6154
end
6255

63-
function compile_package(package, force = false)
56+
function compile_package(package, force = false, reuse = false)
6457
realpath = if ispath(package)
6558
normpath(abspath(package))
6659
else
6760
Pkg.dir(package)
6861
end
6962
testroot = joinpath(realpath, "test")
7063
precompile_file = joinpath(testroot, "precompile.jl")
71-
snoop(joinpath(testroot, "runtests.jl"), precompile_file)
64+
snoop(joinpath(testroot, "runtests.jl"), precompile_file, reuse)
7265
build_sysimg(default_sysimg_path(), "native", precompile_file, force = force)
7366
end
7467

0 commit comments

Comments
 (0)