Skip to content
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

Install RBS for indirect dependency #1228

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/rbs/collection/config/lockfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,27 @@ def generate
if src_data
Sources.from_config_entry(src_data)
else
find_source(name: name) or return
find_source(name: name)
end

installed_version = version
best_version = find_best_version(version: installed_version, versions: source.versions(name))
if source
installed_version = version
best_version = find_best_version(version: installed_version, versions: source.versions(name))

locked = {
name: name,
version: best_version.to_s,
source: source,
}
locked = {
name: name,
version: best_version.to_s,
source: source,
}
end
end

locked or raise

lockfile.gems[name] = locked
if locked
lockfile.gems[name] = locked

locked[:source].dependencies_of(locked[:name], locked[:version])&.each do |dep|
assign_stdlib(name: dep["name"], from_gem: name)
locked[:source].dependencies_of(locked[:name], locked[:version])&.each do |dep|
assign_stdlib(name: dep["name"], from_gem: name)
end
end

gem_hash[name].dependencies.each do |dep|
Expand Down
64 changes: 64 additions & 0 deletions test/rbs/collection/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,70 @@ def test_generate_lock_from_bundler_require_false
end
end

def test_generate_lock_install_indirect_dependency
mktmpdir do |tmpdir|
config_path = tmpdir / 'rbs_collection.yaml'
config_path.write [CONFIG, <<~YAML].join("\n")
sources:
- type: git
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
path: '.gem_rbs_collection'
gems: []
YAML
gemfile_path = tmpdir / 'Gemfile'
gemfile_path.write <<~GEMFILE
source 'https://rubygems.org'

gem "parser"
GEMFILE
gemfile_lock_path = tmpdir / 'Gemfile.lock'
gemfile_lock_path.write <<~GEMFILE_LOCK
GEM
remote: https://rubygems.org/
specs:
parser (3.2.0.0)
ast (~> 2.4.1)
ast (2.4.2)

PLATFORMS
x86_64-linux

DEPENDENCIES
parser

BUNDLED WITH
2.2.0
GEMFILE_LOCK

definition = Bundler::Definition.build(gemfile_path, gemfile_lock_path, false)
_config, lockfile = RBS::Collection::Config.generate_lockfile(config_path: config_path, definition: definition)
string = YAML.dump(lockfile.to_lockfile)

assert_config <<~YAML, string
sources:
- type: git
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
path: ".gem_rbs_collection"
gemfile_lock_path: 'Gemfile.lock'
gems:
- name: ast
version: "2.4"
source:
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
type: git
YAML
end
end

private def assert_config(expected_str, actual_str)
assert_equal YAML.load(expected_str), YAML.load(actual_str)
end
Expand Down