Skip to content

Commit

Permalink
Merge pull request #30 from BetterErrors/fix/load-extension-from-ext-dir
Browse files Browse the repository at this point in the history
Load extension from ext directory when it's not in lib
  • Loading branch information
RobinDaugherty authored Mar 17, 2021
2 parents 7bb0951 + 2680ba0 commit 1b1d576
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
55 changes: 24 additions & 31 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,10 @@ jobs:

- uses: actions/checkout@v2

- name: Determine ruby version name
id: ruby_version
run: |
if [[ $OS == 'windows-latest' && $RUBY == '3.0' ]]; then
# Windows doesn't have 3.0, so run head there but nowhere else.
echo "::set-output name=release::head"
else
echo "::set-output name=release::$RUBY"
fi
shell: bash
env:
OS: ${{ matrix.os }}
RUBY: ${{ matrix.ruby }}

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ steps.ruby_version.outputs.release }}
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Test
Expand All @@ -68,6 +54,8 @@ jobs:
- ubuntu-latest
- windows-latest
ruby:
# This includes rubies that are not actually extended by this gem.
# We want to make sure the gem silently fails to load on those platforms.
- "2"
- "3.0"
- "jruby"
Expand All @@ -81,28 +69,17 @@ jobs:

- uses: actions/checkout@v2

- name: Determine ruby version name
id: ruby_version
run: |
if [[ $OS == 'windows-latest' && $RUBY == '3.0' ]]; then
# Windows doesn't have 3.0, so run head there but nowhere else.
echo "::set-output name=release::head"
else
echo "::set-output name=release::$RUBY"
fi
shell: bash
env:
OS: ${{ matrix.os }}
RUBY: ${{ matrix.ruby }}

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ steps.ruby_version.outputs.release }}
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Build gem
run: bundle exec gem build --verbose debug_inspector.gemspec

- name: Install gem
run: bundle exec rake install
run: gem install --verbose debug_inspector*.gem

- name: Create directory for gem test
run: mkdir -p tmp/gem-test
Expand All @@ -111,9 +88,25 @@ jobs:
run: echo "gem 'debug_inspector'" > Gemfile
working-directory: ./tmp/gem-test

- name: Get gem installation path
id: gem_path
run: |
gem_path=$(bundle show debug_inspector)
echo "gem_path is ${gem_path}"
echo "::set-output name=path::${gem_path}"
shell: bash
working-directory: ./tmp/gem-test

- name: List installed gem contents
run: find .
shell: bash
working-directory: ${{ steps.gem_path.outputs.path }}

- name: Test gem load
run: bundle exec ruby -e "require 'debug_inspector'"
working-directory: ./tmp/gem-test

- name: Test gem functionality
if: ${{ matrix.ruby != 'jruby' && matrix.ruby != 'truffleruby' }}
run: bundle exec ruby -e "require 'debug_inspector'; RubyVM::DebugInspector.open { |dc| dc.frame_binding(1) }"
working-directory: ./tmp/gem-test
13 changes: 11 additions & 2 deletions lib/debug_inspector.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
require 'rbconfig'
dlext = RbConfig::CONFIG['DLEXT']
begin
require_relative "debug_inspector.#{dlext}"
# If the above require fails, we don't want to define any constants.
# If the installation task did its job, the extension is in lib/ next to this file.
require "debug_inspector.#{dlext}"
# We only want to define constants if the extension has loaded.
require_relative "rubyvm/debug_inspector/version"
rescue LoadError
begin
# If not, maybe the extension is in ext/
require_relative "../ext/debug_inspector/debug_inspector.#{dlext}"
# We only want to define constants if the extension has loaded.
require_relative "rubyvm/debug_inspector/version"
rescue LoadError => e
puts "debug_inspector extension was not loaded"
end
end

0 comments on commit 1b1d576

Please sign in to comment.