Module: Ukiryu::ExecutableLocator

Defined in:
lib/ukiryu/executable_locator.rb

Overview

Executable locator for finding tool executables

Uses OOP discovery strategies:

  • AliasDiscovery (via Shell class)

  • SystemCommandDiscovery (which/where/command -v)

  • PathDiscovery (manual PATH search)

Examples:

Finding an executable

path = ExecutableLocator.find(
  tool_name: 'imagemagick',
  aliases: ['magick']
)

Defined Under Namespace

Modules: AliasDiscovery, DiscoveryResult, DiscoveryStrategy, PathDiscovery, PathScanner, SystemCommandDiscovery, SystemCommandExecutor Classes: DiscoveryContext, PathExtensions

Constant Summary collapse

INTERNAL_COMMAND_TIMEOUT =
5

Class Method Summary collapse

Class Method Details

.find(tool_name:, aliases: [], platform: nil) ⇒ String?

Find an executable by name

Parameters:

  • tool_name (String)

    the primary tool name

  • aliases (Array<String>) (defaults to: [])

    alternative names to try

  • platform (Symbol) (defaults to: nil)

    the platform (defaults to Runtime.platform)

Returns:

  • (String, nil)

    the executable path or nil if not found



28
29
30
31
# File 'lib/ukiryu/executable_locator.rb', line 28

def find(tool_name:, aliases: [], platform: nil)
  result = find_with_info(tool_name: tool_name, aliases: aliases, platform: platform)
  result&.dig(:path)
end

.find_in_path(command, additional_paths: []) ⇒ String?

Find an executable in the system PATH

Parameters:

  • command (String)

    the command or executable name

  • additional_paths (Array<String>) (defaults to: [])

    additional search paths (for backward compatibility)

Returns:

  • (String, nil)

    the full path to the executable, or nil if not found



73
74
75
# File 'lib/ukiryu/executable_locator.rb', line 73

def find_in_path(command, additional_paths: [])
  PathScanner.find(command, additional_paths: additional_paths)
end

.find_with_info(tool_name:, aliases: [], platform: nil) ⇒ Hash?

Find an executable with full discovery information

Parameters:

  • tool_name (String)

    the primary tool name

  • aliases (Array<String>) (defaults to: [])

    alternative names to try

  • platform (Symbol) (defaults to: nil)

    the platform (defaults to Runtime.platform)

Returns:

  • (Hash, nil)

    “…”, info: ExecutableInfo or nil if not found



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ukiryu/executable_locator.rb', line 39

def find_with_info(tool_name:, aliases: [], platform: nil)
  platform ||= Ukiryu::Runtime.instance.platform
  context = DiscoveryContext.new(platform)

  # Debug logging for Windows CI
  if ENV['UKIRYU_DEBUG_EXECUTABLE'] || (platform == :windows && ENV['CI'])
    warn "[UKIRYU DEBUG ExecutableLocator] Searching for tool: #{tool_name.inspect}"
    warn "[UKIRYU DEBUG ExecutableLocator] Aliases: #{aliases.inspect}"
    warn "[UKIRYU DEBUG ExecutableLocator] Detected shell: #{context.shell_sym.inspect}"
    warn "[UKIRYU DEBUG ExecutableLocator] Shell class: #{context.shell_class.inspect}"
  end

  # Try primary name first
  result = DiscoveryStrategy.discover(tool_name, context)
  warn "[UKIRYU DEBUG ExecutableLocator] Found #{tool_name}: #{result[:path]}" if result && (ENV['UKIRYU_DEBUG_EXECUTABLE'] || (platform == :windows && ENV['CI']))
  return result if result

  # Try aliases
  aliases.each do |alias_name|
    result = DiscoveryStrategy.discover(alias_name, context)
    warn "[UKIRYU DEBUG ExecutableLocator] Found alias #{alias_name}: #{result[:path]}" if result && (ENV['UKIRYU_DEBUG_EXECUTABLE'] || (platform == :windows && ENV['CI']))
    return result if result
  end

  warn "[UKIRYU DEBUG ExecutableLocator] NO EXECUTABLE FOUND for #{tool_name} or aliases #{aliases}" if ENV['UKIRYU_DEBUG_EXECUTABLE'] || (platform == :windows && ENV['CI'])

  nil
end