From 0abbfc33a3827f964ec3f5bd8cf81047d860d9ed Mon Sep 17 00:00:00 2001 From: Mark Larsen Date: Fri, 23 May 2014 15:59:10 -0700 Subject: [PATCH] incorporate some output for the user --- lib/synxronize.rb | 3 +++ lib/synxronize/pbx_file_reference.rb | 29 +++++++++++++++++++++++++++- lib/synxronize/pbx_group.rb | 21 ++++++++++++++++++++ lib/synxronize/project.rb | 5 +++++ synxronize.gemspec | 1 + 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/synxronize.rb b/lib/synxronize.rb index c4d0a30..0fa591d 100644 --- a/lib/synxronize.rb +++ b/lib/synxronize.rb @@ -5,6 +5,9 @@ require "synxronize/pbx_group" require "synxronize/abstract_object" require "synxronize/pbx_native_target" require "synxronize/pbx_variant_group" +require "synxronize/tabber" + +require "colored" module Synxronize end diff --git a/lib/synxronize/pbx_file_reference.rb b/lib/synxronize/pbx_file_reference.rb index 44ba779..785621c 100644 --- a/lib/synxronize/pbx_file_reference.rb +++ b/lib/synxronize/pbx_file_reference.rb @@ -18,9 +18,21 @@ module Xcodeproj self.path = real_path.relative_path_from((project.work_pathname_to_pathname(group.work_pathname))).to_s end change_build_settings_reference + + output + else + Synxronize::Tabber.puts "skipped #{basename}".red end end + def output + build_settings_ammended = "(build settings ammended: #{@setting_keys_changed.join(", ")})" if @setting_keys_changed.count > 0 + removed_from_groups = "(had multiple parent groups, removed from groups: #{@removed_from_groups.join(", ")})" if @removed_from_groups.count > 0 + str_output = "#{basename} #{build_settings_ammended} #{removed_from_groups}" + str_output = str_output.yellow if removed_from_groups || build_settings_ammended + Synxronize::Tabber.puts str_output + end + def should_sync? # Don't sync files that don't exist or are Apple/Build stuff real_path.exist? && !(real_path.to_s =~ /^\$\{(SDKROOT|DEVELOPER_DIR|BUILT_PRODUCTS_DIR)\}/) @@ -34,15 +46,27 @@ module Xcodeproj private :should_move? def ensure_internal_consistency(group) + @removed_from_groups = [] if referring_groups.count > 1 # Files should only have one referring group -- this is an internal consistency issue if there is more than 1. # Just remove all referring groups but the one we're syncing with - referring_groups.each { |rg| rg.remove_reference(self) unless rg == group } + + referring_groups.each do |rg| + unless rg == group + rg.remove_reference(self) unless rg == group + @removed_from_groups << rg.hierarchy_path + end + end + end + + # Duplicates for some reason? + @removed_from_groups.uniq! end # Fixes things like pch, info.plist references being changed def change_build_settings_reference + @setting_keys_changed = [] return unless basename =~ /\.(pch|plist)$/ project.targets.each do |t| @@ -51,10 +75,13 @@ module Xcodeproj setting_value = bs[setting_key] if setting_value == real_path.relative_path_from(project.root_pathname).to_s bs[setting_key] = hierarchy_path[1..-1] + @setting_keys_changed << setting_key end end if bs end end + + @setting_keys_changed.uniq! end end diff --git a/lib/synxronize/pbx_group.rb b/lib/synxronize/pbx_group.rb index 1526082..c7c6627 100644 --- a/lib/synxronize/pbx_group.rb +++ b/lib/synxronize/pbx_group.rb @@ -7,10 +7,15 @@ module Xcodeproj def sync unless excluded_from_sync? + Synxronize::Tabber.puts "#{basename}/".green + Synxronize::Tabber.increase + work_pathname.mkpath files.each { |pbx_file| pbx_file.sync(self) } all_groups.each { |group| group.sync } sync_path + + Synxronize::Tabber.decrease end end @@ -20,13 +25,18 @@ module Xcodeproj def move_entries_not_in_xcodeproj unless excluded_from_sync? + Synxronize::Tabber.increase + Synxronize::Tabber.puts "#{basename}/".green Dir[real_path.to_s + "/*"].each do |entry| entry_pathname = real_path + entry unless has_entry?(entry_pathname) FileUtils.mv(entry_pathname.realpath, work_pathname.to_s) + + puts_unused_file(entry_pathname) end end all_groups.each(&:move_entries_not_in_xcodeproj) + Synxronize::Tabber.decrease end end @@ -52,6 +62,17 @@ module Xcodeproj end private :variant_groups + def puts_unused_file(file_pathname) + source_file_extensions = %W(.h .m .mm .c) + + output = file_pathname.basename.to_s + if source_file_extensions.include?(file_pathname.extname) + output = "#{output} (source file that is not included in Xcode project)".yellow + end + + Synxronize::Tabber.puts output + end + end end end diff --git a/lib/synxronize/project.rb b/lib/synxronize/project.rb index 14cb0f1..9e25774 100644 --- a/lib/synxronize/project.rb +++ b/lib/synxronize/project.rb @@ -19,9 +19,14 @@ module Synxronize end def sync + Synxronize::Tabber.increase + Synxronize::Tabber.puts "Syncing files that are included in Xcode project...".bold.white main_group.all_groups.each(&:sync) + puts "\n\n" + Synxronize::Tabber.puts "Syncing files that are not included in Xcode project..".bold.white main_group.all_groups.each(&:move_entries_not_in_xcodeproj) transplant_work_project + Synxronize::Tabber.decrease save end diff --git a/synxronize.gemspec b/synxronize.gemspec index 921abed..6fd8979 100644 --- a/synxronize.gemspec +++ b/synxronize.gemspec @@ -27,5 +27,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry" spec.add_dependency "clamp" + spec.add_dependency "colored" spec.add_dependency "xcodeproj" end