Commit 402d214a authored by Fabio Pelosin's avatar Fabio Pelosin

[SupportFilesGenerator] Bring in path logic from Target subclasses

parent 70578126
...@@ -17,7 +17,7 @@ GIT ...@@ -17,7 +17,7 @@ GIT
GIT GIT
remote: https://github.com/CocoaPods/Xcodeproj.git remote: https://github.com/CocoaPods/Xcodeproj.git
revision: 2c25c6712b9ac2472f3e8fd34d0744166af8f7ff revision: d7bacd932526540b6d447dcb4358cec2822a68f9
branch: master branch: master
specs: specs:
xcodeproj (0.10.1) xcodeproj (0.10.1)
...@@ -49,7 +49,7 @@ GIT ...@@ -49,7 +49,7 @@ GIT
GIT GIT
remote: https://github.com/lemurheavy/coveralls-ruby.git remote: https://github.com/lemurheavy/coveralls-ruby.git
revision: 2576b7d37545c6f28f0ad43f56cddc09ca2740f4 revision: 2a7d3f86f1353a97734cc7df476b898e92d89708
specs: specs:
coveralls (0.6.7) coveralls (0.6.7)
multi_json (~> 1.3) multi_json (~> 1.3)
...@@ -99,7 +99,7 @@ GEM ...@@ -99,7 +99,7 @@ GEM
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mocha-on-bacon (0.2.2) mocha-on-bacon (0.2.2)
mocha (>= 0.13.0) mocha (>= 0.13.0)
multi_json (1.7.9) multi_json (1.8.0)
nap (0.5.1) nap (0.5.1)
open4 (1.3.0) open4 (1.3.0)
posix-spawn (0.3.6) posix-spawn (0.3.6)
......
...@@ -47,7 +47,7 @@ module Pod ...@@ -47,7 +47,7 @@ module Pod
@xcconfig = Xcodeproj::Config.new({ @xcconfig = Xcodeproj::Config.new({
'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target), 'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target),
'HEADER_SEARCH_PATHS' => XCConfigHelper.quote(target.sandbox.public_headers.search_paths), 'HEADER_SEARCH_PATHS' => XCConfigHelper.quote(target.sandbox.public_headers.search_paths),
'PODS_ROOT' => target.relative_pods_root, 'PODS_ROOT' => relative_pods_root,
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1', 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1',
}) })
...@@ -72,6 +72,20 @@ module Pod ...@@ -72,6 +72,20 @@ module Pod
@xcconfig @xcconfig
end end
# @return [String] The xcconfig path of the root from the `$(SRCROOT)`
# variable of the user's project.
#
# TODO: return the root of the sandbox
# The pods root is used by the copy resources script
#
def relative_pods_root
if target.user_project_path
"${SRCROOT}/#{target.support_files_root.relative_path_from(target.user_project_path.dirname)}"
else
target.support_files_root.to_s
end
end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
end end
......
...@@ -173,11 +173,9 @@ module Pod ...@@ -173,11 +173,9 @@ module Pod
native_targets = compute_user_project_targets(target_definition, user_project) native_targets = compute_user_project_targets(target_definition, user_project)
target.user_project_path = project_path target.user_project_path = project_path
target.client_root = project_path.dirname
target.user_target_uuids = native_targets.map(&:uuid) target.user_target_uuids = native_targets.map(&:uuid)
target.user_build_configurations = compute_user_build_configurations(target_definition, native_targets) target.user_build_configurations = compute_user_build_configurations(target_definition, native_targets)
else else
target.client_root = config.installation_root
target.user_target_uuids = [] target.user_target_uuids = []
target.user_build_configurations = {} target.user_build_configurations = {}
end end
......
...@@ -53,11 +53,12 @@ module Pod ...@@ -53,11 +53,12 @@ module Pod
# @return [void] # @return [void]
# #
def create_xcconfig_file_aggregate def create_xcconfig_file_aggregate
path = target.xcconfig_path path = file_path(:public_xcconfig)
gen = Generator::XCConfig::AggregateXCConfig.new(target) gen = Generator::XCConfig::AggregateXCConfig.new(target)
gen.save_as(path) gen.save_as(path)
target.xcconfig = gen.xcconfig target.xcconfig = gen.xcconfig
xcconfig_file_ref = add_file_to_support_group(path) xcconfig_file_ref = add_file_to_support_group(path)
target.xcconfig_path = path
target.target.build_configurations.each do |c| target.target.build_configurations.each do |c|
c.base_configuration_reference = xcconfig_file_ref c.base_configuration_reference = xcconfig_file_ref
...@@ -71,11 +72,12 @@ module Pod ...@@ -71,11 +72,12 @@ module Pod
# #
def create_xcconfig_file_pods def create_xcconfig_file_pods
public_gen = Generator::XCConfig::PublicPodXCConfig.new(target) public_gen = Generator::XCConfig::PublicPodXCConfig.new(target)
path = target.xcconfig_path path = file_path(:public_xcconfig)
public_gen.save_as(path) public_gen.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
target.xcconfig_path = path
path = target.xcconfig_private_path path = file_path(:private_xcconfig)
private_gen = Generator::XCConfig::PrivatePodXCConfig.new(target, public_gen.xcconfig) private_gen = Generator::XCConfig::PrivatePodXCConfig.new(target, public_gen.xcconfig)
private_gen.save_as(path) private_gen.save_as(path)
xcconfig_file_ref = add_file_to_support_group(path) xcconfig_file_ref = add_file_to_support_group(path)
...@@ -90,7 +92,7 @@ module Pod ...@@ -90,7 +92,7 @@ module Pod
# pods and the installed specifications of a pod. # pods and the installed specifications of a pod.
# #
def create_target_environment_header def create_target_environment_header
path = target.target_environment_header_path path = file_path(:environment_header)
generator = Generator::TargetEnvironmentHeader.new(target.pod_targets.map { |l| l.specs }.flatten) generator = Generator::TargetEnvironmentHeader.new(target.pod_targets.map { |l| l.specs }.flatten)
generator.save_as(path) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
...@@ -106,7 +108,7 @@ module Pod ...@@ -106,7 +108,7 @@ module Pod
# #
def create_bridge_support_file def create_bridge_support_file
if target.target_definition.podfile.generate_bridge_support? if target.target_definition.podfile.generate_bridge_support?
path = target.bridge_support_path path = file_path(:bridge_support)
headers = target.target.headers_build_phase.files.map { |bf| bf.file_ref.real_path } headers = target.target.headers_build_phase.files.map { |bf| bf.file_ref.real_path }
generator = Generator::BridgeSupport.new(headers) generator = Generator::BridgeSupport.new(headers)
generator.save_as(path) generator.save_as(path)
...@@ -121,7 +123,7 @@ module Pod ...@@ -121,7 +123,7 @@ module Pod
# #
def create_acknowledgements def create_acknowledgements
Generator::Acknowledgements.generators.each do |generator_class| Generator::Acknowledgements.generators.each do |generator_class|
basepath = target.acknowledgements_basepath basepath = file_path(:acknowledgements)
path = generator_class.path_from_basepath(basepath) path = generator_class.path_from_basepath(basepath)
file_accessors = target.pod_targets.map(&:file_accessors).flatten file_accessors = target.pod_targets.map(&:file_accessors).flatten
generator = generator_class.new(file_accessors) generator = generator_class.new(file_accessors)
...@@ -139,7 +141,7 @@ module Pod ...@@ -139,7 +141,7 @@ module Pod
# @return [void] # @return [void]
# #
def create_copy_resources_script def create_copy_resources_script
path = target.copy_resources_script_path path = file_path(:copy_resources_script)
file_accessors = target.pod_targets.map(&:file_accessors).flatten file_accessors = target.pod_targets.map(&:file_accessors).flatten
resource_paths = file_accessors.map { |accessor| accessor.resources.flatten.map { |res| res.relative_path_from(path.dirname) }}.flatten resource_paths = file_accessors.map { |accessor| accessor.resources.flatten.map { |res| res.relative_path_from(path.dirname) }}.flatten
resource_bundles = file_accessors.map { |accessor| accessor.resource_bundles.keys.map {|name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } }.flatten resource_bundles = file_accessors.map { |accessor| accessor.resource_bundles.keys.map {|name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } }.flatten
...@@ -150,6 +152,7 @@ module Pod ...@@ -150,6 +152,7 @@ module Pod
generator = Generator::CopyResourcesScript.new(resources, target.platform) generator = Generator::CopyResourcesScript.new(resources, target.platform)
generator.save_as(path) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
target.copy_resources_script_path = path
end end
# Creates a prefix header file which imports `UIKit` or `Cocoa` according # Creates a prefix header file which imports `UIKit` or `Cocoa` according
...@@ -159,11 +162,12 @@ module Pod ...@@ -159,11 +162,12 @@ module Pod
# @return [void] # @return [void]
# #
def create_prefix_header def create_prefix_header
path = target.prefix_header_path path = file_path(:prefix_header)
generator = Generator::PrefixHeader.new(target.file_accessors, target.platform) generator = Generator::PrefixHeader.new(target.file_accessors, target.platform)
generator.imports << target.target_environment_header_path.basename generator.imports << file_path(:environment_header).basename
generator.save_as(path) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
target.prefix_header_path = path
target.target.build_configurations.each do |c| target.target.build_configurations.each do |c|
relative_path = path.relative_path_from(project.path.dirname) relative_path = path.relative_path_from(project.path.dirname)
...@@ -178,7 +182,7 @@ module Pod ...@@ -178,7 +182,7 @@ module Pod
# @return [void] # @return [void]
# #
def create_dummy_source def create_dummy_source
path = target.dummy_source_path path = file_path(:dummy_source)
generator = Generator::DummySource.new(target.label) generator = Generator::DummySource.new(target.label)
generator.save_as(path) generator.save_as(path)
file_reference = add_file_to_support_group(path) file_reference = add_file_to_support_group(path)
...@@ -189,11 +193,37 @@ module Pod ...@@ -189,11 +193,37 @@ module Pod
end end
private
# @!group Paths
#---------------------------------------------------------------------#
# @return [Hash{Symbol=>String}] The name of the support files by key.
#
SUPPORT_FILES_NAMES = {
:acknowledgements => "acknowledgements",
:bridge_support => "metadata.bridgesupport",
:copy_resources_script => "resources.sh",
:dummy_source => "dummy.m",
:environment_header => "environment.h",
:prefix_header => "prefix.pch",
:private_xcconfig => "private.xcconfig",
:public_xcconfig => "public.xcconfig",
}
# @return [Pathname] The absolute path of the support file with the
# given extension.
#
def file_path(key)
file_name = SUPPORT_FILES_NAMES[key]
raise "Unrecognized key `#{key}`" unless file_name
target.support_files_root + "#{target.label}-#{file_name}"
end
private private
# @!group Private helpers. # @!group Private helpers
#---------------------------------------------------------------------# #---------------------------------------------------------------------#
# @return [PBXGroup] the group where the file references to the support # @return [PBXGroup] the group where the file references to the support
......
...@@ -26,9 +26,10 @@ module Pod ...@@ -26,9 +26,10 @@ module Pod
# @return [void] # @return [void]
# #
def integrate! def integrate!
validate
return if native_targets.empty? return if native_targets.empty?
UI.section(integration_message) do UI.section(integration_message) do
add_xcconfig_base_configuration set_xcconfig
add_pods_library add_pods_library
add_copy_resources_script_phase add_copy_resources_script_phase
add_check_manifest_lock_script_phase add_check_manifest_lock_script_phase
...@@ -36,57 +37,28 @@ module Pod ...@@ -36,57 +37,28 @@ module Pod
end end
end end
# @return [Array<PBXNativeTarget>] the user targets for integration.
#
def native_targets
unless @native_targets
target_uuids = target.user_target_uuids
native_targets = target_uuids.map do |uuid|
native_target = user_project.objects_by_uuid[uuid]
unless native_target
raise Informative, "[Bug] Unable to find the target with " \
"the `#{uuid}` UUID for the `#{target}` integration library"
end
native_target
end
non_integrated = native_targets.reject do |native_target|
native_target.frameworks_build_phase.files.any? do |build_file|
file_ref = build_file.file_ref
file_ref &&
file_ref.isa == 'PBXFileReference' &&
file_ref.display_name == target.product_name
end
end
@native_targets = non_integrated
end
@native_targets
end
# Read the project from the disk to ensure that it is up to date as
# other TargetIntegrators might have modified it.
#
def user_project
@user_project ||= Xcodeproj::Project.open(target.user_project_path)
end
# Read the pods project from the disk to ensure that it is up to date as
# other TargetIntegrators might have modified it.
#
def pods_project
@pods_project ||= Xcodeproj::Project.open(target.sandbox.project_path)
end
# @return [String] a string representation suitable for debugging. # @return [String] a string representation suitable for debugging.
# #
def inspect def inspect
"#<#{self.class} for target `#{target.label}'>" "#<#{self.class} for target `#{target.label}'>"
end end
#---------------------------------------------------------------------#
private
# @!group Integration steps # @!group Integration steps
#---------------------------------------------------------------------#
private # Validates the inputs provided to the integrator.
#
# @returns [void]
#
def validate
raise "Empty user UUIDs for target `#{target}`" if target.user_target_uuids.empty?
raise "Missing project path for target `#{target}`" unless target.user_project_path
raise "Missing xcconfig path for target `#{target}`" unless target.xcconfig_path
raise "Missing copy resources script path for target `#{target}`" unless target.copy_resources_script_path
end
# @return [Specification::Consumer] the consumer for the specifications. # @return [Specification::Consumer] the consumer for the specifications.
# #
...@@ -107,9 +79,9 @@ module Pod ...@@ -107,9 +79,9 @@ module Pod
# #
# @return [void] # @return [void]
# #
def add_xcconfig_base_configuration def set_xcconfig
xcconfig = user_project.files.select { |f| f.path == target.xcconfig_relative_path }.first || xcconfig = user_project.files.select { |f| f.path == xcconfig_relative_path }.first ||
user_project.new_file(target.xcconfig_relative_path) user_project.new_file(xcconfig_relative_path)
native_targets.each do |native_target| native_targets.each do |native_target|
check_overridden_build_settings(target.xcconfig, native_target) check_overridden_build_settings(target.xcconfig, native_target)
native_target.build_configurations.each do |config| native_target.build_configurations.each do |config|
...@@ -147,7 +119,7 @@ module Pod ...@@ -147,7 +119,7 @@ module Pod
native_targets.each do |native_target| native_targets.each do |native_target|
phase = native_target.shell_script_build_phases.select { |bp| bp.name == phase_name }.first || phase = native_target.shell_script_build_phases.select { |bp| bp.name == phase_name }.first ||
native_target.new_shell_script_build_phase(phase_name) native_target.new_shell_script_build_phase(phase_name)
path = target.copy_resources_script_relative_path path = "${SRCROOT}/#{copy_resources_script_path}"
phase.shell_script = %{"#{path}"\n} phase.shell_script = %{"#{path}"\n}
phase.show_env_vars_in_log = '0' phase.show_env_vars_in_log = '0'
end end
...@@ -182,11 +154,56 @@ module Pod ...@@ -182,11 +154,56 @@ module Pod
end end
end end
#---------------------------------------------------------------------#
private
# @!group Private helpers. # @!group Private helpers.
#---------------------------------------------------------------------#
private # @return [Array<PBXNativeTarget>] the user targets for integration.
#
def native_targets
unless @native_targets
target_uuids = target.user_target_uuids
native_targets = target_uuids.map do |uuid|
native_target = user_project.objects_by_uuid[uuid]
unless native_target
raise Informative, "[Bug] Unable to find the target with " \
"the `#{uuid}` UUID for the `#{target}` integration library"
end
native_target
end
non_integrated = native_targets.reject do |native_target|
native_target.frameworks_build_phase.files.any? do |build_file|
file_ref = build_file.file_ref
file_ref &&
file_ref.isa == 'PBXFileReference' &&
file_ref.display_name == target.product_name
end
end
@native_targets = non_integrated
end
@native_targets
end
# Read the project from the disk to ensure that it is up to date as
# other TargetIntegrators might have modified it.
#
def user_project
@user_project ||= Xcodeproj::Project.open(target.user_project_path)
end
# @return [Pathname]
#
def xcconfig_relative_path
target.xcconfig_path.relative_path_from(user_project.path.dirname)
end
# @return [Pathname]
#
def copy_resources_script_path
target.copy_resources_script_path.relative_path_from(user_project.path.dirname)
end
# Informs the user about any build setting of the target which might # Informs the user about any build setting of the target which might
# override the given xcconfig file. # override the given xcconfig file.
...@@ -214,7 +231,7 @@ module Pod ...@@ -214,7 +231,7 @@ module Pod
"Remove the build settings from the target." "Remove the build settings from the target."
] ]
UI.warn("The target `#{name}` overrides the `#{key}` build " \ UI.warn("The target `#{name}` overrides the `#{key}` build " \
"setting defined in `#{target.xcconfig_relative_path}'.", "setting defined in `#{xcconfig_relative_path}'.",
actions) actions)
end end
end end
......
...@@ -72,52 +72,39 @@ module Pod ...@@ -72,52 +72,39 @@ module Pod
@platform ||= target_definition.platform @platform ||= target_definition.platform
end end
#-------------------------------------------------------------------------#
# @!group Support files
# @return [Pathname] the folder where to store the support files of this # @return [Xcodeproj::Config] The configuration file of the target.
# library.
# #
def support_files_root # @note The configuration is generated by the {TargetInstaller} and
@sandbox.library_support_files_dir(name) # used by {UserProjectIntegrator} to check for any overridden
end # values.
# @return [Pathname] the absolute path of the xcconfig file.
# #
def xcconfig_path attr_accessor :xcconfig
support_files_root + "#{label}.xcconfig"
end
# @return [Pathname] the absolute path of the private xcconfig file. # @return [Pathname] The path of the xcconfig file relative to the root of
# the user project.
# #
def xcconfig_private_path attr_accessor :xcconfig_path
support_files_root + "#{label}-Private.xcconfig"
end
# @return [Pathname] the absolute path of the header file which contains # @return [Pathname] The path of the copy resources script relative to the
# the information about the installed pods. # root of the user project.
# #
def target_environment_header_path attr_accessor :copy_resources_script_path
support_files_root + "#{target_definition.label.to_s}-environment.h"
end
# @return [Pathname] the absolute path of the prefix header file.
#
def prefix_header_path
support_files_root + "#{label}-prefix.pch"
end
# @return [Pathname] the absolute path of the bridge support file. # @return [Pathname]
# #
def bridge_support_path attr_accessor :prefix_header_path
support_files_root + "#{label}.bridgesupport"
end
# @return [Pathname] the path of the dummy source generated by CocoaPods #-------------------------------------------------------------------------#
# @!group Support files
# @return [Pathname] the folder where to store the support files of this
# library.
# #
def dummy_source_path def support_files_root
support_files_root + "#{label}-dummy.m" @sandbox.library_support_files_dir(name)
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
...@@ -26,12 +26,7 @@ module Pod ...@@ -26,12 +26,7 @@ module Pod
target_definition.label.to_s target_definition.label.to_s
end end
# @return [Pathname] the folder where the client is stored used for #-------------------------------------------------------------------------#
# computing the relative paths. If integrating it should be the
# folder where the user project is stored, otherwise it should
# be the installation root.
#
attr_accessor :client_root
# @return [Pathname] the path of the user project that this target will # @return [Pathname] the path of the user project that this target will
# integrate as identified by the analyzer. # integrate as identified by the analyzer.
...@@ -42,20 +37,20 @@ module Pod ...@@ -42,20 +37,20 @@ module Pod
attr_accessor :user_project_path attr_accessor :user_project_path
# @return [String] the list of the UUIDs of the user targets that will be # @return [String] the list of the UUIDs of the user targets that will be
# integrated by this target as identified by the analizer. # integrated by this target as identified by the analyzer.
# #
# @note The target instances are not stored to prevent editing different # @note The target instances are not stored to prevent editing different
# instances. # instances.
# #
attr_accessor :user_target_uuids attr_accessor :user_target_uuids
# @return [Xcodeproj::Config] The configuration file of the target.
#
# @note The configuration is generated by the {TargetInstaller} and
# used by {UserProjectIntegrator} to check for any overridden public
# values.
# # @!group Pod targets
attr_accessor :xcconfig #-------------------------------------------------------------------------#
# @return [Array<PodTarget>] The dependencies for this target. # @return [Array<PodTarget>] The dependencies for this target.
# #
...@@ -73,60 +68,6 @@ module Pod ...@@ -73,60 +68,6 @@ module Pod
specs.map { |spec| spec.consumer(platform) } specs.map { |spec| spec.consumer(platform) }
end end
# @return [Pathname] The absolute path of acknowledgements file.
#
# @note The acknowledgements generators add the extension according to
# the file type.
#
def acknowledgements_basepath
support_files_root + "#{label}-acknowledgements"
end
# @return [Pathname] The absolute path of the copy resources script.
#
def copy_resources_script_path
support_files_root + "#{label}-resources.sh"
end
# @return [String] The xcconfig path of the root from the `$(SRCROOT)`
# variable of the user's project.
#
def relative_pods_root
"${SRCROOT}/#{support_files_root.relative_path_from(client_root)}"
end
# @return [String] The path of the xcconfig file relative to the root of
# the user project.
#
def xcconfig_relative_path
relative_to_srcroot(xcconfig_path).to_s
end
# @return [String] The path of the copy resources script relative to the
# root of the user project.
#
def copy_resources_script_relative_path
"${SRCROOT}/#{relative_to_srcroot(copy_resources_script_path)}"
end
#-------------------------------------------------------------------------#
# @!group Private Helpers
private
# Computes the relative path of a sandboxed file from the `$(SRCROOT)`
# variable of the user's project.
#
# @param [Pathname] path
# A relative path from the root of the sandbox.
#
# @return [String] The computed path.
#
def relative_to_srcroot(path)
path.relative_path_from(client_root).to_s
end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
end end
......
...@@ -65,6 +65,8 @@ module Pod ...@@ -65,6 +65,8 @@ module Pod
end.flatten.reject { |dep| dep == pod_name } end.flatten.reject { |dep| dep == pod_name }
end end
#-------------------------------------------------------------------------#
def inhibits_warnings? def inhibits_warnings?
@inhibits_warnings ||= target_definition.inhibits_warnings_for_pod?(pod_name) @inhibits_warnings ||= target_definition.inhibits_warnings_for_pod?(pod_name)
end end
......
...@@ -10,7 +10,7 @@ module Pod ...@@ -10,7 +10,7 @@ module Pod
@consumer = @spec.consumer(:ios) @consumer = @spec.consumer(:ios)
target_definition = Podfile::TargetDefinition.new('Pods', nil) target_definition = Podfile::TargetDefinition.new('Pods', nil)
@target = AggregateTarget.new(target_definition, config.sandbox) @target = AggregateTarget.new(target_definition, config.sandbox)
@target.client_root = config.sandbox.root.dirname @target.user_project_path = config.sandbox.root.dirname + 'Project.xcodeproj'
@target.stubs(:platform).returns(:ios) @target.stubs(:platform).returns(:ios)
@pod_target = PodTarget.new([@spec], target_definition, config.sandbox) @pod_target = PodTarget.new([@spec], target_definition, config.sandbox)
@pod_target.stubs(:platform).returns(:ios) @pod_target.stubs(:platform).returns(:ios)
...@@ -19,9 +19,7 @@ module Pod ...@@ -19,9 +19,7 @@ module Pod
@generator = AggregateXCConfig.new(@target) @generator = AggregateXCConfig.new(@target)
end end
it "returns the path of the pods root relative to the user project" do
@generator.target.relative_pods_root.should == '${SRCROOT}/Pods'
end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
...@@ -80,6 +78,12 @@ module Pod ...@@ -80,6 +78,12 @@ module Pod
generated.class.should == Xcodeproj::Config generated.class.should == Xcodeproj::Config
end end
#-----------------------------------------------------------------------#
it "returns the path of the pods root relative to the user project" do
@generator.send(:relative_pods_root).should == '${SRCROOT}/Pods'
end
end end
end end
end end
......
...@@ -29,10 +29,12 @@ module Pod ...@@ -29,10 +29,12 @@ module Pod
end end
it "returns the path of the prefix header" do it "returns the path of the prefix header" do
@lib.prefix_header_path = temporary_directory + 'Pods/Pods-MyApp-prefix.pch'
@rep.prefix_header_path.should == temporary_directory + 'Pods/Pods-MyApp-prefix.pch' @rep.prefix_header_path.should == temporary_directory + 'Pods/Pods-MyApp-prefix.pch'
end end
it "returns the path of the copy resources script" do it "returns the path of the copy resources script" do
@lib.copy_resources_script_path = temporary_directory + 'Pods/Pods-MyApp-resources.sh'
@rep.copy_resources_script_path.should == temporary_directory + 'Pods/Pods-MyApp-resources.sh' @rep.copy_resources_script_path.should == temporary_directory + 'Pods/Pods-MyApp-resources.sh'
end end
......
...@@ -85,7 +85,6 @@ module Pod ...@@ -85,7 +85,6 @@ module Pod
target.support_files_root.should == config.sandbox.root target.support_files_root.should == config.sandbox.root
target.user_project_path.to_s.should.include 'SampleProject/SampleProject' target.user_project_path.to_s.should.include 'SampleProject/SampleProject'
target.client_root.to_s.should.include 'SampleProject'
target.user_target_uuids.should == ["A346496C14F9BE9A0080D870"] target.user_target_uuids.should == ["A346496C14F9BE9A0080D870"]
user_proj = Xcodeproj::Project.open(target.user_project_path) user_proj = Xcodeproj::Project.open(target.user_project_path)
user_proj.objects_by_uuid[target.user_target_uuids.first].name.should == 'SampleProject' user_proj.objects_by_uuid[target.user_target_uuids.first].name.should == 'SampleProject'
...@@ -96,8 +95,6 @@ module Pod ...@@ -96,8 +95,6 @@ module Pod
it "generates the integration library appropriately if the installation will not integrate" do it "generates the integration library appropriately if the installation will not integrate" do
config.integrate_targets = false config.integrate_targets = false
target = @analyzer.analyze.targets.first target = @analyzer.analyze.targets.first
target.client_root.should == config.installation_root
target.user_target_uuids.should == [] target.user_target_uuids.should == []
target.user_build_configurations.should == {} target.user_build_configurations.should == {}
target.platform.to_s.should == 'iOS 6.0' target.platform.to_s.should == 'iOS 6.0'
......
...@@ -17,7 +17,6 @@ module Pod ...@@ -17,7 +17,6 @@ module Pod
@target.stubs(:label).returns('Pods') @target.stubs(:label).returns('Pods')
@target.stubs(:platform).returns(Platform.new(:ios, '6.0')) @target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@target.user_project_path = config.sandbox.root + '../user_project.xcodeproj' @target.user_project_path = config.sandbox.root + '../user_project.xcodeproj'
@target.client_root = config.sandbox.root.dirname
@target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug } @target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug }
@target.target = native_target @target.target = native_target
...@@ -41,15 +40,15 @@ module Pod ...@@ -41,15 +40,15 @@ module Pod
"Pods-acknowledgements.plist", "Pods-acknowledgements.plist",
"Pods-dummy.m", "Pods-dummy.m",
"Pods-environment.h", "Pods-environment.h",
"Pods-public.xcconfig",
"Pods-resources.sh", "Pods-resources.sh",
"Pods.xcconfig"
] ]
end end
it "creates the xcconfig file" do it "creates the xcconfig file" do
@sut.generate! @sut.generate!
file = config.sandbox.root + @target.xcconfig_path file = @sut.send(:file_path, :public_xcconfig)
xcconfig = Xcodeproj::Config.new(file) xcconfig = Xcodeproj::Config.new(file)
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods' xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end end
...@@ -131,12 +130,12 @@ module Pod ...@@ -131,12 +130,12 @@ module Pod
it "creates the xcconfig file" do it "creates the xcconfig file" do
@sut.generate! @sut.generate!
file = config.sandbox.root + @target.xcconfig_private_path file = @sut.send(:file_path, :private_xcconfig)
xcconfig = Xcodeproj::Config.new(file) xcconfig = Xcodeproj::Config.new(file)
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}' xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}'
end end
it "creates a prefix header, including the contents of the specification's prefix header" do xit "creates a prefix header, including the contents of the specification's prefix header" do
@sut.generate! @sut.generate!
prefix_header = config.sandbox.root + 'Pods-BananaLib-prefix.pch' prefix_header = config.sandbox.root + 'Pods-BananaLib-prefix.pch'
generated = prefix_header.read generated = prefix_header.read
......
...@@ -6,88 +6,53 @@ module Pod ...@@ -6,88 +6,53 @@ module Pod
describe "In general" do describe "In general" do
# The project contains a `PBXReferenceProxy` in the build files of the
# frameworks build phase which implicitly checks for the robustness of
# the detection of the target.
#
before do before do
sample_project_path = SpecHelper.create_sample_app_copy_from_fixture('SampleProject') project_path = SpecHelper.create_sample_app_copy_from_fixture('SampleProject')
@sample_project = Xcodeproj::Project.open(sample_project_path) @project = Xcodeproj::Project.open(project_path)
Xcodeproj::Project.new(config.sandbox.project_path).save Xcodeproj::Project.new(config.sandbox.project_path).save
@target = @sample_project.targets.first @native_target = @project.targets.first
target_definition = Podfile::TargetDefinition.new('Pods', nil) target_definition = Podfile::TargetDefinition.new('Pods', nil)
target_definition.link_with_first_target = true target_definition.link_with_first_target = true
@lib = AggregateTarget.new(target_definition, config.sandbox) @target = AggregateTarget.new(target_definition, config.sandbox)
@lib.user_project_path = sample_project_path @target.user_project_path = project_path
@lib.client_root = sample_project_path.dirname @target.user_target_uuids = [@native_target.uuid]
@lib.user_target_uuids = [@target.uuid] @target.xcconfig_path = config.sandbox.root + 'Pods.xcconfig'
@target_integrator = TargetIntegrator.new(@lib) @target.copy_resources_script_path = config.sandbox.root + 'Pods-resources.sh'
@sut = TargetIntegrator.new(@target)
end end
it 'returns the targets that need to be integrated' do #-----------------------------------------------------------------------#
@target_integrator.native_targets.map(&:name).should == %w[ SampleProject ]
end
it 'returns the targets that need to be integrated' do
pods_library = @sample_project.frameworks_group.new_static_library('Pods')
@target.frameworks_build_phase.add_file_reference(pods_library)
@target_integrator.stubs(:user_project).returns(@sample_project)
@target_integrator.native_targets.map(&:name).should.be.empty?
end
it 'is robust against other types of references in the build files of the frameworks build phase' do
build_file = @sample_project.new(Xcodeproj::Project::PBXBuildFile)
build_file.file_ref = @sample_project.new(Xcodeproj::Project::PBXVariantGroup)
@target_integrator.stubs(:user_project).returns(@sample_project)
@target.frameworks_build_phase.files << build_file
@target_integrator.native_targets.map(&:name).should == %w[ SampleProject ]
end
it 'is robust against build files with missing file references' do
build_file = @sample_project.new(Xcodeproj::Project::PBXBuildFile)
build_file.file_ref = nil
@target_integrator.stubs(:user_project).returns(@sample_project)
@target.frameworks_build_phase.files << build_file
@target_integrator.native_targets.map(&:name).should == %w[ SampleProject ]
end
it 'does not perform the integration if there are no targets to integrate' do describe "#integrate!" do
@target_integrator.stubs(:native_targets).returns([])
@target_integrator.expects(:add_xcconfig_base_configuration).never
@target_integrator.expects(:add_pods_library).never
@target_integrator.expects(:add_copy_resources_script_phase).never
@target_integrator.expects(:save_user_project).never
@target_integrator.integrate!
end
before do before do
@target_integrator.integrate! @sut.integrate!
end end
it 'sets the Pods xcconfig as the base config for each build configuration' do it 'sets the Pods xcconfig as the base config for each build configuration' do
xcconfig_file = @sample_project.files.find { |f| f.path == @lib.xcconfig_relative_path } xcconfig_file = @project.files.find { |f| f.real_path == @target.xcconfig_path }
@target.build_configurations.each do |config| @native_target.build_configurations.each do |config|
config.base_configuration_reference.should == xcconfig_file config.base_configuration_reference.should == xcconfig_file
end end
end end
it 'adds references to the Pods static libraries to the Frameworks group' do it 'adds references to the Pods static libraries to the Frameworks group' do
@target_integrator.user_project["Frameworks/libPods.a"].should.not == nil @sut.send(:user_project)["Frameworks/libPods.a"].should.not == nil
end end
it 'adds the libPods static library to the "Link binary with libraries" build phase of each target' do it 'adds the libPods static library to the "Link binary with libraries" build phase of each target' do
target = @target_integrator.native_targets.first target = @sut.send(:native_targets).first
target.frameworks_build_phase.files.find { |f| f.file_ref.path == 'libPods.a'}.should.not == nil target.frameworks_build_phase.files.find { |f| f.file_ref.path == 'libPods.a'}.should.not == nil
end end
it 'adds a Copy Pods Resources build phase to each target' do it 'adds a Copy Pods Resources build phase to each target' do
target = @target_integrator.native_targets.first target = @sut.send(:native_targets).first
phase = target.shell_script_build_phases.find { |bp| bp.name == "Copy Pods Resources" } phase = target.shell_script_build_phases.find { |bp| bp.name == "Copy Pods Resources" }
phase.shell_script.strip.should == "\"${SRCROOT}/../Pods/Pods-resources.sh\"" phase.shell_script.strip.should == '"${SRCROOT}/../Pods/Pods-resources.sh"'
end end
it 'adds a Check Manifest.lock build phase to each target' do it 'adds a Check Manifest.lock build phase to each target' do
target = @target_integrator.native_targets.first target = @sut.send(:native_targets).first
phase = target.shell_script_build_phases.find { |bp| bp.name == "Check Pods Manifest.lock" } phase = target.shell_script_build_phases.find { |bp| bp.name == "Check Pods Manifest.lock" }
phase.shell_script.should == <<-EOS.strip_heredoc phase.shell_script.should == <<-EOS.strip_heredoc
diff "${PODS_ROOT}/../Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null diff "${PODS_ROOT}/../Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null
...@@ -101,11 +66,61 @@ module Pod ...@@ -101,11 +66,61 @@ module Pod
end end
it 'adds the Check Manifest.lock build phase as the first build phase' do it 'adds the Check Manifest.lock build phase as the first build phase' do
target = @target_integrator.native_targets.first target = @sut.send(:native_targets).first
phase = target.build_phases.find { |bp| bp.name == "Check Pods Manifest.lock" } phase = target.build_phases.find { |bp| bp.name == "Check Pods Manifest.lock" }
target.build_phases.first.should.equal? phase target.build_phases.first.should.equal? phase
end end
end end
#-----------------------------------------------------------------------#
describe "Private helpers" do
describe "#native_targets" do
it 'returns the targets that need to be integrated' do
@sut.send(:native_targets).map(&:name).should == %w[ SampleProject ]
end
it 'returns the targets that need to be integrated' do
pods_library = @project.frameworks_group.new_static_library('Pods')
@native_target.frameworks_build_phase.add_file_reference(pods_library)
@sut.stubs(:user_project).returns(@project)
@sut.send(:native_targets).map(&:name).should.be.empty?
end
it 'is robust against other types of references in the build files of the frameworks build phase' do
build_file = @project.new(Xcodeproj::Project::PBXBuildFile)
build_file.file_ref = @project.new(Xcodeproj::Project::PBXVariantGroup)
@sut.stubs(:user_project).returns(@project)
@native_target.frameworks_build_phase.files << build_file
@sut.send(:native_targets).map(&:name).should == %w[ SampleProject ]
end
it 'is robust against build files with missing file references' do
build_file = @project.new(Xcodeproj::Project::PBXBuildFile)
build_file.file_ref = nil
@sut.stubs(:user_project).returns(@project)
@native_target.frameworks_build_phase.files << build_file
@sut.send(:native_targets).map(&:name).should == %w[ SampleProject ]
end
end
it 'does not perform the integration if there are no targets to integrate' do
@sut.stubs(:native_targets).returns([])
@sut.expects(:set_xcconfig).never
@sut.expects(:add_pods_library).never
@sut.expects(:add_copy_resources_script_phase).never
@sut.expects(:save_user_project).never
@sut.integrate!
end
end
#-----------------------------------------------------------------------#
end
end end
end end
...@@ -19,9 +19,10 @@ module Pod ...@@ -19,9 +19,10 @@ module Pod
config.sandbox.project = Project.new(config.sandbox.project_path) config.sandbox.project = Project.new(config.sandbox.project_path)
Xcodeproj::Project.new(config.sandbox.project_path).save Xcodeproj::Project.new(config.sandbox.project_path).save
@library = AggregateTarget.new(@podfile.target_definitions['Pods'], config.sandbox) @library = AggregateTarget.new(@podfile.target_definitions['Pods'], config.sandbox)
@library.client_root = sample_project_path.dirname
@library.user_project_path = sample_project_path @library.user_project_path = sample_project_path
@library.user_target_uuids = ['A346496C14F9BE9A0080D870'] @library.user_target_uuids = ['A346496C14F9BE9A0080D870']
@library.xcconfig_path = config.sandbox.root + 'Pods.xcconfig'
@library.copy_resources_script_path = config.sandbox.root + 'Pods-resources.sh'
empty_library = AggregateTarget.new(@podfile.target_definitions[:empty], config.sandbox) empty_library = AggregateTarget.new(@podfile.target_definitions[:empty], config.sandbox)
@integrator = Installer::UserProjectIntegrator.new(@podfile, config.sandbox, temporary_directory, [@library, empty_library]) @integrator = Installer::UserProjectIntegrator.new(@podfile, config.sandbox, temporary_directory, [@library, empty_library])
end end
......
require File.expand_path('../../spec_helper', __FILE__)
module Pod
describe Pod::AggregateTarget do
describe "In general" do
before do
@target_definition = Podfile::TargetDefinition.new('Pods', nil)
@target_definition.link_with_first_target = true
@lib = AggregateTarget.new(@target_definition, config.sandbox)
end
it "returns the target_definition that generated it" do
@lib.target_definition.should == @target_definition
end
it "returns the label of the target definition" do
@lib.label.should == 'Pods'
end
it "returns its name" do
@lib.name.should == 'Pods'
end
it "returns the name of its product" do
@lib.product_name.should == 'libPods.a'
end
end
describe "Support files" do
before do
@target_definition = Podfile::TargetDefinition.new('Pods', nil)
@target_definition.link_with_first_target = true
@lib = AggregateTarget.new(@target_definition, config.sandbox)
@lib.client_root = config.sandbox.root.dirname
end
it "returns the absolute path of the xcconfig file" do
@lib.xcconfig_path.to_s.should.include?('Pods/Pods.xcconfig')
end
it "returns the absolute path of the resources script" do
@lib.copy_resources_script_path.to_s.should.include?('Pods/Pods-resources.sh')
end
it "returns the absolute path of the target header file" do
@lib.target_environment_header_path.to_s.should.include?('Pods/Pods-environment.h')
end
it "returns the absolute path of the prefix header file" do
@lib.prefix_header_path.to_s.should.include?('Pods/Pods-prefix.pch')
end
it "returns the absolute path of the bridge support file" do
@lib.bridge_support_path.to_s.should.include?('Pods/Pods.bridgesupport')
end
it "returns the absolute path of the acknowledgements files without extension" do
@lib.acknowledgements_basepath.to_s.should.include?('Pods/Pods-acknowledgements')
end
#--------------------------------------#
it "returns the path of the resources script relative to the user project" do
@lib.copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Pods-resources.sh'
end
it "returns the path of the xcconfig file relative to the user project" do
@lib.xcconfig_relative_path.should == 'Pods/Pods.xcconfig'
end
end
end
end
...@@ -26,49 +26,6 @@ module Pod ...@@ -26,49 +26,6 @@ module Pod
end end
end end
describe "Support files" do
before do
@target_definition = Podfile::TargetDefinition.new('Pods', nil)
@target_definition.link_with_first_target = true
@target = AggregateTarget.new(@target_definition, config.sandbox)
@target.client_root = config.sandbox.root.dirname
end
it "returns the absolute path of the xcconfig file" do
@target.xcconfig_path.to_s.should.include?('Pods/Pods.xcconfig')
end
it "returns the absolute path of the resources script" do
@target.copy_resources_script_path.to_s.should.include?('Pods/Pods-resources.sh')
end
it "returns the absolute path of the target header file" do
@target.target_environment_header_path.to_s.should.include?('Pods/Pods-environment.h')
end
it "returns the absolute path of the prefix header file" do
@target.prefix_header_path.to_s.should.include?('Pods/Pods-prefix.pch')
end
it "returns the absolute path of the bridge support file" do
@target.bridge_support_path.to_s.should.include?('Pods/Pods.bridgesupport')
end
it "returns the absolute path of the acknowledgements files without extension" do
@target.acknowledgements_basepath.to_s.should.include?('Pods/Pods-acknowledgements')
end
#--------------------------------------#
it "returns the path of the resources script relative to the user project" do
@target.copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Pods-resources.sh'
end
it "returns the path of the xcconfig file relative to the user project" do
@target.xcconfig_relative_path.should == 'Pods/Pods.xcconfig'
end
end
describe "Pod targets" do describe "Pod targets" do
before do before do
spec = fixture_spec('banana-lib/BananaLib.podspec') spec = fixture_spec('banana-lib/BananaLib.podspec')
......
...@@ -51,28 +51,5 @@ module Pod ...@@ -51,28 +51,5 @@ module Pod
end end
end end
describe "Support files" do
it "returns the absolute path of the xcconfig file" do
@pod_target.xcconfig_path.to_s.should.include 'Pods/Pods-BananaLib.xcconfig'
end
it "returns the absolute path of the target header file" do
@pod_target.target_environment_header_path.to_s.should.include 'Pods/Pods-environment.h'
end
it "returns the absolute path of the prefix header file" do
@pod_target.prefix_header_path.to_s.should.include 'Pods/Pods-BananaLib-prefix.pch'
end
it "returns the absolute path of the bridge support file" do
@pod_target.bridge_support_path.to_s.should.include 'Pods/Pods-BananaLib.bridgesupport'
end
it "returns the absolute path of the public and private xcconfig files" do
@pod_target.xcconfig_path.to_s.should.include 'Pods/Pods-BananaLib.xcconfig'
@pod_target.xcconfig_private_path.to_s.should.include 'Pods/Pods-BananaLib-Private.xcconfig'
end
end
end end
end end
...@@ -2,6 +2,26 @@ require File.expand_path('../../spec_helper', __FILE__) ...@@ -2,6 +2,26 @@ require File.expand_path('../../spec_helper', __FILE__)
module Pod module Pod
describe Target do describe Target do
before do
@target_definition = Podfile::TargetDefinition.new('Pods', nil)
@target_definition.link_with_first_target = true
@lib = AggregateTarget.new(@target_definition, config.sandbox)
end
it "returns the target_definition that generated it" do
@lib.target_definition.should == @target_definition
end
it "returns the label of the target definition" do
@lib.label.should == 'Pods'
end
it "returns its name" do
@lib.name.should == 'Pods'
end
it "returns the name of its product" do
@lib.product_name.should == 'libPods.a'
end
end end
end end
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