Class: Kompo::CheckStdlibs
- Inherits:
-
Taski::Task
- Object
- Taski::Task
- Kompo::CheckStdlibs
- Defined in:
- lib/kompo/tasks/check_stdlibs.rb
Overview
Get Ruby standard library paths from installed Ruby
Instance Method Summary collapse
Instance Method Details
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 52 53 54 55 56 |
# File 'lib/kompo/tasks/check_stdlibs.rb', line 10 def run # Check if stdlib should be excluded no_stdlib = Taski.args.fetch(:no_stdlib, false) if no_stdlib @paths = [] puts "Skipping standard library (--no-stdlib)" return end ruby = InstallRuby.ruby_path ruby_install_dir = InstallRuby.ruby_install_dir original_ruby_install_dir = InstallRuby.original_ruby_install_dir ruby_major_minor = InstallRuby.ruby_major_minor # Include the Ruby standard library root directory # This includes bundler and other default gems that are not in $: # Ruby uses "X.Y.0" format for lib/ruby paths (e.g., "3.4.0" not "3.4") stdlib_root = File.join(ruby_install_dir, "lib", "ruby", "#{ruby_major_minor}.0") # RubyGems needs gemspec files in specifications/ directory gems_specs_root = File.join(ruby_install_dir, "lib", "ruby", "gems", "#{ruby_major_minor}.0", "specifications") if Dir.exist?(stdlib_root) @paths = [stdlib_root, gems_specs_root].select { |p| Dir.exist?(p) } puts "Including Ruby standard library: #{stdlib_root}" puts "Including gem specifications: #{gems_specs_root}" if Dir.exist?(gems_specs_root) else # Fallback to $: paths if stdlib root doesn't exist output, status = Open3.capture2(ruby, "-e", "puts $:", err: File::NULL) unless status.success? raise "Failed to get Ruby standard library paths: exit code #{status.exitstatus}, output: #{output}" end raw_paths = output.split("\n").reject(&:empty?) @paths = raw_paths.map do |path| next nil unless path.start_with?("/") if original_ruby_install_dir != ruby_install_dir && path.start_with?(original_ruby_install_dir) path.sub(original_ruby_install_dir, ruby_install_dir) else path end end.compact puts "Found #{@paths.size} standard library paths (fallback)" end end |