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

Look for groups matching the test target name outside of the main group #708

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 22 additions & 2 deletions gem/lib/earlgrey/configure_earlgrey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ def has_swift?(target)
def copy_swift_files(project, target, swift_version = nil)
return unless has_swift?(target) || !swift_version.to_s.empty?
project_test_targets = project.main_group.children
test_target_group = project_test_targets.find { |g| g.display_name == target.name }
test_target_group = recursively_find_group_with_name(project_test_targets, target.name)

raise "Test target group not found! #{test_target_group}" unless test_target_group
raise "Test target group not found! An Xcode group with the name '#{target.name}' should exist in your project" unless test_target_group

swift_version ||= '4.0'
src_root = File.join(__dir__, 'files')
Expand Down Expand Up @@ -405,5 +405,25 @@ def copy_swift_files(project, target, swift_version = nil)
target.source_build_phase.add_file_reference earlgrey_swift_file_ref, true
end
end

# Recursively iterate through the group tree. Will return the first group with a matching name
#
# @param [Array<PBXGroup>] Array of groups
# @param [String] the group name to look for
def recursively_find_group_with_name(groups, name)
target_group = groups.find { |g| g.display_name == name }
if target_group.nil?
groups.each do |group|
if group.respond_to?(:children) && !group.children.nil?
target_group = recursively_find_group_with_name(group.children, name)
end
if !target_group.nil?
# Exit early if a group with a matching name has been found
break
end
end
end
return target_group
end
end
end