Skip to content

Commit

Permalink
Add shortcuts to the spec for frameworks and libraries. Closes #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Sep 19, 2011
1 parent 08c2979 commit e91db0a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
16 changes: 14 additions & 2 deletions lib/cocoapods/specification.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.from_podspec(path)


def initialize(&block) def initialize(&block)
@dependencies = [] @dependencies = []
@xcconfig = {} @xcconfig = Xcode::Config.new
instance_eval(&block) if block_given? instance_eval(&block) if block_given?
end end


Expand Down Expand Up @@ -87,9 +87,21 @@ def dependency(name, *version_requirements)
end end


def xcconfig(hash) def xcconfig(hash)
@xcconfig = hash @xcconfig.merge!(hash)
end end


def frameworks(*frameworks)
frameworks.unshift('')
xcconfig 'OTHER_LDFLAGS' => frameworks.join(' -framework ').strip
end
alias_method :framework, :frameworks

def libraries(*libraries)
libraries.unshift('')
xcconfig 'OTHER_LDFLAGS' => libraries.join(' -l ').strip
end
alias_method :library, :libraries

# Not attributes # Not attributes


include Config::Mixin include Config::Mixin
Expand Down
8 changes: 4 additions & 4 deletions lib/cocoapods/xcode/config.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,17 +1,17 @@
module Pod module Pod
module Xcode module Xcode
class Config class Config
def initialize(xcconfig_hash = {}) def initialize(xcconfig = {})
@attributes = {} @attributes = {}
merge!(xcconfig_hash) merge!(xcconfig)
end end


def to_hash def to_hash
@attributes @attributes
end end


def merge!(xcconfig_hash) def merge!(xcconfig)
xcconfig_hash.each do |key, value| xcconfig.to_hash.each do |key, value|
if existing_value = @attributes[key] if existing_value = @attributes[key]
@attributes[key] = "#{existing_value} #{value}" @attributes[key] = "#{existing_value} #{value}"
else else
Expand Down
2 changes: 1 addition & 1 deletion spec/functional/command_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def command.master_repo_url; SpecHelper.fixture('spec-repos/master'); end
spec.read(:source).should == { :git => 'http://example.com/Bananas.git', :tag => '1.0.0' } spec.read(:source).should == { :git => 'http://example.com/Bananas.git', :tag => '1.0.0' }
spec.read(:description).should == 'An optional longer description of Bananas.' spec.read(:description).should == 'An optional longer description of Bananas.'
spec.read(:source_files).should == [Pathname.new('Classes'), Pathname.new('Classes/**/*.{h,m}')] spec.read(:source_files).should == [Pathname.new('Classes'), Pathname.new('Classes/**/*.{h,m}')]
spec.read(:xcconfig).should == { 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework' } spec.read(:xcconfig).to_hash.should == { 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework' }
spec.read(:dependencies).should == [Pod::Dependency.new('SomeLibraryThatBananasDependsOn', '>= 1.0.0')] spec.read(:dependencies).should == [Pod::Dependency.new('SomeLibraryThatBananasDependsOn', '>= 1.0.0')]
end end


Expand Down
18 changes: 17 additions & 1 deletion spec/unit/specification_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -92,11 +92,27 @@
end end


it "returns the pod's xcconfig settings" do it "returns the pod's xcconfig settings" do
@spec.read(:xcconfig).should == { @spec.read(:xcconfig).to_hash.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration' 'OTHER_LDFLAGS' => '-framework SystemConfiguration'
} }
end end


it "has a shortcut to add frameworks to the xcconfig" do
@spec.frameworks('CFNetwork', 'CoreText')
@spec.read(:xcconfig).to_hash.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration ' \
'-framework CFNetwork ' \
'-framework CoreText'
}
end

it "has a shortcut to add libraries to the xcconfig" do
@spec.libraries('z', 'xml2')
@spec.read(:xcconfig).to_hash.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration -l z -l xml2'
}
end

it "returns that it's equal to another specification if the name and version are equal" do it "returns that it's equal to another specification if the name and version are equal" do
@spec.should == Pod::Spec.new { name 'BananaLib'; version '1.0' } @spec.should == Pod::Spec.new { name 'BananaLib'; version '1.0' }
@spec.should.not == Pod::Spec.new { name 'OrangeLib'; version '1.0' } @spec.should.not == Pod::Spec.new { name 'OrangeLib'; version '1.0' }
Expand Down

0 comments on commit e91db0a

Please sign in to comment.