Skip to content

Commit 8827d24

Browse files
committed
Merge pull request #231 in G/truffleruby from pitr-ch/patching to master
* commit '74ba6cdb7e12d4a196584cc8250fe10f1f154efc': Simpler and more robust patching
2 parents d164b01 + 74ba6cd commit 8827d24

File tree

27 files changed

+171
-227
lines changed

27 files changed

+171
-227
lines changed

doc/contributor/workarounds.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
# Patching system
2-
3-
The patching system is loaded in `post-boot.rb` and is able to patch stdlib and
4-
installed gems. The code implementing the patching itself can be found in
5-
`lib/truffle/truffle/patching.rb`. It can be disabled by passing the
6-
`-Xpatching=false` option.
7-
8-
The patching system works for gems as follows. When a gem *g* is activated,
9-
there is a directory `g` in `lib/patches`, and the directory is listed in
10-
`lib/truffle/truffle/patching.rb`, the directory is inserted into `$LOAD_PATH`
11-
before the original load-paths of the *g* gem. As a result the patching files
12-
are loaded first before the original files in the gem. The patching file is
13-
responsible for loading the original file (if desirable), which can be done with
14-
`Truffle::Patching.require_original __FILE__`.
1+
# Ruby files patching system
2+
3+
When `require 'some/patch'` (has to be a relative path) is called
4+
and an original file exists on `$LOAD_PATH`
5+
and there is a patch file `some/patch.rb` in a special directory `lib/patches`
6+
then the TruffleRuby will first evaluate (not require) the file
7+
`lib/patches/some/patch.rb` instead.
8+
9+
To require the original file call `require 'some/patch'` in the
10+
`lib/patches/some/patch.rb` file. It will require the original ruby
11+
file found on `$LOAD_PATH` ( stdlib file or a gem file).
12+
13+
When requiring the original file is not desired just omit the
14+
`require 'some/patch'` in the patch file. The patch file will be evaluated
15+
only once.
16+
17+
The evaluated patch files are not visible in `$LOAD_PATH` nor `$LOADED_FEATURES`.
18+
19+
Patching can be disabled by passing the `-Xpatching=false` option.
20+
`-X.log=CONFIG` can be used to see paths of loaded patch files.
1521

1622
# C file preprocessing
1723

lib/patches/bundler/bundler.rb renamed to lib/patches/bundler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Truffle::Patching.require_original __FILE__
1+
require 'bundler'
22

33
unless Bundler::VERSION =~ /^1\.16\./
44
raise "unsupported bundler version #{Bundler::VERSION}, please use 1.16.x"

lib/patches/bundler/bundler/runtime.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/patches/bundler/bundler/cli/exec.rb renamed to lib/patches/bundler/cli/exec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2323
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424

25-
Truffle::Patching.require_original __FILE__
25+
require 'bundler/cli/exec'
2626

2727
module Bundler
2828
class CLI::Exec

lib/patches/bundler/bundler/current_ruby.rb renamed to lib/patches/bundler/current_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2323
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424

25-
Truffle::Patching.require_original __FILE__
25+
require 'bundler/current_ruby'
2626

2727
module Bundler
2828
class CurrentRuby

lib/patches/bundler/bundler/dependency.rb renamed to lib/patches/bundler/dependency.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2323
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424

25-
Truffle::Patching.require_original __FILE__
25+
require 'bundler/dependency'
2626

2727
class Bundler::Dependency
2828

lib/patches/bundler/bundler/ruby_version.rb renamed to lib/patches/bundler/ruby_version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2323
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424

25-
Truffle::Patching.require_original __FILE__
25+
require 'bundler/ruby_version'
2626

2727
module Bundler
2828
class RubyVersion

lib/patches/bundler/bundler/source/rubygems.rb renamed to lib/patches/bundler/source/rubygems.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2525
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626

27-
Truffle::Patching.require_original __FILE__
27+
require 'bundler/source/rubygems'
2828

2929
# TruffleRuby: do not skips gems with extensions not built
3030

lib/patches/launchy/launchy/detect/ruby_engine.rb renamed to lib/patches/launchy/detect/ruby_engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1313
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1414

15-
Truffle::Patching.require_original __FILE__
15+
require 'launchy/detect/ruby_engine'
1616

1717
module Launchy::Detect
1818
class RubyEngine

0 commit comments

Comments
 (0)