Skip to content

Commit 140a023

Browse files
Merge pull request #9 from rubyatscale/cli-create-output-directory
Create output directory before trying to have rbspy write to it
2 parents db04e03 + 7ee1603 commit 140a023

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/singed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def output_directory=(directory)
1313
end
1414

1515
def self.output_directory
16-
@output_directory || raise("output directory hasn't been set!")
16+
@output_directory
1717
end
1818

1919
def enabled=(enabled)

lib/singed/cli.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'shellwords'
22
require 'tmpdir'
33
require 'optionparser'
4+
require 'pathname'
45

56
# 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
67

@@ -64,6 +65,7 @@ def run
6465

6566
Singed.output_directory = @output_directory if @output_directory
6667
Singed.output_directory ||= Dir.tmpdir
68+
FileUtils.mkdir_p Singed.output_directory
6769
@filename = Singed::Flamegraph.generate_filename(label: 'cli')
6870

6971
options = {
@@ -86,11 +88,19 @@ def run
8688
prompt_password
8789
end
8890

89-
Bundler.with_unbundled_env do
91+
rbspy = lambda do
9092
# don't run things with spring, because it forks and rbspy won't see it
9193
sudo ['rbspy', *rbspy_args], reason: 'Singed needs to run as root, but will drop permissions back to your user.', env: { 'DISABLE_SPRING' => '1' }
9294
end
9395

96+
if defined?(Bundler)
97+
Bundler.with_unbundled_env do
98+
rbspy.call
99+
end
100+
else
101+
rbspy.call
102+
end
103+
94104
unless filename.exist?
95105
puts "#{filename} doesn't exist. Maybe rbspy had a failure capturing it? Check the scrollback."
96106
exit 1
@@ -102,9 +112,9 @@ def run
102112
end
103113

104114
# clean the report, similar to how Singed::Report does
105-
json = JSON.parse(filename.read).with_indifferent_access
115+
json = JSON.parse(filename.read)
106116
json['shared']['frames'].each do |frame|
107-
frame[:file] = Singed.filter_line(frame[:file])
117+
frame['file'] = Singed.filter_line(frame['file'])
108118
end
109119
filename.write(JSON.dump(json))
110120

0 commit comments

Comments
 (0)