Module: FluentTools::Utils
- Defined in:
- lib/fluent_tools/utils.rb
Overview
Shared utilities for fluent-tools
Defined Under Namespace
Modules: Logger
Constant Summary collapse
- REPO_OWNER =
Project constants
'Automattic'- BINARY_NAME =
'fluent-tools'- REPO_NAME =
'fluent-rust-tools'- PLATFORM_RUST_TARGETS =
Platform to Rust target mapping
{ 'x86_64-linux' => 'x86_64-unknown-linux-gnu', 'arm64-linux' => 'aarch64-unknown-linux-gnu', 'x86_64-darwin' => 'x86_64-apple-darwin', 'arm64-darwin' => 'aarch64-apple-darwin', 'x86_64-windows' => 'x86_64-pc-windows-gnu', 'arm64-windows' => 'aarch64-pc-windows-gnullvm' }.freeze
Class Method Summary collapse
-
.binary_extension(platform = nil) ⇒ Object
Get binary extension for current platform.
-
.binary_name_for_platform(platform) ⇒ Object
Generate the expected binary name for a given platform Adds .exe extension for Windows platforms.
-
.detect_platform ⇒ Object
Platform detection using RbConfig to identify the current system Returns a string in the format "architecture-os" (e.g., "arm64-darwin") Returns nil if the platform is not supported.
- .determine_install_dir ⇒ Object
-
.platform_to_rust_target(platform) ⇒ Object
Convert platform name to Rust target triple.
-
.validate_platform!(platform) ⇒ Object
Validate that a platform is supported.
-
.windows_platform?(platform = nil) ⇒ Boolean
Check if the current platform is Windows.
Class Method Details
.binary_extension(platform = nil) ⇒ Object
Get binary extension for current platform
67 68 69 |
# File 'lib/fluent_tools/utils.rb', line 67 def self.binary_extension(platform = nil) windows_platform?(platform) ? '.exe' : '' end |
.binary_name_for_platform(platform) ⇒ Object
Generate the expected binary name for a given platform Adds .exe extension for Windows platforms
55 56 57 58 |
# File 'lib/fluent_tools/utils.rb', line 55 def self.binary_name_for_platform(platform) extension = binary_extension(platform) "#{BINARY_NAME}-#{platform}#{extension}" end |
.detect_platform ⇒ Object
Platform detection using RbConfig to identify the current system Returns a string in the format "architecture-os" (e.g., "arm64-darwin") Returns nil if the platform is not supported
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fluent_tools/utils.rb', line 26 def self.detect_platform host_os = RbConfig::CONFIG['host_os'] host_cpu = RbConfig::CONFIG['host_cpu'] platform = case host_os when /linux/ 'linux' when /darwin/ 'darwin' when /mingw|mswin/ 'windows' else return nil end architecture = case host_cpu when /x86_64|amd64/ 'x86_64' when /arm64|aarch64/ 'arm64' else return nil end "#{architecture}-#{platform}" end |
.determine_install_dir ⇒ Object
84 85 86 87 88 89 |
# File 'lib/fluent_tools/utils.rb', line 84 def self.determine_install_dir root_gem_dir = File.join(__dir__, '..', '..') bin_dir = File.join(root_gem_dir, 'bin') FileUtils.mkdir_p(bin_dir) bin_dir end |
.platform_to_rust_target(platform) ⇒ Object
Convert platform name to Rust target triple
79 80 81 82 |
# File 'lib/fluent_tools/utils.rb', line 79 def self.platform_to_rust_target(platform) validate_platform!(platform) PLATFORM_RUST_TARGETS[platform] end |
.validate_platform!(platform) ⇒ Object
Validate that a platform is supported
72 73 74 75 76 |
# File 'lib/fluent_tools/utils.rb', line 72 def self.validate_platform!(platform) return if PLATFORM_RUST_TARGETS.key?(platform) raise "Invalid platform: #{platform}. Valid platforms: #{PLATFORM_RUST_TARGETS.keys.join(', ')}" end |
.windows_platform?(platform = nil) ⇒ Boolean
Check if the current platform is Windows
61 62 63 64 |
# File 'lib/fluent_tools/utils.rb', line 61 def self.windows_platform?(platform = nil) platform ||= detect_platform platform&.include?('windows') || false end |