Commit aa36ea80 authored by Fabio Pelosin's avatar Fabio Pelosin

Added Generator::TargetHeader

- Needs a new name :-)
- Closes #695
parent edb8860a
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
###### TODO ###### TODO
- Add Rake FileList warning. - LocalPod should return a has for the resources.
- Rake FileList is not working. - FileList is not working.
- Enable CocoaPods Core-warnings
- Bad bug with Specification default values being corroded exponentially in subsequent calls. - Bad bug with Specification default values being corroded exponentially in subsequent calls.
- Dropped script for resources. - Drop script for resources.?
- Added support for `prefix_header_file` in subspecs - Add support for `prefix_header_file` in subspecs
- Added support for `prefix_header_contents` in subspecs - Add support for `prefix_header_contents` in subspecs
- Add Rake FileList warning.
- Release: Enable CocoaPods Core-warnings
###### Specification DSL ###### Specification DSL
......
...@@ -35,14 +35,15 @@ module Pod ...@@ -35,14 +35,15 @@ module Pod
autoload :Pathname, 'pathname' autoload :Pathname, 'pathname'
module Generator module Generator
autoload :Acknowledgements, 'cocoapods/generator/acknowledgements'
autoload :BridgeSupport, 'cocoapods/generator/bridge_support' autoload :BridgeSupport, 'cocoapods/generator/bridge_support'
autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script' autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script'
autoload :Documentation, 'cocoapods/generator/documentation' autoload :Documentation, 'cocoapods/generator/documentation'
autoload :Acknowledgements, 'cocoapods/generator/acknowledgements'
autoload :Plist, 'cocoapods/generator/acknowledgements/plist'
autoload :Markdown, 'cocoapods/generator/acknowledgements/markdown'
autoload :DummySource, 'cocoapods/generator/dummy_source' autoload :DummySource, 'cocoapods/generator/dummy_source'
autoload :Markdown, 'cocoapods/generator/acknowledgements/markdown'
autoload :Plist, 'cocoapods/generator/acknowledgements/plist'
autoload :PrefixHeader, 'cocoapods/generator/prefix_header' autoload :PrefixHeader, 'cocoapods/generator/prefix_header'
autoload :TargetHeader, 'cocoapods/generator/target_header'
autoload :XCConfig, 'cocoapods/generator/xcconfig' autoload :XCConfig, 'cocoapods/generator/xcconfig'
end end
......
...@@ -11,12 +11,6 @@ module Pod ...@@ -11,12 +11,6 @@ module Pod
@target_definition, @pods = target_definition, pods @target_definition, @pods = target_definition, pods
end end
def save_as(path)
Acknowledgements.generators.each do |generator|
generator.new(@target_definition, @pods).save_as(path)
end
end
def header_title def header_title
"Acknowledgements" "Acknowledgements"
end end
......
...@@ -19,16 +19,19 @@ module Pod ...@@ -19,16 +19,19 @@ module Pod
# #
attr_reader :pods attr_reader :pods
# @return [Array<String>] any header to import (with quotes).
#
attr_reader :imports
# @param [Platform] platform @see platform # @param [Platform] platform @see platform
# @param [Array<LocalPod>] pods @see pods # @param [Array<LocalPod>] pods @see pods
# #
def initialize(platform, pods) def initialize(platform, pods)
@platform = platform @platform = platform
@pods = pods @pods = pods
@imports = []
end end
#--------------------------------------#
# Generates the contents of the prefix header according to the platform # Generates the contents of the prefix header according to the platform
# and the pods. # and the pods.
# #
...@@ -45,6 +48,10 @@ module Pod ...@@ -45,6 +48,10 @@ module Pod
result << "#import #{platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}\n" result << "#import #{platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}\n"
result << "#endif\n" result << "#endif\n"
imports.each do |import|
result << %|\n#import "#{import}"|
end
pods.each do |pod| pods.each do |pod|
result << "\n" result << "\n"
if prefix_header_contents = pod.top_specification.prefix_header_contents if prefix_header_contents = pod.top_specification.prefix_header_contents
......
module Pod
module Generator
# Generates a header which allows to inspect at compile time the installed
# pods and the installed specifications of a pod.
#
# Example output:
#
# #define __COCOA_PODS
#
# #define __POD_AFIncrementaStore
# #define __POD_AFNetworking
# #define __POD_libextobjc_EXTConcreteProtocol
# #define __POD_libextobjc_EXTKeyPathCoding
# #define __POD_libextobjc_EXTScope
#
# Example usage:
#
# #ifdef __COCOA_PODS
# #ifdef __POD__AFNetworking
# #import "MYLib+AFNetworking.h"
# #endif
# #else
# // Non CocoaPods code
# #endif
#
class TargetHeader
# @return [Array<LocalPod>] the specifications installed for the target.
#
attr_reader :specs
# @param [Array<LocalPod>] pods @see pods
#
def initialize(specs)
@specs = specs
end
# Generates and saves the file.
#
# @param [Pathname] pathname
# The path where to save the generated file.
#
# @return [void]
#
def save_as(pathname)
pathname.open('w') do |source|
source.puts "#define __COCOA_PODS"
source.puts
specs.each do |specs|
source.puts "#define __POD_#{specs.name.gsub(/[^\w]/,'_')}"
end
end
end
end
end
end
...@@ -25,6 +25,7 @@ module Pod ...@@ -25,6 +25,7 @@ module Pod
create_suport_files_group create_suport_files_group
create_xcconfig_file create_xcconfig_file
create_target_header
create_prefix_header create_prefix_header
create_bridge_support_file create_bridge_support_file
create_copy_resources_script create_copy_resources_script
...@@ -188,6 +189,18 @@ module Pod ...@@ -188,6 +189,18 @@ module Pod
end end
end end
# Generates a header which allows to inspect at compile time the installed
# pods and the installed specifications of a pod.
#
def create_target_header
path = library.target_header_path
UI.message "- Creating target header at #{UI.path(path)}" do
generator = Generator::TargetHeader.new(library.specs)
generator.save_as(path)
add_file_to_support_group(path)
end
end
# Creates a prefix header file which imports `UIKit` or `Cocoa` according # Creates a prefix header file which imports `UIKit` or `Cocoa` according
# to the platform of the target. This file also include any prefix header # to the platform of the target. This file also include any prefix header
# content reported by the specification of the pods. # content reported by the specification of the pods.
...@@ -197,8 +210,9 @@ module Pod ...@@ -197,8 +210,9 @@ module Pod
def create_prefix_header def create_prefix_header
path = library.prefix_header_path path = library.prefix_header_path
UI.message "- Generating prefix header at #{UI.path(path)}" do UI.message "- Generating prefix header at #{UI.path(path)}" do
gen = Generator::PrefixHeader.new(target_definition.platform, pods) generator = Generator::PrefixHeader.new(target_definition.platform, pods)
gen.save_as(path) generator.imports << library.target_header_path.basename
generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
target.build_configurations.each do |c| target.build_configurations.each do |c|
......
...@@ -96,50 +96,23 @@ module Pod ...@@ -96,50 +96,23 @@ module Pod
# @!group Support files # @!group Support files
# @return [String] The xcconfig path of the root from the `$(SRCROOT)`
# variable of the user's project.
#
def relative_pods_root
"${SRCROOT}/#{relative_to_srcroot}"
end
# @return [String] the name of the xcconfig file relative to this target.
#
def xcconfig_name
"#{label}.xcconfig"
end
# @return [Pathname] the absolute path of the xcconfig file. # @return [Pathname] the absolute path of the xcconfig file.
# #
def xcconfig_path def xcconfig_path
support_files_root + xcconfig_name support_files_root + "#{label}.xcconfig"
end
# @return [String] the path of the xcconfig file relative to the root of
# the user project.
#
def xcconfig_relative_path
relative_to_srcroot("#{xcconfig_name}").to_s
end
# @return [String] the name of the copy resources script relative to this
# target.
#
def copy_resources_script_name
"#{label}-resources.sh"
end end
# @return [Pathname] the absolute path of the copy resources script. # @return [Pathname] the absolute path of the copy resources script.
# #
def copy_resources_script_path def copy_resources_script_path
support_files_root + copy_resources_script_name support_files_root + "#{label}-resources.sh"
end end
# @return [String] the path of the copy resources script relative to the # @return [Pathname] the absolute path of the header file which contains
# root of the user project. # the information about the installed pods.
# #
def copy_resources_script_relative_path def target_header_path
"${SRCROOT}/#{relative_to_srcroot("#{copy_resources_script_name}")}" support_files_root + "#{label}-header.h"
end end
# @return [Pathname] the absolute path of the prefix header file. # @return [Pathname] the absolute path of the prefix header file.
...@@ -160,13 +133,36 @@ module Pod ...@@ -160,13 +133,36 @@ module Pod
# the file type. # the file type.
# #
def acknowledgements_basepath def acknowledgements_basepath
support_files_root + "#{label}-Acknowledgements" support_files_root + "#{label}-acknowledgements"
end end
# @return [Pathname] the path of the dummy source generated by CocoaPods # @return [Pathname] the path of the dummy source generated by CocoaPods
# #
def dummy_source_path def dummy_source_path
support_files_root + "#{label}-Dummy.m" support_files_root + "#{label}-dummy.m"
end
#--------------------------------------#
# @return [String] The xcconfig path of the root from the `$(SRCROOT)`
# variable of the user's project.
#
def relative_pods_root
"${SRCROOT}/#{support_files_root.relative_path_from(user_project_path.dirname)}"
end
# @return [String] the path of the xcconfig file relative to the root of
# the user project.
#
def xcconfig_relative_path
relative_to_srcroot(xcconfig_path).to_s
end
# @return [String] the path of the copy resources script relative to the
# root of the user project.
#
def copy_resources_script_relative_path
"${SRCROOT}/#{relative_to_srcroot(copy_resources_script_path)}"
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -183,9 +179,8 @@ module Pod ...@@ -183,9 +179,8 @@ module Pod
# #
# @return [String] the computed path. # @return [String] the computed path.
# #
def relative_to_srcroot(path = nil) def relative_to_srcroot(path)
base_path = path ? support_files_root + path : support_files_root path.relative_path_from(user_project_path.dirname).to_s
base_path.relative_path_from(user_project_path.dirname).to_s
end end
end end
end end
...@@ -34,6 +34,18 @@ describe PrefixHeader = Pod::Generator::PrefixHeader do ...@@ -34,6 +34,18 @@ describe PrefixHeader = Pod::Generator::PrefixHeader do
EOS EOS
end end
it "includes the imports" do
@gen.imports << "header.h"
@gen.generate.should == <<-EOS.strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "header.h"
#import <BananaTree/BananaTree.h>
EOS
end
it "prefers the inline specification of the prefix header contents" do it "prefers the inline specification of the prefix header contents" do
spec = @pod.top_specification spec = @pod.top_specification
spec.prefix_header_contents = '#import "BlocksKit.h"' spec.prefix_header_contents = '#import "BlocksKit.h"'
......
require File.expand_path('../../../spec_helper', __FILE__)
describe Pod::Generator::TargetHeader do
before do
specification = fixture_spec('banana-lib/BananaLib.podspec')
@gen = Pod::Generator::TargetHeader.new([specification])
end
it "generates a header files wihc include the CocoaPods definition" do
file = temporary_directory + 'PodsDummy.m'
@gen.save_as(file)
file.read.should == <<-EOS.strip_heredoc
#define __COCOA_PODS
#define __POD_BananaLib
EOS
end
end
...@@ -20,6 +20,7 @@ module Pod ...@@ -20,6 +20,7 @@ module Pod
@library.user_project_path = config.sandbox.root + '../user_project.xcodeproj' @library.user_project_path = config.sandbox.root + '../user_project.xcodeproj'
@library.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug } @library.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug }
specification = fixture_spec('banana-lib/BananaLib.podspec') specification = fixture_spec('banana-lib/BananaLib.podspec')
@library.specs = [specification]
@pod = LocalPod.new(specification, config.sandbox, @library.platform) @pod = LocalPod.new(specification, config.sandbox, @library.platform)
@library.local_pods = [@pod] @library.local_pods = [@pod]
...@@ -34,9 +35,10 @@ module Pod ...@@ -34,9 +35,10 @@ module Pod
@installer.install! @installer.install!
group = @project.support_files_group['Pods'] group = @project.support_files_group['Pods']
group.children.map(&:display_name).sort.should == [ group.children.map(&:display_name).sort.should == [
"Pods-Acknowledgements.markdown", "Pods-acknowledgements.markdown",
"Pods-Acknowledgements.plist", "Pods-acknowledgements.plist",
"Pods-Dummy.m", "Pods-dummy.m",
"Pods-header.h",
"Pods-prefix.pch", "Pods-prefix.pch",
"Pods-resources.sh", "Pods-resources.sh",
"Pods.xcconfig" "Pods.xcconfig"
...@@ -147,6 +149,14 @@ module Pod ...@@ -147,6 +149,14 @@ module Pod
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods' xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end end
it "creates a header for the target which contains the information about the installed Pods" do
@installer.install!
file = config.sandbox.root + 'Pods-header.h'
contents = file.read
contents.should.include?('#define __COCOA_PODS')
contents.should.include?('#define __POD_BananaLib')
end
it "creates a prefix header, including the contents of the specification's prefix header" do it "creates a prefix header, including the contents of the specification's prefix header" do
@pod.top_specification.prefix_header_contents = '#import "BlocksKit.h"' @pod.top_specification.prefix_header_contents = '#import "BlocksKit.h"'
@installer.install! @installer.install!
...@@ -156,6 +166,7 @@ module Pod ...@@ -156,6 +166,7 @@ module Pod
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#endif #endif
#import "Pods-header.h"
#import "BlocksKit.h" #import "BlocksKit.h"
EOS EOS
end end
...@@ -183,10 +194,10 @@ module Pod ...@@ -183,10 +194,10 @@ module Pod
it "creates a dummy source to ensure the compilation of libraries with only categories" do it "creates a dummy source to ensure the compilation of libraries with only categories" do
@installer.install! @installer.install!
build_files = @installer.target.source_build_phase.files build_files = @installer.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.name == 'Pods-Dummy.m' } build_file = build_files.find { |bf| bf.file_ref.name == 'Pods-dummy.m' }
build_file.should.be.not.nil build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-Dummy.m' build_file.file_ref.path.should == 'Pods-dummy.m'
dummy = config.sandbox.root + 'Pods-Dummy.m' dummy = config.sandbox.root + 'Pods-dummy.m'
dummy.read.should.include?('@interface PodsDummy_Pods') dummy.read.should.include?('@interface PodsDummy_Pods')
end end
end end
......
...@@ -34,28 +34,16 @@ module Pod ...@@ -34,28 +34,16 @@ module Pod
@lib.user_project_path = config.sandbox.root + '../user_project.xcodeproj' @lib.user_project_path = config.sandbox.root + '../user_project.xcodeproj'
end end
it "returns the xcconfig name" do
@lib.xcconfig_name.should == 'Pods.xcconfig'
end
it "returns the absolute path of the xcconfig file" do it "returns the absolute path of the xcconfig file" do
@lib.xcconfig_path.to_s.should.include?('Pods/Pods.xcconfig') @lib.xcconfig_path.to_s.should.include?('Pods/Pods.xcconfig')
end end
it "returns the path of the xcconfig file relative to the user project" do
@lib.xcconfig_relative_path.should == 'Pods/Pods.xcconfig'
end
it "returns the resources script name" do
@lib.copy_resources_script_name.should == 'Pods-resources.sh'
end
it "returns the absolute path of the resources script" do it "returns the absolute path of the resources script" do
@lib.copy_resources_script_path.to_s.should.include?('Pods/Pods-resources.sh') @lib.copy_resources_script_path.to_s.should.include?('Pods/Pods-resources.sh')
end end
it "returns the path of the resources script relative to the user project" do it "returns the absolute path of the target header file" do
@lib.copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Pods-resources.sh' @lib.target_header_path.to_s.should.include?('Pods/Pods-header.h')
end end
it "returns the absolute path of the prefix header file" do it "returns the absolute path of the prefix header file" do
...@@ -67,8 +55,19 @@ module Pod ...@@ -67,8 +55,19 @@ module Pod
end end
it "returns the absolute path of the acknowledgements files without extension" do it "returns the absolute path of the acknowledgements files without extension" do
@lib.acknowledgements_basepath.to_s.should.include?('Pods/Pods-Acknowledgements') @lib.acknowledgements_basepath.to_s.should.include?('Pods/Pods-acknowledgements')
end end
#--------------------------------------#
it "returns the path of the resources script relative to the user project" do
@lib.copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Pods-resources.sh'
end
it "returns the path of the xcconfig file relative to the user project" do
@lib.xcconfig_relative_path.should == 'Pods/Pods.xcconfig'
end
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment