diff --git a/lib/rbs/collection/config/lockfile_generator.rb b/lib/rbs/collection/config/lockfile_generator.rb index 1f6575573f..ebf4ab71c3 100644 --- a/lib/rbs/collection/config/lockfile_generator.rb +++ b/lib/rbs/collection/config/lockfile_generator.rb @@ -21,6 +21,17 @@ class LockfileGenerator "pstore" => nil, } + NONGEM_STDLIBS = Set[ + "cgi-escape", + "coverage", + "monitor", + "objspace", + "pathname", + "pty", + "ripper", + "socket", + ] + class GemfileLockMismatchError < StandardError def initialize(expected:, actual:) @expected = expected @@ -168,7 +179,9 @@ def generate end end else - RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})" + unless NONGEM_STDLIBS.include?(name) + RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})" + end end end diff --git a/sig/collection/config/lockfile_generator.rbs b/sig/collection/config/lockfile_generator.rbs index d3387ad45c..066f9f4fc3 100644 --- a/sig/collection/config/lockfile_generator.rbs +++ b/sig/collection/config/lockfile_generator.rbs @@ -6,6 +6,8 @@ module RBS # ALUMNI_STDLIBS: Hash[String, String?] + NONGEM_STDLIBS: Set[String] + class GemfileLockMismatchError < StandardError @expected: Pathname diff --git a/test/rbs/cli_test.rb b/test/rbs/cli_test.rb index 9dc3b59251..a9becac114 100644 --- a/test/rbs/cli_test.rb +++ b/test/rbs/cli_test.rb @@ -1491,6 +1491,54 @@ def test_collection_install__pathname_set end end + def test_collection_install__nongem_stdlib_no_warning + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + dir = Pathname(dir) + dir.join(RBS::Collection::Config::PATH).write(<<~YAML) + sources: + - name: ruby/gem_rbs_collection + remote: https://github.com/ruby/gem_rbs_collection.git + revision: b4d3b346d9657543099a35a1fd20347e75b8c523 + repo_dir: gems + + path: #{dir.join('gem_rbs_collection')} + + gems: + - name: socket + - name: pathname + YAML + + bundle_install('ast', 'logger', 'tsort') + + # First install creates the lockfile with socket as stdlib + _stdout, stderr = run_rbs_collection("install", bundler: true) + + lockfile = RBS::Collection::Config::Lockfile.from_lockfile( + lockfile_path: dir + "rbs_collection.lock.yaml", + data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read) + ) + + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["socket"][:source] + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["pathname"][:source] + + # Second install with existing lockfile should not warn about nongem stdlibs + _stdout, stderr = run_rbs_collection("install", bundler: true) + + refute_match(/Cannot find `socket` gem/, stderr) + refute_match(/Cannot find `pathname` gem/, stderr) + + lockfile = RBS::Collection::Config::Lockfile.from_lockfile( + lockfile_path: dir + "rbs_collection.lock.yaml", + data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read) + ) + + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["socket"][:source] + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["pathname"][:source] + end + end + end + def test_collection_install__set_pathname__manifest Dir.mktmpdir do |dir| Dir.chdir(dir) do