Unverified Commit 7813c5f0 authored by Dimitris Koutsogiorgas's avatar Dimitris Koutsogiorgas Committed by GitHub

Merge pull request #7581 from dnkoutso/immutability_wins_4

Even more "immutability" across classes
parents 1f95c589 cf14392d
...@@ -16,18 +16,21 @@ module Pod ...@@ -16,18 +16,21 @@ module Pod
# @param [String] podfile_path # @param [String] podfile_path
# @see AbstractExternalSource#podfile_path # @see AbstractExternalSource#podfile_path
# #
# @param [Boolean] can_cache
# @see AbstractExternalSource#can_cache
#
# @return [AbstractExternalSource] an initialized instance of the concrete # @return [AbstractExternalSource] an initialized instance of the concrete
# external source class associated with the option specified in the # external source class associated with the option specified in the
# hash. # hash.
# #
def self.from_dependency(dependency, podfile_path) def self.from_dependency(dependency, podfile_path, can_cache)
from_params(dependency.external_source, dependency, podfile_path) from_params(dependency.external_source, dependency, podfile_path, can_cache)
end end
def self.from_params(params, dependency, podfile_path) def self.from_params(params, dependency, podfile_path, can_cache)
name = dependency.root_name name = dependency.root_name
if klass = concrete_class_from_params(params) if klass = concrete_class_from_params(params)
klass.new(name, params, podfile_path) klass.new(name, params, podfile_path, can_cache)
else else
msg = "Unknown external source parameters for `#{name}`: `#{params}`" msg = "Unknown external source parameters for `#{name}`: `#{params}`"
raise Informative, msg raise Informative, msg
......
...@@ -19,7 +19,7 @@ module Pod ...@@ -19,7 +19,7 @@ module Pod
# @return [Boolean] Whether the source is allowed to touch the cache. # @return [Boolean] Whether the source is allowed to touch the cache.
# #
attr_accessor :can_cache attr_reader :can_cache
alias_method :can_cache?, :can_cache alias_method :can_cache?, :can_cache
# Initialize a new instance # Initialize a new instance
...@@ -27,12 +27,13 @@ module Pod ...@@ -27,12 +27,13 @@ module Pod
# @param [String] name @see #name # @param [String] name @see #name
# @param [Hash] params @see #params # @param [Hash] params @see #params
# @param [String] podfile_path @see #podfile_path # @param [String] podfile_path @see #podfile_path
# @param [Boolean] can_cache @see #can_cache
# #
def initialize(name, params, podfile_path) def initialize(name, params, podfile_path, can_cache = true)
@name = name @name = name
@params = params @params = params
@podfile_path = podfile_path @podfile_path = podfile_path
@can_cache = true @can_cache = can_cache
end end
# @return [Bool] whether an external source source is equal to another # @return [Bool] whether an external source source is equal to another
......
...@@ -17,7 +17,7 @@ module Pod ...@@ -17,7 +17,7 @@ module Pod
# @return [Array<String>] The list of the modules to import. # @return [Array<String>] The list of the modules to import.
# #
attr_accessor :module_imports attr_reader :module_imports
# Initialize a new instance # Initialize a new instance
# #
......
...@@ -13,10 +13,6 @@ module Pod ...@@ -13,10 +13,6 @@ module Pod
# #
attr_reader :configuration_name attr_reader :configuration_name
# @return [Xcodeproj::Config] The generated xcconfig.
#
attr_reader :xcconfig
# Initialize a new instance # Initialize a new instance
# #
# @param [Target] target @see #target # @param [Target] target @see #target
...@@ -32,10 +28,12 @@ module Pod ...@@ -32,10 +28,12 @@ module Pod
# @param [Pathname] path # @param [Pathname] path
# the path where the xcconfig should be stored. # the path where the xcconfig should be stored.
# #
# @return [void] # @return [Xcodeproj::Config]
# #
def save_as(path) def save_as(path)
generate.save_as(path) result = generate
result.save_as(path)
result
end end
# Generates the xcconfig. # Generates the xcconfig.
...@@ -66,23 +64,23 @@ module Pod ...@@ -66,23 +64,23 @@ module Pod
'SWIFT_INCLUDE_PATHS' => '$(inherited) ', 'SWIFT_INCLUDE_PATHS' => '$(inherited) ',
}.merge(embedded_content_settings) }.merge(embedded_content_settings)
@xcconfig = Xcodeproj::Config.new(config) xcconfig = Xcodeproj::Config.new(config)
@xcconfig.merge!(merged_user_target_xcconfigs) xcconfig.merge!(merged_user_target_xcconfigs)
generate_settings_to_import_pod_targets generate_settings_to_import_pod_targets(xcconfig)
XCConfigHelper.add_target_specific_settings(target, @xcconfig) XCConfigHelper.add_target_specific_settings(target, xcconfig)
targets = pod_targets + target.search_paths_aggregate_targets.flat_map(&:pod_targets) targets = pod_targets + target.search_paths_aggregate_targets.flat_map(&:pod_targets)
XCConfigHelper.generate_vendored_build_settings(target, targets, @xcconfig) XCConfigHelper.generate_vendored_build_settings(target, targets, xcconfig)
XCConfigHelper.generate_other_ld_flags(target, pod_targets, @xcconfig) XCConfigHelper.generate_other_ld_flags(target, pod_targets, xcconfig)
# TODO: Need to decide how we are going to ensure settings like these # TODO: Need to decide how we are going to ensure settings like these
# are always excluded from the user's project. # are always excluded from the user's project.
# #
# See https://github.com/CocoaPods/CocoaPods/issues/1216 # See https://github.com/CocoaPods/CocoaPods/issues/1216
@xcconfig.attributes.delete('USE_HEADERMAP') xcconfig.attributes.delete('USE_HEADERMAP')
# If any of the aggregate target dependencies bring in any vendored dynamic artifacts we should ensure to # If any of the aggregate target dependencies bring in any vendored dynamic artifacts we should ensure to
# update the runpath search paths. # update the runpath search paths.
...@@ -90,48 +88,15 @@ module Pod ...@@ -90,48 +88,15 @@ module Pod
symbol_type = target.user_targets.map(&:symbol_type).uniq.first symbol_type = target.user_targets.map(&:symbol_type).uniq.first
test_bundle = symbol_type == :octest_bundle || symbol_type == :unit_test_bundle || symbol_type == :ui_test_bundle test_bundle = symbol_type == :octest_bundle || symbol_type == :unit_test_bundle || symbol_type == :ui_test_bundle
XCConfigHelper.generate_ld_runpath_search_paths(target, target.requires_host_target?, test_bundle, @xcconfig) if target.requires_frameworks? || vendored_dynamic_artifacts.count > 0 XCConfigHelper.generate_ld_runpath_search_paths(target, target.requires_host_target?, test_bundle, xcconfig) if target.requires_frameworks? || vendored_dynamic_artifacts.count > 0
@xcconfig xcconfig
end end
#---------------------------------------------------------------------# #---------------------------------------------------------------------#
protected protected
# @return String the SWIFT_VERSION of the target being integrated
#
def target_swift_version
target.target_definition.swift_version unless target.target_definition.swift_version.blank?
end
EMBED_STANDARD_LIBRARIES_MINIMUM_VERSION = Gem::Version.new('2.3')
# @return [Hash<String, String>] the build settings necessary for Swift
# targets to be correctly embedded in their host.
#
def embedded_content_settings
# For embedded targets, which live in a host target, CocoaPods
# copies all of the embedded target's pod_targets its host
# target. Therefore, this check will properly require the Swift
# libs in the host target, if the embedded target has any pod targets
# that use Swift. Setting this for the embedded target would
# cause an App Store rejection because frameworks cannot be embedded
# in embedded targets.
swift_version = Gem::Version.new(target_swift_version)
should_embed = !target.requires_host_target? && pod_targets.any?(&:uses_swift?)
config = {}
if should_embed
if swift_version >= EMBED_STANDARD_LIBRARIES_MINIMUM_VERSION
config['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
else
config['EMBEDDED_CONTENT_CONTAINS_SWIFT'] = 'YES'
end
end
config
end
# @return [Hash<String, String>] the build settings necessary to import # @return [Hash<String, String>] the build settings necessary to import
# the pod targets. # the pod targets.
# #
...@@ -167,28 +132,61 @@ module Pod ...@@ -167,28 +132,61 @@ module Pod
end end
end end
#---------------------------------------------------------------------#
private private
# @return String the SWIFT_VERSION of the target being integrated
#
def target_swift_version
target.target_definition.swift_version unless target.target_definition.swift_version.blank?
end
EMBED_STANDARD_LIBRARIES_MINIMUM_VERSION = Gem::Version.new('2.3')
# @return [Hash<String, String>] the build settings necessary for Swift
# targets to be correctly embedded in their host.
#
def embedded_content_settings
# For embedded targets, which live in a host target, CocoaPods
# copies all of the embedded target's pod_targets its host
# target. Therefore, this check will properly require the Swift
# libs in the host target, if the embedded target has any pod targets
# that use Swift. Setting this for the embedded target would
# cause an App Store rejection because frameworks cannot be embedded
# in embedded targets.
swift_version = Gem::Version.new(target_swift_version)
should_embed = !target.requires_host_target? && pod_targets.any?(&:uses_swift?)
config = {}
if should_embed
if swift_version >= EMBED_STANDARD_LIBRARIES_MINIMUM_VERSION
config['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
else
config['EMBEDDED_CONTENT_CONTAINS_SWIFT'] = 'YES'
end
end
config
end
# Add build settings, which ensure that the pod targets can be imported from the integrating target. # Add build settings, which ensure that the pod targets can be imported from the integrating target.
# For >= 1.5.0 we use modular (stricter) header search paths this means that the integrated target will only be # For >= 1.5.0 we use modular (stricter) header search paths this means that the integrated target will only be
# able to import public headers using `<>` or `@import` notation, but never import any private headers. # able to import public headers using `<>` or `@import` notation, but never import any private headers.
# #
# For < 1.5.0 legacy header search paths the same rules apply: It's the wild west. # For < 1.5.0 legacy header search paths the same rules apply: It's the wild west.
# #
def generate_settings_to_import_pod_targets def generate_settings_to_import_pod_targets(xcconfig)
@xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(target, pod_targets) xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(target, pod_targets)
@xcconfig.merge!(settings_to_import_pod_targets) xcconfig.merge!(settings_to_import_pod_targets)
target.search_paths_aggregate_targets.each do |search_paths_target| target.search_paths_aggregate_targets.each do |search_paths_target|
generator = AggregateXCConfig.new(search_paths_target, configuration_name) generator = AggregateXCConfig.new(search_paths_target, configuration_name)
@xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(nil, search_paths_target.pod_targets) xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(nil, search_paths_target.pod_targets)
@xcconfig.merge!(generator.settings_to_import_pod_targets) xcconfig.merge!(generator.settings_to_import_pod_targets)
# Propagate any HEADER_SEARCH_PATHS settings from the search paths. # Propagate any HEADER_SEARCH_PATHS settings from the search paths.
XCConfigHelper.propagate_header_search_paths_from_search_paths(search_paths_target, @xcconfig) XCConfigHelper.propagate_header_search_paths_from_search_paths(search_paths_target, xcconfig)
end end
end end
private
#---------------------------------------------------------------------# #---------------------------------------------------------------------#
# !@group Private Helpers # !@group Private Helpers
......
...@@ -12,9 +12,10 @@ module Pod ...@@ -12,9 +12,10 @@ module Pod
# #
attr_reader :target attr_reader :target
# @return [Xcodeproj::Config] The generated xcconfig. # @return [Boolean] whether this xcconfig is for a test target.
# #
attr_reader :xcconfig attr_reader :test_xcconfig
alias test_xcconfig? test_xcconfig
# Initialize a new instance # Initialize a new instance
# #
...@@ -31,12 +32,14 @@ module Pod ...@@ -31,12 +32,14 @@ module Pod
# Generates and saves the xcconfig to the given path. # Generates and saves the xcconfig to the given path.
# #
# @param [Pathname] path # @param [Pathname] path
# the path where the prefix header should be stored. # the path where the xcconfig should be stored.
# #
# @return [void] # @return [Xcodeproj::Config]
# #
def save_as(path) def save_as(path)
generate.save_as(path) result = generate
result.save_as(path)
result
end end
# Generates the xcconfig. # Generates the xcconfig.
...@@ -47,10 +50,10 @@ module Pod ...@@ -47,10 +50,10 @@ module Pod
config = { config = {
'FRAMEWORK_SEARCH_PATHS' => '$(inherited) ', 'FRAMEWORK_SEARCH_PATHS' => '$(inherited) ',
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1', 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1',
'HEADER_SEARCH_PATHS' => '$(inherited) ' + XCConfigHelper.quote(target.header_search_paths(@test_xcconfig)), 'HEADER_SEARCH_PATHS' => '$(inherited) ' + XCConfigHelper.quote(target.header_search_paths(test_xcconfig?)),
'LIBRARY_SEARCH_PATHS' => '$(inherited) ', 'LIBRARY_SEARCH_PATHS' => '$(inherited) ',
'OTHER_CFLAGS' => '$(inherited) ', 'OTHER_CFLAGS' => '$(inherited) ',
'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target, @test_xcconfig), 'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target, test_xcconfig?),
'OTHER_SWIFT_FLAGS' => '$(inherited) ', 'OTHER_SWIFT_FLAGS' => '$(inherited) ',
'PODS_ROOT' => '${SRCROOT}', 'PODS_ROOT' => '${SRCROOT}',
'PODS_TARGET_SRCROOT' => target.pod_target_srcroot, 'PODS_TARGET_SRCROOT' => target.pod_target_srcroot,
...@@ -60,24 +63,24 @@ module Pod ...@@ -60,24 +63,24 @@ module Pod
'SWIFT_INCLUDE_PATHS' => '$(inherited) ', 'SWIFT_INCLUDE_PATHS' => '$(inherited) ',
} }
@xcconfig = Xcodeproj::Config.new(config) xcconfig = Xcodeproj::Config.new(config)
XCConfigHelper.add_settings_for_file_accessors_of_target(nil, target, @xcconfig, true, @test_xcconfig) XCConfigHelper.add_settings_for_file_accessors_of_target(nil, target, xcconfig, true, test_xcconfig?)
target.file_accessors.each do |file_accessor| target.file_accessors.each do |file_accessor|
@xcconfig.merge!(file_accessor.spec_consumer.pod_target_xcconfig) if @test_xcconfig == file_accessor.spec.test_specification? xcconfig.merge!(file_accessor.spec_consumer.pod_target_xcconfig) if test_xcconfig? == file_accessor.spec.test_specification?
end end
XCConfigHelper.add_target_specific_settings(target, @xcconfig) XCConfigHelper.add_target_specific_settings(target, xcconfig)
recursive_dependent_targets = target.recursive_dependent_targets recursive_dependent_targets = target.recursive_dependent_targets
@xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(target, recursive_dependent_targets, @test_xcconfig) xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(target, recursive_dependent_targets, test_xcconfig?)
XCConfigHelper.generate_vendored_build_settings(target, recursive_dependent_targets, @xcconfig, false, @test_xcconfig) if target.requires_frameworks? XCConfigHelper.generate_vendored_build_settings(target, recursive_dependent_targets, xcconfig, false, test_xcconfig?) if target.requires_frameworks?
if @test_xcconfig if test_xcconfig?
test_dependent_targets = [target, *target.recursive_test_dependent_targets].uniq test_dependent_targets = [target, *target.recursive_test_dependent_targets].uniq
@xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(target, test_dependent_targets - recursive_dependent_targets, @test_xcconfig) xcconfig.merge! XCConfigHelper.search_paths_for_dependent_targets(target, test_dependent_targets - recursive_dependent_targets, test_xcconfig?)
XCConfigHelper.generate_vendored_build_settings(nil, target.all_dependent_targets, @xcconfig, true, @test_xcconfig) XCConfigHelper.generate_vendored_build_settings(nil, target.all_dependent_targets, xcconfig, true, test_xcconfig?)
XCConfigHelper.generate_other_ld_flags(nil, target.all_dependent_targets, @xcconfig) XCConfigHelper.generate_other_ld_flags(nil, target.all_dependent_targets, xcconfig)
XCConfigHelper.generate_ld_runpath_search_paths(target, false, true, @xcconfig) XCConfigHelper.generate_ld_runpath_search_paths(target, false, true, xcconfig)
end end
@xcconfig xcconfig
end end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
......
...@@ -685,11 +685,10 @@ module Pod ...@@ -685,11 +685,10 @@ module Pod
def fetch_external_source(dependency, use_lockfile_options) def fetch_external_source(dependency, use_lockfile_options)
checkout_options = lockfile.checkout_options_for_pod_named(dependency.root_name) if lockfile checkout_options = lockfile.checkout_options_for_pod_named(dependency.root_name) if lockfile
source = if checkout_options && use_lockfile_options source = if checkout_options && use_lockfile_options
ExternalSources.from_params(checkout_options, dependency, podfile.defined_in_file) ExternalSources.from_params(checkout_options, dependency, podfile.defined_in_file, installation_options.clean?)
else else
ExternalSources.from_dependency(dependency, podfile.defined_in_file) ExternalSources.from_dependency(dependency, podfile.defined_in_file, installation_options.clean?)
end end
source.can_cache = installation_options.clean?
source.fetch(sandbox) source.fetch(sandbox)
end end
......
...@@ -5,40 +5,48 @@ module Pod ...@@ -5,40 +5,48 @@ module Pod
# @return [TargetDefinition] the target definition, whose project was # @return [TargetDefinition] the target definition, whose project was
# inspected # inspected
# #
attr_accessor :target_definition attr_reader :target_definition
# @return [Pathname] the path of the user project that the # @return [Xcodeproj::Project] the user's Xcode project
# #target_definition should integrate
# #
attr_accessor :project_path attr_reader :project
# @return [Array<String>] the uuid of the user's targets # @return [Array<String>] the uuid of the user's targets
# #
attr_accessor :project_target_uuids attr_reader :project_target_uuids
# @return [Hash{String=>Symbol}] A hash representing the user build # @return [Hash{String=>Symbol}] A hash representing the user build
# configurations where each key corresponds to the name of a # configurations where each key corresponds to the name of a
# configuration and its value to its type (`:debug` or # configuration and its value to its type (`:debug` or
# `:release`). # `:release`).
# #
attr_accessor :build_configurations attr_reader :build_configurations
# @return [Platform] the platform of the user targets # @return [Platform] the platform of the user targets
# #
attr_accessor :platform attr_reader :platform
# @return [Array<String>] the architectures used by user's targets # @return [Array<String>] the architectures used by user's targets
# #
attr_accessor :archs attr_reader :archs
# @return [Bool] whether frameworks are recommended for the integration
# due to the presence of Swift source in the user's targets
#
attr_accessor :recommends_frameworks
# @return [Xcodeproj::Project] the user's Xcode project # Initialize a new instance
# #
attr_accessor :project # @param [TargetDefinition] target_definition @see #target_definition
# @param [Xcodeproj::Project] project @see #project
# @param [Array<String>] project_target_uuids @see #project_target_uuids
# @param [Hash{String=>Symbol}] build_configurations @see #build_configurations
# @param [Platform] platform @see #platform
# @param [Array<String>] archs @see #archs
#
def initialize(target_definition, project, project_target_uuids, build_configurations, platform, archs)
@target_definition = target_definition
@project = project
@project_target_uuids = project_target_uuids
@build_configurations = build_configurations
@platform = platform
@archs = archs
end
end end
end end
end end
......
...@@ -32,22 +32,21 @@ module Pod ...@@ -32,22 +32,21 @@ module Pod
# #
# @raise If no `user_project` is set # @raise If no `user_project` is set
# #
# @return [TargetInspectionResult] # @return [TargetInspectionResult] the result of the inspection of the target definition within the user project
# #
def compute_results(user_project) def compute_results(user_project)
raise ArgumentError, 'Cannot compute results without a user project set' unless user_project raise ArgumentError, 'Cannot compute results without a user project set' unless user_project
targets = compute_targets(user_project) targets = compute_targets(user_project)
project_target_uuids = targets.map(&:uuid)
result = TargetInspectionResult.new build_configurations = compute_build_configurations(targets)
result.target_definition = target_definition platform = compute_platform(targets)
result.project_path = user_project.path archs = compute_archs(targets)
result.project_target_uuids = targets.map(&:uuid) swift_version = compute_swift_version_from_targets(targets)
result.build_configurations = compute_build_configurations(targets)
result.platform = compute_platform(targets) result = TargetInspectionResult.new(target_definition, user_project, project_target_uuids,
result.archs = compute_archs(targets) build_configurations, platform, archs)
result.project = user_project result.target_definition.swift_version = swift_version
result.target_definition.swift_version = compute_swift_version_from_targets(targets)
result result
end end
......
...@@ -171,8 +171,7 @@ module Pod ...@@ -171,8 +171,7 @@ module Pod
end.compact.group_by(&:dirname) end.compact.group_by(&:dirname)
pod_targets.sort_by(&:name).each do |pod_target| pod_targets.sort_by(&:name).each do |pod_target|
target_installer = PodTargetInstaller.new(sandbox, pod_target) target_installer = PodTargetInstaller.new(sandbox, pod_target, umbrella_headers_by_dir)
target_installer.umbrella_headers_by_dir = umbrella_headers_by_dir
target_installer.install! target_installer.install!
end end
......
...@@ -93,8 +93,8 @@ module Pod ...@@ -93,8 +93,8 @@ module Pod
native_target.build_configurations.each do |configuration| native_target.build_configurations.each do |configuration|
path = target.xcconfig_path(configuration.name) path = target.xcconfig_path(configuration.name)
gen = Generator::XCConfig::AggregateXCConfig.new(target, configuration.name) gen = Generator::XCConfig::AggregateXCConfig.new(target, configuration.name)
update_changed_file(gen, path) xcconfig = update_changed_file(gen, path)
target.xcconfigs[configuration.name] = gen.xcconfig target.xcconfigs[configuration.name] = xcconfig
xcconfig_file_ref = add_file_to_support_group(path) xcconfig_file_ref = add_file_to_support_group(path)
configuration.base_configuration_reference = xcconfig_file_ref configuration.base_configuration_reference = xcconfig_file_ref
end end
......
...@@ -6,6 +6,22 @@ module Pod ...@@ -6,6 +6,22 @@ module Pod
# relative support files. # relative support files.
# #
class PodTargetInstaller < TargetInstaller class PodTargetInstaller < TargetInstaller
# @return [Hash{Pathname => Pathname}] A hash of all umbrella headers, grouped by the directory
# the are stored in. This can be `nil` if there is no grouping.
#
attr_reader :umbrella_headers_by_dir
# Initialize a new instance
#
# @param [Sandbox] sandbox @see TargetInstaller#sandbox
# @param [Target] target @see TargetInstaller#target
# @param [Hash{Pathname => Pathname}] umbrella_headers_by_dir @see #umbrella_headers_by_dir
#
def initialize(sandbox, target, umbrella_headers_by_dir = nil)
super(sandbox, target)
@umbrella_headers_by_dir = umbrella_headers_by_dir
end
# Creates the target in the Pods project and the relative support files. # Creates the target in the Pods project and the relative support files.
# #
# @return [void] # @return [void]
...@@ -70,11 +86,6 @@ module Pod ...@@ -70,11 +86,6 @@ module Pod
end end
end end
# @return [Hash<Pathname,Pathname>] A hash of all umbrella headers, grouped by the directory
# the are stored in
#
attr_accessor :umbrella_headers_by_dir
private private
# @param [Array<Specification>] specs # @param [Array<Specification>] specs
......
...@@ -99,19 +99,20 @@ module Pod ...@@ -99,19 +99,20 @@ module Pod
# #
# Saves the content the provided path unless the path exists and the contents are exactly the same. # Saves the content the provided path unless the path exists and the contents are exactly the same.
# #
# @return [Void] # @return [Object] the result of the generator.
# #
def update_changed_file(generator, path) def update_changed_file(generator, path)
path.dirname.mkpath path.dirname.mkpath
if path.exist? if path.exist?
generator.save_as(support_files_temp_dir) result = generator.save_as(support_files_temp_dir)
unless FileUtils.identical?(support_files_temp_dir, path) unless FileUtils.identical?(support_files_temp_dir, path)
FileUtils.mv(support_files_temp_dir, path) FileUtils.mv(support_files_temp_dir, path)
end end
else else
generator.save_as(path) result = generator.save_as(path)
end end
clean_support_files_temp_dir if support_files_temp_dir.exist? clean_support_files_temp_dir if support_files_temp_dir.exist?
result
end end
# Creates the directory where to store the support files of the target. # Creates the directory where to store the support files of the target.
......
...@@ -16,11 +16,11 @@ module Pod ...@@ -16,11 +16,11 @@ module Pod
# @return [Pathname] The root of the list whose files and directories # @return [Pathname] The root of the list whose files and directories
# are used to perform the matching operations. # are used to perform the matching operations.
# #
attr_accessor :root attr_reader :root
# Initialize a new instance # Initialize a new instance
# #
# @param [Pathname] root The root of the PathList. # @param [Pathname] root @see #root
# #
def initialize(root) def initialize(root)
root_dir = ActiveSupport::Multibyte::Unicode.normalize(root.to_s) root_dir = ActiveSupport::Multibyte::Unicode.normalize(root.to_s)
......
...@@ -4,7 +4,7 @@ module Pod ...@@ -4,7 +4,7 @@ module Pod
describe ExternalSources::AbstractExternalSource do describe ExternalSources::AbstractExternalSource do
before do before do
dependency = Dependency.new('Reachability', :git => fixture('integration/Reachability')) dependency = Dependency.new('Reachability', :git => fixture('integration/Reachability'))
@subject = ExternalSources.from_dependency(dependency, nil) @subject = ExternalSources.from_dependency(dependency, nil, true)
config.sandbox.prepare config.sandbox.prepare
end end
......
...@@ -8,7 +8,7 @@ module Pod ...@@ -8,7 +8,7 @@ module Pod
:branch => 'master', :branch => 'master',
} }
dep = Dependency.new('Reachability', params) dep = Dependency.new('Reachability', params)
@subject = ExternalSources.from_dependency(dep, nil) @subject = ExternalSources.from_dependency(dep, nil, true)
end end
it 'creates a copy of the podspec' do it 'creates a copy of the podspec' do
......
...@@ -6,7 +6,7 @@ module Pod ...@@ -6,7 +6,7 @@ module Pod
params = { :path => fixture('integration/Reachability') } params = { :path => fixture('integration/Reachability') }
dependency = Dependency.new('Reachability', params) dependency = Dependency.new('Reachability', params)
podfile_path = fixture('integration/Podfile') podfile_path = fixture('integration/Podfile')
@subject = ExternalSources.from_dependency(dependency, podfile_path) @subject = ExternalSources.from_dependency(dependency, podfile_path, true)
end end
it 'creates a copy of the podspec' do it 'creates a copy of the podspec' do
......
...@@ -7,7 +7,7 @@ module Pod ...@@ -7,7 +7,7 @@ module Pod
podspec_path = fixture('integration/Reachability/Reachability.podspec') podspec_path = fixture('integration/Reachability/Reachability.podspec')
dependency = Dependency.new('Reachability', :podspec => podspec_path.to_s) dependency = Dependency.new('Reachability', :podspec => podspec_path.to_s)
podfile_path = fixture('integration/Podfile') podfile_path = fixture('integration/Podfile')
@subject = ExternalSources.from_dependency(dependency, podfile_path) @subject = ExternalSources.from_dependency(dependency, podfile_path, true)
end end
it 'creates a copy of the podspec' do it 'creates a copy of the podspec' do
......
...@@ -9,20 +9,20 @@ module Pod ...@@ -9,20 +9,20 @@ module Pod
describe 'from_dependency' do describe 'from_dependency' do
it 'supports a podspec source' do it 'supports a podspec source' do
dep = Dependency.new('Reachability', :podspec => '') dep = Dependency.new('Reachability', :podspec => '')
klass = @subject.from_dependency(dep, nil).class klass = @subject.from_dependency(dep, nil, true).class
klass.should == @subject::PodspecSource klass.should == @subject::PodspecSource
end end
it 'supports a path source' do it 'supports a path source' do
dep = Dependency.new('Reachability', :path => '') dep = Dependency.new('Reachability', :path => '')
klass = @subject.from_dependency(dep, nil).class klass = @subject.from_dependency(dep, nil, true).class
klass.should == @subject::PathSource klass.should == @subject::PathSource
end end
it 'supports all the strategies implemented by the downloader' do it 'supports all the strategies implemented by the downloader' do
[:git, :svn, :hg, :bzr, :http].each do |strategy| [:git, :svn, :hg, :bzr, :http].each do |strategy|
dep = Dependency.new('Reachability', strategy => '') dep = Dependency.new('Reachability', strategy => '')
klass = @subject.from_dependency(dep, nil).class klass = @subject.from_dependency(dep, nil, true).class
klass.should == @subject::DownloaderSource klass.should == @subject::DownloaderSource
end end
end end
......
...@@ -12,7 +12,7 @@ module Pod ...@@ -12,7 +12,7 @@ module Pod
target_definition.user_project_path = 'SampleProject/SampleProject' target_definition.user_project_path = 'SampleProject/SampleProject'
target_inspector = TargetInspector.new(target_definition, config.installation_root) target_inspector = TargetInspector.new(target_definition, config.installation_root)
path = target_inspector.send(:compute_project_path) path = target_inspector.compute_project_path
path.to_s.should.include 'SampleProject/SampleProject.xcodeproj' path.to_s.should.include 'SampleProject/SampleProject.xcodeproj'
end end
...@@ -21,7 +21,7 @@ module Pod ...@@ -21,7 +21,7 @@ module Pod
target_definition.user_project_path = 'Test' target_definition.user_project_path = 'Test'
target_inspector = TargetInspector.new(target_definition, config.installation_root) target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_project_path) }.should.raise Informative e = lambda { target_inspector.compute_project_path }.should.raise Informative
e.message.should.match /Unable to find/ e.message.should.match /Unable to find/
end end
...@@ -30,7 +30,7 @@ module Pod ...@@ -30,7 +30,7 @@ module Pod
config.installation_root = config.installation_root + 'SampleProject' config.installation_root = config.installation_root + 'SampleProject'
target_inspector = TargetInspector.new(target_definition, config.installation_root) target_inspector = TargetInspector.new(target_definition, config.installation_root)
path = target_inspector.send(:compute_project_path) path = target_inspector.compute_project_path
path.to_s.should.include 'SampleProject/SampleProject.xcodeproj' path.to_s.should.include 'SampleProject/SampleProject.xcodeproj'
end end
...@@ -38,7 +38,7 @@ module Pod ...@@ -38,7 +38,7 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
target_inspector = TargetInspector.new(target_definition, config.installation_root) target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_project_path) }.should.raise Informative e = lambda { target_inspector.compute_project_path }.should.raise Informative
e.message.should.match /Could not.*select.*project/ e.message.should.match /Could not.*select.*project/
end end
...@@ -49,7 +49,7 @@ module Pod ...@@ -49,7 +49,7 @@ module Pod
config.installation_root = config.installation_root + 'Project[With]Special{chars}in*path?' config.installation_root = config.installation_root + 'Project[With]Special{chars}in*path?'
target_inspector = TargetInspector.new(target_definition, config.installation_root) target_inspector = TargetInspector.new(target_definition, config.installation_root)
path = target_inspector.send(:compute_project_path) path = target_inspector.compute_project_path
path.to_s.should.include 'Project[With]Special{chars}in*path?/Project[With]Special{chars}in*path?.xcodeproj' path.to_s.should.include 'Project[With]Special{chars}in*path?/Project[With]Special{chars}in*path?.xcodeproj'
end end
end end
......
...@@ -1061,10 +1061,9 @@ module Pod ...@@ -1061,10 +1061,9 @@ module Pod
@sandbox_manifest.send(:checkout_options_data).delete('BananaLib') @sandbox_manifest.send(:checkout_options_data).delete('BananaLib')
downloader = stub('DownloaderSource') downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file).returns(downloader) ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file, true).returns(downloader)
downloader.expects(:fetch) downloader.expects(:fetch)
downloader.expects(:can_cache=).with(true).once
@analyzer.send(:fetch_external_sources) @analyzer.send(:fetch_external_sources)
end end
...@@ -1073,10 +1072,9 @@ module Pod ...@@ -1073,10 +1072,9 @@ module Pod
@sandbox_manifest.send(:checkout_options_data)['BananaLib'] = @lockfile_checkout_options.merge(:commit => 'other commit') @sandbox_manifest.send(:checkout_options_data)['BananaLib'] = @lockfile_checkout_options.merge(:commit => 'other commit')
downloader = stub('DownloaderSource') downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file).returns(downloader) ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file, true).returns(downloader)
downloader.expects(:fetch) downloader.expects(:fetch)
downloader.expects(:can_cache=).with(true).once
@analyzer.send(:fetch_external_sources) @analyzer.send(:fetch_external_sources)
end end
...@@ -1084,10 +1082,9 @@ module Pod ...@@ -1084,10 +1082,9 @@ module Pod
@analyzer.result.podfile_state.changed << 'BananaLib' @analyzer.result.podfile_state.changed << 'BananaLib'
downloader = stub('DownloaderSource') downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@dependency.external_source, @dependency, @podfile.defined_in_file).returns(downloader) ExternalSources.stubs(:from_params).with(@dependency.external_source, @dependency, @podfile.defined_in_file, true).returns(downloader)
downloader.expects(:fetch) downloader.expects(:fetch)
downloader.expects(:can_cache=).with(true).once
@analyzer.send(:fetch_external_sources) @analyzer.send(:fetch_external_sources)
end end
...@@ -1096,10 +1093,9 @@ module Pod ...@@ -1096,10 +1093,9 @@ module Pod
@analyzer.stubs(:update).returns(:pods => %w(BananaLib)) @analyzer.stubs(:update).returns(:pods => %w(BananaLib))
downloader = stub('DownloaderSource') downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@dependency.external_source, @dependency, @podfile.defined_in_file).returns(downloader) ExternalSources.stubs(:from_params).with(@dependency.external_source, @dependency, @podfile.defined_in_file, true).returns(downloader)
downloader.expects(:fetch) downloader.expects(:fetch)
downloader.expects(:can_cache=).with(true).once
@analyzer.send(:fetch_external_sources) @analyzer.send(:fetch_external_sources)
end end
...@@ -1108,10 +1104,9 @@ module Pod ...@@ -1108,10 +1104,9 @@ module Pod
@analyzer.stubs(:update).returns(true) @analyzer.stubs(:update).returns(true)
downloader = stub('DownloaderSource') downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@dependency.external_source, @dependency, @podfile.defined_in_file).returns(downloader) ExternalSources.stubs(:from_params).with(@dependency.external_source, @dependency, @podfile.defined_in_file, true).returns(downloader)
downloader.expects(:fetch) downloader.expects(:fetch)
downloader.expects(:can_cache=).with(true).once
@analyzer.send(:fetch_external_sources) @analyzer.send(:fetch_external_sources)
end end
...@@ -1120,10 +1115,9 @@ module Pod ...@@ -1120,10 +1115,9 @@ module Pod
@sandbox_manifest.send(:checkout_options_data).delete('BananaLib') @sandbox_manifest.send(:checkout_options_data).delete('BananaLib')
downloader = stub('DownloaderSource') downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file).returns(downloader) ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file, false).returns(downloader)
downloader.expects(:fetch) downloader.expects(:fetch)
downloader.expects(:can_cache=).with(false).once
@analyzer.installation_options.clean = false @analyzer.installation_options.clean = false
@analyzer.send(:fetch_external_sources) @analyzer.send(:fetch_external_sources)
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