Do not re-write generated files that have not changed

parent b1c6fabb
...@@ -16,6 +16,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -16,6 +16,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Eric Amorde](https://github.com/amorde) [Eric Amorde](https://github.com/amorde)
[#6814](https://github.com/CocoaPods/CocoaPods/pull/6814) [#6814](https://github.com/CocoaPods/CocoaPods/pull/6814)
* Do not re-write generated files that have not changed
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[dingjingpisces2015](https://github.com/dingjingpisces2015)
[#6825](https://github.com/CocoaPods/CocoaPods/pull/6825)
##### Bug Fixes ##### Bug Fixes
* Integrate test targets to embed frameworks and resources * Integrate test targets to embed frameworks and resources
......
...@@ -279,10 +279,18 @@ module Pod ...@@ -279,10 +279,18 @@ module Pod
# #
def clean_sandbox def clean_sandbox
sandbox.public_headers.implode! sandbox.public_headers.implode!
target_support_dirs = sandbox.target_support_files_root.children.select(&:directory?)
pod_targets.each do |pod_target| pod_targets.each do |pod_target|
pod_target.build_headers.implode! pod_target.build_headers.implode!
target_support_dirs.delete(pod_target.support_files_dir)
end end
aggregate_targets.each do |aggregate_target|
target_support_dirs.delete(aggregate_target.support_files_dir)
end
target_support_dirs.each { |dir| FileUtils.rm_rf(dir) }
unless sandbox_state.deleted.empty? unless sandbox_state.deleted.empty?
title_options = { :verbose_prefix => '-> '.red } title_options = { :verbose_prefix => '-> '.red }
sandbox_state.deleted.each do |pod_name| sandbox_state.deleted.each do |pod_name|
......
...@@ -84,7 +84,7 @@ module Pod ...@@ -84,7 +84,7 @@ 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)
gen.save_as(path) update_changed_file(gen, path)
target.xcconfigs[configuration.name] = gen.xcconfig target.xcconfigs[configuration.name] = gen.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
...@@ -104,7 +104,7 @@ module Pod ...@@ -104,7 +104,7 @@ module Pod
path = target.bridge_support_path path = target.bridge_support_path
headers = native_target.headers_build_phase.files.map { |bf| sandbox.root + bf.file_ref.path } headers = native_target.headers_build_phase.files.map { |bf| sandbox.root + bf.file_ref.path }
generator = Generator::BridgeSupport.new(headers) generator = Generator::BridgeSupport.new(headers)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
end end
...@@ -120,7 +120,7 @@ module Pod ...@@ -120,7 +120,7 @@ module Pod
def create_copy_resources_script def create_copy_resources_script
path = target.copy_resources_script_path path = target.copy_resources_script_path
generator = Generator::CopyResourcesScript.new(target.resource_paths_by_config, target.platform) generator = Generator::CopyResourcesScript.new(target.resource_paths_by_config, target.platform)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
...@@ -136,7 +136,7 @@ module Pod ...@@ -136,7 +136,7 @@ module Pod
def create_embed_frameworks_script def create_embed_frameworks_script
path = target.embed_frameworks_script_path path = target.embed_frameworks_script_path
generator = Generator::EmbedFrameworksScript.new(target.framework_paths_by_config) generator = Generator::EmbedFrameworksScript.new(target.framework_paths_by_config)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
...@@ -150,7 +150,7 @@ module Pod ...@@ -150,7 +150,7 @@ module Pod
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)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
end end
......
...@@ -248,7 +248,7 @@ module Pod ...@@ -248,7 +248,7 @@ module Pod
path.dirname.mkdir unless path.dirname.exist? path.dirname.mkdir unless path.dirname.exist?
info_plist_path = path.dirname + "ResourceBundle-#{bundle_name}-#{path.basename}" info_plist_path = path.dirname + "ResourceBundle-#{bundle_name}-#{path.basename}"
generator = Generator::InfoPlistFile.new(target, :bundle_package_type => :bndl) generator = Generator::InfoPlistFile.new(target, :bundle_package_type => :bndl)
generator.save_as(info_plist_path) update_changed_file(generator, info_plist_path)
add_file_to_support_group(info_plist_path) add_file_to_support_group(info_plist_path)
bundle_target.build_configurations.each do |c| bundle_target.build_configurations.each do |c|
...@@ -279,7 +279,7 @@ module Pod ...@@ -279,7 +279,7 @@ module Pod
def create_xcconfig_file def create_xcconfig_file
path = target.xcconfig_path path = target.xcconfig_path
xcconfig_gen = Generator::XCConfig::PodXCConfig.new(target) xcconfig_gen = Generator::XCConfig::PodXCConfig.new(target)
xcconfig_gen.save_as(path) update_changed_file(xcconfig_gen, path)
xcconfig_file_ref = add_file_to_support_group(path) xcconfig_file_ref = add_file_to_support_group(path)
native_target.build_configurations.each do |c| native_target.build_configurations.each do |c|
...@@ -302,7 +302,7 @@ module Pod ...@@ -302,7 +302,7 @@ module Pod
target.supported_test_types.each do |test_type| target.supported_test_types.each do |test_type|
path = target.xcconfig_path(test_type.to_s) path = target.xcconfig_path(test_type.to_s)
xcconfig_gen = Generator::XCConfig::PodXCConfig.new(target, true) xcconfig_gen = Generator::XCConfig::PodXCConfig.new(target, true)
xcconfig_gen.save_as(path) update_changed_file(xcconfig_gen, path)
xcconfig_file_ref = add_file_to_support_group(path) xcconfig_file_ref = add_file_to_support_group(path)
target.test_native_targets.each do |test_target| target.test_native_targets.each do |test_target|
...@@ -326,7 +326,7 @@ module Pod ...@@ -326,7 +326,7 @@ module Pod
pod_targets = [target, *target.test_dependent_targets] pod_targets = [target, *target.test_dependent_targets]
resource_paths_by_config = { 'Debug' => pod_targets.flat_map(&:resource_paths) } resource_paths_by_config = { 'Debug' => pod_targets.flat_map(&:resource_paths) }
generator = Generator::CopyResourcesScript.new(resource_paths_by_config, target.platform) generator = Generator::CopyResourcesScript.new(resource_paths_by_config, target.platform)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
...@@ -342,7 +342,7 @@ module Pod ...@@ -342,7 +342,7 @@ module Pod
pod_targets = [target, *target.test_dependent_targets] pod_targets = [target, *target.test_dependent_targets]
framework_paths_by_config = { 'Debug' => pod_targets.flat_map(&:framework_paths) } framework_paths_by_config = { 'Debug' => pod_targets.flat_map(&:framework_paths) }
generator = Generator::EmbedFrameworksScript.new(framework_paths_by_config) generator = Generator::EmbedFrameworksScript.new(framework_paths_by_config)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
...@@ -387,7 +387,7 @@ module Pod ...@@ -387,7 +387,7 @@ module Pod
def create_prefix_header def create_prefix_header
path = target.prefix_header_path path = target.prefix_header_path
generator = Generator::PrefixHeader.new(target.file_accessors, target.platform) generator = Generator::PrefixHeader.new(target.file_accessors, target.platform)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
native_target.build_configurations.each do |c| native_target.build_configurations.each do |c|
...@@ -473,7 +473,9 @@ module Pod ...@@ -473,7 +473,9 @@ module Pod
return super unless custom_module_map return super unless custom_module_map
path = target.module_map_path path = target.module_map_path
UI.message "- Copying module map file to #{UI.path(path)}" do UI.message "- Copying module map file to #{UI.path(path)}" do
FileUtils.cp(custom_module_map, path) unless path.exist? && FileUtils.identical?(custom_module_map, path)
FileUtils.cp(custom_module_map, path)
end
add_file_to_support_group(path) add_file_to_support_group(path)
native_target.build_configurations.each do |c| native_target.build_configurations.each do |c|
......
...@@ -89,10 +89,44 @@ module Pod ...@@ -89,10 +89,44 @@ module Pod
settings settings
end end
# @param [Generator] generator
# the generator to use for generating the content.
#
# @param [Pathname] path
# the pathname to save the content into.
#
# Saves the content the provided path unless the path exists and the contents are exactly the same.
#
# @return [Void]
#
def update_changed_file(generator, path)
if path.exist?
generator.save_as(support_files_temp_dir)
unless FileUtils.identical?(support_files_temp_dir, path)
FileUtils.mv(support_files_temp_dir, path)
end
else
generator.save_as(path)
end
clean_support_files_temp_dir if support_files_temp_dir.exist?
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.
# #
def create_support_files_dir def create_support_files_dir
target.support_files_dir.mkdir target.support_files_dir.mkpath
end
# Remove temp file whose store .prefix/config/dummy file.
#
def clean_support_files_temp_dir
support_files_temp_dir.rmtree
end
# @return [String] The temp file path to store temporary files.
#
def support_files_temp_dir
sandbox.target_support_files_dir('generated_files_tmp')
end end
# Creates the Info.plist file which sets public framework attributes # Creates the Info.plist file which sets public framework attributes
...@@ -103,7 +137,7 @@ module Pod ...@@ -103,7 +137,7 @@ module Pod
path = target.info_plist_path path = target.info_plist_path
UI.message "- Generating Info.plist file at #{UI.path(path)}" do UI.message "- Generating Info.plist file at #{UI.path(path)}" do
generator = Generator::InfoPlistFile.new(target) generator = Generator::InfoPlistFile.new(target)
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
native_target.build_configurations.each do |c| native_target.build_configurations.each do |c|
...@@ -126,7 +160,7 @@ module Pod ...@@ -126,7 +160,7 @@ module Pod
UI.message "- Generating module map file at #{UI.path(path)}" do UI.message "- Generating module map file at #{UI.path(path)}" do
generator = Generator::ModuleMap.new(target) generator = Generator::ModuleMap.new(target)
yield generator if block_given? yield generator if block_given?
generator.save_as(path) update_changed_file(generator, path)
add_file_to_support_group(path) add_file_to_support_group(path)
native_target.build_configurations.each do |c| native_target.build_configurations.each do |c|
...@@ -147,7 +181,7 @@ module Pod ...@@ -147,7 +181,7 @@ module Pod
UI.message "- Generating umbrella header at #{UI.path(path)}" do UI.message "- Generating umbrella header at #{UI.path(path)}" do
generator = Generator::UmbrellaHeader.new(target) generator = Generator::UmbrellaHeader.new(target)
yield generator if block_given? yield generator if block_given?
generator.save_as(path) update_changed_file(generator, path)
# Add the file to the support group and the native target, # Add the file to the support group and the native target,
# so it will been added to the header build phase # so it will been added to the header build phase
...@@ -169,7 +203,7 @@ module Pod ...@@ -169,7 +203,7 @@ module Pod
def create_dummy_source def create_dummy_source
path = target.dummy_source_path path = target.dummy_source_path
generator = Generator::DummySource.new(target.label) generator = Generator::DummySource.new(target.label)
generator.save_as(path) update_changed_file(generator, path)
file_reference = add_file_to_support_group(path) file_reference = add_file_to_support_group(path)
native_target.source_build_phase.add_file_reference(file_reference) native_target.source_build_phase.add_file_reference(file_reference)
end end
......
...@@ -89,8 +89,8 @@ module Pod ...@@ -89,8 +89,8 @@ module Pod
path = pod_dir(name) path = pod_dir(name)
path.rmtree if path.exist? path.rmtree if path.exist?
end end
podspe_path = specification_path(name) podspec_path = specification_path(name)
podspe_path.rmtree if podspe_path podspec_path.rmtree if podspec_path
end end
# Prepares the sandbox for a new installation removing any file that will # Prepares the sandbox for a new installation removing any file that will
...@@ -98,7 +98,6 @@ module Pod ...@@ -98,7 +98,6 @@ module Pod
# #
def prepare def prepare
FileUtils.rm_rf(headers_root) FileUtils.rm_rf(headers_root)
FileUtils.rm_rf(target_support_files_root)
FileUtils.mkdir_p(headers_root) FileUtils.mkdir_p(headers_root)
FileUtils.mkdir_p(sources_root) FileUtils.mkdir_p(sources_root)
......
...@@ -276,12 +276,14 @@ module Pod ...@@ -276,12 +276,14 @@ module Pod
describe 'Dependencies Resolution' do describe 'Dependencies Resolution' do
describe 'updating spec repos' do describe 'updating spec repos' do
it 'does not updates the repositories by default' do it 'does not update the repositories by default' do
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
config.sources_manager.expects(:update).never config.sources_manager.expects(:update).never
@installer.send(:resolve_dependencies) @installer.send(:resolve_dependencies)
end end
it 'updates the repositories if that was requested' do it 'updates the repositories if that was requested' do
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
@installer.repo_update = true @installer.repo_update = true
config.sources_manager.expects(:update).once config.sources_manager.expects(:update).once
@installer.send(:resolve_dependencies) @installer.send(:resolve_dependencies)
...@@ -346,12 +348,16 @@ module Pod ...@@ -346,12 +348,16 @@ module Pod
@analysis_result = Installer::Analyzer::AnalysisResult.new @analysis_result = Installer::Analyzer::AnalysisResult.new
@analysis_result.specifications = [] @analysis_result.specifications = []
@analysis_result.sandbox_state = Installer::Analyzer::SpecsState.new @analysis_result.sandbox_state = Installer::Analyzer::SpecsState.new
@pod_targets = [PodTarget.new([stub('Spec')], [fixture_target_definition], config.sandbox)] @spec = stub(:name => 'Spec')
@spec.stubs(:root => @spec)
@pod_targets = [PodTarget.new([@spec], [fixture_target_definition], config.sandbox)]
@installer.stubs(:analysis_result).returns(@analysis_result) @installer.stubs(:analysis_result).returns(@analysis_result)
@installer.stubs(:pod_targets).returns(@pod_targets) @installer.stubs(:pod_targets).returns(@pod_targets)
@installer.stubs(:aggregate_targets).returns([])
end end
it 'cleans the header stores' do it 'cleans the header stores' do
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
config.sandbox.public_headers.expects(:implode!) config.sandbox.public_headers.expects(:implode!)
@installer.pod_targets.each do |pods_target| @installer.pod_targets.each do |pods_target|
pods_target.build_headers.expects(:implode!) pods_target.build_headers.expects(:implode!)
...@@ -360,10 +366,61 @@ module Pod ...@@ -360,10 +366,61 @@ module Pod
end end
it 'deletes the sources of the removed Pods' do it 'deletes the sources of the removed Pods' do
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
@analysis_result.sandbox_state.add_name('Deleted-Pod', :deleted) @analysis_result.sandbox_state.add_name('Deleted-Pod', :deleted)
config.sandbox.expects(:clean_pod).with('Deleted-Pod') config.sandbox.expects(:clean_pod).with('Deleted-Pod')
@installer.send(:clean_sandbox) @installer.send(:clean_sandbox)
end end
it 'deletes the target support file dirs of the removed pod targets' do
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
FileUtils.mkdir_p(@installer.pod_targets.first.support_files_dir)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should == [
'Spec',
]
@installer.stubs(:pod_targets).returns([])
@installer.send(:clean_sandbox)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should.be.empty
end
it 'does not delete the target support file dirs for non removed pod targets' do
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
FileUtils.mkdir_p(@installer.pod_targets.first.support_files_dir)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should == [
'Spec',
]
@installer.send(:clean_sandbox)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should == [
'Spec',
]
end
it 'deletes the target support file dirs of the removed aggregate targets' do
aggregate_target = AggregateTarget.new(fixture_target_definition('MyApp'), config.sandbox)
@installer.stubs(:aggregate_targets).returns([aggregate_target])
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
FileUtils.mkdir_p(@installer.aggregate_targets.first.support_files_dir)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should == [
'Pods-MyApp',
]
@installer.stubs(:aggregate_targets).returns([])
@installer.send(:clean_sandbox)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should.be.empty
end
it 'does not delete the target support file dirs for non removed aggregate targets' do
aggregate_target = AggregateTarget.new(fixture_target_definition('MyApp'), config.sandbox)
@installer.stubs(:aggregate_targets).returns([aggregate_target])
FileUtils.mkdir_p(config.sandbox.target_support_files_root)
FileUtils.mkdir_p(@installer.aggregate_targets.first.support_files_dir)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should == [
'Pods-MyApp',
]
@installer.send(:clean_sandbox)
config.sandbox.target_support_files_root.children.map(&:basename).map(&:to_s).should == [
'Pods-MyApp',
]
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