Module: Tracetool::Env

Defined in:
lib/tracetool/utils/env.rb

Overview

Utility methods for working with environment

Class Method Summary collapse

Class Method Details

.ensure_atosObject

Checks if ‘atos` can be found in path

Raises:

  • (ArgumentError)

    if can’t find atos



29
30
31
# File 'lib/tracetool/utils/env.rb', line 29

def ensure_atos
  ensure_command('atos')
end

.ensure_command(cmd) ⇒ Object

Raises exception if can’t find executable in path

Raises:

  • (ArgumentError)

    if executable not found



17
18
19
# 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_stackObject

Checks if ‘ndk-stack` can be found in path

Raises:

  • (ArgumentError)

    if can’t find ndk-stack



23
24
25
# File 'lib/tracetool/utils/env.rb', line 23

def ensure_ndk_stack
  ensure_command('ndk-stack')
end

.which(cmd) ⇒ Object

Finds executable in path



6
7
8
9
10
11
12
13
# 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