New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rubygems installer uses absolute pathnames in generated windows stub batch files #2111

Open
oxygene opened this Issue Dec 11, 2017 · 2 comments

Comments

Projects
None yet
5 participants
@oxygene

oxygene commented Dec 11, 2017

I'd like to propose to use %~dp0 instead of the hardcoded absolute path to ruby when generating the windows stub batch files.

The rationale is that I'd like to use some gems with jruby in order to deploy a portable self-contained folder that I can put on a build-VM without internet access. Please see jruby/jruby#4890 for my initial bug report that I have wrongfully filed on the jruby project.

Here seems to be the relevant code:

def windows_stub_script(bindir, bin_file_name)
ruby = Gem.ruby.gsub(/^\"|\"$/, "").tr(File::SEPARATOR, "\\")
return <<-TEXT
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"#{ruby}" "#{File.join(bindir, bin_file_name)}" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"#{ruby}" "%~dpn0" %*
TEXT
end

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Dec 17, 2017

Anyone able to test the proposed fix? I currently have no windows platform available.

ghost commented Dec 17, 2017

Anyone able to test the proposed fix? I currently have no windows platform available.

@MSP-Greg

This comment has been minimized.

Show comment
Hide comment
@MSP-Greg

MSP-Greg Dec 19, 2017

Contributor

@shevegen

Anyone able to test the proposed fix?

Where is the proposed fix?

This has been on my to-do list for a while, and I've got a bookmark to the code (same as above). Been busy with 2.5 and --enable-frozen-string-literal issues (including in RubyGems)...

I'll get to it, as it creates quite a mess when people (me) try to create portable install sets/images. I've got code in my build system, but that only affects bin files included in the build.

Within the next few days, Greg

EDIT: I'll create the patch, test it locally in ruby-loco, then use it with a build or two on Appveyor. If all is ok, I'll do a PR here...

Contributor

MSP-Greg commented Dec 19, 2017

@shevegen

Anyone able to test the proposed fix?

Where is the proposed fix?

This has been on my to-do list for a while, and I've got a bookmark to the code (same as above). Been busy with 2.5 and --enable-frozen-string-literal issues (including in RubyGems)...

I'll get to it, as it creates quite a mess when people (me) try to create portable install sets/images. I've got code in my build system, but that only affects bin files included in the build.

Within the next few days, Greg

EDIT: I'll create the patch, test it locally in ruby-loco, then use it with a build or two on Appveyor. If all is ok, I'll do a PR here...

@MSP-Greg MSP-Greg referenced this issue Dec 20, 2017

Merged

Make Windows bin stubs portable #2119

2 of 4 tasks complete

bundlerbot added a commit that referenced this issue Jun 11, 2018

Auto merge of #2119 - MSP-Greg:windows_bin_stub_portable, r=hsbt
Make Windows bin stubs portable

# Description:

Windows bin stubs for installed gems are not portable due to the fact that the path (at install time) is  embedded in the .bat or .cmd file.  This patch removes the path and replaces with `%~dp0`, which is the windows cmd variable for the running script's path.

It passed tests locally, and I patched a fresh 2.4.3 install with it and updated/installed bundler and rake.  I even added a space to the path and all commands correcty ran from a command prompt.

See #2111

______________

# Tasks:

- [X] Describe the problem / feature
- [ ] Write tests
- [X] Write code to solve the problem
- [ ] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment