class ArduinoCI::Host

Tools for interacting with the host machine

Constants

e.g. 11/27/2020 01:02 AM <SYMLINKD> ExcludeSomething [C:projectsarduino-ciSampleProjectsExcludeSomething]

WINDOWS_VARIANT_REGEX

TODO: this came from stackoverflow.com/a/22716582/2063546

and I'm not sure if it can be replaced by self.os == :windows

Public Class Methods

os() click to toggle source

return [Symbol] the operating system of the host

# File lib/arduino_ci/host.rb, line 42
def self.os
  return :osx if OS.osx?
  return :linux if OS.linux?
  return :windows if OS.windows?
end
pathname_to_windows(path) click to toggle source

Hack for “realpath” which on windows joins paths with slashes instead of backslashes @param path [Pathname] the path to render @return [String] A path that will work on windows

# File lib/arduino_ci/host.rb, line 70
def self.pathname_to_windows(path)
  path.to_s.tr("/", "\\")
end
run_and_capture(*args, **kwargs) click to toggle source
# File lib/arduino_ci/host.rb, line 32
def self.run_and_capture(*args, **kwargs)
  stdout, stderr, status = Open3.capture3(*args, **kwargs)
  { out: stdout, err: stderr, success: status.exitstatus.zero? }
end
run_and_output(*args, **kwargs) click to toggle source
# File lib/arduino_ci/host.rb, line 37
def self.run_and_output(*args, **kwargs)
  system(*args, **kwargs)
end
which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH. via stackoverflow.com/a/5471032/2063546

which('ruby') #=> /usr/bin/ruby

@param cmd [String] the command to search for @return [String] the full path to the command if it exists

# File lib/arduino_ci/host.rb, line 21
def self.which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end
windows_to_pathname(str) click to toggle source

Hack for “realpath” which on windows joins paths with slashes instead of backslashes @param str [String] the windows path @return [Pathname] A path that will be recognized by pathname

# File lib/arduino_ci/host.rb, line 77
def self.windows_to_pathname(str)
  Pathname.new(str.tr("\\", "/"))
end