Commit 14228a83 authored by Eloy Duran's avatar Eloy Duran

Make Specification attributes that take platform specific values work.

parent 918619a6
GIT GIT
remote: git://github.com/CocoaPods/Xcodeproj.git remote: git://github.com/CocoaPods/Xcodeproj.git
revision: 338e4d37f282121754f10f6d169256a57a64860d revision: 21d9afe2ffde71f15b7a77a43d8fa97552eb6044
specs: specs:
xcodeproj (0.1.0) xcodeproj (0.1.0)
...@@ -15,7 +15,7 @@ GEM ...@@ -15,7 +15,7 @@ GEM
kicker (2.5.0) kicker (2.5.0)
rb-fsevent rb-fsevent
metaclass (0.0.1) metaclass (0.0.1)
mocha (0.10.4) mocha (0.10.5)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mocha-on-bacon (0.2.0) mocha-on-bacon (0.2.0)
mocha (>= 0.9.8) mocha (>= 0.9.8)
...@@ -23,7 +23,7 @@ GEM ...@@ -23,7 +23,7 @@ GEM
rake (0.9.2.2) rake (0.9.2.2)
rb-fsevent (0.9.0) rb-fsevent (0.9.0)
vcr (2.0.0) vcr (2.0.0)
webmock (1.8.0) webmock (1.8.4)
addressable (>= 2.2.7) addressable (>= 2.2.7)
crack (>= 0.1.7) crack (>= 0.1.7)
......
...@@ -31,9 +31,14 @@ module Pod ...@@ -31,9 +31,14 @@ module Pod
# TODO This is just to work around a MacRuby bug # TODO This is just to work around a MacRuby bug
def post_initialize def post_initialize
@dependencies, @source_files, @resources, @clean_paths, @subspecs = [], [], [], [], [] @define_for_platforms = [:osx, :ios]
#@dependencies, @source_files, @resources, @clean_paths, @subspecs = [], [], [], [], []
@clean_paths, @subspecs = [], []
@dependencies, @source_files, @resources = {}, {}, {}
@platform = Platform.new(nil) @platform = Platform.new(nil)
@xcconfig = Xcodeproj::Config.new #@xcconfig = Xcodeproj::Config.new
@xcconfig = {}
@compiler_flags = {}
end end
# Attributes **without** multiple platform support # Attributes **without** multiple platform support
...@@ -108,7 +113,11 @@ module Pod ...@@ -108,7 +113,11 @@ module Pod
end end
attr_reader :platform attr_reader :platform
attr_accessor :requires_arc def requires_arc=(requires_arc)
self.compiler_flags = '-fobjc-arc' if requires_arc
@requires_arc = requires_arc
end
attr_reader :requires_arc
def subspec(name, &block) def subspec(name, &block)
subspec = Subspec.new(self, name, &block) subspec = Subspec.new(self, name, &block)
...@@ -119,19 +128,47 @@ module Pod ...@@ -119,19 +128,47 @@ module Pod
### Attributes **with** multiple platform support ### Attributes **with** multiple platform support
class PlatformProxy
def initialize(specification, platform)
@specification, @platform = specification, platform
end
%w{ source_files= resource= resources= xcconfig= framework= frameworks= library= libraries= compiler_flags= dependency }.each do |method|
define_method(method) do |args|
@specification._on_platform(@platform) do
@specification.send(method, args)
end
end
end
end
def ios
PlatformProxy.new(self, :ios)
end
def osx
PlatformProxy.new(self, :osx)
end
def source_files=(patterns) def source_files=(patterns)
@source_files = pattern_list(patterns) @define_for_platforms.each do |platform|
@source_files[platform] = pattern_list(patterns)
end
end end
attr_reader :source_files attr_reader :source_files
def resources=(patterns) def resources=(patterns)
@resources = pattern_list(patterns) @define_for_platforms.each do |platform|
@resources[platform] = pattern_list(patterns)
end
end end
attr_reader :resources attr_reader :resources
alias_method :resource=, :resources= alias_method :resource=, :resources=
def xcconfig=(hash) def xcconfig=(build_settings)
@xcconfig.merge!(hash) @define_for_platforms.each do |platform|
(@xcconfig[platform] ||= Xcodeproj::Config.new).merge!(build_settings)
end
end end
attr_reader :xcconfig attr_reader :xcconfig
...@@ -147,23 +184,39 @@ module Pod ...@@ -147,23 +184,39 @@ module Pod
end end
alias_method :library=, :libraries= alias_method :library=, :libraries=
attr_writer :compiler_flags attr_reader :compiler_flags
def compiler_flags def compiler_flags=(flags)
flags = "#{@compiler_flags}" @define_for_platforms.each do |platform|
flags << ' -fobjc-arc' if requires_arc if @compiler_flags[platform]
flags @compiler_flags[platform] << ' ' << flags
else
@compiler_flags[platform] = flags.dup
end
end
end end
def dependency(*name_and_version_requirements) def dependency(*name_and_version_requirements)
name, *version_requirements = name_and_version_requirements.flatten name, *version_requirements = name_and_version_requirements.flatten
dep = Dependency.new(name, *version_requirements) dep = Dependency.new(name, *version_requirements)
@dependencies << dep @define_for_platforms.each do |platform|
(@dependencies[platform] ||= []) << dep
end
dep dep
end end
attr_reader :dependencies attr_reader :dependencies
### Not attributes ### Not attributes
# @visibility private
#
# This is used by PlatformProxy to assign attributes for the scoped platform.
def _on_platform(platform)
before, @define_for_platforms = @define_for_platforms, [platform]
yield
ensure
@define_for_platforms = before
end
include Config::Mixin include Config::Mixin
def local? def local?
......
...@@ -454,7 +454,7 @@ describe "A Pod::Specification, concerning its attributes that support different ...@@ -454,7 +454,7 @@ describe "A Pod::Specification, concerning its attributes that support different
describe "when platform specific values are given" do describe "when platform specific values are given" do
before do before do
@spec = Pod::Spec.new do |s| @spec = Pod::Spec.new do |s|
s.ios.source_file = 'file1' s.ios.source_files = 'file1'
s.osx.source_files = 'file1', 'file2' s.osx.source_files = 'file1', 'file2'
s.ios.resource = 'file1' s.ios.resource = 'file1'
...@@ -503,8 +503,8 @@ describe "A Pod::Specification, concerning its attributes that support different ...@@ -503,8 +503,8 @@ describe "A Pod::Specification, concerning its attributes that support different
it "returns the same list of dependencies for each platform" do it "returns the same list of dependencies for each platform" do
@spec.dependencies.should == { @spec.dependencies.should == {
:ios => Pod::Dependency.new('JSONKit'), :ios => [Pod::Dependency.new('JSONKit')],
:osx => Pod::Dependency.new('SSZipArchive') :osx => [Pod::Dependency.new('SSZipArchive')]
} }
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