Skip to content

Commit

Permalink
Store rubyopt value in Direction object
Browse files Browse the repository at this point in the history
  • Loading branch information
shinokaro committed Jul 29, 2024
1 parent 0f6699d commit 1b75c10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
14 changes: 0 additions & 14 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ module Ocran

def self.script = @option.script

def self.rubyopt = @rubyopt

def self.run_script? = @option.run_script?

def Ocran.init
Expand All @@ -53,18 +51,6 @@ module Ocran
ARGV.replace(opt.argv)
end

# Initializes @rubyopt with the user-intended RUBYOPT environment variable.
# This ensures that RUBYOPT matches the user's initial settings before any
# modifications that may occur during script execution.
@rubyopt = @option.rubyopt || ENV["RUBYOPT"] || ""

# FIXME: Remove the absolute path to bundler/setup from RUBYOPT
# This is a temporary measure to ensure compatibility with self-extracting executables
# built in a bundle exec environment, particularly for Ruby 3.2 and later where
# absolute paths are included in RUBYOPT.
# In the future, we plan to implement a more appropriate solution.
@rubyopt = @rubyopt.gsub(%r(-r#{Regexp.escape(RbConfig::TOPDIR)}(/.*/bundler/setup)), "")

@ignore_modules = ObjectSpace.each_object(Module).to_a
end

Expand Down
17 changes: 15 additions & 2 deletions lib/ocran/direction.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require "rbconfig"
require "pathname"
require_relative "refine_pathname"
require_relative "host_config_helper"
Expand All @@ -17,11 +18,23 @@ class Direction

include HostConfigHelper, CommandOutput

attr_reader :ruby_executable
attr_reader :ruby_executable, :rubyopt

def initialize(post_env, pre_env, option)
@post_env, @pre_env, @option = post_env, pre_env, option
@ruby_executable = @option.windowed? ? rubyw_exe : ruby_exe

# Initializes @rubyopt with the user-intended RUBYOPT environment variable.
# This ensures that RUBYOPT matches the user's initial settings before any
# modifications that may occur during script execution.
@rubyopt = @option.rubyopt || pre_env.env["RUBYOPT"] || ""

# FIXME: Remove the absolute path to bundler/setup from RUBYOPT
# This is a temporary measure to ensure compatibility with self-extracting executables
# built in a bundle exec environment, particularly for Ruby 3.2 and later where
# absolute paths are included in RUBYOPT.
# In the future, we plan to implement a more appropriate solution.
@rubyopt = @rubyopt.gsub(%r(-r#{Regexp.escape(RbConfig::TOPDIR)}(/.*/bundler/setup)), "")
end

# Resolves the common root directory prefix from an array of absolute paths.
Expand Down Expand Up @@ -300,7 +313,7 @@ def to_proc
end

# Set environment variable
builder.export("RUBYOPT", Ocran.rubyopt)
builder.export("RUBYOPT", rubyopt)
# Add the load path that are required with the correct path after
# src_prefix was adjusted.
load_path = src_load_path.map { |path| SRCDIR / path.relative_path_from(inst_src_prefix) }.uniq
Expand Down

0 comments on commit 1b75c10

Please sign in to comment.