-
Notifications
You must be signed in to change notification settings - Fork 104
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
Allow custom ordering of script phases (#204) #210
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,19 @@ 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) | ||
|
||
# -1 means last as index | ||
if script.length > 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of supporting multiple formats, maybe we should just switch to this format and make the |
||
file = script["file"] | ||
name = script["name"] | ||
index = script.fetch("index", -1) | ||
else | ||
file, name = script.first | ||
index = -1 | ||
end | ||
|
||
puts "Adding shell script build phase '#{name}'" | ||
add_shell_script_build_phase(file_manager.template_contents(file), name, index) | ||
end | ||
end | ||
end | ||
|
@@ -79,10 +89,22 @@ 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 | ||
|
||
# This is not the prettiest way of achieving this but I found no other way | ||
# There's probably another way that people that actually know Ruby could think of | ||
target.build_phases.delete(build_phase) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, unfortunately, I think this is the best way to handle this. |
||
|
||
# Sanitize values so that no exception come about | ||
if index >= target.build_phases.length || index < -1 | ||
index = -1 | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels overly defensive to me. I don't think we need this check. Trust the user to not be an idiot. |
||
|
||
target.build_phases.insert(index, build_phase) | ||
|
||
xcode_project.save | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding this comment, maybe make a constant to hold the value:
LAST_INDEX = -1