From 98814ec6acc623890853c235689ea0cd1ae20e32 Mon Sep 17 00:00:00 2001 From: Juan Pablo Civile Date: Thu, 22 Jan 2015 12:12:50 -0300 Subject: [PATCH] Allow custom ordering of script phases Extend the script phase configuration to allow users to specify a specific index for the build phase. --- defaults/liftoffrc | 6 ++++-- lib/liftoff/xcodeproj_helper.rb | 18 ++++++++++++++---- man/liftoffrc.5 | 3 ++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/defaults/liftoffrc b/defaults/liftoffrc index 1d1db64..b7fd501 100644 --- a/defaults/liftoffrc +++ b/defaults/liftoffrc @@ -19,8 +19,10 @@ strict_prompts: false deployment_target: 8.0 run_script_phases: - - todo.sh: Warn for TODO and FIXME comments - - bundle_version.sh: Set version number + - file: todo.sh + name: Warn for TODO and FIXME comments + - file: bundle_version.sh + name: Set version number templates: - travis.yml: .travis.yml diff --git a/lib/liftoff/xcodeproj_helper.rb b/lib/liftoff/xcodeproj_helper.rb index 5406e79..f7f41d5 100644 --- a/lib/liftoff/xcodeproj_helper.rb +++ b/lib/liftoff/xcodeproj_helper.rb @@ -1,5 +1,7 @@ module Liftoff class XcodeprojHelper + LAST_INDEX = -1 + def treat_warnings_as_errors(enable_errors) if enable_errors puts 'Setting GCC_TREAT_WARNINGS_AS_ERRORS for Release builds' @@ -40,9 +42,13 @@ def set_indentation_level(level, use_tabs) def add_script_phases(scripts) if scripts scripts.each do |script| - key, value = script.first - puts "Adding shell script build phase '#{value}'" - add_shell_script_build_phase(file_manager.template_contents(key), value) + + file = script['file'] + name = script['name'] + index = script.fetch('index', LAST_INDEX) + + puts "Adding shell script build phase '#{name}'" + add_shell_script_build_phase(file_manager.template_contents(file), name, index) end end end @@ -79,10 +85,14 @@ def available_targets xcode_project.targets.to_a.reject { |t| t.name.end_with?('Tests') } end - def add_shell_script_build_phase(script, name) + def add_shell_script_build_phase(script, name, index) if build_phase_does_not_exist_with_name?(name) build_phase = target.new_shell_script_build_phase(name) build_phase.shell_script = script + + target.build_phases.delete(build_phase) + target.build_phases.insert(index, build_phase) + xcode_project.save end end diff --git a/man/liftoffrc.5 b/man/liftoffrc.5 index 53cb2f6..8fc483d 100644 --- a/man/liftoffrc.5 +++ b/man/liftoffrc.5 @@ -301,7 +301,8 @@ for more information on the format of this key. .Ic liftoff installs two Run Script Build Phases by default: .Bd -literal - - todo.sh: Warn for TODO and FIXME comments + - file: todo.sh + name: Warn for TODO and FIXME comments .Ed .Pp This script turns any