ruby-build
ruby-build copied to clipboard
Feature: more flexible mirror URL by a command
This PR provides a more flexible way to specify the mirror URL by using a shell function than #1457.
For #1457, users need to know the complete mirror URL, and another drawback is users need to change the RUBY_BUILD_MIRROR_PACKAGE_URL
env every time they install a different version.
This PR resolves these two drawbacks. Users can build the final mirror URL by any shell commands.
Thanks to the author of #1032, the idea comes from that thread.
@eregon I've updated the example to a POSIX compatible one. Please have a review. Thanks.
Thanks, that variant avoids relying on exporting shell functions which seems far more portable.
I feel like an env var to set the mirror base URL could be simpler, but one issue is e.g.
https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
is mirrored as
https://mirror.cyberbits.eu/ruby/3.0/ruby-3.0.0.tar.gz
https://cache.ruby-china.com/pub/ruby/3.0/ruby-3.0.0.tar.gz
CRuby mirror list
BTW many of these mirrors don't have recent releases, I wonder which are actually used.
The China 2 (Ruby China)
mirror at least has the same structure as cache.ruby-lang.org/
so for those we could just reuse the URL path and just change the domain.
@hsbt What do you think?
IMO, just changing the domain is definitely the simplest solution. But so far, ruby-build
actually doesn't support this way, some codes need to be added. For example, for RUBY_BUILD_MIRROR_URL
, the final mirror URL is built by concatenating RUBY_BUILD_MIRROR_URL
with the checksum, so we cannot rely on it.
https://github.com/rbenv/ruby-build/blob/57c397d7cabf9f0ff73b8c03c4c1859a3850405a/bin/ruby-build#L364-L371
Just changing the domain may also not work for other ruby variants, like jruby (e.g. one url is https://s3.amazonaws.com/jruby.org/downloads/1.7.22/jruby-bin-1.7.22.tar.gz#554da042087bd4a787c73626c81fa354c9ce1168735032f7d954cffec85f5a4a
).
This looks mostly compatible with the implementation that node-build uses from nodenv/node-build#210
As @uzxmx mentioned different mirror urls, it's the same reason node-build opted to accept the _CMD
env var: to be flexible enough to handle any mirror and not be limited to those that preserve identical path formats, or that accept the checksum in different ways.
@mislav Thanks for the suggestion. It's truly useful. Already adopted.
I agree the combination of RUBY_BUILD_MIRROR_PACKAGE_URL
with RUBY_BUILD_DEFAULT_MIRROR
is a bit confusing unless we read the whole logic carefully. Those names might mislead new users. If the old compatibility is not desired, I also vote to eliminate them.
Those names might mislead new users. If the old compatibility is not desired, I also vote to eliminate them.
Ah, I just realized that RUBY_BUILD_MIRROR_PACKAGE_URL was supported since Dec 2020. I wasn't aware of that. In the interest of backwards compatibility, it should keep being supported, but perhaps we should strip it from documentation in favor of RUBY_BUILD_MIRROR_CMD and perhaps print a deprecation warning to stderr when someone attempts to use it.
@eregon @hsbt @mislav
Could you help to make a conclusion about what else should be done? I'm eager to make the according changes to get it merged. 😄