Skip to content

Commit

Permalink
[Installer|TargetInstaller] Move code.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Dec 18, 2012
1 parent 2caeb0b commit 06008ef
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
25 changes: 2 additions & 23 deletions lib/cocoapods/installer.rb
Expand Up @@ -445,42 +445,21 @@ def run_post_install_hooks
# Installs the targets of the Pods projects and generates their support
# files.
#
# @todo Move the acknowledgements to the target installer?
#
def generate_target_support_files
UI.message"- Installing targets" do
target_installers.each do |target_installer|
target_installer.install!
acknowledgements_path = target_installer.library.acknowledgements_path
Generator::Acknowledgements.new(target_installer.library.target_definition,
target_installer.library.local_pods).save_as(acknowledgements_path)
generate_dummy_source(target_installer)
end
end
end

# Generates a dummy source file for each target so libraries that contain
# only categories build.
#
# @todo Move to the target installer?
#
def generate_dummy_source(target_installer)
class_name_identifier = target_installer.library.label
dummy_source = Generator::DummySource.new(class_name_identifier)
filename = "#{dummy_source.class_name}.m"
pathname = Pathname.new(sandbox.root + filename)
dummy_source.save_as(pathname)
file = pods_project.new_file(filename, "Targets Support Files")
target_installer.target.source_build_phase.add_file_reference(file)
end

# Writes the Pods project to the disk.
#
# @return [void]
#
def write_pod_project
UI.message "- Writing Xcode project file to #{UI.path @sandbox.project_path}" do
pods_project.save_as(@sandbox.project_path)
UI.message "- Writing Xcode project file to #{UI.path sandbox.project_path}" do
pods_project.save_as(sandbox.project_path)
end
end

Expand Down
24 changes: 24 additions & 0 deletions lib/cocoapods/installer/target_installer.rb
Expand Up @@ -28,6 +28,8 @@ def install!
create_prefix_header
create_bridge_support_file
create_copy_resources_script
create_acknowledgements
create_dummy_source
end

#-----------------------------------------------------------------------#
Expand Down Expand Up @@ -198,6 +200,28 @@ def create_copy_resources_script
end
end

# Generates the acknowledgement files (markdown and plist) for the target.
#
# @return [void]
#
def create_acknowledgements
path = library.acknowledgements_path
Generator::Acknowledgements.new(target_definition, pods).save_as(path)
end

# Generates a dummy source file for each target so libraries that contain
# only categories build.
#
# @return [void]
#
def create_dummy_source
path = library.dummy_source_path
Generator::DummySource.new(library.label).save_as(path)
relative_path = path.relative_path_from(sandbox.root)
file_reference = project.new_file(relative_path, "Targets Support Files")
target.source_build_phase.add_file_reference(file_reference)
end

#-----------------------------------------------------------------------#

# @!group Private helpers.
Expand Down
6 changes: 6 additions & 0 deletions lib/cocoapods/library.rb
Expand Up @@ -177,6 +177,12 @@ def acknowledgements_path
support_files_root + "#{label}-Acknowledgements"
end

# @return [Pathname] the path of the dummy source generated by CocoaPods
#
def dummy_source_path
support_files_root + "PodsDummy_#{label}.m"
end

#-------------------------------------------------------------------------#

# @!group Private Helpers
Expand Down
20 changes: 19 additions & 1 deletion spec/unit/installer/target_installer_spec.rb
Expand Up @@ -123,7 +123,7 @@ module Pod
it 'adds the source files of each pod to the target of the Pod library' do
@installer.install!
names = @installer.target.source_build_phase.files.map { |bf| bf.file_ref.name }
names.should == [ "Banana.m" ]
names.should.include("Banana.m")
end

#--------------------------------------#
Expand Down Expand Up @@ -159,6 +159,24 @@ module Pod
script = config.sandbox.root + 'Pods-resources.sh'
script.read.should.include?('logo-sidebar.png')
end

it "creates the acknowledgements files " do
@installer.install!
markdown = config.sandbox.root + 'Pods-Acknowledgements.markdown'
markdown.read.should.include?('Permission is hereby granted')
plist = config.sandbox.root + 'Pods-Acknowledgements.plist'
plist.read.should.include?('Permission is hereby granted')
end

it "creates a dummy source to ensure the compilation of libraries with only categories" do
@installer.install!
build_files = @installer.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.name == 'PodsDummy_Pods.m' }
build_file.should.be.not.nil
build_file.file_ref.path.should == 'PodsDummy_Pods.m'
dummy = config.sandbox.root + 'PodsDummy_Pods.m'
dummy.read.should.include?('@interface PodsDummy_Pods')
end
end
end
end

0 comments on commit 06008ef

Please sign in to comment.