Class: Enola::Probe

Inherits:
Object
  • Object
show all
Defined in:
lib/enola/probe.rb

Constant Summary collapse

SURFACES =
%w[constraints providers check plan hook].freeze
PROBE_ENV =

A probed binary may be this wrapper wearing another name. The marker travels into the child, where the resolver reads it and leaves PATH alone, so a probe cannot start another one.

"ENOLA_RESOLVER_PROBE"
CHILD_ENV =
{PROBE_ENV => "1"}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(binary) ⇒ Probe

Returns a new instance of Probe.



15
16
17
# File 'lib/enola/probe.rb', line 15

def initialize(binary)
  @binary = binary
end

Instance Method Details

#capabilitiesObject

A surface the binary has prints its usage (exit code 2 is its convention for --help); one it lacks is refused by the top-level dispatch by name.



30
31
32
33
34
35
36
37
# File 'lib/enola/probe.rb', line 30

def capabilities
  SURFACES.to_h do |surface|
    out, = Open3.capture2e(CHILD_ENV, @binary, surface, "--help")
    [surface.to_sym, !out.include?("unknown command \"#{surface}\"")]
  rescue SystemCallError
    [surface.to_sym, false]
  end
end

#report(channel: Enola.channel) ⇒ Object



39
40
41
# File 'lib/enola/probe.rb', line 39

def report(channel: Enola.channel)
  { channel: channel.name, pinned: channel.version, binary: @binary, version: version, capabilities: capabilities }
end

#versionObject



19
20
21
22
23
24
25
26
# File 'lib/enola/probe.rb', line 19

def version
  out, status = Open3.capture2e(CHILD_ENV, @binary, "--version")
  return nil unless status.success?

  out[/\d+\.\d+\.\d+(?:[.-][\w.]+)?/]
rescue SystemCallError
  nil
end