scint 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/FEATURES.md +13 -0
  3. data/README.md +216 -0
  4. data/bin/bundler-vs-scint +233 -0
  5. data/bin/scint +35 -0
  6. data/bin/scint-io-summary +46 -0
  7. data/bin/scint-syscall-trace +41 -0
  8. data/lib/bundler/setup.rb +5 -0
  9. data/lib/bundler.rb +168 -0
  10. data/lib/scint/cache/layout.rb +131 -0
  11. data/lib/scint/cache/metadata_store.rb +75 -0
  12. data/lib/scint/cache/prewarm.rb +192 -0
  13. data/lib/scint/cli/add.rb +85 -0
  14. data/lib/scint/cli/cache.rb +316 -0
  15. data/lib/scint/cli/exec.rb +150 -0
  16. data/lib/scint/cli/install.rb +1047 -0
  17. data/lib/scint/cli/remove.rb +60 -0
  18. data/lib/scint/cli.rb +77 -0
  19. data/lib/scint/commands/exec.rb +17 -0
  20. data/lib/scint/commands/install.rb +17 -0
  21. data/lib/scint/credentials.rb +153 -0
  22. data/lib/scint/debug/io_trace.rb +218 -0
  23. data/lib/scint/debug/sampler.rb +138 -0
  24. data/lib/scint/downloader/fetcher.rb +113 -0
  25. data/lib/scint/downloader/pool.rb +112 -0
  26. data/lib/scint/errors.rb +63 -0
  27. data/lib/scint/fs.rb +119 -0
  28. data/lib/scint/gem/extractor.rb +86 -0
  29. data/lib/scint/gem/package.rb +62 -0
  30. data/lib/scint/gemfile/dependency.rb +30 -0
  31. data/lib/scint/gemfile/editor.rb +93 -0
  32. data/lib/scint/gemfile/parser.rb +275 -0
  33. data/lib/scint/index/cache.rb +166 -0
  34. data/lib/scint/index/client.rb +301 -0
  35. data/lib/scint/index/parser.rb +142 -0
  36. data/lib/scint/installer/extension_builder.rb +264 -0
  37. data/lib/scint/installer/linker.rb +226 -0
  38. data/lib/scint/installer/planner.rb +140 -0
  39. data/lib/scint/installer/preparer.rb +207 -0
  40. data/lib/scint/lockfile/parser.rb +251 -0
  41. data/lib/scint/lockfile/writer.rb +178 -0
  42. data/lib/scint/platform.rb +71 -0
  43. data/lib/scint/progress.rb +579 -0
  44. data/lib/scint/resolver/provider.rb +230 -0
  45. data/lib/scint/resolver/resolver.rb +249 -0
  46. data/lib/scint/runtime/exec.rb +141 -0
  47. data/lib/scint/runtime/setup.rb +45 -0
  48. data/lib/scint/scheduler.rb +392 -0
  49. data/lib/scint/source/base.rb +46 -0
  50. data/lib/scint/source/git.rb +92 -0
  51. data/lib/scint/source/path.rb +70 -0
  52. data/lib/scint/source/rubygems.rb +79 -0
  53. data/lib/scint/vendor/pub_grub/assignment.rb +20 -0
  54. data/lib/scint/vendor/pub_grub/basic_package_source.rb +169 -0
  55. data/lib/scint/vendor/pub_grub/failure_writer.rb +182 -0
  56. data/lib/scint/vendor/pub_grub/incompatibility.rb +150 -0
  57. data/lib/scint/vendor/pub_grub/package.rb +43 -0
  58. data/lib/scint/vendor/pub_grub/partial_solution.rb +121 -0
  59. data/lib/scint/vendor/pub_grub/rubygems.rb +45 -0
  60. data/lib/scint/vendor/pub_grub/solve_failure.rb +19 -0
  61. data/lib/scint/vendor/pub_grub/static_package_source.rb +61 -0
  62. data/lib/scint/vendor/pub_grub/strategy.rb +42 -0
  63. data/lib/scint/vendor/pub_grub/term.rb +105 -0
  64. data/lib/scint/vendor/pub_grub/version.rb +3 -0
  65. data/lib/scint/vendor/pub_grub/version_constraint.rb +129 -0
  66. data/lib/scint/vendor/pub_grub/version_range.rb +423 -0
  67. data/lib/scint/vendor/pub_grub/version_solver.rb +236 -0
  68. data/lib/scint/vendor/pub_grub/version_union.rb +178 -0
  69. data/lib/scint/vendor/pub_grub.rb +32 -0
  70. data/lib/scint/worker_pool.rb +114 -0
  71. data/lib/scint.rb +87 -0
  72. metadata +116 -0
