diff --git a/lib/singed.rb b/lib/singed.rb index aca2d11..31559df 100644 --- a/lib/singed.rb +++ b/lib/singed.rb @@ -13,7 +13,7 @@ def output_directory=(directory) end def self.output_directory - @output_directory || raise("output directory hasn't been set!") + @output_directory end def enabled=(enabled) diff --git a/lib/singed/cli.rb b/lib/singed/cli.rb index 4ec8981..60954c3 100644 --- a/lib/singed/cli.rb +++ b/lib/singed/cli.rb @@ -1,6 +1,7 @@ require 'shellwords' require 'tmpdir' require 'optionparser' +require 'pathname' # NOTE: we defer requiring singed until we run. that lets Rails load it if its in the gemfile, so the railtie has had a chance to run @@ -64,6 +65,7 @@ def run Singed.output_directory = @output_directory if @output_directory Singed.output_directory ||= Dir.tmpdir + FileUtils.mkdir_p Singed.output_directory @filename = Singed::Flamegraph.generate_filename(label: 'cli') options = { @@ -86,11 +88,19 @@ def run prompt_password end - Bundler.with_unbundled_env do + rbspy = lambda do # don't run things with spring, because it forks and rbspy won't see it sudo ['rbspy', *rbspy_args], reason: 'Singed needs to run as root, but will drop permissions back to your user.', env: { 'DISABLE_SPRING' => '1' } end + if defined?(Bundler) + Bundler.with_unbundled_env do + rbspy.call + end + else + rbspy.call + end + unless filename.exist? puts "#{filename} doesn't exist. Maybe rbspy had a failure capturing it? Check the scrollback." exit 1 @@ -102,9 +112,9 @@ def run end # clean the report, similar to how Singed::Report does - json = JSON.parse(filename.read).with_indifferent_access + json = JSON.parse(filename.read) json['shared']['frames'].each do |frame| - frame[:file] = Singed.filter_line(frame[:file]) + frame['file'] = Singed.filter_line(frame['file']) end filename.write(JSON.dump(json))