Skip to content

Commit c85521c

Browse files
committed
improve build process
1 parent df35e16 commit c85521c

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
deps.jl
55
*.csv
66
snoopy.jl
7+
precompile.jl
78
*.so
89
*.ji
910
*.dll

deps/build.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function build()
4040
"sys-root", "mingw", "bin", "gcc.exe"
4141
)
4242
if !isfile(gccpath)
43-
WinRPM.install("gcc")
43+
WinRPM.install("gcc", yes = true)
4444
end
4545
if !isfile(gccpath)
4646
error("Couldn't install gcc via winrpm")

src/PackageCompiler.jl

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module PackageCompiler
44
using SnoopCompile
55

66
include("build_sysimg.jl")
7+
const sysimage_binaries = (
8+
"sys.o", "sys.$(Libdl.dlext)", "sys.ji", "inference.o", "inference.ji"
9+
)
710

811
function snoop(path, compilationfile, csv, reuse)
912
cd(@__DIR__)
@@ -55,59 +58,75 @@ end
5558
function revert(debug = false)
5659
syspath = default_sysimg_path(debug)
5760
sysimg_backup = joinpath(@__DIR__, "..", "sysimg_backup")
58-
sysfiles = ("sys.o", "sys.so", "sys.ji", "inference.o", "inference.ji")
59-
if all(x-> isfile(joinpath(sysimg_backup, x)), sysfiles) # we have a backup
61+
if all(x-> isfile(joinpath(sysimg_backup, x)), sysimage_binaries) # we have a backup
6062
for file in sysfiles
6163
# backup
6264
bfile = joinpath(sysimg_backup, file)
6365
if isfile(bfile)
6466
sfile = joinpath(dirname(syspath), file)
65-
isfile(sfile) && rm(sfile)
66-
mv(bfile, sfile)
67+
isfile(sfile) && mv(sfile, sfile*".old", remove_destination = true)
68+
mv(bfile, sfile, remove_destination = false)
6769
else
6870
warn("No backup of $file found")
6971
end
7072
end
7173
else
7274
warn("No backup found but restoring. Need to build a new system image from scratch")
7375
sysimg_backup = joinpath(@__DIR__, "..", "sysimg_backup") # build directly into backup
76+
isdir(sysimg_backup) || mkdir(sysimg_backup)
7477
build_sysimg(joinpath(sysimg_backup, "sys"))
7578
# now we should have a backup.
7679
# make sure that we have all files to not end up with an endless recursion!
77-
if all(x-> isfile(joinpath(sysimg_backup, x)), sysfiles)
80+
if all(x-> isfile(joinpath(sysimg_backup, x)), sysimage_binaries)
7881
revert(debug)
7982
else
8083
error("Revert went wrong")
8184
end
8285
end
8386
end
8487

88+
function get_root_dir(path)
89+
path, name = splitdir(path)
90+
if isempty(name)
91+
return splitdir(path)[2]
92+
else
93+
name
94+
end
95+
end
96+
97+
8598
function compile_package(package, force = false, reuse = false; debug = false)
8699
realpath = if ispath(package)
87100
normpath(abspath(package))
88101
else
89102
Pkg.dir(package)
90103
end
91104
testroot = joinpath(realpath, "test")
92-
precompile_file = joinpath(testroot, "precompile.jl")
93-
sysimg_tmp = joinpath(@__DIR__, "..", "sysimg_tmp", basename(realpath))
94-
snoop(joinpath(testroot, "runtests.jl"), precompile_file, joinpath(sysimg_tmp, "snooped.csv"), reuse)
95-
!isdir(sysimg_tmp) && mkdir(sysimg_tmp)
96-
build_sysimg(joinpath(sysimg_tmp, "sys"), "native", precompile_file)
105+
sysimg_tmp = normpath(joinpath(@__DIR__, "..", "sysimg_tmp", get_root_dir(realpath)))
97106
sysimg_backup = joinpath(@__DIR__, "..", "sysimg_backup")
107+
isdir(sysimg_backup) || mkdir(sysimg_tmp)
108+
isdir(sysimg_tmp) || mkdir(sysimg_tmp)
109+
precompile_file = joinpath(sysimg_tmp, "precompile.jl")
110+
snoop(
111+
joinpath(testroot, "runtests.jl"),
112+
precompile_file,
113+
joinpath(sysimg_tmp, "snooped.csv"),
114+
reuse
115+
)
116+
build_sysimg(joinpath(sysimg_tmp, "sys"), "native", precompile_file)
98117
if force
99118
try
100119
syspath = default_sysimg_path(debug)
101-
for file in ("sys.o", "sys.so", "sys.ji", "inference.o", "inference.ji")
120+
for file in sysimage_binaries
102121
# backup
103122
bfile = joinpath(sysimg_backup, file)
104123
sfile = joinpath(dirname(syspath), file)
105124
if !isfile(bfile) # use the one that is already there
106125
mv(sfile, bfile, remove_destination = true)
107126
else
108-
rm(sfile) # remove so we don't overwrite (seems to be problematic on windows)
127+
mv(sfile, sfile*".old", remove_destination = true) # remove so we don't overwrite (seems to be problematic on windows)
109128
end
110-
mv(joinpath(sysimg_tmp, file), sfile)
129+
mv(joinpath(sysimg_tmp, file), sfile, remove_destination = false)
111130
end
112131
catch e
113132
warn("An error has occured while replacing sysimg files:")
@@ -116,7 +135,10 @@ function compile_package(package, force = false, reuse = false; debug = false)
116135
revert(debug)
117136
end
118137
else
119-
info("Not forcing system image. You can start julia with julia -J $(joinpath(sysimg_tmp, "sys")) to load the compiled files.")
138+
info("""
139+
Not replacing system image.
140+
You can start julia with julia -J $(joinpath(sysimg_tmp, "sys")) to load the compiled files.
141+
""")
120142
end
121143
end
122144

0 commit comments

Comments
 (0)