Permalink
Browse files

Start on simple resolving. We don't try to fix conflicts yet to keep …

…things simple, so for now that's up to the user.
  • Loading branch information...
1 parent f0193f1 commit 701db8168f9f75b9405d0aff1b3023ffe96acbda @alloy alloy committed Sep 11, 2011
View
@@ -1,13 +1,18 @@
+#dependency 'ASIHTTPRequest', '1.8'
+dependency 'ASIWebPageRequest', '= 1.8'
+
# is part of ASIHTTPRequest 1.8 and 1.8.1
dependency 'Reachability' #, '>= 2.0'
# is part of ASIHTTPRequest
-dependency 'ASIWebPageRequest', '>= 1.8'
+#dependency 'ASIWebPageRequest', '>= 1.8'
+#dependency 'ASIWebPageRequest', '= 1.8'
# this should fail the ASIHTTPRequest 1.8.1 hard requirement
#dependency 'ASIWebPageRequest', '1.8.0'
# we have a hard requirement here so:
# * the Reachability dependency should be taken from this version
# * the ASIWebPageRequest dependency requirement matches this one so should work
-dependency 'ASIHTTPRequest', '1.8.1'
+#dependency 'ASIHTTPRequest', '1.8.1'
+dependency 'ASIHTTPRequest', '>= 1.8'
View
@@ -2,6 +2,7 @@ module Pod
autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency'
+ autoload :Resolver, 'cocoa_pods/resolver'
autoload :Source, 'cocoa_pods/source'
autoload :Spec, 'cocoa_pods/specification'
autoload :Specification, 'cocoa_pods/specification'
@@ -4,7 +4,7 @@ class Install < Command
def run
if spec = Specification.from_podfile(podfile)
p spec
- spec.install!
+ Resolver.new(spec).resolve
else
$stderr.puts "No Podfile found in current working directory."
end
@@ -4,6 +4,5 @@ module Gem
module Pod
class Dependency < Gem::Dependency
-
end
end
View
@@ -16,9 +16,7 @@ def initialize(repo)
def search(dependency)
if dir = @repo.children.find { |c| c.basename.to_s == dependency.name }
- set = Specification::Set.new(dir)
- set.add_dependency(dependency)
- set
+ Specification::Set.new(dir)
end
end
end
@@ -62,7 +62,8 @@ def description(description)
end
def part_of(name, *version_requirements)
- @part_of = Dependency.new(name, *version_requirements)
+ #@part_of = Dependency.new(name, *version_requirements)
+ dependency(name, *version_requirements)
end
def source_files(*patterns)
@@ -75,7 +76,6 @@ def source(remote)
attr_reader :dependencies
def dependency(name, *version_requirements)
- #version = args || [">= 0"]
@dependencies << Dependency.new(name, *version_requirements)
end
@@ -87,31 +87,14 @@ def from_podfile?
def to_s
if from_podfile?
- "#<#{self.class.name} for podfile at `#{@defined_in_file}'>"
+ "podfile at `#{@defined_in_file}'"
else
- "#<#{self.class.name} for `#{@name}' version `#{@version}'>"
+ "`#{@name}' version `#{@version}'"
end
end
- alias_method :inspect, :to_s
- # TODO move to seperate installer class
- def install!
- #p @name, @version, @authors, @dependencies
- @dependency_sets = @dependencies.map { |dep| Source.search(dep) }.flatten
- @dependency_sets.each do |set|
- p set
- p set.podspec
- end
- end
-
- private
-
- def attr(name, arg)
- if arg.nil? || arg.empty?
- instance_variable_get("@#{name}")
- else
- instance_variable_set("@#{name}", block_given? ? yield : arg)
- end
+ def inspect
+ "#<#{self.class.name} for #{to_s}>"
end
end
@@ -3,10 +3,21 @@ class Specification
class Set
def initialize(pod_dir)
@pod_dir = pod_dir
+ @required_by = []
end
- def add_dependency(dependency)
- @dependency = dependency
+ def required_by(specification, dependency)
+ unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version)
+ # TODO add graph that shows which dependencies led to this.
+ required_by = @required_by.map(&:first).join(', ')
+ raise "#{specification} tries to activate `#{dependency}', " \
+ "but already activated version `#{required_version}' by #{required_by}."
+ end
+ @required_by << [specification, dependency]
+ end
+
+ def dependency
+ @required_by.inject(Dependency.new(name)) { |previous, (_, dep)| previous.merge(dep) }
end
def name
@@ -23,12 +34,16 @@ def podspec
# Return the first version that matches the current dependency.
def required_version
- unless v = versions.find { |v| @dependency.match?(name, v) }
- raise "Required version (#{@dependency}) not found for `#{name}'."
+ unless v = versions.find { |v| dependency.match?(name, v) }
+ raise "Required version (#{dependency}) not found for `#{name}'."
end
v
end
+ def ==(other)
+ self.class === other && name == other.name
+ end
+
def to_s
"#<#{self.class.name} for `#{name}' with required version `#{required_version}'>"
end
@@ -39,7 +54,7 @@ def to_s
# Returns Pod::Version instances, for each version directory, sorted from
# lowest version to highest.
def versions
- @pod_dir.children.map { |v| Version.new(v.basename) }.sort
+ @pod_dir.children.map { |v| Version.new(v.basename) }.sort.reverse
end
end
end

0 comments on commit 701db81

Please sign in to comment.