Skip to content

Commit

Permalink
[Validator] No master specs cloning when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
adellibovi committed Apr 8, 2017
1 parent 25d41a0 commit 5f54ada
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### Bug Fixes

* None.
* No master specs cloning when not needed for `pod lib lint`.
[Alfredo Delli Bovi](https://github.com/adellibovi)
[#6154](https://github.com/CocoaPods/CocoaPods/issues/6154)


## 1.2.1.rc.1 (2017-04-05)
Expand Down
7 changes: 7 additions & 0 deletions lib/cocoapods/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def initialize(sandbox, podfile, lockfile = nil)
@lockfile = lockfile

@use_default_plugins = true
@has_dependencies = true
end

# @return [Hash, Boolean, nil] Pods that have been requested to be
Expand All @@ -80,6 +81,11 @@ def initialize(sandbox, podfile, lockfile = nil)
#
attr_accessor :update

# @return [Boolean] Whether it has dependencies. Defaults to true.
#
attr_accessor :has_dependencies
alias_method :has_dependencies?, :has_dependencies

# @return [Boolean] Whether the spec repos should be updated.
#
attr_accessor :repo_update
Expand Down Expand Up @@ -240,6 +246,7 @@ def analyze(analyzer = create_analyzer)
def create_analyzer
Analyzer.new(sandbox, podfile, lockfile).tap do |analyzer|
analyzer.installation_options = installation_options
analyzer.has_dependencies = has_dependencies?
end
end

Expand Down
14 changes: 12 additions & 2 deletions lib/cocoapods/installer/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def initialize(sandbox, podfile, lockfile = nil)

@update = false
@allow_pre_downloads = true
@has_dependencies = true
end

# Performs the analysis.
Expand Down Expand Up @@ -152,6 +153,15 @@ def update_mode
attr_accessor :allow_pre_downloads
alias_method :allow_pre_downloads?, :allow_pre_downloads

# @return [Bool] Whether the analysis has dependencies and thus
# sources must be configured.
#
# @note This is used by the `pod lib lint` command to prevent
# update of specs when not needed.
#
attr_accessor :has_dependencies
alias_method :has_dependencies?, :has_dependencies

#-----------------------------------------------------------------------#

private
Expand Down Expand Up @@ -819,11 +829,11 @@ def sources

# Add any sources specified using the :source flag on individual dependencies.
dependency_sources = podfile.dependencies.map(&:podspec_repo).compact

all_dependencies_have_sources = dependency_sources.count == podfile.dependencies.count

if all_dependencies_have_sources
sources = dependency_sources
elsif sources.empty?
elsif has_dependencies? && sources.empty?
sources = ['https://github.com/CocoaPods/Specs.git']
else
sources += dependency_sources
Expand Down
7 changes: 6 additions & 1 deletion lib/cocoapods/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ class Validator
# the Source URLs to use in creating a {Podfile}.
#
def initialize(spec_or_path, source_urls)
@source_urls = source_urls.map { |url| config.sources_manager.source_with_name_or_url(url) }.map(&:url)
@linter = Specification::Linter.new(spec_or_path)
@source_urls = if @linter.spec && @linter.spec.dependencies.empty?
[]
else
source_urls.map { |url| config.sources_manager.source_with_name_or_url(url) }.map(&:url)
end
end

#-------------------------------------------------------------------------#
Expand Down Expand Up @@ -405,6 +409,7 @@ def download_pod
sandbox = Sandbox.new(config.sandbox_root)
@installer = Installer.new(sandbox, podfile)
@installer.use_default_plugins = false
@installer.has_dependencies = !spec.dependencies.empty?
%i(prepare resolve_dependencies download_dependencies).each { |m| @installer.send(m) }
@file_accessor = @installer.pod_targets.flat_map(&:file_accessors).find { |fa| fa.spec.name == consumer.spec.name }
end
Expand Down
33 changes: 32 additions & 1 deletion spec/unit/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,46 @@ def podspec_path(name = 'JSONKit', version = '1.4')
end
end

it 'repects the source_urls parameter' do
it 'empties sources when no dependencies' do
sources = %w(master https://github.com/CocoaPods/Specs.git)
Command::Repo::Add.any_instance.stubs(:run)
validator = Validator.new(podspec_path, sources)
validator.stubs(:validate_url)
podfile = validator.send(:podfile_from_spec, :ios, '5.0')
podfile.sources.should == %w()
end

it 'repects the source_urls parameter when there are dependencies' do
podspec = stub_podspec(/.*name.*/, '"name": "SBJson",').gsub(/.*version.*/, '"version": "3.2",')
file = write_podspec(podspec, 'SBJson.podspec.json')
spec = Specification.from_file(file)
set = mock
set.stubs(:all_specifications).returns([spec])
Source::Aggregate.any_instance.stubs(:search).with(Dependency.new('SBJson', '~> 3.2')).returns(set)

podspec = stub_podspec(/.*name.*/, '"name": "ZKit",')
podspec.gsub!(/.*requires_arc.*/, '"dependencies": { "SBJson": [ "~> 3.2" ] }, "requires_arc": false')
file = write_podspec(podspec, 'ZKit.podspec.json')

spec = Specification.from_file(file)

sources = %w(master https://github.com/CocoaPods/Specs.git)
Command::Repo::Add.any_instance.stubs(:run)
validator = Validator.new(spec, sources)
validator.stubs(:validate_url)
podfile = validator.send(:podfile_from_spec, :ios, '5.0')
podfile.sources.should == %w(https://github.com/CocoaPods/Specs.git)
end

it 'avoids creation of sources when no dependencies' do
sources = %w(master https://github.com/CocoaPods/Specs.git)
config.sources_manager.expects(:find_or_create_source_with_url).never
Command::Repo::Add.any_instance.stubs(:run)
validator = Validator.new(podspec_path, sources)
validator.stubs(:validate_url)
validator.validate
end

it 'uses xcodebuild to generate warnings' do
validator = Validator.new(podspec_path, config.sources_manager.master.map(&:url))
validator.stubs(:check_file_patterns)
Expand Down

0 comments on commit 5f54ada

Please sign in to comment.