Skip to content

Commit

Permalink
Merge pull request #3 from ccorn90/ccorn90/rubyopt
Browse files Browse the repository at this point in the history
Add option to suppress or override RUBYOPT environment variable
  • Loading branch information
Largo authored Sep 8, 2023
2 parents d39cf1c + 24413aa commit a9efa78
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
=== 1.3.14
- Add option to suppress or override RUBYOPT environment variable #3 by ccorn90

=== 1.3.13
- Fixed the bug why Innosetup did not run because of missing encode method
- Fix an issue where rubyinstaller did not find the msys path by putting in an empty msys-2.0.dll into msys64/usr/bin/msys-2.0.dll
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Executable options:
--console Force console application (ruby.exe)
--chdir-first When exe starts, change working directory to app dir.
--icon <ico> Replace icon with a custom one.
--rubyopt <str> Set the RUBYOPT environment variable when running the executable
--debug Executable will be verbose.
--debug-extract Executable will unpack to local dir and not delete after.

Expand Down
8 changes: 6 additions & 2 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ module Ocran
a.sort.inject([]) { |r, e| r.last == e ? r : r << e }
end

VERSION = "1.3.13"
VERSION = "1.3.14"

IGNORE_MODULE_NAMES = /\/(enumerator.so|rational.so|complex.so|fiber.so|thread.rb|ruby2_keywords.rb)$/

Expand Down Expand Up @@ -230,6 +230,7 @@ module Ocran
:force_windows => false,
:force_console => false,
:icon_filename => nil,
:rubyopt => nil,
:gemfile => nil,
:inno_script => nil,
:quiet => false,
Expand Down Expand Up @@ -362,6 +363,7 @@ Executable options:
--console Force console application (ruby.exe)
--chdir-first When exe starts, change working directory to app dir.
--icon <ico> Replace icon with a custom one.
--rubyopt <str> Set the RUBYOPT environment variable when running the executable
--debug Executable will be verbose.
--debug-extract Executable will unpack to local dir and not delete after.
EOF
Expand Down Expand Up @@ -393,6 +395,8 @@ EOF
when /\A--icon\z/
@options[:icon_filename] = Pathname(argv.shift)
Ocran.fatal_error "Icon file #{icon_filename} not found.\n" unless icon_filename.exist?
when /\A--rubyopt\z/
@options[:rubyopt] = argv.shift
when /\A--gemfile\z/
@options[:gemfile] = Pathname(argv.shift)
Ocran.fatal_error "Gemfile #{gemfile} not found.\n" unless gemfile.exist?
Expand Down Expand Up @@ -979,7 +983,7 @@ EOF
sb.createfile((Tempfile.new("msys-2.0.dll")).path.to_s, 'msys64/usr/bin/msys-2.0.dll') unless sb.files.keys.any? { |entry| entry.to_s.include?("msys-2.0.dll") }

# Set environment variable
sb.setenv("RUBYOPT", ENV["RUBYOPT"] || "")
sb.setenv("RUBYOPT", Ocran.rubyopt || ENV["RUBYOPT"] || "")
sb.setenv("RUBYLIB", load_path.map { |path| path.to_native }.uniq.join(";"))

sb.setenv("GEM_PATH", (TEMPDIR_ROOT / GEMHOMEDIR).to_native)
Expand Down
2 changes: 1 addition & 1 deletion lib/ocran/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Ocran
VERSION = "1.3.13"
VERSION = "1.3.14"
end
18 changes: 17 additions & 1 deletion test/test_ocra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def test_exception
end
end

# Test that the RUBYOPT environment variable is preserved.
# Test that the RUBYOPT environment variable is preserved when --rubyopt is not passed
def test_rubyopt
with_fixture 'environment' do
with_env "RUBYOPT" => "-rtime" do
Expand All @@ -563,6 +563,22 @@ def test_rubyopt
end
end

# Test that the RUBYOPT environment variable can be set manually with --rubyopt
def test_rubyopt_manual
specified_rubyopt = "-rbundler --verbose"
test_args = DefaultArgs + ["--rubyopt", "'#{specified_rubyopt}'"
with_fixture 'environment' do
with_env "RUBYOPT" => "-rtime" do
assert system("ruby", ocran, "environment.rb", *test_args)
pristine_env "environment.exe" do
assert system("environment.exe")
env = Marshal.load(File.open("environment", "rb") { |f| f.read })
assert_equal specified_rubyopt, env['RUBYOPT']
end
end
end
end

def test_exit
with_fixture 'exit' do
assert system("ruby", ocran, "exit.rb", *DefaultArgs)
Expand Down

0 comments on commit a9efa78

Please sign in to comment.