Skip to content

Commit

Permalink
Merge pull request #1544 from ruby/no-source-in-lockfile
Browse files Browse the repository at this point in the history
Delete `sources` section from lockfile
  • Loading branch information
soutaro authored Oct 19, 2023
2 parents 88523a3 + 90ad29c commit 2cac4e7
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 121 deletions.
25 changes: 0 additions & 25 deletions lib/rbs/collection/config/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def initialize(lockfile_path:, path:, gemfile_lock_path:)
@path = path
@gemfile_lock_path = gemfile_lock_path

@sources = {}
@gems = {}
end

Expand All @@ -26,27 +25,15 @@ def gemfile_lock_fullpath
end
end

def each_source(&block)
if block
sources.each_value(&block)
yield Sources::Rubygems.instance
yield Sources::Stdlib.instance
else
enum_for :each_source
end
end

def to_lockfile
# @type var data: lockfile_data

data = {
"sources" => sources.each_value.sort_by {|s| s.name }.map {|source| source.to_lockfile },
"path" => path.to_s,
"gems" => gems.each_value.sort_by {|g| g[:name] }.map {|hash| library_data(hash) },
"gemfile_lock_path" => gemfile_lock_path.to_s
}

data.delete("sources") if sources.empty?
data.delete("gems") if gems.empty?

data
Expand All @@ -60,18 +47,6 @@ def self.from_lockfile(lockfile_path:, data:)

lockfile = Lockfile.new(lockfile_path: lockfile_path, path: path, gemfile_lock_path: gemfile_lock_path)

if sources = data["sources"]
sources.each do |src|
git = Sources::Git.new(
name: src["name"],
revision: src["revision"],
remote: src["remote"],
repo_dir: src["repo_dir"]
)
lockfile.sources[git.name] = git
end
end

if gems = data["gems"]
gems.each do |gem|
src = gem["source"]
Expand Down
6 changes: 0 additions & 6 deletions lib/rbs/collection/config/lockfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ def initialize(config:, definition:, with_lockfile:)
path: config.repo_path_data,
gemfile_lock_path: definition.lockfile.relative_path_from(lockfile_dir)
)
config.sources.each do |source|
case source
when Sources::Git
lockfile.sources[source.name] = source
end
end

if with_lockfile && lockfile_path.file?
@existing_lockfile = Lockfile.from_lockfile(lockfile_path: lockfile_path, data: YAML.load_file(lockfile_path.to_s))
Expand Down
6 changes: 0 additions & 6 deletions sig/collection/config/lockfile.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module RBS
# Data structure stored in `rbs_collection.lock.yaml`
#
type lockfile_data = {
"sources" => Array[Sources::Git::source_entry]?, # null if empty
"path" => String,
"gems" => Array[library_data]?, # null if empty
"gemfile_lock_path" => String? # gemfile_lock_path is optional because older versions doesn't have it
Expand Down Expand Up @@ -43,8 +42,6 @@ module RBS
#
attr_reader gemfile_lock_path: Pathname?

attr_reader sources: Hash[String, Sources::Git]

attr_reader gems: Hash[String, library]

def initialize: (lockfile_path: Pathname, path: Pathname, gemfile_lock_path: Pathname?) -> void
Expand All @@ -59,9 +56,6 @@ module RBS

def to_lockfile: () -> lockfile_data

def each_source: () { (Sources::t) -> void } -> void
| () -> Enumerator[Sources::t, void]

def self.from_lockfile: (lockfile_path: Pathname, data: lockfile_data) -> Lockfile

# Validates if directories are set up correctly
Expand Down
84 changes: 0 additions & 84 deletions test/rbs/collection/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ def test_generate_lock_from_collection_repository
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: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -115,12 +109,6 @@ def test_generate_lock_from_relative_git_repository
string = YAML.dump(lockfile.to_lockfile)

assert_config <<~YAML, string
sources:
- type: git
name: ruby/gem_rbs_collection
remote: #{remote}
revision: b4d3b346d9657543099a35a1fd20347e75b8c523
repo_dir: gems
path: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -155,12 +143,6 @@ def test_generate_lock_from_collection_repository_with_lockfile
gemfile_lock_path.write GEMFILE_LOCK

lockfile_yaml = <<~YAML
sources:
- type: git
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
path: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -212,12 +194,6 @@ def test_generate_lock_from_collection_repository_ignoring
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: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -277,12 +253,6 @@ def test_generate_lock_from_collection_with_manifest_yaml
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: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -359,12 +329,6 @@ def test_generate_lock_from_stdlib
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: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -414,12 +378,6 @@ def test_generate_lock_from_rubygems
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: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -461,12 +419,6 @@ def test_generate_lock_with_empty_gemfile_lock
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: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
YAML
Expand Down Expand Up @@ -564,12 +516,6 @@ def test_generate_lock_from_bundler_require_false
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:
Expand Down Expand Up @@ -628,12 +574,6 @@ def test_generate_lock_install_indirect_dependency
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:
Expand Down Expand Up @@ -690,12 +630,6 @@ def test_generate_lockfile_dependency_with_platform
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'
YAML
Expand Down Expand Up @@ -740,12 +674,6 @@ def test_generate_lockfile__gems_not_included_in_gemfile
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:
Expand Down Expand Up @@ -824,12 +752,6 @@ def test_generate_lockfile__dependency_source
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: 9612e5e67697153dcc7464c01115db44d29b1e34
repo_dir: gems
path: ".gem_rbs_collection"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down Expand Up @@ -896,12 +818,6 @@ def test_generate_lockfile_from_mismatched_lockfiles

# Version mismatched rbs_collection.lock.yaml (Gemfile.lock expects rainbow-3.0.0, but this expects 2.0)
lockfile_yaml = <<~YAML
sources:
- type: git
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
path: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
Expand Down

0 comments on commit 2cac4e7

Please sign in to comment.