Module: Bulldogger::Flt

Defined in:
lib/bulldogger/flt.rb

Constant Summary collapse

SCHEMA_VERSION =
1

Class Method Summary collapse

Class Method Details

.run(fid, command, index: nil, output_dir: ENV.fetch("BULLDOGGER_OUTPUT_DIR", "tmp/bulldogger"), stdout: $stdout, stderr: $stderr) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bulldogger/flt.rb', line 15

def run(fid, command, index: nil, output_dir: ENV.fetch("BULLDOGGER_OUTPUT_DIR", "tmp/bulldogger"), stdout: $stdout, stderr: $stderr)
  target = ExecutionTarget.parse(fid, "flt")
  raise ArgumentError, "flt requires a command after --" if command.empty?

  code_state = CodeState.capture(target.root)
  return 1 unless ExecutionTarget.acceptable?(target, index: index, code_state: code_state, verb: "flt", stderr: stderr, fid: fid)

  output_dir = File.expand_path(output_dir)
  FileUtils.mkdir_p(output_dir)
  base_path = File.join(output_dir, "flt")
  env = CollectorEnvironment.build("flt_collector.rb", "BULLDOGGER_FLT_OUT" => base_path, "BULLDOGGER_FLT_FID" => fid)
  pid = Process.spawn(env, *command)
  _waited_pid, status = Process.wait2(pid)
  path = "#{base_path}-#{pid}.jsonl"
  records = File.file?(path) ? File.readlines(path, chomp: true).map { |entry| JSON.parse(entry) } : []
  summary = records.reverse.find { |record| record["type"] == "target_summary" }
  envelope = {
    "type" => "envelope", "schema_version" => SCHEMA_VERSION,
    "code_state" => code_state, "command" => command, "exit_status" => status.exitstatus
  }
  if summary
    envelope["observed_calls"] = summary["observed_calls"]
    envelope["target_index"] = summary["target_index"]
    envelope["traced"] = false
  end
  File.open(path, "a") { |file| file.puts JSON.generate(envelope) }
  stdout.puts "bulldogger flt: #{path}"
  stdout.puts "bulldogger note: #{never_traced_note(summary)}" if summary
  stdout.puts "bulldogger result: #{Frames.send(:outcome, status)} (exit #{status.exitstatus || status.termsig})"
  status
end