Skip to content
This repository has been archived by the owner on Jul 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #4 from devxoul/remove-from-target
Browse files Browse the repository at this point in the history
Remove files from targets if not needed any more.
  • Loading branch information
devxoul committed May 13, 2015
2 parents 1d47810 + dd2912a commit b0c6256
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
48 changes: 32 additions & 16 deletions lib/cocoaseeds/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def github(repo, tag, options={})
seed.files = [seed.files]
end
self.seeds[seed.name] = seed
self.targets[@current_target_name] ||= []
self.targets[@current_target_name] << seed
self.targets[seed.name] ||= []
self.targets[seed.name] << @current_target_name.to_s
end
end

Expand Down Expand Up @@ -198,28 +198,44 @@ def configure_project
end

def configure_phase
self.targets.each do |target_name, seeds|
target = self.project.target_named(target_name)
self.project.targets.each do |target|
phase = target.sources_build_phase
if not phase
raise Seeds::Exception.new\
"Target `#{target}` doesn't have build phase 'Compile Sources'."
end
next if not phase

# remove zombie file references
phase.files_references.each do |file_reference|
# remove zombie build files
phase.files_references.each do |file|
begin
file_reference.real_path
file.real_path
rescue
phase.remove_file_reference(file_reference)
phase.files.each do |build_file|
phase.files.delete(build_file) if build_file.file_ref == file
end
end
end

removings = [] # name of seeds going to be removed from the target
addings = [] # name of seeds going to be added to the target

self.targets.keys.sort.each do |seed_name|
target_names = self.targets[seed_name]
if not target_names.include?(target.name)
removings << seed_name if not removings.include?(seed_name)
else
addings << seed_name if not addings.include?(seed_name)
end
end

# add file references to sources build phase
seed_names = seeds.map { |seed| seed.name }
self.file_references.each do |file|
if not phase.include?(file) and seed_names.include?(file.parent.name)
uuid = Digest::MD5.hexdigest("#{target_name}:#{file.name}").upcase
removings.each do |seed_names|
next if not seed_names.include?(file.parent.name)
phase.files.each do |build_file|
phase.files.delete(build_file) if build_file.file_ref == file
end
end

addings.each do |seed_names|
next if not seed_names.include?(file.parent.name)
uuid = Digest::MD5.hexdigest("#{target.name}:#{file.name}").upcase
phase.add_file_reference_with_uuid(file, uuid, true)
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/test_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def test_install_common_before_separated_target
assert\
self.phase(:TestProj).include_filename?(/JLToast.*\.(h|swift)/),
"TestProj should have JLToast files."
refute\
self.phase(:TestProj).include_filename?(/.*SwipeBack\.(h|m)/),
"TestProj shouldn't have SwipeBack files."

assert\
self.phase(:TestProjTests).include_filename?(/.*SwipeBack\.(h|m)/),
"TestProjTests should have SwipeBack files."
Expand All @@ -152,6 +156,10 @@ def test_install_common_after_separated_target
assert\
self.phase(:TestProj).include_filename?(/JLToast.*\.(h|swift)/),
"TestProj should have JLToast files."
refute\
self.phase(:TestProj).include_filename?(/.*SwipeBack\.(h|m)/),
"TestProj shouldn't have SwipeBack files."

assert\
self.phase(:TestProjTests).include_filename?(/.*SwipeBack\.(h|m)/),
"TestProjTests should have SwipeBack files."
Expand Down

0 comments on commit b0c6256

Please sign in to comment.