Skip to content

Commit

Permalink
[Resolver] Lazy repo update.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Sep 21, 2012
1 parent b8ef7bf commit 8fe92e1
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 31 deletions.
8 changes: 0 additions & 8 deletions lib/cocoapods/command.rb
Expand Up @@ -142,14 +142,6 @@ def verify_lockfile_exists!
raise Informative, "No `Podfile.lock' found in the current working directory, run `pod install'."
end
end

def update_spec_repos_if_necessary!
if @update_repo
UI.section 'Updating Spec Repositories' do
Repo.new(ARGV.new(["update"])).run
end
end
end
end
end

3 changes: 1 addition & 2 deletions lib/cocoapods/command/install.rb
Expand Up @@ -35,7 +35,7 @@ def initialize(argv)
config.clean = !argv.option('--no-clean')
config.generate_docs = !argv.option('--no-doc')
config.integrate_targets = !argv.option('--no-integrate')
@update_repo = !argv.option('--no-update')
config.skip_repo_update = !argv.option('--no-update')
super unless argv.empty?
end

Expand All @@ -48,7 +48,6 @@ def run_install_with_update(update)

def run
verify_podfile_exists!
update_spec_repos_if_necessary!
run_install_with_update(false)
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/cocoapods/command/outdated.rb
Expand Up @@ -11,13 +11,11 @@ def self.banner
end

def self.options
[
["--no-update", "Skip running `pod repo update` before install"],
].concat(super)
[["--no-update", "Skip running `pod repo update` before install"]].concat(super)
end

def initialize(argv)
@update_repo = !argv.option('--no-update')
config.skip_repo_update = argv.option('--no-update')
super unless argv.empty?
end

Expand Down
10 changes: 9 additions & 1 deletion lib/cocoapods/command/update.rb
Expand Up @@ -9,10 +9,18 @@ def self.banner
Updates all dependencies.}
end

def self.options
[["--no-update", "Skip running `pod repo update` before install"]].concat(super)
end

def initialize(argv)
config.skip_repo_update = argv.option('--no-update')
super unless argv.empty?
end

def run
verify_podfile_exists!
verify_lockfile_exists!
update_spec_repos_if_necessary!
run_install_with_update(true)
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/cocoapods/config.rb
Expand Up @@ -14,19 +14,20 @@ def self.instance=(instance)
attr_accessor :clean, :verbose, :silent
attr_accessor :generate_docs, :doc_install
attr_accessor :integrate_targets
attr_accessor :new_version_message
attr_accessor :new_version_message, :skip_repo_update

alias_method :clean?, :clean
alias_method :verbose?, :verbose
alias_method :silent?, :silent
alias_method :generate_docs?, :generate_docs
alias_method :doc_install?, :doc_install
alias_method :integrate_targets?, :integrate_targets
alias_method :skip_repo_update?, :skip_repo_update
alias_method :new_version_message?, :new_version_message

def initialize
@repos_dir = Pathname.new(File.expand_path("~/.cocoapods"))
@verbose = @silent = false
@verbose = @silent = @skip_repo_update = false
@clean = @generate_docs = @doc_install = @integrate_targets = @new_version_message = true
end

Expand Down
6 changes: 6 additions & 0 deletions lib/cocoapods/resolver.rb
Expand Up @@ -80,6 +80,12 @@ def resolve
@pods_to_lock = (lockfile.pods_names - @pods_by_state[:added] - @pods_by_state[:changed] - @pods_by_state[:removed]).uniq
end

unless config.skip_repo_update?
UI.section 'Updating Spec Repositories' do
Command::Repo.new(Command::ARGV.new(["update"])).run
end if !@pods_by_state || !(@pods_by_state[:added] + @pods_by_state[:changed]).empty? || update_mode
end

@podfile.target_definitions.values.each do |target_definition|
UI.section "Resolving dependencies for target `#{target_definition.name}' (#{target_definition.platform}):" do
@loaded_specs = []
Expand Down
16 changes: 8 additions & 8 deletions spec/integration_spec.rb
Expand Up @@ -27,9 +27,9 @@ def specs_by_target
extend SpecHelper::TemporaryDirectory

def create_config!
config.repos_dir = fixture('spec-repos')
config.project_root = temporary_directory
config.integrate_targets = false
config.repos_dir = fixture('spec-repos')
config.project_root = temporary_directory
config.integrate_targets = false
end

before do
Expand Down Expand Up @@ -208,7 +208,6 @@ def should_xcodebuild(target_definition)
result['DEPENDENCIES'].should == ["ASIHTTPRequest", "JSONKit (= 1.4)"]
# TODO might be nicer looking to not show the dependencies of the top level spec for each subspec (Reachability).

should_xcodebuild(podfile.target_definitions[:ios_target])
should_xcodebuild(podfile.target_definitions[:osx_target])
end