@@ -0,0 +1,169 @@
1
+ require_relative 'version_constraint'
2
+ require_relative 'incompatibility'
3
+
4
+ module Scint::PubGrub
5
+ # Types:
6
+ #
7
+ # Where possible, Scint::PubGrub will accept user-defined types, so long as they quack.
8
+ #
9
+ # ## "Package":
10
+ #
11
+ # This class will be used to represent the various packages being solved for.
12
+ # .to_s will be called when displaying errors and debugging info, it should
13
+ # probably return the package's name.
14
+ # It must also have a reasonable definition of #== and #hash
15
+ #
16
+ # Example classes: String ("rails")
17
+ #
18
+ #
19
+ # ## "Version":
20
+ #
21
+ # This class will be used to represent a single version number.
22
+ #
23
+ # Versions don't need to store their associated package, however they will
24
+ # only be compared against other versions of the same package.
25
+ #
26
+ # It must be Comparible (and implement <=> reasonably)
27
+ #
28
+ # Example classes: Gem::Version, Integer
29
+ #
30
+ #
31
+ # ## "Dependency"
32
+ #
33
+ # This class represents the requirement one package has on another. It is
34
+ # returned by dependencies_for(package, version) and will be passed to
35
+ # parse_dependency to convert it to a format Scint::PubGrub understands.
36
+ #
37
+ # It must also have a reasonable definition of #==
38
+ #
39
+ # Example classes: String ("~> 1.0"), Gem::Requirement
40
+ #
41
+ class BasicPackageSource
42
+ # Override me!
43
+ #
44
+ # This is called per package to find all possible versions of a package.
45
+ #
46
+ # It is called at most once per-package
47
+ #
48
+ # Returns: Array of versions for a package, in preferred order of selection
49
+ def all_versions_for(package)
50
+ raise NotImplementedError
51
+ end
52
+
53
+ # Override me!
54
+ #
55
+ # Returns: Hash in the form of { package => requirement, ... }
56
+ def dependencies_for(package, version)
57
+ raise NotImplementedError
58
+ end
59
+
60
+ # Override me!
61
+ #
62
+ # Convert a (user-defined) dependency into a format Scint::PubGrub understands.
63
+ #
64
+ # Package is passed to this method but for many implementations is not
65
+ # needed.
66
+ #
67
+ # Returns: either a Scint::PubGrub::VersionRange, Scint::PubGrub::VersionUnion, or a
68
+ # Scint::PubGrub::VersionConstraint
69
+ def parse_dependency(package, dependency)
70
+ raise NotImplementedError
71
+ end
72
+
73
+ # Override me!
74
+ #
75
+ # If not overridden, this will call dependencies_for with the root package.
76
+ #
77
+ # Returns: Hash in the form of { package => requirement, ... } (see dependencies_for)
78
+ def root_dependencies
79
+ dependencies_for(@root_package, @root_version)
80
+ end
81
+
82
+ def initialize
83
+ @root_package = Package.root
84
+ @root_version = Package.root_version
85
+
86
+ @sorted_versions = Hash.new do |h,k|
87
+ if k == @root_package
88
+ h[k] = [@root_version]
89
+ else
90
+ h[k] = all_versions_for(k).sort
91
+ end
92
+ end
93
+
94
+ @cached_dependencies = Hash.new do |packages, package|
95
+ if package == @root_package
96
+ packages[package] = {
97
+ @root_version => root_dependencies
98
+ }
99
+ else
100
+ packages[package] = Hash.new do |versions, version|
101
+ versions[version] = dependencies_for(package, version)
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ def versions_for(package, range=VersionRange.any)
108
+ range.select_versions(@sorted_versions[package])
109
+ end
110
+
111
+ def no_versions_incompatibility_for(_package, unsatisfied_term)
112
+ cause = Incompatibility::NoVersions.new(unsatisfied_term)
113
+
114
+ Incompatibility.new([unsatisfied_term], cause: cause)
115
+ end
116
+
117
+ def incompatibilities_for(package, version)
118
+ package_deps = @cached_dependencies[package]
119
+ sorted_versions = @sorted_versions[package]
120
+ package_deps[version].map do |dep_package, dep_constraint_name|
121
+ low = high = sorted_versions.index(version)
122
+
123
+ # find version low such that all >= low share the same dep
124
+ while low > 0 &&
125
+ package_deps[sorted_versions[low - 1]][dep_package] == dep_constraint_name
126
+ low -= 1
127
+ end
128
+ low =
129
+ if low == 0
130
+ nil
131
+ else
132
+ sorted_versions[low]
133
+ end
134
+
135
+ # find version high such that all < high share the same dep
136
+ while high < sorted_versions.length &&
137
+ package_deps[sorted_versions[high]][dep_package] == dep_constraint_name
138
+ high += 1
139
+ end
140
+ high =
141
+ if high == sorted_versions.length
142
+ nil
143
+ else
144
+ sorted_versions[high]
145
+ end
146
+
147
+ range = VersionRange.new(min: low, max: high, include_min: !low.nil?)
148
+
149
+ self_constraint = VersionConstraint.new(package, range: range)
150
+
151
+ if !@packages.include?(dep_package)
152
+ # no such package -> this version is invalid
153
+ end
154
+
155
+ dep_constraint = parse_dependency(dep_package, dep_constraint_name)
156
+ if !dep_constraint
157
+ # falsey indicates this dependency was invalid
158
+ cause = Scint::PubGrub::Incompatibility::InvalidDependency.new(dep_package, dep_constraint_name)
159
+ return [Incompatibility.new([Term.new(self_constraint, true)], cause: cause)]
160
+ elsif !dep_constraint.is_a?(VersionConstraint)
161
+ # Upgrade range/union to VersionConstraint
162
+ dep_constraint = VersionConstraint.new(dep_package, range: dep_constraint)
163
+ end
164
+
165
+ Incompatibility.new([Term.new(self_constraint, true), Term.new(dep_constraint, false)], cause: :dependency)
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,182 @@
1
+ module Scint::PubGrub
2
+ class FailureWriter
3
+ def initialize(root)
4
+ @root = root
5
+
6
+ # { Incompatibility => Integer }
7
+ @derivations = {}
8
+
9
+ # [ [ String, Integer or nil ] ]
10
+ @lines = []
11
+
12
+ # { Incompatibility => Integer }
13
+ @line_numbers = {}
14
+
15
+ count_derivations(root)
16
+ end
17
+
18
+ def write
19
+ return @root.to_s unless @root.conflict?
20
+
21
+ visit(@root)
22
+
23
+ padding = @line_numbers.empty? ? 0 : "(#{@line_numbers.values.last}) ".length
24
+
25
+ @lines.map do |message, number|
26
+ next "" if message.empty?
27
+
28
+ lead = number ? "(#{number}) " : ""
29
+ lead = lead.ljust(padding)
30
+ message = message.gsub("\n", "\n" + " " * (padding + 2))
31
+ "#{lead}#{message}"
32
+ end.join("\n")
33
+ end
34
+
35
+ private
36
+
37
+ def write_line(incompatibility, message, numbered:)
38
+ if numbered
39
+ number = @line_numbers.length + 1
40
+ @line_numbers[incompatibility] = number
41
+ end
42
+
43
+ @lines << [message, number]
44
+ end
45
+
46
+ def visit(incompatibility, conclusion: false)
47
+ raise unless incompatibility.conflict?
48
+
49
+ numbered = conclusion || @derivations[incompatibility] > 1;
50
+ conjunction = conclusion || incompatibility == @root ? "So," : "And"
51
+
52
+ cause = incompatibility.cause
53
+
54
+ if cause.conflict.conflict? && cause.other.conflict?
55
+ conflict_line = @line_numbers[cause.conflict]
56
+ other_line = @line_numbers[cause.other]
57
+
58
+ if conflict_line && other_line
59
+ write_line(
60
+ incompatibility,
61
+ "Because #{cause.conflict} (#{conflict_line})\nand #{cause.other} (#{other_line}),\n#{incompatibility}.",
62
+ numbered: numbered
63
+ )
64
+ elsif conflict_line || other_line
65
+ with_line = conflict_line ? cause.conflict : cause.other
66
+ without_line = conflict_line ? cause.other : cause.conflict
67
+ line = @line_numbers[with_line]
68
+
69
+ visit(without_line);
70
+ write_line(
71
+ incompatibility,
72
+ "#{conjunction} because #{with_line} (#{line}),\n#{incompatibility}.",
73
+ numbered: numbered
74
+ )
75
+ else
76
+ single_line_conflict = single_line?(cause.conflict.cause)
77
+ single_line_other = single_line?(cause.other.cause)
78
+
79
+ if single_line_conflict || single_line_other
80
+ first = single_line_other ? cause.conflict : cause.other
81
+ second = single_line_other ? cause.other : cause.conflict
82
+ visit(first)
83
+ visit(second)
84
+ write_line(
85
+ incompatibility,
86
+ "Thus, #{incompatibility}.",
87
+ numbered: numbered
88
+ )
89
+ else
90
+ visit(cause.conflict, conclusion: true)
91
+ @lines << ["", nil]
92
+ visit(cause.other)
93
+
94
+ write_line(
95
+ incompatibility,
96
+ "#{conjunction} because #{cause.conflict} (#{@line_numbers[cause.conflict]}),\n#{incompatibility}.",
97
+ numbered: numbered
98
+ )
99
+ end
100
+ end
101
+ elsif cause.conflict.conflict? || cause.other.conflict?
102
+ derived = cause.conflict.conflict? ? cause.conflict : cause.other
103
+ ext = cause.conflict.conflict? ? cause.other : cause.conflict
104
+
105
+ derived_line = @line_numbers[derived]
106
+ if derived_line
107
+ write_line(
108
+ incompatibility,
109
+ "Because #{ext}\nand #{derived} (#{derived_line}),\n#{incompatibility}.",
110
+ numbered: numbered
111
+ )
112
+ elsif collapsible?(derived)
113
+ derived_cause = derived.cause
114
+ if derived_cause.conflict.conflict?
115
+ collapsed_derived = derived_cause.conflict
116
+ collapsed_ext = derived_cause.other
117
+ else
118
+ collapsed_derived = derived_cause.other
119
+ collapsed_ext = derived_cause.conflict
120
+ end
121
+
122
+ visit(collapsed_derived)
123
+
124
+ write_line(
125
+ incompatibility,
126
+ "#{conjunction} because #{collapsed_ext}\nand #{ext},\n#{incompatibility}.",
127
+ numbered: numbered
128
+ )
129
+ else
130
+ visit(derived)
131
+ write_line(
132
+ incompatibility,
133
+ "#{conjunction} because #{ext},\n#{incompatibility}.",
134
+ numbered: numbered
135
+ )
136
+ end
137
+ else
138
+ write_line(
139
+ incompatibility,
140
+ "Because #{cause.conflict}\nand #{cause.other},\n#{incompatibility}.",
141
+ numbered: numbered
142
+ )
143
+ end
144
+ end
145
+
146
+ def single_line?(cause)
147
+ !cause.conflict.conflict? && !cause.other.conflict?
148
+ end
149
+
150
+ def collapsible?(incompatibility)
151
+ return false if @derivations[incompatibility] > 1
152
+
153
+ cause = incompatibility.cause
154
+ # If incompatibility is derived from two derived incompatibilities,
155
+ # there are too many transitive causes to display concisely.
156
+ return false if cause.conflict.conflict? && cause.other.conflict?
157
+
158
+ # If incompatibility is derived from two external incompatibilities, it
159
+ # tends to be confusing to collapse it.
160
+ return false unless cause.conflict.conflict? || cause.other.conflict?
161
+
162
+ # If incompatibility's internal cause is numbered, collapsing it would
163
+ # get too noisy.
164
+ complex = cause.conflict.conflict? ? cause.conflict : cause.other
165
+
166
+ !@line_numbers.has_key?(complex)
167
+ end
168
+
169
+ def count_derivations(incompatibility)
170
+ if @derivations.has_key?(incompatibility)
171
+ @derivations[incompatibility] += 1
172
+ else
173
+ @derivations[incompatibility] = 1
174
+ if incompatibility.conflict?
175
+ cause = incompatibility.cause
176
+ count_derivations(cause.conflict)
177
+ count_derivations(cause.other)
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,150 @@
1
+ module Scint::PubGrub
2
+ class Incompatibility
3
+ ConflictCause = Struct.new(:incompatibility, :satisfier) do
4
+ alias_method :conflict, :incompatibility
5
+ alias_method :other, :satisfier
6
+ end
7
+
8
+ InvalidDependency = Struct.new(:package, :constraint) do
9
+ end
10
+
11
+ NoVersions = Struct.new(:constraint) do
12
+ end
13
+
14
+ attr_reader :terms, :cause
15
+
16
+ def initialize(terms, cause:, custom_explanation: nil)
17
+ @cause = cause
18
+ @terms = cleanup_terms(terms)
19
+ @custom_explanation = custom_explanation
20
+
21
+ if cause == :dependency && @terms.length != 2
22
+ raise ArgumentError, "a dependency Incompatibility must have exactly two terms. Got #{@terms.inspect}"
23
+ end
24
+ end
25
+
26
+ def hash
27
+ cause.hash ^ terms.hash
28
+ end
29
+
30
+ def eql?(other)
31
+ cause.eql?(other.cause) &&
32
+ terms.eql?(other.terms)
33
+ end
34
+
35
+ def failure?
36
+ terms.empty? || (terms.length == 1 && Package.root?(terms[0].package) && terms[0].positive?)
37
+ end
38
+
39
+ def conflict?
40
+ ConflictCause === cause
41
+ end
42
+
43
+ # Returns all external incompatibilities in this incompatibility's
44
+ # derivation graph
45
+ def external_incompatibilities
46
+ if conflict?
47
+ [
48
+ cause.conflict,
49
+ cause.other
50
+ ].flat_map(&:external_incompatibilities)
51
+ else
52
+ [this]
53
+ end
54
+ end
55
+
56
+ def to_s
57
+ return @custom_explanation if @custom_explanation
58
+
59
+ case cause
60
+ when :root
61
+ "(root dependency)"
62
+ when :dependency
63
+ "#{terms[0].to_s(allow_every: true)} depends on #{terms[1].invert}"
64
+ when Scint::PubGrub::Incompatibility::InvalidDependency
65
+ "#{terms[0].to_s(allow_every: true)} depends on unknown package #{cause.package}"
66
+ when Scint::PubGrub::Incompatibility::NoVersions
67
+ "no versions satisfy #{cause.constraint}"
68
+ when Scint::PubGrub::Incompatibility::ConflictCause
69
+ if failure?
70
+ "version solving has failed"
71
+ elsif terms.length == 1
72
+ term = terms[0]
73
+ if term.positive?
74
+ if term.constraint.any?
75
+ "#{term.package} cannot be used"
76
+ else
77
+ "#{term.to_s(allow_every: true)} cannot be used"
78
+ end
79
+ else
80
+ "#{term.invert} is required"
81
+ end
82
+ else
83
+ if terms.all?(&:positive?)
84
+ if terms.length == 2
85
+ "#{terms[0].to_s(allow_every: true)} is incompatible with #{terms[1]}"
86
+ else
87
+ "one of #{terms.map(&:to_s).join(" or ")} must be false"
88
+ end
89
+ elsif terms.all?(&:negative?)
90
+ if terms.length == 2
91
+ "either #{terms[0].invert} or #{terms[1].invert}"
92
+ else
93
+ "one of #{terms.map(&:invert).join(" or ")} must be true";
94
+ end
95
+ else
96
+ positive = terms.select(&:positive?)
97
+ negative = terms.select(&:negative?).map(&:invert)
98
+
99
+ if positive.length == 1
100
+ "#{positive[0].to_s(allow_every: true)} requires #{negative.join(" or ")}"
101
+ else
102
+ "if #{positive.join(" and ")} then #{negative.join(" or ")}"
103
+ end
104
+ end
105
+ end
106
+ else
107
+ raise "unhandled cause: #{cause.inspect}"
108
+ end
109
+ end
110
+
111
+ def inspect
112
+ "#<#{self.class} #{to_s}>"
113
+ end
114
+
115
+ def pretty_print(q)
116
+ q.group 2, "#<#{self.class}", ">" do
117
+ q.breakable
118
+ q.text to_s
119
+
120
+ q.breakable
121
+ q.text " caused by "
122
+ q.pp @cause
123
+ end
124
+ end
125
+
126
+ private
127
+
128
+ def cleanup_terms(terms)
129
+ terms.each do |term|
130
+ raise "#{term.inspect} must be a term" unless term.is_a?(Term)
131
+ end
132
+
133
+ if terms.length != 1 && ConflictCause === cause
134
+ terms = terms.reject do |term|
135
+ term.positive? && Package.root?(term.package)
136
+ end
137
+ end
138
+
139
+ # Optimized simple cases
140
+ return terms if terms.length <= 1
141
+ return terms if terms.length == 2 && terms[0].package != terms[1].package
142
+
143
+ terms.group_by(&:package).map do |package, common_terms|
144
+ common_terms.inject do |acc, term|
145
+ acc.intersect(term)
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Scint::PubGrub
4
+ class Package
5
+
6
+ attr_reader :name
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def inspect
13
+ "#<#{self.class} #{name.inspect}>"
14
+ end
15
+
16
+ def <=>(other)
17
+ name <=> other.name
18
+ end
19
+
20
+ ROOT = Package.new(:root)
21
+ ROOT_VERSION = 0
22
+
23
+ def self.root
24
+ ROOT
25
+ end
26
+
27
+ def self.root_version
28
+ ROOT_VERSION
29
+ end
30
+
31
+ def self.root?(package)
32
+ if package.respond_to?(:root?)
33
+ package.root?
34
+ else
35
+ package == root
36
+ end
37
+ end
38
+
39
+ def to_s
40
+ name.to_s
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,121 @@
1
+ require_relative 'assignment'
2
+
3
+ module Scint::PubGrub
4
+ class PartialSolution
5
+ attr_reader :assignments, :decisions
6
+ attr_reader :attempted_solutions
7
+
8
+ def initialize
9
+ reset!
10
+
11
+ @attempted_solutions = 1
12
+ @backtracking = false
13
+ end
14
+
15
+ def decision_level
16
+ @decisions.length
17
+ end
18
+
19
+ def relation(term)
20
+ package = term.package
21
+ return :overlap if !@terms.key?(package)
22
+
23
+ @relation_cache[package][term] ||=
24
+ @terms[package].relation(term)
25
+ end
26
+
27
+ def satisfies?(term)
28
+ relation(term) == :subset
29
+ end
30
+
31
+ def derive(term, cause)
32
+ add_assignment(Assignment.new(term, cause, decision_level, assignments.length))
33
+ end
34
+
35
+ def satisfier(term)
36
+ assignment =
37
+ @assignments_by[term.package].bsearch do |assignment_by|
38
+ @cumulative_assignments[assignment_by].satisfies?(term)
39
+ end
40
+
41
+ assignment || raise("#{term} unsatisfied")
42
+ end
43
+
44
+ # A list of unsatisfied terms
45
+ def unsatisfied
46
+ @required.keys.reject do |package|
47
+ @decisions.key?(package)
48
+ end.map do |package|
49
+ @terms[package]
50
+ end
51
+ end
52
+
53
+ def decide(package, version)
54
+ @attempted_solutions += 1 if @backtracking
55
+ @backtracking = false;
56
+
57
+ decisions[package] = version
58
+ assignment = Assignment.decision(package, version, decision_level, assignments.length)
59
+ add_assignment(assignment)
60
+ end
61
+
62
+ def backtrack(previous_level)
63
+ @backtracking = true
64
+
65
+ new_assignments = assignments.select do |assignment|
66
+ assignment.decision_level <= previous_level
67
+ end
68
+
69
+ new_decisions = Hash[decisions.first(previous_level)]
70
+
71
+ reset!
72
+
73
+ @decisions = new_decisions
74
+
75
+ new_assignments.each do |assignment|
76
+ add_assignment(assignment)
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def reset!
83
+ # { Array<Assignment> }
84
+ @assignments = []
85
+
86
+ # { Package => Array<Assignment> }
87
+ @assignments_by = Hash.new { |h,k| h[k] = [] }
88
+ @cumulative_assignments = {}.compare_by_identity
89
+
90
+ # { Package => Package::Version }
91
+ @decisions = {}
92
+
93
+ # { Package => Term }
94
+ @terms = {}
95
+ @relation_cache = Hash.new { |h,k| h[k] = {} }
96
+
97
+ # { Package => Boolean }
98
+ @required = {}
99
+ end
100
+
101
+ def add_assignment(assignment)
102
+ term = assignment.term
103
+ package = term.package
104
+
105
+ @assignments << assignment
106
+ @assignments_by[package] << assignment
107
+
108
+ @required[package] = true if term.positive?
109
+
110
+ if @terms.key?(package)
111
+ old_term = @terms[package]
112
+ @terms[package] = old_term.intersect(term)
113
+ else
114
+ @terms[package] = term
115
+ end
116
+ @relation_cache[package].clear
117
+
118
+ @cumulative_assignments[assignment] = @terms[package]
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,45 @@
1
+ module Scint::PubGrub
2
+ module RubyGems
3
+ extend self
4
+
5
+ def requirement_to_range(requirement)
6
+ ranges = requirement.requirements.map do |(op, ver)|
7
+ case op
8
+ when "~>"
9
+ name = "~> #{ver}"
10
+ bump = ver.class.new(ver.bump.to_s + ".A")
11
+ VersionRange.new(name: name, min: ver, max: bump, include_min: true)
12
+ when ">"
13
+ VersionRange.new(min: ver)
14
+ when ">="
15
+ VersionRange.new(min: ver, include_min: true)
16
+ when "<"
17
+ VersionRange.new(max: ver)
18
+ when "<="
19
+ VersionRange.new(max: ver, include_max: true)
20
+ when "="
21
+ VersionRange.new(min: ver, max: ver, include_min: true, include_max: true)
22
+ when "!="
23
+ VersionRange.new(min: ver, max: ver, include_min: true, include_max: true).invert
24
+ else
25
+ raise "bad version specifier: #{op}"
26
+ end
27
+ end
28
+
29
+ ranges.inject(&:intersect)
30
+ end
31
+
32
+ def requirement_to_constraint(package, requirement)
33
+ Scint::PubGrub::VersionConstraint.new(package, range: requirement_to_range(requirement))
34
+ end
35
+
36
+ def parse_range(dep)
37
+ requirement_to_range(Gem::Requirement.new(dep))
38
+ end
39
+
40
+ def parse_constraint(package, dep)
41
+ range = parse_range(dep)
42
+ Scint::PubGrub::VersionConstraint.new(package, range: range)
43
+ end
44
+ end
45
+ end