Commit 9b11b799 authored by Samuel Giddins's avatar Samuel Giddins

Move empty podfile validation to the podfile validator

parent 92a04dca
...@@ -160,6 +160,7 @@ module Pod ...@@ -160,6 +160,7 @@ module Pod
unless validator.valid? unless validator.valid?
raise Informative, validator.message raise Informative, validator.message
end end
validator.warnings.uniq.each { |w| UI.warn(w) }
end end
# @!group Analysis steps # @!group Analysis steps
......
...@@ -12,6 +12,11 @@ module Pod ...@@ -12,6 +12,11 @@ module Pod
# #
attr_reader :errors attr_reader :errors
# @return [Array<String>] any warnings that have occured during the validation
#
attr_reader :warnings
# Initialize a new instance # Initialize a new instance
# @param [Podfile] podfile # @param [Podfile] podfile
# The podfile to validate # The podfile to validate
...@@ -19,6 +24,7 @@ module Pod ...@@ -19,6 +24,7 @@ module Pod
def initialize(podfile) def initialize(podfile)
@podfile = podfile @podfile = podfile
@errors = [] @errors = []
@warnings = []
@validated = false @validated = false
end end
...@@ -28,6 +34,7 @@ module Pod ...@@ -28,6 +34,7 @@ module Pod
def validate def validate
validate_pod_directives validate_pod_directives
validate_no_abstract_only_pods! validate_no_abstract_only_pods!
validate_dependencies_are_present!
@validated = true @validated = true
end end
...@@ -55,6 +62,10 @@ module Pod ...@@ -55,6 +62,10 @@ module Pod
errors << error errors << error
end end
def add_warning(warning)
warnings << warning
end
def validate_pod_directives def validate_pod_directives
dependencies = podfile.target_definitions.flat_map do |_, target| dependencies = podfile.target_definitions.flat_map do |_, target|
target.dependencies target.dependencies
...@@ -83,6 +94,23 @@ module Pod ...@@ -83,6 +94,23 @@ module Pod
end end
end end
# Warns the user if the podfile is empty.
#
# @note The workspace is created in any case and all the user projects
# are added to it, however the projects are not integrated as
# there is no way to discern between target definitions which are
# empty and target definitions which just serve the purpose to
# wrap other ones. This is not an issue because empty target
# definitions generate empty libraries.
#
# @return [void]
#
def validate_dependencies_are_present!
if podfile.target_definitions.values.all?(&:empty?)
add_warning 'The Podfile does not contain any dependencies.'
end
end
def validate_no_abstract_only_pods! def validate_no_abstract_only_pods!
abstract_pods = ->(target_definition) do abstract_pods = ->(target_definition) do
if !target_definition.abstract? || !target_definition.children.empty? if !target_definition.abstract? || !target_definition.children.empty?
......
...@@ -61,7 +61,6 @@ module Pod ...@@ -61,7 +61,6 @@ module Pod
def integrate! def integrate!
create_workspace create_workspace
integrate_user_targets integrate_user_targets
warn_about_empty_podfile
warn_about_xcconfig_overrides warn_about_xcconfig_overrides
save_projects save_projects
end end
...@@ -152,23 +151,6 @@ module Pod ...@@ -152,23 +151,6 @@ module Pod
end end
end end
# Warns the user if the podfile is empty.
#
# @note The workspace is created in any case and all the user projects
# are added to it, however the projects are not integrated as
# there is no way to discern between target definitions which are
# empty and target definitions which just serve the purpose to
# wrap other ones. This is not an issue because empty target
# definitions generate empty libraries.
#
# @return [void]
#
def warn_about_empty_podfile
if podfile.target_definitions.values.all?(&:empty?)
UI.warn '[!] The Podfile does not contain any dependencies.'
end
end
IGNORED_KEYS = %w(CODE_SIGN_IDENTITY).freeze IGNORED_KEYS = %w(CODE_SIGN_IDENTITY).freeze
INHERITED_FLAGS = %w($(inherited) ${inherited}).freeze INHERITED_FLAGS = %w($(inherited) ${inherited}).freeze
......
...@@ -62,5 +62,15 @@ module Pod ...@@ -62,5 +62,15 @@ module Pod
validator.errors[0].should.match /The dependency `JSONKit` specifies more than one/ validator.errors[0].should.match /The dependency `JSONKit` specifies more than one/
end end
end end
it 'warns if the podfile does not contain any dependency' do
podfile = Pod::Podfile.new
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.be.valid
validator.errors.should.be.empty
validator.warnings.should == ['The Podfile does not contain any dependencies.']
end
end end
end end
...@@ -51,13 +51,6 @@ module Pod ...@@ -51,13 +51,6 @@ module Pod
@integrator.integrate! @integrator.integrate!
end end
it 'warns if the podfile does not contain any dependency' do
@podfile = Pod::Podfile.new
@integrator.stubs(:podfile).returns(@podfile)
@integrator.integrate!
UI.warnings.should.include?('The Podfile does not contain any dependencies')
end
it 'deintegrates targets that are not associated with the podfile' do it 'deintegrates targets that are not associated with the podfile' do
additional_project = Xcodeproj::Project.new('Project.xcodeproj') additional_project = Xcodeproj::Project.new('Project.xcodeproj')
Deintegrator.any_instance.expects(:deintegrate_target).with additional_project.new_target(:application, 'Other App', :ios) Deintegrator.any_instance.expects(:deintegrate_target).with additional_project.new_target(:application, 'Other App', :ios)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment