module Tracetool::Env

Utility methods for working with environment

Public Class Methods

ensure_atos() click to toggle source

Checks if `atos` can be found in path @raise [ArgumentError] if can't find atos

# File lib/tracetool/utils/env.rb, line 29
def ensure_atos
  ensure_command('atos')
end
ensure_command(cmd) click to toggle source

Raises exception if can't find executable in path @raise [ArgumentError] if executable not found

# File lib/tracetool/utils/env.rb, line 17
def ensure_command(cmd)
  raise(ArgumentError, "#{cmd} not found in PATH") unless which(cmd)
end
ensure_ndk_stack() click to toggle source

Checks if `ndk-stack` can be found in path @raise [ArgumentError] if can't find ndk-stack

# File lib/tracetool/utils/env.rb, line 23
def ensure_ndk_stack
  ensure_command('ndk-stack')
end
which(cmd) click to toggle source

Finds executable in path

# File lib/tracetool/utils/env.rb, line 6
def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  candidates = ENV['PATH'].split(File::PATH_SEPARATOR).flat_map do |path|
    exts.map { |ext| File.join(path, "#{cmd}#{ext}") }
  end

  candidates.find { |exe| File.executable?(exe) && !File.directory?(exe) }
end