Module: Pkg::Util::Tool

Defined in:
lib/packaging/util/tool.rb

Overview

Utility methods for handling system binaries

Constant Summary collapse

GIT =

Set up paths to system tools we use in the packaging repo

no matter what distribution we're packaging for.
Pkg::Util::Tool.check_tool('git')

Class Method Summary collapse

Class Method Details

.check_tool(tool) ⇒ Object



7
8
9
# File 'lib/packaging/util/tool.rb', line 7

def check_tool(tool)
  find_tool(tool, :required => true)
end

.find_tool(tool, args = { :required => false }) ⇒ Object Also known as: has_tool



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/packaging/util/tool.rb', line 11

def find_tool(tool, args = { :required => false })
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |root|
    location = File.join(root, tool)

    if Pkg::Util::OS.windows? && File.extname(location).empty?
      exts = ENV['PATHEXT']
      exts = exts ? exts.split(File::PATH_SEPARATOR) : %w[.EXE .BAT .CMD .COM]
      exts.each do |ext|
        locationext = File.expand_path(location + ext)

        return "\"#{locationext}\"" if FileTest.executable?(locationext)
      end
    end

    return location if FileTest.executable? location
  end
  fail "#{tool} tool not found...exiting" if args[:required]
  return nil
end