Commit fcdc97c7 authored by Marius Rackwitz's avatar Marius Rackwitz

[PodTarget] Allow to be scoped

parent 8b972f10
...@@ -30,6 +30,14 @@ module Pod ...@@ -30,6 +30,14 @@ module Pod
@resource_bundle_targets = [] @resource_bundle_targets = []
end end
# @return [PodTarget] the same target, but scoped.
#
def scoped
clone.tap do |scoped_target|
scoped_target.scoped = true
end
end
# @return [String] the label for the target. # @return [String] the label for the target.
# #
def label def label
......
...@@ -14,7 +14,7 @@ module Pod ...@@ -14,7 +14,7 @@ module Pod
@gen.save_as(path) @gen.save_as(path)
path.read.should == <<-EOS.strip_heredoc path.read.should == <<-EOS.strip_heredoc
framework module BananaLib { framework module BananaLib {
umbrella header "Pods-default-BananaLib-umbrella.h" umbrella header "BananaLib-umbrella.h"
export * export *
module * { export * } module * { export * }
...@@ -26,7 +26,7 @@ module Pod ...@@ -26,7 +26,7 @@ module Pod
@gen.stubs(:private_headers).returns(['Private.h']) @gen.stubs(:private_headers).returns(['Private.h'])
@gen.generate.should == <<-EOS.strip_heredoc @gen.generate.should == <<-EOS.strip_heredoc
framework module BananaLib { framework module BananaLib {
umbrella header "Pods-default-BananaLib-umbrella.h" umbrella header "BananaLib-umbrella.h"
export * export *
module * { export * } module * { export * }
......
...@@ -8,9 +8,13 @@ module Pod ...@@ -8,9 +8,13 @@ module Pod
fixture_spec('banana-lib/BananaLib.podspec') fixture_spec('banana-lib/BananaLib.podspec')
end end
def pod_target(spec)
fixture_pod_target(spec)
end
before do before do
@spec = spec @spec = spec
@pod_target = fixture_pod_target(@spec) @pod_target = pod_target(@spec)
@consumer = @pod_target.spec_consumers.last @consumer = @pod_target.spec_consumers.last
@target = fixture_aggregate_target([@pod_target]) @target = fixture_aggregate_target([@pod_target])
@target.target_definition.should == @pod_target.target_definition @target.target_definition.should == @pod_target.target_definition
...@@ -103,9 +107,21 @@ module Pod ...@@ -103,9 +107,21 @@ module Pod
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected @xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end end
describe 'with a scoped pod target' do
def pod_target(spec)
fixture_pod_target(spec).scoped
end
it 'links the pod targets with the aggregate target' do it 'links the pod targets with the aggregate target' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-l"Pods-BananaLib"' @xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-l"Pods-BananaLib"'
end end
end
describe 'with an unscoped pod target' do
it 'links the pod targets with the aggregate target' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-l"BananaLib"'
end
end
it 'does not links the pod targets with the aggregate target for non-whitelisted configuration' do it 'does not links the pod targets with the aggregate target for non-whitelisted configuration' do
@generator = AggregateXCConfig.new(@target, 'Debug') @generator = AggregateXCConfig.new(@target, 'Debug')
...@@ -139,6 +155,11 @@ module Pod ...@@ -139,6 +155,11 @@ module Pod
@xcconfig.to_hash['PODS_FRAMEWORK_BUILD_PATH'].should == '$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods' @xcconfig.to_hash['PODS_FRAMEWORK_BUILD_PATH'].should == '$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods'
end end
describe 'with a scoped pod target' do
def pod_target(spec)
fixture_pod_target(spec).scoped
end
it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do
@xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '$(inherited) "$PODS_FRAMEWORK_BUILD_PATH"' @xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '$(inherited) "$PODS_FRAMEWORK_BUILD_PATH"'
end end
...@@ -147,6 +168,18 @@ module Pod ...@@ -147,6 +168,18 @@ module Pod
expected = '$(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/OrangeFramework.framework/Headers"' expected = '$(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/OrangeFramework.framework/Headers"'
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected @xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end end
end
describe 'with an unscoped pod target' do
it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do
@xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should.be.nil
end
it 'adds the framework header paths to the xcconfig, with quotes, as local headers' do
expected = '$(inherited) -iquote "$CONFIGURATION_BUILD_DIR/OrangeFramework.framework/Headers"'
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end
end
it 'links the pod targets with the aggregate target' do it 'links the pod targets with the aggregate target' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-framework "OrangeFramework"' @xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-framework "OrangeFramework"'
......
...@@ -34,26 +34,6 @@ module Pod ...@@ -34,26 +34,6 @@ module Pod
@spec.prefix_header_contents = '#import "BlocksKit.h"' @spec.prefix_header_contents = '#import "BlocksKit.h"'
end end
it 'adds file references for the support files of the target' do
@installer.install!
@project.support_files_group
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'Pods-BananaLib-Private.xcconfig',
'Pods-BananaLib-dummy.m',
'Pods-BananaLib-prefix.pch',
'Pods-BananaLib.xcconfig',
]
end
#--------------------------------------#
it 'adds the target for the static library to the project' do
@installer.install!
@project.targets.count.should == 1
@project.targets.first.name.should == 'Pods-BananaLib'
end
it 'sets the platform and the deployment target for iOS targets' do it 'sets the platform and the deployment target for iOS targets' do
@installer.install! @installer.install!
target = @project.targets.first target = @project.targets.first
...@@ -100,6 +80,40 @@ module Pod ...@@ -100,6 +80,40 @@ module Pod
#--------------------------------------# #--------------------------------------#
it 'adds framework resources to the framework target' do
@pod_target.stubs(:requires_frameworks? => true)
@installer.install!
resources = @project.targets.first.resources_build_phase.files
resources.count.should > 0
resource = resources.find { |res| res.file_ref.path.include?('logo-sidebar.png') }
resource.should.be.not.nil
end
#--------------------------------------#
describe 'with a scoped pod target' do
before do
@pod_target.scoped = true
end
it 'adds file references for the support files of the target' do
@installer.install!
@project.support_files_group
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'Pods-BananaLib-Private.xcconfig',
'Pods-BananaLib-dummy.m',
'Pods-BananaLib-prefix.pch',
'Pods-BananaLib.xcconfig',
]
end
it 'adds the target for the static library to the project' do
@installer.install!
@project.targets.count.should == 1
@project.targets.first.name.should == 'Pods-BananaLib'
end
it 'adds the resource bundle targets' do it 'adds the resource bundle targets' do
@pod_target.file_accessors.first.stubs(:resource_bundles).returns('banana_bundle' => []) @pod_target.file_accessors.first.stubs(:resource_bundles).returns('banana_bundle' => [])
@installer.install! @installer.install!
...@@ -109,25 +123,59 @@ module Pod ...@@ -109,25 +123,59 @@ module Pod
bundle_target.product_reference.path.should == 'banana_bundle.bundle' bundle_target.product_reference.path.should == 'banana_bundle.bundle'
end end
it 'adds framework resources to the framework target' do it 'adds the build configurations to the resources bundle targets' do
@pod_target.stubs(:requires_frameworks? => true) @pod_target.file_accessors.first.stubs(:resource_bundles).returns('banana_bundle' => [])
@installer.install! @installer.install!
resources = @project.targets.first.resources_build_phase.files bundle_target = @project.targets.find { |t| t.name == 'Pods-BananaLib-banana_bundle' }
resources.count.should > 0
resource = resources.find { |res| res.file_ref.path.include?('logo-sidebar.png') } file = config.sandbox.root + @pod_target.xcconfig_private_path
resource.should.be.not.nil bundle_target.build_configurations.each do |bc|
bc.base_configuration_reference.real_path.should == file
end
end
end
#--------------------------------------#
describe 'with an unscoped pod target' do
it 'adds file references for the support files of the target' do
@installer.install!
@project.support_files_group
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'BananaLib-Private.xcconfig',
'BananaLib-dummy.m',
'BananaLib-prefix.pch',
'BananaLib.xcconfig',
]
end
it 'adds the target for the static library to the project' do
@installer.install!
@project.targets.count.should == 1
@project.targets.first.name.should == 'BananaLib'
end
it 'adds the resource bundle targets' do
@pod_target.file_accessors.first.stubs(:resource_bundles).returns('banana_bundle' => [])
@installer.install!
bundle_target = @project.targets.find { |t| t.name == 'BananaLib-banana_bundle' }
bundle_target.should.be.an.instance_of Xcodeproj::Project::Object::PBXNativeTarget
bundle_target.product_reference.name.should == 'banana_bundle.bundle'
bundle_target.product_reference.path.should == 'banana_bundle.bundle'
end end
it 'adds the build configurations to the resources bundle targets' do it 'adds the build configurations to the resources bundle targets' do
@pod_target.file_accessors.first.stubs(:resource_bundles).returns('banana_bundle' => []) @pod_target.file_accessors.first.stubs(:resource_bundles).returns('banana_bundle' => [])
@installer.install! @installer.install!
bundle_target = @project.targets.find { |t| t.name == 'Pods-BananaLib-banana_bundle' } bundle_target = @project.targets.find { |t| t.name == 'BananaLib-banana_bundle' }
file = config.sandbox.root + @pod_target.xcconfig_private_path file = config.sandbox.root + @pod_target.xcconfig_private_path
bundle_target.build_configurations.each do |bc| bundle_target.build_configurations.each do |bc|
bc.base_configuration_reference.real_path.should == file bc.base_configuration_reference.real_path.should == file
end end
end end
end
#--------------------------------------# #--------------------------------------#
...@@ -141,9 +189,7 @@ module Pod ...@@ -141,9 +189,7 @@ module Pod
it "creates a prefix header, including the contents of the specification's prefix header" do it "creates a prefix header, including the contents of the specification's prefix header" do
@spec.prefix_header_contents = '#import "BlocksKit.h"' @spec.prefix_header_contents = '#import "BlocksKit.h"'
@installer.install! @installer.install!
support_files_dir = config.sandbox.target_support_files_dir('Pods-BananaLib') generated = @pod_target.prefix_header_path.read
prefix_header = support_files_dir + 'Pods-BananaLib-prefix.pch'
generated = prefix_header.read
expected = <<-EOS.strip_heredoc expected = <<-EOS.strip_heredoc
#ifdef __OBJC__ #ifdef __OBJC__
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
...@@ -157,13 +203,12 @@ module Pod ...@@ -157,13 +203,12 @@ module Pod
it 'creates a dummy source to ensure the compilation of libraries with only categories' do it 'creates a dummy source to ensure the compilation of libraries with only categories' do
@installer.install! @installer.install!
dummy_source_basename = @pod_target.dummy_source_path.basename.to_s
build_files = @installer.target.native_target.source_build_phase.files build_files = @installer.target.native_target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.display_name == 'Pods-BananaLib-dummy.m' } build_file = build_files.find { |bf| bf.file_ref.display_name == dummy_source_basename }
build_file.should.be.not.nil build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-BananaLib-dummy.m' build_file.file_ref.path.should == dummy_source_basename
support_files_dir = config.sandbox.target_support_files_dir('Pods-BananaLib') @pod_target.dummy_source_path.read.should.include?('@interface PodsDummy_BananaLib')
dummy = support_files_dir + 'Pods-BananaLib-dummy.m'
dummy.read.should.include?('@interface PodsDummy_Pods')
end end
#--------------------------------------------------------------------------------# #--------------------------------------------------------------------------------#
......
...@@ -130,6 +130,10 @@ module Pod ...@@ -130,6 +130,10 @@ module Pod
pod 'BananaLib', :path => (fixture_path + 'banana-lib').to_s pod 'BananaLib', :path => (fixture_path + 'banana-lib').to_s
pod 'OrangeFramework', :path => (fixture_path + 'orange-framework').to_s pod 'OrangeFramework', :path => (fixture_path + 'orange-framework').to_s
pod 'monkey', :path => (fixture_path + 'monkey').to_s pod 'monkey', :path => (fixture_path + 'monkey').to_s
target 'TestRunner', :exclusive => true do
pod 'monkey', :path => (fixture_path + 'monkey').to_s
end
end end
lockfile = generate_lockfile lockfile = generate_lockfile
config.integrate_targets = false config.integrate_targets = false
...@@ -140,9 +144,9 @@ module Pod ...@@ -140,9 +144,9 @@ module Pod
target = @installer.aggregate_targets.first target = @installer.aggregate_targets.first
target.requires_frameworks?.should == true target.requires_frameworks?.should == true
target.pod_targets.select(&:requires_frameworks?).map(&:name).sort.should == [ target.pod_targets.select(&:requires_frameworks?).map(&:name).sort.should == [
'Pods-BananaLib', 'BananaLib',
'Pods-OrangeFramework', 'OrangeFramework',
'Pods-monkey', 'monkey',
] ]
end end
end end
...@@ -261,7 +265,7 @@ module Pod ...@@ -261,7 +265,7 @@ module Pod
it 'stores the targets created by the analyzer' do it 'stores the targets created by the analyzer' do
@installer.send(:analyze) @installer.send(:analyze)
@installer.aggregate_targets.map(&:name).sort.should == ['Pods'] @installer.aggregate_targets.map(&:name).sort.should == ['Pods']
@installer.pod_targets.map(&:name).sort.should == ['Pods-JSONKit'] @installer.pod_targets.map(&:name).sort.should == ['JSONKit']
end end
it 'configures the analyzer to use update mode if appropriate' do it 'configures the analyzer to use update mode if appropriate' do
...@@ -269,7 +273,7 @@ module Pod ...@@ -269,7 +273,7 @@ module Pod
Installer::Analyzer.any_instance.expects(:update=).with(true) Installer::Analyzer.any_instance.expects(:update=).with(true)
@installer.send(:analyze) @installer.send(:analyze)
@installer.aggregate_targets.map(&:name).sort.should == ['Pods'] @installer.aggregate_targets.map(&:name).sort.should == ['Pods']
@installer.pod_targets.map(&:name).sort.should == ['Pods-JSONKit'] @installer.pod_targets.map(&:name).sort.should == ['JSONKit']
end end
end end
......
...@@ -9,17 +9,34 @@ module Pod ...@@ -9,17 +9,34 @@ module Pod
@pod_target.stubs(:platform).returns(:ios) @pod_target.stubs(:platform).returns(:ios)
end end
describe 'Meta' do
describe '#scoped' do
it 'returns a cloned target, which is scoped' do
@pod_target.should.not.be.scoped
@pod_target.scoped.should.be.scoped
@pod_target.should.not.be.scoped
end
end
end
describe 'In general' do describe 'In general' do
it 'returns the target_definition that generated it' do it 'returns the target_definition that generated it' do
@pod_target.target_definition.should == @target_definition @pod_target.target_definition.should == @target_definition
end end
it 'returns its name' do it 'returns its name' do
@pod_target.name.should == 'Pods-BananaLib' @pod_target.name.should == 'BananaLib'
@pod_target.scoped.name.should == 'Pods-BananaLib'
end
it 'returns its label' do
@pod_target.label.should == 'BananaLib'
@pod_target.scoped.label.should == 'Pods-BananaLib'
end end
it 'returns the name of its product' do it 'returns the name of its product' do
@pod_target.product_name.should == 'libPods-BananaLib.a' @pod_target.product_name.should == 'libBananaLib.a'
@pod_target.scoped.product_name.should == 'libPods-BananaLib.a'
end end
it 'returns the spec consumers for the pod targets' do it 'returns the spec consumers for the pod targets' do
...@@ -35,7 +52,8 @@ module Pod ...@@ -35,7 +52,8 @@ module Pod
end end
it 'returns the name of the resources bundle target' do it 'returns the name of the resources bundle target' do
@pod_target.resources_bundle_target_label('Fruits').should == 'Pods-BananaLib-Fruits' @pod_target.resources_bundle_target_label('Fruits').should == 'BananaLib-Fruits'
@pod_target.scoped.resources_bundle_target_label('Fruits').should == 'Pods-BananaLib-Fruits'
end end
it 'returns the name of the Pods on which this target depends' do it 'returns the name of the Pods on which this target depends' do
...@@ -84,40 +102,61 @@ module Pod ...@@ -84,40 +102,61 @@ module Pod
describe 'Support files' do describe 'Support files' do
it 'returns the absolute path of the xcconfig file' do it 'returns the absolute path of the xcconfig file' do
@pod_target.xcconfig_path('Release').to_s.should.include?( @pod_target.xcconfig_path('Release').to_s.should.include?(
'Pods/Target Support Files/BananaLib/BananaLib.release.xcconfig',
)
@pod_target.scoped.xcconfig_path('Release').to_s.should.include?(
'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib.release.xcconfig', 'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib.release.xcconfig',
) )
end end
it 'escapes the file separators in variant build configuration name in the xcconfig file' do it 'escapes the file separators in variant build configuration name in the xcconfig file' do
@pod_target.xcconfig_path("Release#{File::SEPARATOR}1").to_s.should.include?( @pod_target.xcconfig_path("Release#{File::SEPARATOR}1").to_s.should.include?(
'Pods/Target Support Files/BananaLib/BananaLib.release-1.xcconfig',
)
@pod_target.scoped.xcconfig_path("Release#{File::SEPARATOR}1").to_s.should.include?(
'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib.release-1.xcconfig', 'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib.release-1.xcconfig',
) )
end end
it 'returns the absolute path of the prefix header file' do it 'returns the absolute path of the prefix header file' do
@pod_target.prefix_header_path.to_s.should.include?( @pod_target.prefix_header_path.to_s.should.include?(
'Pods/Target Support Files/BananaLib/BananaLib-prefix.pch',
)
@pod_target.scoped.prefix_header_path.to_s.should.include?(
'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib-prefix.pch', 'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib-prefix.pch',
) )
end end
it 'returns the absolute path of the bridge support file' do it 'returns the absolute path of the bridge support file' do
@pod_target.bridge_support_path.to_s.should.include?( @pod_target.bridge_support_path.to_s.should.include?(
'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib.bridgesupport', 'Pods/Target Support Files/BananaLib/BananaLib.bridgesupport',
) )
end end
it 'returns the absolute path of the info plist file' do it 'returns the absolute path of the info plist file' do
@pod_target.info_plist_path.to_s.should.include?( @pod_target.info_plist_path.to_s.should.include?(
'Pods/Target Support Files/BananaLib/Info.plist',
)
@pod_target.scoped.info_plist_path.to_s.should.include?(
'Pods/Target Support Files/Pods-BananaLib/Info.plist', 'Pods/Target Support Files/Pods-BananaLib/Info.plist',
) )
end end
it 'returns the absolute path of the dummy source file' do
@pod_target.dummy_source_path.to_s.should.include?(
'Pods/Target Support Files/BananaLib/BananaLib-dummy.m',
)
@pod_target.scoped.dummy_source_path.to_s.should.include?(
'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib-dummy.m',
)
end
it 'returns the absolute path of the public and private xcconfig files' do it 'returns the absolute path of the public and private xcconfig files' do
@pod_target.xcconfig_path.to_s.should.include?( @pod_target.xcconfig_path.to_s.should.include?(
'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib.xcconfig', 'Pods/Target Support Files/BananaLib/BananaLib.xcconfig',
) )
@pod_target.xcconfig_private_path.to_s.should.include( @pod_target.xcconfig_private_path.to_s.should.include(
'Pods/Target Support Files/Pods-BananaLib/Pods-BananaLib-Private.xcconfig', 'Pods/Target Support Files/BananaLib/BananaLib-Private.xcconfig',
) )
end end
...@@ -150,7 +189,8 @@ module Pod ...@@ -150,7 +189,8 @@ module Pod
end end
it 'returns the library name' do it 'returns the library name' do
@pod_target.static_library_name.should == 'libPods-BananaLib.a' @pod_target.static_library_name.should == 'libBananaLib.a'
@pod_target.scoped.static_library_name.should == 'libPods-BananaLib.a'
end end
it 'returns :framework as product type' do it 'returns :framework as product type' do
...@@ -164,7 +204,8 @@ module Pod ...@@ -164,7 +204,8 @@ module Pod
describe 'Host does not requires frameworks' do describe 'Host does not requires frameworks' do
it 'returns the product name' do it 'returns the product name' do
@pod_target.product_name.should == 'libPods-BananaLib.a' @pod_target.product_name.should == 'libBananaLib.a'
@pod_target.scoped.product_name.should == 'libPods-BananaLib.a'
end end
it 'returns the framework name' do it 'returns the framework name' do
...@@ -172,7 +213,8 @@ module Pod ...@@ -172,7 +213,8 @@ module Pod
end end
it 'returns the library name' do it 'returns the library name' do
@pod_target.static_library_name.should == 'libPods-BananaLib.a' @pod_target.static_library_name.should == 'libBananaLib.a'
@pod_target.scoped.static_library_name.should == 'libPods-BananaLib.a'
end end
it 'returns :static_library as product type' do it 'returns :static_library as product type' do
...@@ -208,7 +250,8 @@ module Pod ...@@ -208,7 +250,8 @@ module Pod
end end
it 'returns the library name' do it 'returns the library name' do
@pod_target.static_library_name.should == 'libPods-OrangeFramework.a' @pod_target.static_library_name.should == 'libOrangeFramework.a'
@pod_target.scoped.static_library_name.should == 'libPods-OrangeFramework.a'
end end
it 'returns :framework as product type' do it 'returns :framework as product type' do
......
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