Skip to content

Commit

Permalink
Execute dsymutil on build on macOS (#4969)
Browse files Browse the repository at this point in the history
* Execute dsymutil on build on macOS

* Use `Process.find_executable` instead of `which`

* Let `--no-debug` imply not running dsymutil
  • Loading branch information
asterite authored and RX14 committed Sep 14, 2017
1 parent 464268b commit 429bda3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/compiler/crystal/command.cr
Expand Up @@ -192,7 +192,10 @@ class Crystal::Command
output_filename = Crystal.tempfile(config.output_filename)

result = config.compile output_filename
execute output_filename, config.arguments unless config.compiler.no_codegen?

unless config.compiler.no_codegen?
execute output_filename, config.arguments, config.compiler
end
end

private def types
Expand All @@ -211,7 +214,7 @@ class Crystal::Command
{config, result}
end

private def execute(output_filename, run_args)
private def execute(output_filename, run_args, compiler)
time? = @time && !@progress_tracker.stats?
status, elapsed_time = @progress_tracker.stage("Execute") do
begin
Expand All @@ -224,6 +227,13 @@ class Crystal::Command
{$?, Time.now - start_time}
ensure
File.delete(output_filename) rescue nil

# Delete related dwarf generated by dsymutil, if any exists
{% if flag?(:darwin) %}
unless compiler.debug.none?
File.delete("#{output_filename}.dwarf") rescue nil
end
{% end %}
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/command/eval.cr
Expand Up @@ -27,6 +27,6 @@ class Crystal::Command
output_filename = Crystal.tempfile "eval"

result = compiler.compile sources, output_filename
execute output_filename, program_args
execute output_filename, program_args, compiler
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/command/spec.cr
Expand Up @@ -68,6 +68,6 @@ class Crystal::Command
output_filename = Crystal.tempfile "spec"

result = compiler.compile sources, output_filename
execute output_filename, options
execute output_filename, options, compiler
end
end
13 changes: 13 additions & 0 deletions src/compiler/crystal/compiler.cr
Expand Up @@ -254,13 +254,26 @@ module Crystal
cross_compile program, units, output_filename
else
result = codegen program, units, output_filename, output_dir

{% if flag?(:darwin) %}
run_dsymutil(output_filename) unless debug.none?
{% end %}
end

CacheDir.instance.cleanup if @cleanup

result
end

private def run_dsymutil(filename)
dsymutil = Process.find_executable("dsymutil")
return unless dsymutil

@progress_tracker.stage("dsymutil") do
Process.run(dsymutil, ["--flat", filename])
end
end

private def cross_compile(program, units, output_filename)
llvm_mod = units.first.llvm_mod
object_name = "#{output_filename}.o"
Expand Down

0 comments on commit 429bda3

Please sign in to comment.