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

Respect explicit source: option on gem entries #130

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions lib/gel/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def to_s
@uri.to_s
end

def match?(uri)
@uri == normalize_uri(uri)
end

private

def normalize_uri(uri)
Expand Down
16 changes: 14 additions & 2 deletions lib/gel/catalog_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ def gem_version
end
end

def initialize(catalogs)
def initialize(catalogs, gemfile)
@catalogs = catalogs
@gemfile = gemfile

@cached_specs = Hash.new { |h, k| h[k] = {} }
@specs_by_package_version = {}
Expand Down Expand Up @@ -68,8 +69,19 @@ def platform_for(package, version)
def fetch_package_info(package)
return if @specs_by_package_version.key?(package.name)

catalogs = @catalogs

if gem_entry = @gemfile.gems.assoc(package.name)
if specified_sources = gem_entry[2][:source]
catalogs = catalogs.select do |catalog|
catalog.is_a?(Gel::Catalog) &&
Array(specified_sources).any? { |s| catalog.match?(s) }
end
end
end

specs = []
@catalogs.each do |catalog|
catalogs.each do |catalog|
if catalog.nil?
break unless specs.empty?
next
Expand Down
11 changes: 8 additions & 3 deletions lib/gel/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ def self.solve_for_gemfile(store: store(), output: nil, gemfile: Gel::Environmen
require_relative "catalog"
all_sources = (gemfile.sources | gemfile.gems.flat_map { |_, _, o| o[:source] }).compact
local_source = all_sources.delete(:local)
server_gems = gemfile.gems.select { |_, _, o| !o[:path] && !o[:git] }.map(&:first)
server_gems = gemfile.gems.select { |_, _, o| !o[:path] && !o[:git] }
catalog_pool = Gel::WorkPool.new(8, name: "gel-catalog")
server_catalogs = all_sources.map { |s| Gel::Catalog.new(s, initial_gems: server_gems, work_pool: catalog_pool, **catalog_options) }
server_catalogs = all_sources.map do |s|
source_gems = server_gems.
select { |_, _, o| Array(o[:source]).include?(s) || o[:source].nil? }.
map(&:first)
Gel::Catalog.new(s, initial_gems: source_gems, work_pool: catalog_pool, **catalog_options)
end

require_relative "store_catalog"
store = store.inner if store.is_a?(Gel::LockedStore)
Expand Down Expand Up @@ -239,7 +244,7 @@ def self.solve_for_gemfile(store: store(), output: nil, gemfile: Gel::Environmen
end

require_relative "catalog_set"
catalog_set = Gel::CatalogSet.new(catalogs)
catalog_set = Gel::CatalogSet.new(catalogs, gemfile)

if solve
require_relative "pub_grub/solver"
Expand Down
51 changes: 51 additions & 0 deletions test/resolve_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,57 @@ def test_respects_range_specifier
LOCKFILE
end

def test_respects_explicit_source
gemfile = <<GEMFILE
source "https://rubygems.org"

gem "rack", source: "https://other.org"
GEMFILE

stub_request(:get, "https://index.rubygems.org/versions").
to_return(body: <<VERSIONS)
created_at: 2017-03-27T04:38:13+00:00
---
rack 0.1.0,2.0.3 xxx
rack 0.1.1 yyy
VERSIONS

stub_request(:get, "https://index.rubygems.org/info/rack").
to_return(body: <<INFO)
---
0.1.0 |checksum:zzz
2.0.3 |checksum:zzz
0.1.1 |checksum:zzz
INFO

stub_request(:get, "https://other.org/versions").
to_return(body: <<VERSIONS)
created_at: 2017-03-27T04:38:13+00:00
---
rack 0.5.0 qqq
VERSIONS

stub_request(:get, "https://other.org/info/rack").
to_return(body: <<INFO)
---
0.5.0 |checksum:ccc
INFO

assert_equal <<LOCKFILE, lockfile_for_gemfile(gemfile, platforms: "ruby")
GEM
remote: https://rubygems.org/
remote: https://other.org/
specs:
rack (0.5.0)

PLATFORMS
ruby

DEPENDENCIES
rack!
LOCKFILE
end

def test_dependencies_are_followed_and_recorded
gemfile = <<GEMFILE
source "https://gem-mimer.org"
Expand Down