Skip to content

Commit 429bda3

Browse files
asteriteRX14
authored andcommittedSep 14, 2017
Execute dsymutil on build on macOS (#4969)
* Execute dsymutil on build on macOS * Use `Process.find_executable` instead of `which` * Let `--no-debug` imply not running dsymutil
1 parent 464268b commit 429bda3

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed
 

‎src/compiler/crystal/command.cr

+12-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ class Crystal::Command
192192
output_filename = Crystal.tempfile(config.output_filename)
193193

194194
result = config.compile output_filename
195-
execute output_filename, config.arguments unless config.compiler.no_codegen?
195+
196+
unless config.compiler.no_codegen?
197+
execute output_filename, config.arguments, config.compiler
198+
end
196199
end
197200

198201
private def types
@@ -211,7 +214,7 @@ class Crystal::Command
211214
{config, result}
212215
end
213216

214-
private def execute(output_filename, run_args)
217+
private def execute(output_filename, run_args, compiler)
215218
time? = @time && !@progress_tracker.stats?
216219
status, elapsed_time = @progress_tracker.stage("Execute") do
217220
begin
@@ -224,6 +227,13 @@ class Crystal::Command
224227
{$?, Time.now - start_time}
225228
ensure
226229
File.delete(output_filename) rescue nil
230+
231+
# Delete related dwarf generated by dsymutil, if any exists
232+
{% if flag?(:darwin) %}
233+
unless compiler.debug.none?
234+
File.delete("#{output_filename}.dwarf") rescue nil
235+
end
236+
{% end %}
227237
end
228238
end
229239

‎src/compiler/crystal/command/eval.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class Crystal::Command
2727
output_filename = Crystal.tempfile "eval"
2828

2929
result = compiler.compile sources, output_filename
30-
execute output_filename, program_args
30+
execute output_filename, program_args, compiler
3131
end
3232
end

‎src/compiler/crystal/command/spec.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ class Crystal::Command
6868
output_filename = Crystal.tempfile "spec"
6969

7070
result = compiler.compile sources, output_filename
71-
execute output_filename, options
71+
execute output_filename, options, compiler
7272
end
7373
end

‎src/compiler/crystal/compiler.cr

+13
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,26 @@ module Crystal
254254
cross_compile program, units, output_filename
255255
else
256256
result = codegen program, units, output_filename, output_dir
257+
258+
{% if flag?(:darwin) %}
259+
run_dsymutil(output_filename) unless debug.none?
260+
{% end %}
257261
end
258262

259263
CacheDir.instance.cleanup if @cleanup
260264

261265
result
262266
end
263267

268+
private def run_dsymutil(filename)
269+
dsymutil = Process.find_executable("dsymutil")
270+
return unless dsymutil
271+
272+
@progress_tracker.stage("dsymutil") do
273+
Process.run(dsymutil, ["--flat", filename])
274+
end
275+
end
276+
264277
private def cross_compile(program, units, output_filename)
265278
llvm_mod = units.first.llvm_mod
266279
object_name = "#{output_filename}.o"

0 commit comments

Comments
 (0)
Please sign in to comment.