Skip test file accessors for `uses_swift?` and `should_build?` methods

parent 781d5047
......@@ -27,6 +27,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7688](https://github.com/CocoaPods/CocoaPods/pull/7688)
* Skip test file accessors for `uses_swift?` and `should_build?` methods
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7671](https://github.com/CocoaPods/CocoaPods/pull/7671)
* Remove [system] declaration attribute from generated module maps
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7589](https://github.com/CocoaPods/CocoaPods/issues/7589)
......
......@@ -284,7 +284,7 @@ module Pod
product_type = target.product_type_for_test_type(test_type)
name = target.test_target_label(test_type)
platform_name = target.platform.name
language = target.all_dependent_targets.any?(&:uses_swift?) ? :swift : :objc
language = target.uses_swift_for_test_type?(test_type) ? :swift : :objc
test_native_target = project.new_target(product_type, name, platform_name, deployment_target, nil, language)
test_native_target.product_reference.name = name
......
......@@ -146,11 +146,10 @@ module Pod
#
def should_build?
return @should_build if defined? @should_build
return @should_build = true if contains_script_phases?
source_files = file_accessors.flat_map(&:source_files)
source_files -= file_accessors.flat_map(&:headers)
accessors = file_accessors.reject { |fa| fa.spec.test_specification? }
source_files = accessors.flat_map(&:source_files)
source_files -= accessors.flat_map(&:headers)
@should_build = !source_files.empty?
end
......@@ -166,7 +165,24 @@ module Pod
def uses_swift?
return @uses_swift if defined? @uses_swift
@uses_swift = begin
file_accessors.any? do |file_accessor|
file_accessors.reject { |a| a.spec.test_specification? }.any? do |file_accessor|
file_accessor.source_files.any? { |sf| sf.extname == '.swift' }
end
end
end
# Checks whether a particular test type uses Swift or not.
#
# @param [Symbol] test_type
# The test type to check whether it uses Swift or not.
#
# @return [Boolean] Whether the target uses Swift code in the specified test type.
#
def uses_swift_for_test_type?(test_type)
@uses_swift_for_test_type ||= {}
return @uses_swift_for_test_type[test_type] if @uses_swift_for_test_type.key?(test_type)
@uses_swift_for_test_type[test_type] = begin
file_accessors.select { |a| a.spec.test_specification? && a.spec.test_type == test_type }.any? do |file_accessor|
file_accessor.source_files.any? { |sf| sf.extname == '.swift' }
end
end
......
......@@ -513,8 +513,8 @@ module Pod
(build_configuration.build_settings['OTHER_CFLAGS'] ||= '$(inherited)') << ' -Wincomplete-umbrella'
build_configuration.build_settings['SWIFT_VERSION'] = (pod_target.swift_version || swift_version) if pod_target.uses_swift?
end
if pod_target.uses_swift?
pod_target_installation_result.test_native_targets.each do |test_native_target|
pod_target_installation_result.test_specs_by_native_target.each do |test_native_target, test_specs|
if pod_target.uses_swift_for_test_type?(test_specs.first.test_type)
test_native_target.build_configuration_list.build_configurations.each do |build_configuration|
build_configuration.build_settings['SWIFT_VERSION'] = swift_version
end
......
......@@ -3,10 +3,11 @@ require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe PodTarget do
before do
spec = fixture_spec('banana-lib/BananaLib.podspec')
@banana_spec = fixture_spec('banana-lib/BananaLib.podspec')
@target_definition = Podfile::TargetDefinition.new('Pods', nil)
@target_definition.abstract = false
@pod_target = PodTarget.new(config.sandbox, false, {}, [], Platform.ios, [spec], [@target_definition])
@pod_target = PodTarget.new(config.sandbox, false, {}, [],
Platform.ios, [@banana_spec], [@target_definition])
end
describe 'Meta' do
......@@ -94,7 +95,7 @@ module Pod
end
it 'builds a pod target if there are actual source files' do
fa = Sandbox::FileAccessor.new(nil, @pod_target)
fa = Sandbox::FileAccessor.new(nil, @banana_spec.consumer(Platform.ios))
fa.stubs(:source_files).returns([Pathname.new('foo.m')])
@pod_target.stubs(:file_accessors).returns([fa])
......@@ -102,7 +103,7 @@ module Pod
end
it 'does not build a pod target if there are only header files' do
fa = Sandbox::FileAccessor.new(nil, @pod_target)
fa = Sandbox::FileAccessor.new(nil, @banana_spec.consumer(Platform.ios))
fa.stubs(:source_files).returns([Pathname.new('foo.h')])
@pod_target.stubs(:file_accessors).returns([fa])
......@@ -110,7 +111,7 @@ module Pod
end
it 'builds a pod target if there are no actual source files but there are script phases' do
fa = Sandbox::FileAccessor.new(nil, @pod_target)
fa = Sandbox::FileAccessor.new(nil, @banana_spec.consumer(Platform.ios))
fa.stubs(:source_files).returns([Pathname.new('foo.h')])
@pod_target.stubs(:file_accessors).returns([fa])
@pod_target.root_spec.script_phase = { :name => 'Hello World', :script => 'echo "Hello World"' }
......@@ -251,8 +252,8 @@ module Pod
@pod_target.sandbox.public_headers.add_search_path('BananaLib', Platform.ios)
@pod_target.sandbox.public_headers.add_search_path('monkey', Platform.ios)
monkey_spec = fixture_spec('monkey/monkey.podspec')
monkey_pod_target = PodTarget.new(config.sandbox, false, {}, [], Platform.ios, [monkey_spec], [@target_definition])
monkey_pod_target.stubs(:platform).returns(Platform.ios)
monkey_pod_target = PodTarget.new(config.sandbox, false, {}, [],
Platform.ios, [monkey_spec], [@target_definition])
@pod_target.stubs(:dependent_targets).returns([monkey_pod_target])
header_search_paths = @pod_target.header_search_paths
header_search_paths.sort.should == [
......@@ -269,8 +270,8 @@ module Pod
@pod_target.sandbox.public_headers.add_search_path('BananaLib', Platform.ios)
@pod_target.sandbox.public_headers.add_search_path('monkey', Platform.osx)
monkey_spec = fixture_spec('monkey/monkey.podspec')
monkey_pod_target = PodTarget.new(config.sandbox, false, {}, [], Platform.ios, [monkey_spec], [@target_definition])
monkey_pod_target.stubs(:platform).returns(Platform.ios)
monkey_pod_target = PodTarget.new(config.sandbox, false, {}, [],
Platform.ios, [monkey_spec], [@target_definition])
@pod_target.stubs(:dependent_targets).returns([monkey_pod_target])
header_search_paths = @pod_target.header_search_paths
# The monkey lib header search paths should not be present since they are only present in OSX.
......@@ -291,7 +292,6 @@ module Pod
it 'uses modular header search paths when specified in the podfile' do
@pod_target.unstub(:defines_module?)
@pod_target.target_definitions.first.stubs(:build_pod_as_module?).with('BananaLib').returns(true)
@pod_target.build_headers.add_search_path('BananaLib', Platform.ios)
@pod_target.sandbox.public_headers.add_search_path('BananaLib', Platform.ios)
header_search_paths = @pod_target.header_search_paths
......@@ -352,7 +352,8 @@ module Pod
@pod_target.sandbox.public_headers.add_search_path('BananaLib', Platform.ios)
@pod_target.sandbox.public_headers.add_search_path('monkey', Platform.osx)
monkey_spec = fixture_spec('monkey/monkey.podspec')
monkey_pod_target = PodTarget.new(config.sandbox, false, {}, [], Platform.ios, [monkey_spec], [@target_definition])
monkey_pod_target = PodTarget.new(config.sandbox, false, {}, [],
Platform.ios, [monkey_spec], [@target_definition])
monkey_pod_target.stubs(:platform).returns(Platform.ios)
@pod_target.stubs(:dependent_targets).returns([monkey_pod_target])
header_search_paths = @pod_target.header_search_paths
......@@ -520,8 +521,10 @@ module Pod
@coconut_spec = fixture_spec('coconut-lib/CoconutLib.podspec')
@test_spec_target_definition = Podfile::TargetDefinition.new('Pods', nil)
@test_spec_target_definition.abstract = false
@test_pod_target = PodTarget.new(config.sandbox, false, {}, [], Platform.ios, [@coconut_spec, *@coconut_spec.recursive_subspecs], [@test_spec_target_definition])
@test_pod_target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@platform = Platform.new(:ios, '6.0')
@test_pod_target = PodTarget.new(config.sandbox, false, {}, [],
@platform, [@coconut_spec, *@coconut_spec.recursive_subspecs],
[@test_spec_target_definition])
end
it 'returns that it has test specifications' do
......@@ -579,7 +582,7 @@ module Pod
end
it 'returns the correct resource path for test resource bundles' do
fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
fa = Sandbox::FileAccessor.new(nil, @coconut_spec.test_specs.first.consumer(@platform))
fa.stubs(:resource_bundles).returns('TestResourceBundle' => [Pathname.new('Model.xcdatamodeld')])
fa.stubs(:resources).returns([])
fa.stubs(:spec).returns(stub(:test_specification? => true))
......@@ -588,10 +591,10 @@ module Pod
end
it 'includes framework paths from test specifications' do
fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
fa = Sandbox::FileAccessor.new(nil, @coconut_spec.test_specs.first.consumer(@platform))
fa.stubs(:vendored_dynamic_artifacts).returns([config.sandbox.root + Pathname.new('Vendored/Vendored.framework')])
fa.stubs(:spec).returns(stub(:test_specification? => false))
test_fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
test_fa = Sandbox::FileAccessor.new(nil, @coconut_spec.test_specs.first.consumer(@platform))
test_fa.stubs(:vendored_dynamic_artifacts).returns([config.sandbox.root + Pathname.new('Vendored/TestVendored.framework')])
test_fa.stubs(:spec).returns(stub(:test_specification? => true))
@test_pod_target.stubs(:file_accessors).returns([fa, test_fa])
......@@ -607,10 +610,10 @@ module Pod
end
it 'excludes framework paths from test specifications when not requested' do
fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
fa = Sandbox::FileAccessor.new(nil, @coconut_spec.consumer(@platform))
fa.stubs(:vendored_dynamic_artifacts).returns([config.sandbox.root + Pathname.new('Vendored/Vendored.framework')])
fa.stubs(:spec).returns(stub(:test_specification? => false))
test_fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
test_fa = Sandbox::FileAccessor.new(nil, @coconut_spec.test_specs.first.consumer(@platform))
test_fa.stubs(:vendored_dynamic_artifacts).returns([config.sandbox.root + Pathname.new('Vendored/TestVendored.framework')])
test_fa.stubs(:spec).returns(stub(:test_specification? => true))
@test_pod_target.stubs(:file_accessors).returns([fa, test_fa])
......@@ -624,11 +627,11 @@ module Pod
it 'includes resource paths from test specifications' do
config.sandbox.stubs(:project => stub(:path => Pathname.new('ProjectPath')))
fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
fa = Sandbox::FileAccessor.new(nil, @coconut_spec.consumer(@platform))
fa.stubs(:resource_bundles).returns({})
fa.stubs(:resources).returns([Pathname.new('Model.xcdatamodeld')])
fa.stubs(:spec).returns(stub(:test_specification? => false))
test_fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
test_fa = Sandbox::FileAccessor.new(nil, @coconut_spec.test_specs.first.consumer(@platform))
test_fa.stubs(:resource_bundles).returns({})
test_fa.stubs(:resources).returns([Pathname.new('TestModel.xcdatamodeld')])
test_fa.stubs(:spec).returns(stub(:test_specification? => true))
......@@ -638,11 +641,11 @@ module Pod
it 'excludes resource paths from test specifications when not requested' do
config.sandbox.stubs(:project => stub(:path => Pathname.new('ProjectPath')))
fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
fa = Sandbox::FileAccessor.new(nil, @coconut_spec.consumer(@platform))
fa.stubs(:resource_bundles).returns({})
fa.stubs(:resources).returns([Pathname.new('Model.xcdatamodeld')])
fa.stubs(:spec).returns(stub(:test_specification? => false))
test_fa = Sandbox::FileAccessor.new(nil, @test_pod_target)
test_fa = Sandbox::FileAccessor.new(nil, @coconut_spec.test_specs.first.consumer(@platform))
test_fa.stubs(:resource_bundles).returns({})
test_fa.stubs(:resources).returns([Pathname.new('TestModel.xcdatamodeld')])
test_fa.stubs(:spec).returns(stub(:test_specification? => true))
......
......@@ -1080,9 +1080,15 @@ module Pod
native_target_one = stub(:build_configuration_list => stub(:build_configurations => [debug_configuration_one]))
native_target_two = stub(:build_configuration_list => stub(:build_configurations => [debug_configuration_two]))
pod_target_one = stub(:name => 'PodTarget1', :uses_swift? => true, :swift_version => '4.0')
pod_target_one.stubs(:uses_swift_for_test_type?).with(:unit).returns(true)
pod_target_two = stub(:name => 'PodTarget2', :uses_swift? => true, :swift_version => '3.2')
pod_target_installation_one = stub(:target => pod_target_one, :native_target => native_target_one, :test_native_targets => [])
pod_target_installation_two = stub(:target => pod_target_two, :native_target => native_target_two, :test_native_targets => [])
pod_target_two.stubs(:uses_swift_for_test_type?).with(:unit).returns(true)
pod_target_installation_one = stub(:target => pod_target_one, :native_target => native_target_one,
:test_native_targets => [],
:test_specs_by_native_target => {})
pod_target_installation_two = stub(:target => pod_target_two, :native_target => native_target_two,
:test_native_targets => [],
:test_specs_by_native_target => {})
pod_target_installation_results = { 'PodTarget1' => pod_target_installation_one, 'PodTarget2' => pod_target_installation_two }
aggregate_target = stub(:pod_targets => [pod_target_one, pod_target_two])
installer = stub(:pod_targets => [pod_target_one, pod_target_two])
......@@ -1102,8 +1108,12 @@ module Pod
native_target_two = stub(:build_configuration_list => stub(:build_configurations => [debug_configuration_two]))
pod_target_one = stub(:name => 'PodTarget1', :uses_swift? => true, :swift_version => '4.0')
pod_target_two = stub(:name => 'PodTarget2', :uses_swift? => true, :swift_version => '3.2')
pod_target_installation_one = stub(:target => pod_target_one, :native_target => native_target_one, :test_native_targets => [])
pod_target_installation_two = stub(:target => pod_target_two, :native_target => native_target_two, :test_native_targets => [])
pod_target_installation_one = stub(:target => pod_target_one, :native_target => native_target_one,
:test_native_targets => [],
:test_specs_by_native_target => {})
pod_target_installation_two = stub(:target => pod_target_two, :native_target => native_target_two,
:test_native_targets => [],
:test_specs_by_native_target => {})
pod_target_installation_results = { 'PodTarget1' => pod_target_installation_one, 'PodTarget2' => pod_target_installation_two }
aggregate_target = stub(:pod_targets => [pod_target_one])
installer = stub(:pod_targets => [pod_target_one, pod_target_two])
......
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