Skip to content

Commit b0b0cbc

Browse files
musmtkelman
authored andcommitted
Print warnings after system image building (#22670)
Print non critical compiler search warnings after system image building, otherwise the error gets lost due to the large number of printed statements
1 parent def79c7 commit b0b0cbc

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

contrib/build_sysimg.jl

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Build a system image binary at sysimg_path.dlext. Allow insertion of a userimg via
55
# userimg_path. If sysimg_path.dlext is currently loaded into memory, don't continue
6-
# unless force is set to true. Allow targeting of a CPU architecture via cpu_target.
6+
# unless force is set to true. Allow targeting of a CPU architecture via cpu_target.
77
function default_sysimg_path(debug=false)
88
if Sys.isunix()
99
splitext(Libdl.dlpath(debug ? "sys-debug" : "sys"))[1]
@@ -47,7 +47,7 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
4747
base_dir = dirname(Base.find_source_file("sysimg.jl"))
4848
cd(base_dir) do
4949
julia = joinpath(JULIA_HOME, debug ? "julia-debug" : "julia")
50-
cc = find_system_compiler()
50+
cc, warn_msg = find_system_compiler()
5151

5252
# Ensure we have write-permissions to wherever we're trying to write to
5353
try
@@ -64,7 +64,7 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
6464
error("$userimg_path is not found, ensure it is an absolute path.")
6565
end
6666
if isfile("userimg.jl")
67-
error("$base_dir/userimg.jl already exists, delete manually to continue.")
67+
error("$(joinpath(base_dir, "userimg.jl")) already exists, delete manually to continue.")
6868
end
6969
cp(userimg_path, "userimg.jl")
7070
end
@@ -82,12 +82,14 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
8282

8383
if cc !== nothing
8484
link_sysimg(sysimg_path, cc, debug)
85+
!isempty(warn_msg) && foreach(warn, warn_msg)
8586
else
87+
!isempty(warn_msg) && foreach(warn, warn_msg)
8688
info("System image successfully built at $sysimg_path.ji.")
8789
end
8890

8991
if !Base.samefile("$(default_sysimg_path(debug)).ji", "$sysimg_path.ji")
90-
if Base.isfile("$sysimg_path.$(Libdl.dlext)")
92+
if isfile("$sysimg_path.$(Libdl.dlext)")
9193
info("To run Julia with this image loaded, run: `julia -J $sysimg_path.$(Libdl.dlext)`.")
9294
else
9395
info("To run Julia with this image loaded, run: `julia -J $sysimg_path.ji`.")
@@ -104,14 +106,10 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
104106
end
105107
end
106108

107-
# Search for a compiler to link sys.o into sys.dl_ext. Honor LD environment variable.
109+
# Search for a compiler to link sys.o into sys.dl_ext. Honor LD environment variable.
108110
function find_system_compiler()
109-
if haskey(ENV, "CC")
110-
if !success(`$(ENV["CC"]) -v`)
111-
warn("Using compiler override $(ENV["CC"]), but unable to run `$(ENV["CC"]) -v`.")
112-
end
113-
return ENV["CC"]
114-
end
111+
cc = nothing
112+
warn_msg = String[] # save warning messages into an array
115113

116114
# On Windows, check to see if WinRPM is installed, and if so, see if gcc is installed
117115
if Sys.iswindows()
@@ -120,24 +118,34 @@ function find_system_compiler()
120118
winrpmgcc = joinpath(WinRPM.installdir, "usr", "$(Sys.ARCH)-w64-mingw32",
121119
"sys-root", "mingw", "bin", "gcc.exe")
122120
if success(`$winrpmgcc --version`)
123-
return winrpmgcc
121+
cc = winrpmgcc
124122
else
125123
throw()
126124
end
127125
catch
128-
warn("Install GCC via `Pkg.add(\"WinRPM\"); WinRPM.install(\"gcc\")` to generate sys.dll for faster startup times.")
126+
push!(warn_msg, "Install GCC via `Pkg.add(\"WinRPM\"); WinRPM.install(\"gcc\")` to generate sys.dll for faster startup times.")
129127
end
130128
end
131129

130+
if haskey(ENV, "CC")
131+
if !success(`$(ENV["CC"]) -v`)
132+
push!(warn_msg, "Using compiler override $(ENV["CC"]), but unable to run `$(ENV["CC"]) -v`.")
133+
end
134+
cc = ENV["CC"]
135+
end
132136

133137
# See if `cc` exists
134138
try
135139
if success(`cc -v`)
136-
return "cc"
140+
cc = "cc"
137141
end
138142
end
139143

140-
warn("No supported compiler found; startup times will be longer.")
144+
if cc === nothing
145+
push!(warn_msg, "No supported compiler found; startup times will be longer.")
146+
end
147+
148+
return cc, warn_msg
141149
end
142150

143151
# Link sys.o into sys.$(dlext)
@@ -168,11 +176,11 @@ function link_sysimg(sysimg_path=nothing, cc=find_system_compiler(), debug=false
168176
run(`$cc $FLAGS -o $sysimg_file $sysimg_path.o`)
169177
end
170178
info("System image successfully built at $sysimg_path.$(Libdl.dlext)")
179+
return
171180
end
172181

173-
# When running this file as a script, try to do so with default values. If arguments are passed
182+
# When running this file as a script, try to do so with default values. If arguments are passed
174183
# in, use them as the arguments to build_sysimg above.
175-
#
176184
# Also check whether we are running `genstdlib.jl`, in which case we don't want to build a
177185
# system image and instead only need `build_sysimg`'s docstring to be available.
178186
if !isdefined(Main, :GenStdLib) && !isinteractive()

0 commit comments

Comments
 (0)