Skip to content
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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
30 changes: 26 additions & 4 deletions lib/liftoff/xcodeproj_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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

if script.length > 1
Copy link
Member

Choose a reason for hiding this comment

The 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 index key optional. That way, we don't need this conditional.

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
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
10 changes: 10 additions & 0 deletions man/liftoffrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ This script turns any
or
.Ic FIXME
comments into warnings at compilation time.
.Pp
You can also customize when your build phase is executed by using the following
syntax:
.Bd -literal
- file: todo.sh
name: Warn for TODO and FIXME comments
index: 1
.Ed
.Pp
This will insert the same script phase at the index 1 in the build phase list.
.
.Sh WARNINGS
.Ic liftoff
Expand Down