Skip to content

Commit

Permalink
Merge pull request #1735 from ruby/backport-1731
Browse files Browse the repository at this point in the history
Merge pull request #1731 from ruby/gem-rbs-load
  • Loading branch information
soutaro committed Jan 25, 2024
2 parents 69ff8d9 + 83d4008 commit 9d3e988
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 41 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ on:
merge_group: {}

jobs:
test:
comments:
runs-on: "ubuntu-latest"
container:
image: rubylang/ruby:3.2-dev-focal
env:
RUBY_COMMIT: v3_3_0
# env:
# RUBY_COMMIT: v3_3_0
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler: none
- name: Install dependencies
run: |
apt-get update
apt-get install -y libdb-dev curl
sudo apt-get update
sudo apt-get install -y libdb-dev curl
- name: Update rubygems & bundler
run: |
ruby -v
Expand Down
43 changes: 18 additions & 25 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,32 @@ jobs:
strategy:
fail-fast: false
matrix:
container_tag:
- master-nightly-focal
- 3.2-dev-focal
- 3.1-dev-focal
- 3.0-dev-focal
ruby: ['3.0', '3.1', '3.2', '3.3', head]
job:
- test
- stdlib_test
- rubocop validate test_doc build test_generate_stdlib
- lexer confirm_lexer
- lexer compile
exclude:
- container_tag: master-nightly-focal
job: confirm_lexer
- container_tag: 3.0-dev-focal
include:
- ruby: head
job: stdlib_test rubocop
- ruby: "3.3"
job: stdlib_test
- container_tag: 3.1-dev-focal
job: stdlib_test
- container_tag: 3.2-dev-focal
job: stdlib_test
container:
image: rubylang/ruby:${{ matrix.container_tag }}
- ruby: "3.3"
job: lexer compile confirm_lexer
- ruby: "3.3"
job: rubocop validate test_doc build test_generate_stdlib
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler: none
- name: Set working directory as safe
run: git config --global --add safe.directory $(pwd)
- name: Install dependencies
run: |
apt-get update
apt-get install -y libdb-dev curl autoconf automake m4 libtool python3
sudo apt-get update
sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool python3
- name: Install Re2c
if: contains(matrix.job, 'lexer')
if: ${{ contains(matrix.job, 'lexer') }}
run: |
cd /tmp
curl -L https://github.com/skvadrik/re2c/archive/refs/tags/3.1.tar.gz > re2c-3.1.tar.gz
Expand All @@ -53,7 +47,7 @@ jobs:
autoreconf -i -W all
./configure
make
make install
sudo make install
- name: Update rubygems & bundler
run: |
ruby -v
Expand All @@ -62,14 +56,13 @@ jobs:
run: |
echo "NO_MINITEST=true" >> $GITHUB_ENV
bundle config set --local without 'minitest'
if: ${{ contains(matrix.container_tag, 'master-nightly') }}
if: ${{ contains(matrix.ruby, 'head') }}
- name: bin/setup
run: |
bin/setup
- name: Run test
run: |
bundle exec rake ${{ matrix.job }}
continue-on-error: ${{ matrix.allow_failures == 'true' && (github.event_name == 'push' || github.event_name == 'merge_group') }}
windows:
runs-on: ${{ matrix.os }}
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ on:
merge_group: {}

jobs:
test:
steep:
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
container_tag:
- 3.2-dev-focal
container:
image: rubylang/ruby:${{ matrix.container_tag }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler: none
- name: Set working directory as safe
run: git config --global --add safe.directory $(pwd)
- name: Install dependencies
run: |
apt-get update
apt-get install -y libdb-dev curl autoconf automake m4 libtool
sudo apt-get update
sudo apt-get install -y libdb-dev curl
- name: Update rubygems & bundler
run: |
ruby -v
Expand Down
16 changes: 15 additions & 1 deletion lib/rbs/environment_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,21 @@ def add_collection(lockfile)
repository.add(lockfile.fullpath)

lockfile.gems.each_value do |gem|
add(library: gem[:name], version: gem[:version], resolve_dependencies: false)
name = gem[:name]
locked_version = gem[:version]

if (source = gem[:source]).is_a?(Collection::Sources::Rubygems)
# allow loading different version of a gem

unless source.has?(name, locked_version)
if (spec, _ = self.class.gem_sig_path(name, nil))
RBS.logger.warn { "Loading type definition from gem `#{name}-#{spec.version}` because locked version `#{locked_version}` is unavailable. Try `rbs collection update` to fix the (potential) issue." }
locked_version = spec.version.to_s
end
end
end

add(library: gem[:name], version: locked_version, resolve_dependencies: false)
end
end

Expand Down
42 changes: 42 additions & 0 deletions test/rbs/environment_loader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,48 @@ def test_loading_from_rbs_collection
end
end

def test_loading_from_rbs_collection__gem_version_mismatch
mktmpdir do |path|
lockfile_path = path.join('rbs_collection.lock.yaml')
lockfile_path.write(<<~YAML)
sources:
- name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: b4d3b346d9657543099a35a1fd20347e75b8c523
repo_dir: gems
path: '.gem_rbs_collection'
gems:
- name: rbs-amber
version: "1.1"
source:
type: "rubygems"
YAML
RBS::Collection::Installer.new(lockfile_path: lockfile_path, stdout: StringIO.new).install_from_lockfile
lock = RBS::Collection::Config::Lockfile.from_lockfile(lockfile_path: lockfile_path, data: YAML.load_file(lockfile_path))

repo = RBS::Repository.new()

loader = EnvironmentLoader.new(repository: repo)

io = StringIO.new
old_output = RBS.logger_output
RBS.logger_output = io
begin
loader.add_collection(lock)
env = Environment.new
loader.load(env: env)
ensure
RBS.logger_output = old_output
end

assert_operator(
io.string,
:include?,
"Loading type definition from gem `rbs-amber-1.0.0` because locked version `1.1` is unavailable. Try `rbs collection update` to fix the (potential) issue."
)
end
end

def test_loading_from_rbs_collection_git_source_without_install
mktmpdir do |path|
lockfile_path = path.join('rbs_collection.lock.yaml')
Expand Down

0 comments on commit 9d3e988

Please sign in to comment.