Commit c6377023 authored by Luke Redpath's avatar Luke Redpath

If we want to provide options for the platform, it's probably best to make Platform an object.

We can probably also use this new platform object in the future to refactor out platform-specific
logic.
parent a3bce83e
......@@ -11,6 +11,7 @@ module Pod
autoload :Downloader, 'cocoapods/downloader'
autoload :Executable, 'cocoapods/executable'
autoload :Installer, 'cocoapods/installer'
autoload :Platform, 'cocoapods/platform'
autoload :Podfile, 'cocoapods/podfile'
autoload :Resolver, 'cocoapods/resolver'
autoload :Source, 'cocoapods/source'
......
module Pod
class Platform
attr_reader :options
def initialize(symbolic_name, options = {})
@symbolic_name = symbolic_name
@options = options
end
def name
@symbolic_name
end
def ==(other_platform_or_symbolic_name)
if other_platform_or_symbolic_name.is_a?(Symbol)
@symbolic_name == other_platform_or_symbolic_name
else
self == (other_platform_or_symbolic_name.name)
end
end
def to_s
name.to_s
end
def to_sym
name
end
def nil?
name.nil?
end
end
end
......@@ -49,7 +49,7 @@ module Pod
# This can be either `:osx` for Mac OS X applications, or `:ios` for iOS
# applications.
def platform(platform = nil)
platform ? @platform = platform : @platform
platform ? @platform = Platform.new(platform) : @platform
end
# Specifies a dependency of the project.
......@@ -236,7 +236,7 @@ module Pod
def validate!
lines = []
lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless [:osx, :ios].include?(@platform)
lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless @platform && [:osx, :ios].include?(@platform.name)
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
......
......@@ -28,6 +28,7 @@ module Pod
# TODO This is just to work around a MacRuby bug
def post_initialize
@dependencies, @source_files, @resources, @clean_paths, @subspecs = [], [], [], [], []
@platform = Platform.new(nil)
@xcconfig = Xcodeproj::Config.new
end
......@@ -123,7 +124,10 @@ module Pod
flags
end
attr_accessor :platform
def platform=(platform)
@platform = Platform.new(platform)
end
attr_reader :platform
attr_accessor :requires_arc
......@@ -321,7 +325,7 @@ module Pod
incorrect = []
allowed = [nil, :ios, :osx]
incorrect << ["`platform'", allowed] unless allowed.include?(platform)
incorrect << ["`platform'", allowed] unless allowed.include?(platform.name)
unless missing.empty? && incorrect.empty?
message = "The following #{(missing + incorrect).size == 1 ? 'attribute is' : 'attributes are'}:\n"
......
......@@ -106,7 +106,7 @@ module Xcodeproj
}
def self.build_settings(platform, scheme)
settings = COMMON_BUILD_SETTINGS[:all].merge(COMMON_BUILD_SETTINGS[platform])
settings = COMMON_BUILD_SETTINGS[:all].merge(COMMON_BUILD_SETTINGS[platform.name])
settings['COPY_PHASE_STRIP'] = scheme == :debug ? 'NO' : 'YES'
if scheme == :debug
settings.merge!(COMMON_BUILD_SETTINGS[:debug])
......
require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Platform" do
before do
@platform = Pod::Platform.new(:ios)
end
it "exposes it's symbolic name" do
@platform.name.should == :ios
end
it "can be compared for equality with another platform with the same symbolic name" do
@platform.should == Pod::Platform.new(:ios)
end
it "can be compared for equality with a matching symbolic name (backwards compatibility reasons)" do
@platform.should == :ios
end
it "uses it's name as it's string version" do
@platform.to_s.should == "ios"
end
it "uses it's name as it's symbold version" do
@platform.to_sym.should == :ios
end
end
describe "Pod::Platform with a nil value" do
before do
@platform = Pod::Platform.new(nil)
end
it "behaves like a nil object" do
@platform.should.be.nil
end
end
......@@ -42,7 +42,7 @@ describe 'Xcodeproj::Project' do
describe "for the :ios platform" do
before do
@project = Xcodeproj::Project.for_platform(:ios)
@project = Xcodeproj::Project.for_platform(Pod::Platform.new(:ios))
end
behaves_like "for any platform"
......
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