diff --git a/CHANGELOG.md b/CHANGELOG.md index ba13d35636..01e6cfdbf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ##### Enhancements +* Integrate execution position for shell script phases + [Dimitris Koutsogiorgas](https://github.com/dnkoutso) + [#7101](https://github.com/CocoaPods/CocoaPods/pull/7101) + * Add support to integrate script phases from podspecs [Dimitris Koutsogiorgas](https://github.com/dnkoutso) [#7092](https://github.com/CocoaPods/CocoaPods/pull/7092) diff --git a/Gemfile.lock b/Gemfile.lock index aa76f1d7e7..afb7d6155e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/CocoaPods/Core.git - revision: 3f98bce41fd8eb6d385441eef4e5611665d13e64 + revision: 153c5dfdd02eaac8bec160f6a3b3bc49b07ecf48 branch: master specs: cocoapods-core (1.4.0.beta.1) diff --git a/lib/cocoapods/installer/user_project_integrator/target_integrator.rb b/lib/cocoapods/installer/user_project_integrator/target_integrator.rb index 144781a1d0..acc2e43ab1 100644 --- a/lib/cocoapods/installer/user_project_integrator/target_integrator.rb +++ b/lib/cocoapods/installer/user_project_integrator/target_integrator.rb @@ -165,21 +165,29 @@ def create_or_update_user_script_phases(script_phases, native_target) end # Create or update the ones that are expected to be. script_phases.each do |td_script_phase| - phase = TargetIntegrator.create_or_update_build_phase(native_target, USER_BUILD_PHASE_PREFIX + td_script_phase[:name]) + name_with_prefix = USER_BUILD_PHASE_PREFIX + td_script_phase[:name] + phase = TargetIntegrator.create_or_update_build_phase(native_target, name_with_prefix) phase.shell_script = td_script_phase[:script] phase.shell_path = td_script_phase[:shell_path] if td_script_phase.key?(:shell_path) phase.input_paths = td_script_phase[:input_files] if td_script_phase.key?(:input_files) phase.output_paths = td_script_phase[:output_files] if td_script_phase.key?(:output_files) phase.show_env_vars_in_log = td_script_phase[:show_env_vars_in_log] ? '1' : '0' if td_script_phase.key?(:show_env_vars_in_log) - end - # Move script phases to their correct index if the order has changed. - offset = native_target.build_phases.count - script_phases.count - script_phases.each_with_index do |td_script_phase, index| - current_index = native_target.build_phases.index do |bp| - bp.is_a?(Xcodeproj::Project::Object::PBXShellScriptBuildPhase) && bp.name.sub(USER_BUILD_PHASE_PREFIX, '') == td_script_phase[:name] + + execution_position = td_script_phase[:execution_position] + unless execution_position == :any + compile_build_phase_index = native_target.build_phases.index do |bp| + bp.is_a?(Xcodeproj::Project::Object::PBXSourcesBuildPhase) + end + unless compile_build_phase_index.nil? + script_phase_index = native_target.build_phases.index do |bp| + bp.is_a?(Xcodeproj::Project::Object::PBXShellScriptBuildPhase) && !bp.name.nil? && bp.name == name_with_prefix + end + if (execution_position == :before_compile && script_phase_index > compile_build_phase_index) || + (execution_position == :after_compile && script_phase_index < compile_build_phase_index) + native_target.build_phases.move_from(script_phase_index, compile_build_phase_index) + end + end end - expected_index = offset + index - native_target.build_phases.insert(expected_index, native_target.build_phases.delete_at(current_index)) if current_index != expected_index end end end diff --git a/spec/unit/installer/user_project_integrator/target_integrator_spec.rb b/spec/unit/installer/user_project_integrator/target_integrator_spec.rb index 20174004dc..25f4d69fc6 100644 --- a/spec/unit/installer/user_project_integrator/target_integrator_spec.rb +++ b/spec/unit/installer/user_project_integrator/target_integrator_spec.rb @@ -388,32 +388,50 @@ module Pod target.shell_script_build_phases.find { |bp| bp.name == @user_script_phase_name }.should.be.nil end - it 'moves custom shell scripts to their correct index' do - shell_script_one = { :name => 'Custom Script', :script => 'echo "Hello World"' } + it 'moves custom shell scripts according to their execution position' do + shell_script_one = { :name => 'Custom Script', :script => 'echo "Hello World"', :execution_position => :before_compile } shell_script_two = { :name => 'Custom Script 2', :script => 'echo "Hello Aliens"' } @pod_bundle.target_definition.stubs(:script_phases).returns([shell_script_one, shell_script_two]) @target_integrator.integrate! target = @target_integrator.send(:native_targets).first - target.shell_script_build_phases.map(&:name).should == [ + target.build_phases.map(&:display_name).should == [ '[CP] Check Pods Manifest.lock', + '[CP-User] Custom Script', + 'Sources', + 'Frameworks', + 'Resources', '[CP] Embed Pods Frameworks', '[CP] Copy Pods Resources', - '[CP-User] Custom Script', '[CP-User] Custom Script 2', ] - shell_script_one_uuid = target.shell_script_build_phases[3].uuid - shell_script_two_uuid = target.shell_script_build_phases[4].uuid - @pod_bundle.target_definition.stubs(:script_phases).returns([shell_script_two, shell_script_one]) + shell_script_one = { :name => 'Custom Script', :script => 'echo "Hello World"', :execution_position => :after_compile } + shell_script_two = { :name => 'Custom Script 2', :script => 'echo "Hello Aliens"', :execution_position => :before_compile } + @pod_bundle.target_definition.stubs(:script_phases).returns([shell_script_one, shell_script_two]) @target_integrator.integrate! - target.shell_script_build_phases.map(&:name).should == [ + target.build_phases.map(&:display_name).should == [ '[CP] Check Pods Manifest.lock', + '[CP-User] Custom Script 2', + 'Sources', + '[CP-User] Custom Script', + 'Frameworks', + 'Resources', '[CP] Embed Pods Frameworks', '[CP] Copy Pods Resources', + ] + shell_script_one = { :name => 'Custom Script', :script => 'echo "Hello World"' } + shell_script_two = { :name => 'Custom Script 2', :script => 'echo "Hello Aliens"' } + @pod_bundle.target_definition.stubs(:script_phases).returns([shell_script_one, shell_script_two]) + @target_integrator.integrate! + target.build_phases.map(&:display_name).should == [ + '[CP] Check Pods Manifest.lock', '[CP-User] Custom Script 2', + 'Sources', '[CP-User] Custom Script', + 'Frameworks', + 'Resources', + '[CP] Embed Pods Frameworks', + '[CP] Copy Pods Resources', ] - target.shell_script_build_phases[3].uuid.should == shell_script_two_uuid - target.shell_script_build_phases[4].uuid.should == shell_script_one_uuid end it 'adds, removes and moves custom shell script phases' do @@ -424,8 +442,11 @@ module Pod @pod_bundle.target_definition.stubs(:script_phases).returns([shell_script_one, shell_script_two, shell_script_three]) @target_integrator.integrate! target = @target_integrator.send(:native_targets).first - target.shell_script_build_phases.map(&:name).should == [ + target.build_phases.map(&:display_name).should == [ '[CP] Check Pods Manifest.lock', + 'Sources', + 'Frameworks', + 'Resources', '[CP] Embed Pods Frameworks', '[CP] Copy Pods Resources', '[CP-User] Custom Script', @@ -434,8 +455,11 @@ module Pod ] @pod_bundle.target_definition.stubs(:script_phases).returns([shell_script_two, shell_script_four]) @target_integrator.integrate! - target.shell_script_build_phases.map(&:name).should == [ + target.build_phases.map(&:display_name).should == [ '[CP] Check Pods Manifest.lock', + 'Sources', + 'Frameworks', + 'Resources', '[CP] Embed Pods Frameworks', '[CP] Copy Pods Resources', '[CP-User] Custom Script 2', @@ -449,8 +473,11 @@ module Pod target.new_shell_script_build_phase('User Script Phase 1') target.new_shell_script_build_phase('User Script Phase 2') @target_integrator.integrate! - target.shell_script_build_phases.map(&:name).should == [ + target.build_phases.map(&:display_name).should == [ '[CP] Check Pods Manifest.lock', + 'Sources', + 'Frameworks', + 'Resources', 'User Script Phase 1', 'User Script Phase 2', '[CP] Embed Pods Frameworks', @@ -459,8 +486,11 @@ module Pod ] @pod_bundle.target_definition.stubs(:script_phases).returns([]) @target_integrator.integrate! - target.shell_script_build_phases.map(&:name).should == [ + target.build_phases.map(&:display_name).should == [ '[CP] Check Pods Manifest.lock', + 'Sources', + 'Frameworks', + 'Resources', 'User Script Phase 1', 'User Script Phase 2', '[CP] Embed Pods Frameworks',