8000 Integrate execution position for shell script phases by dnkoutso · Pull Request #7101 · CocoaPods/CocoaPods · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Integrate execution position for shell script phases #7101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
0