Commit 4d9fecdf authored by Eloy Duran's avatar Eloy Duran

Add a separate Podfile class which has a friendlier DSL. Closes #26.

parent 2716b347
Pod::File.new do |f|
f.platform = :ios
f.dependency 'AFNetworking'
f.dependency 'FormatterKit'
end
platform :ios
dependency 'AFNetworking'
dependency 'FormatterKit'
Pod::File.new do |f|
f.platform = :ios
f.dependency 'MGSplitViewController', '1.0.0'
end
platform :ios
dependency 'MGSplitViewController', '1.0.0'
......@@ -126,6 +126,7 @@
51657564144AFA12002A4EFA /* Sources */,
51657565144AFA12002A4EFA /* Frameworks */,
51657566144AFA12002A4EFA /* Resources */,
51F33E491450BB7D00C19A4B /* ShellScript */,
);
buildRules = (
);
......@@ -177,6 +178,23 @@
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
51F33E491450BB7D00C19A4B /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${SRCROOT}/Pods/PodsResources.sh";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
51657564144AFA12002A4EFA /* Sources */ = {
isa = PBXSourcesBuildPhase;
......
Pod::File.new do |f|
f.platform = :osx
f.generate_bridge_support = true
f.dependency 'ASIHTTPRequest'
f.dependency 'AFNetworking'
f.dependency 'CocoaLumberjack'
end
platform :osx
generate_bridge_support!
dependency 'ASIHTTPRequest'
dependency 'CocoaLumberjack'
Pod::File.new do |f|
f.platform = :ios
f.dependency 'RestKit-ObjectMapping'
f.dependency 'RestKit-JSON-JSONKit'
end
platform :ios
dependency 'RestKit-ObjectMapping'
dependency 'RestKit-JSON-JSONKit'
Pod::File.new do |f|
f.platform = :ios
f.dependency 'SSToolkit'
f.dependency 'AFNetworking'
end
platform :ios
dependency 'SSToolkit'
dependency 'AFNetworking'
......@@ -11,6 +11,7 @@ module Pod
autoload :Downloader, 'cocoapods/downloader'
autoload :Executable, 'cocoapods/executable'
autoload :Installer, 'cocoapods/installer'
autoload :Podfile, 'cocoapods/podfile'
autoload :Resolver, 'cocoapods/resolver'
autoload :Source, 'cocoapods/source'
autoload :Spec, 'cocoapods/specification'
......
......@@ -17,9 +17,9 @@ module Pod
def create_in(root)
puts "==> Generating BridgeSupport metadata file" unless config.silent?
cflags = %{-c "#{search_paths.join(' ')}"}
output = %{-o '#{root + "Pods.bridgesupport"}'}
gen_bridge_metadata %{#{cflags} #{output} '#{headers.join("' '")}'}
file = root + "Pods.bridgesupport"
gen_bridge_metadata %{-c "#{search_paths.join(' ')}" -o '#{file}' '#{headers.join("' '")}'}
file
end
end
end
......@@ -16,7 +16,7 @@ module Pod
alias_method :silent?, :silent
def initialize
@repos_dir = Pathname.new(::File.expand_path("~/.cocoapods"))
@repos_dir = Pathname.new(File.expand_path("~/.cocoapods"))
@clean = true
@verbose = false
@silent = false
......@@ -43,7 +43,13 @@ module Pod
# Returns the spec at the pat returned from `project_podfile`.
def rootspec
unless @rootspec
@rootspec = Specification.from_file(project_podfile) if project_podfile
if project_podfile
if project_podfile.basename.to_s == 'Podfile'
@rootspec = Podfile.from_file(project_podfile)
else
@rootspec = Specification.from_file(project_podfile)
end
end
end
@rootspec
end
......
......@@ -62,7 +62,7 @@ module Pod
end
def copy_resources_script
Xcode::CopyResourcesScript.new(build_specifications.map { |spec| spec.expanded_resources }.flatten)
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map { |spec| spec.expanded_resources }.flatten)
end
def bridge_support_generator
......@@ -81,8 +81,11 @@ module Pod
root = config.project_pods_root
xcodeproj.create_in(root)
xcconfig.create_in(root)
if @specification.generate_bridge_support?
path = bridge_support_generator.create_in(root)
copy_resources_script.resources << path.relative_path_from(config.project_pods_root)
end
copy_resources_script.create_in(root)
bridge_support_generator.create_in(root) if @specification.generate_bridge_support
build_specifications.each(&:post_install)
end
......
module Pod
class Podfile
def self.from_file(path)
podfile = Podfile.new do
eval(path.read, nil, path.to_s)
end
podfile.defined_in_file = path
podfile.validate!
podfile
end
def initialize(&block)
@dependencies = []
instance_eval(&block)
end
# Specifies the platform for which a static library should be build.
#
# This can be either `:osx` for Mac OS X applications, or `:ios` for iOS
# applications.
def platform(platform = nil)
platform ? @platform = platform : @platform
end
# Specifies a dependency of the project.
#
# A dependency requirement is defined by the name of the Pod and _optionally_
# a list of version requirements.
#
#
# When starting out with a project it is likely that you will want to use the
# latest version of a Pod. If this is the case, simply omit the version
# requirements.
#
# dependency 'SSZipArchive'
#
#
# Later on in the project you may want to freeze to a specific version of a
# Pod, in which case you can specify that version number.
#
# dependency 'Objection', '0.9'
#
#
# Besides no version, or a specific one, it is also possible to use operators:
#
# * `> 0.1` Any version higher than 0.1
# * `>= 0.1` Version 0.1 and any higher version
# * `< 0.1` Any version lower than 0.1
# * `<= 0.1` Version 0.1 and any lower version
# * `~> 0.1.2` Version 0.1.2 and the versions upto 0.2, not including 0.2
#
#
# Finally, a list of version requirements can be specified for even more fine
# grained control.
def dependency(name, *version_requirements)
@dependencies << Dependency.new(name, *version_requirements)
end
attr_reader :dependencies
# Specifies that a BridgeSupport metadata should be generated from the
# headers of all installed Pods.
#
# This is for scripting languages such as MacRuby, Nu, and JSCocoa, which use
# it to bridge types, functions, etc better.
def generate_bridge_support!
@generate_bridge_support = true
end
# This is to be compatible with a Specification for use in the Installer and
# Resolver.
def podfile?
true
end
attr_accessor :defined_in_file
def generate_bridge_support?
@generate_bridge_support
end
def dependency_by_name(name)
@dependencies.find { |d| d.name == name }
end
def validate!
lines = []
lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless [:osx, :ios].include?(@platform)
lines << "* no dependencies were specified, which is, well, kinda pointless" if @dependencies.empty?
raise(Informative, (["The Podfile at `#{@defined_in_file}' is invalid:"] + lines).join("\n")) unless lines.empty?
end
end
end
......@@ -28,7 +28,7 @@ module Pod
def validate_platform!(set)
spec = set.specification
unless spec.any_platform? || spec.platform == @specification.platform
unless spec.platform.nil? || spec.platform == @specification.platform
raise Informative, "The platform required by the Podfile (:#{@specification.platform}) " \
"does not match that of #{spec} (:#{spec.platform})"
end
......
......@@ -5,10 +5,10 @@ module Pod
eval(path.read, nil, path.to_s)
end
class Specification
class Specification
autoload :Set, 'cocoapods/specification/set'
# The file is expected to define and return either a Pods::Specification or a Pod::File.
# The file is expected to define and return a Pods::Specification.
def self.from_file(path)
spec = Pod._eval_podspec(path)
spec.defined_in_file = path
......@@ -79,14 +79,6 @@ module Pod
end
attr_reader :clean_paths
def dependency(*name_and_version_requirements)
name, *version_requirements = name_and_version_requirements.flatten
dep = Dependency.new(name, *version_requirements)
@dependencies << dep
dep
end
attr_reader :dependencies
def xcconfig=(hash)
@xcconfig.merge!(hash)
end
......@@ -111,8 +103,6 @@ module Pod
@header_dir || pod_destroot_name
end
attr_accessor :requires_arc
attr_writer :compiler_flags
def compiler_flags
flags = "#{@compiler_flags} "
......@@ -120,9 +110,22 @@ module Pod
flags
end
# These are attributes which are also on a Podfile
attr_accessor :platform
attr_accessor :requires_arc
attr_accessor :generate_bridge_support
alias_method :generate_bridge_support?, :generate_bridge_support
def dependency(*name_and_version_requirements)
name, *version_requirements = name_and_version_requirements.flatten
dep = Dependency.new(name, *version_requirements)
@dependencies << dep
dep
end
attr_reader :dependencies
# Not attributes
......@@ -171,10 +174,6 @@ module Pod
false
end
def any_platform?
platform.nil?
end
# Returns all resource files of this pod, but relative to the
# project pods root.
def expanded_resources
......@@ -342,18 +341,4 @@ module Pod
end
Spec = Specification
class File < Specification
def podfile?
true
end
def to_s
"podfile at `#{defined_in_file}'"
end
def pod_destroot
# A Podfile has none
end
end
end
module Pod
module Xcode
class CopyResourcesScript
attr_reader :resources
# A list of files relative to the project pods root.
def initialize(resources)
@resources = resources
......
......@@ -220,9 +220,9 @@ module Pod
# TODO this is a workaround for an issue with MacRuby with compiled files
# that makes the use of __FILE__ impossible.
#
#TEMPLATES_DIR = Pathname.new(::File.expand_path('../../../../xcode-project-templates', __FILE__))
#TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', __FILE__))
file = $LOADED_FEATURES.find { |file| file =~ %r{cocoapods/xcode/project\.rbo?$} }
TEMPLATES_DIR = Pathname.new(::File.expand_path('../../../../xcode-project-templates', file))
TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', file))
def self.static_library(platform)
case platform
......
Pod::File.new do |f|
f.platform = :ios
f.dependency 'SSZipArchive', '>= 1'
f.dependency 'ASIHTTPRequest', '~> 1.8.0'
f.dependency 'Reachability' # part of ASIHTTPRequest
f.dependency 'ASIWebPageRequest', '< 1.8.2' # part of ASIHTTPRequest
end
platform :ios
dependency 'SSZipArchive', '>= 1'
dependency 'ASIHTTPRequest', '~> 1.8.0'
dependency 'Reachability' # part of ASIHTTPRequest
dependency 'ASIWebPageRequest', '< 1.8.2' # part of ASIHTTPRequest
......@@ -44,11 +44,11 @@ else
# TODO add a simple source file which uses the compiled lib to check that it really really works
it "should activate required pods and create a working static library xcode project" do
spec = Pod::File.new do |s|
s.platform = platform
s.dependency 'ASIWebPageRequest', '>= 1.8.1'
s.dependency 'JSONKit', '>= 1.0'
s.dependency 'SSZipArchive', '< 2'
spec = Pod::Podfile.new do
self.platform platform
dependency 'ASIWebPageRequest', '>= 1.8.1'
dependency 'JSONKit', '>= 1.0'
dependency 'SSZipArchive', '< 2'
end
installer = SpecHelper::Installer.new(spec)
......@@ -74,9 +74,9 @@ else
end
it "does not activate pods that are only part of other pods" do
spec = Pod::File.new do |s|
s.platform = platform
s.dependency 'Reachability'
spec = Pod::Podfile.new do
self.platform platform
dependency 'Reachability'
end
installer = SpecHelper::Installer.new(spec)
......@@ -87,9 +87,9 @@ else
end
it "adds resources to the xcode copy script" do
spec = Pod::File.new do |s|
s.platform = platform
s.dependency 'SSZipArchive'
spec = Pod::Podfile.new do
self.platform platform
dependency 'SSZipArchive'
end
installer = SpecHelper::Installer.new(spec)
......@@ -104,18 +104,18 @@ else
# TODO we need to do more cleaning and/or add a --prune task
it "overwrites an existing project.pbxproj file" do
spec = Pod::File.new do |s|
s.platform = platform
s.dependency 'JSONKit'
spec = Pod::Podfile.new do
self.platform platform
dependency 'JSONKit'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
Pod::Source.reset!
Pod::Spec::Set.reset!
spec = Pod::File.new do |s|
s.platform = platform
s.dependency 'SSZipArchive'
spec = Pod::Podfile.new do
self.platform platform
dependency 'SSZipArchive'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
......
require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Podfile" do
it "loads from a file" do
podfile = Pod::Podfile.from_file(fixture('Podfile'))
podfile.defined_in_file.should == fixture('Podfile')
end
it "assigns the platform attribute" do
podfile = Pod::Podfile.new { platform :ios }
podfile.platform.should == :ios
end
it "adds dependencies" do
podfile = Pod::Podfile.new { dependency 'ASIHTTPRequest'; dependency 'SSZipArchive', '>= 0.1' }
podfile.dependencies.size.should == 2
podfile.dependency_by_name('ASIHTTPRequest').should == Pod::Dependency.new('ASIHTTPRequest')
podfile.dependency_by_name('SSZipArchive').should == Pod::Dependency.new('SSZipArchive', '>= 0.1')
end
it "specifies if BridgeSupport metadata should be generated" do
podfile = Pod::Podfile.new { generate_bridge_support! }
podfile.generate_bridge_support?.should == true
end
describe "concerning validations" do
it "raises if no platform is specified" do
exception = lambda {
Pod::Podfile.new {}.validate!
}.should.raise Pod::Informative
exception.message.should.include "platform"
end
it "raises if an invalid platform is specified" do
exception = lambda {
Pod::Podfile.new { platform :windows }.validate!
}.should.raise Pod::Informative
exception.message.should.include "platform"
end
it "raises if no dependencies were specified" do
exception = lambda {
Pod::Podfile.new {}.validate!
}.should.raise Pod::Informative
exception.message.should.include "dependencies"
end
end
end
require File.expand_path('../../spec_helper', __FILE__)
describe "A Pod::Specification loaded from a Podfile" do
before do
@spec = Pod::Specification.from_file(fixture('Podfile'))
end
it "lists the project's dependencies" do
@spec.dependencies.should == [
Pod::Dependency.new('SSZipArchive', '>= 1'),
Pod::Dependency.new('ASIHTTPRequest', '~> 1.8.0'),
Pod::Dependency.new('Reachability', '>= 0'),
Pod::Dependency.new('ASIWebPageRequest', ' < 1.8.2')
]
end
it "returns the path to the Podfile" do
@spec.defined_in_file.should == fixture('Podfile')
end
it "returns that it's loaded from a Podfile" do
@spec.should.be.podfile
end
it "does not have a destroot" do
@spec.pod_destroot.should == nil
end
end
describe "A Pod::Specification loaded from a podspec" do
before do
@spec = Pod::Specification.from_file(fixture('banana-lib/BananaLib.podspec'))
......@@ -286,9 +259,7 @@ describe "A Pod::Specification, in general," do
end
it "returns the platform that the static library should be build for" do
@spec.should.be.any_platform
@spec.platform = :ios
@spec.platform.should == :ios
@spec.should.not.be.any_platform
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