Expand All @@ -217,10 +216,11 @@ def should_xcodebuild(target_definition)
::Pod::Config.instance = nil
::Pod::Config.instance.tap do |c|
ENV['VERBOSE_SPECS'] ? c.verbose = true : c.silent = true
c.doc_install = false
c.repos_dir = fixture('spec-repos')
c.project_root = temporary_directory
c.integrate_targets = false
c.doc_install = false
c.repos_dir = fixture('spec-repos')
c.project_root = temporary_directory
c.integrate_targets = false
c.skip_repo_update = true
end

Pod::Generator::Documentation.any_instance.stubs(:already_installed?).returns(false)
Expand Down
9 changes: 5 additions & 4 deletions spec/spec_helper/config.rb
Expand Up @@ -8,10 +8,11 @@ class Context
::Pod::Config.instance = nil
::Pod::Config.instance.tap do |c|
ENV['VERBOSE_SPECS'] ? c.verbose = true : c.silent = true
c.repos_dir = SpecHelper.tmp_repos_path
c.project_root = SpecHelper.temporary_directory
c.doc_install = false
c.generate_docs = false
c.repos_dir = SpecHelper.tmp_repos_path
c.project_root = SpecHelper.temporary_directory
c.doc_install = false
c.generate_docs = false
c.skip_repo_update = true
end
old_run_requirement.bind(self).call(description, spec)
end
Expand Down
66 changes: 64 additions & 2 deletions spec/unit/resolver_spec.rb
Expand Up @@ -4,7 +4,6 @@ module Pod
describe Resolver do
before do
config.repos_dir = fixture('spec-repos')

@podfile = Podfile.new do
platform :ios
pod 'BlocksKit'
Expand Down Expand Up @@ -261,7 +260,7 @@ def set.specification; spec = super; spec.platform = @stubbed_platform; spec; en
platform :ios
pod 'JSONKit'
pod 'BlocksKit'
pod 'libPusher'
pod 'libPusher' # New pod
end
@resolver = Resolver.new(podfile, @lockfile, stub('sandbox'))
installed = @resolver.resolve.values.flatten.map(&:to_s)
Expand Down Expand Up @@ -294,6 +293,56 @@ def set.specification; spec = super; spec.platform = @stubbed_platform; spec; en
@resolver.resolve
@resolver.should_install?("JSONKit").should.be.false
end

it "doesn't updates the repos if there no change in the pods" do
podfile = Podfile.new do
platform :ios
pod 'BlocksKit'
pod 'JSONKit'
end
config.skip_repo_update = false
Pod::Command::Repo.any_instance.expects(:run).never
@resolver = Resolver.new(podfile, @lockfile, stub('sandbox'))
@resolver.resolve
end

it "updates the repos if there is a new pod" do
podfile = Podfile.new do
platform :ios
pod 'BlocksKit'
pod 'JSONKit'
pod 'libPusher' # New pod
end
config.skip_repo_update = false
Pod::Command::Repo.any_instance.expects(:run).once
@resolver = Resolver.new(podfile, @lockfile, stub('sandbox'))
@resolver.resolve
end

it "doesn't update the repos if config indicate to skip it in any case" do
podfile = Podfile.new do
platform :ios
pod 'BlocksKit'
pod 'JSONKit', :head #changed to head
pod 'libPusher' # New pod
end
config.skip_repo_update = true
Pod::Command::Repo.any_instance.expects(:run).never
@resolver = Resolver.new(podfile, @lockfile, stub('sandbox'))
@resolver.resolve
end

it "updates the repos if there is a new pod" do
podfile = Podfile.new do
platform :ios
pod 'BlocksKit'
pod 'JSONKit', :head #changed to head
end
config.skip_repo_update = false
Pod::Command::Repo.any_instance.expects(:run).once
@resolver = Resolver.new(podfile, @lockfile, stub('sandbox'))
@resolver.resolve
end
end

describe "Concerning Update mode" do
Expand Down Expand Up @@ -356,6 +405,19 @@ def set.specification; spec = super; spec.platform = @stubbed_platform; spec; en
@resolver.should_install?("libPusher").should.be.true
end

it "always updates the repos even if there is change in the pods" do
podfile = Podfile.new do
platform :ios
pod 'JSONKit'
pod 'libPusher'
end
config.skip_repo_update = false
Pod::Command::Repo.any_instance.expects(:run).once
@resolver = Resolver.new(podfile, @lockfile, stub('sandbox'))
@resolver.update_mode = true
@resolver.resolve
end

# TODO: stub the specification resolution for the sandbox
xit "it always suggests to update pods from external sources" do
podfile = Podfile.new do
Expand Down

0 comments on commit 8fe92e1

Please sign in to comment.