Class: Fastlane::Helper::HexsignHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/hexsign/helper/hexsign_helper.rb

Constant Summary collapse

INSTALL_HINT =
"Install it with `brew install hexsign` or via the hexsign/hexsign-cli GitHub Action."

Class Method Summary collapse

Class Method Details

.binary_pathObject



14
15
16
# File 'lib/fastlane/plugin/hexsign/helper/hexsign_helper.rb', line 14

def self.binary_path
  @binary_path ||= find_binary
end

.find_binaryObject



23
24
25
26
27
# File 'lib/fastlane/plugin/hexsign/helper/hexsign_helper.rb', line 23

def self.find_binary
  path = which("hexsign")
  UI.user_error!("hexsign binary not found on PATH. #{INSTALL_HINT}") if path.nil?
  path
end

.reset!Object

Resets memoization. Tests only.



19
20
21
# File 'lib/fastlane/plugin/hexsign/helper/hexsign_helper.rb', line 19

def self.reset!
  @binary_path = nil
end

.run(args) ⇒ Object

Runs the CLI and returns stdout. Raises FastlaneCore::Interface::FastlaneError on non-zero exit, surfacing stderr to the user.



42
43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/hexsign/helper/hexsign_helper.rb', line 42

def self.run(args)
  cmd = [binary_path, *args]
  UI.command(cmd.shelljoin)
  stdout, stderr, status = Open3.capture3(*cmd)
  unless status.success?
    UI.error(stderr.strip) unless stderr.strip.empty?
    UI.user_error!("hexsign exited with status #{status.exitstatus}")
  end
  stdout
end

.which(cmd) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/fastlane/plugin/hexsign/helper/hexsign_helper.rb', line 29

def self.which(cmd)
  exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
  ENV["PATH"].to_s.split(File::PATH_SEPARATOR).each do |dir|
    exts.each do |ext|
      candidate = File.join(dir, "#{cmd}#{ext}")
      return candidate if File.executable?(candidate) && !File.directory?(candidate)
    end
  end
  nil
end