Commit be78f0dc authored by Nolan Waite's avatar Nolan Waite

Switch to xcodeproj gem

parent 87e1a0bf
...@@ -31,8 +31,7 @@ Gem::Specification.new do |s| ...@@ -31,8 +31,7 @@ Gem::Specification.new do |s|
" $ sudo macgem install rubygems-compile\n" \ " $ sudo macgem install rubygems-compile\n" \
" $ sudo macgem compile cocoapods\n\n" " $ sudo macgem compile cocoapods\n\n"
s.add_runtime_dependency 'activesupport', '~> 3.1.1' s.add_runtime_dependency 'xcodeproj', '~> 0.0.1'
s.add_runtime_dependency 'i18n', '~> 0.6.0' # only needed for ActiveSupport :-/
## Make sure you can build the gem on older versions of RubyGems too: ## Make sure you can build the gem on older versions of RubyGems too:
s.rubygems_version = "1.6.2" s.rubygems_version = "1.6.2"
......
require 'rubygems'
require 'xcodeproj'
module Pod module Pod
VERSION = '0.2.0' VERSION = '0.2.0'
...@@ -19,13 +22,6 @@ module Pod ...@@ -19,13 +22,6 @@ module Pod
autoload :Specification, 'cocoapods/specification' autoload :Specification, 'cocoapods/specification'
autoload :Version, 'cocoapods/version' autoload :Version, 'cocoapods/version'
module Xcode
autoload :Config, 'cocoapods/xcode/config'
autoload :CopyResourcesScript, 'cocoapods/xcode/copy_resources_script'
autoload :Project, 'cocoapods/xcode/project'
autoload :Workspace, 'cocoapods/xcode/workspace'
end
autoload :Pathname, 'pathname' autoload :Pathname, 'pathname'
end end
...@@ -35,3 +31,25 @@ class Pathname ...@@ -35,3 +31,25 @@ class Pathname
end end
end end
# Sorry to dump these here...
class Xcode::Project
# Shortcut access to the `Pods' PBXGroup.
def pods
groups.find { |g| g.name == 'Pods' } || groups.new({ 'name' => 'Pods' })
end
# Adds a group as child to the `Pods' group.
def add_pod_group(name)
pods.groups.new('name' => name)
end
class PBXCopyFilesBuildPhase
def self.new_pod_dir(project, pod_name, path)
new(project, nil, {
"dstPath" => "$(PUBLIC_HEADERS_FOLDER_PATH)/#{path}",
"name" => "Copy #{pod_name} Public Headers",
})
end
end
end
...@@ -14,6 +14,36 @@ module Pod ...@@ -14,6 +14,36 @@ module Pod
end end
end end
class CopyResourcesScript
CONTENT = <<EOS
#!/bin/sh
install_resource()
{
echo "cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
}
EOS
attr_reader :resources
# A list of files relative to the project pods root.
def initialize(resources)
@resources = resources
end
def save_as(pathname)
pathname.open('w') do |script|
script.puts CONTENT
@resources.each do |resource|
script.puts "install_resource '#{resource}'"
end
end
# TODO use File api
system("chmod +x '#{pathname}'")
end
end
class Target class Target
include Config::Mixin include Config::Mixin
include Shared include Shared
...@@ -40,7 +70,7 @@ module Pod ...@@ -40,7 +70,7 @@ module Pod
end end
def copy_resources_script def copy_resources_script
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec| @copy_resources_script ||= CopyResourcesScript.new(build_specifications.map do |spec|
spec.expanded_resources spec.expanded_resources
end.flatten) end.flatten)
end end
......
...@@ -38,7 +38,8 @@ module Pod ...@@ -38,7 +38,8 @@ module Pod
'INSTALL_PATH' => "$(BUILT_PRODUCTS_DIR)", 'INSTALL_PATH' => "$(BUILT_PRODUCTS_DIR)",
'GCC_WARN_ABOUT_MISSING_PROTOTYPES' => 'YES', 'GCC_WARN_ABOUT_MISSING_PROTOTYPES' => 'YES',
'GCC_WARN_ABOUT_RETURN_TYPE' => 'YES', 'GCC_WARN_ABOUT_RETURN_TYPE' => 'YES',
'GCC_WARN_UNUSED_VARIABLE' => 'YES' 'GCC_WARN_UNUSED_VARIABLE' => 'YES',
'OTHER_LDFLAGS' => ''
}, },
:debug => { :debug => {
'GCC_DYNAMIC_NO_PIC' => 'NO', 'GCC_DYNAMIC_NO_PIC' => 'NO',
......
module Pod
module Xcode
class Config
def initialize(xcconfig = {})
@attributes = {}
merge!(xcconfig)
end
def to_hash
@attributes
end
def merge!(xcconfig)
xcconfig.to_hash.each do |key, value|
if existing_value = @attributes[key]
@attributes[key] = "#{existing_value} #{value}"
else
@attributes[key] = value
end
end
end
alias_method :<<, :merge!
def to_s
@attributes.map { |key, value| "#{key} = #{value}" }.join("\n")
end
def save_as(pathname)
pathname.open('w') { |file| file << to_s }
end
end
end
end
module Pod
module Xcode
class CopyResourcesScript
CONTENT = <<EOS
#!/bin/sh
install_resource()
{
echo "cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
}
EOS
attr_reader :resources
# A list of files relative to the project pods root.
def initialize(resources)
@resources = resources
end
def save_as(pathname)
pathname.open('w') do |script|
script.puts CONTENT
@resources.each do |resource|
script.puts "install_resource '#{resource}'"
end
end
# TODO use File api
system("chmod +x '#{pathname}'")
end
end
end
end
This diff is collapsed.
framework 'Foundation'
require 'fileutils'
module Pod
module Xcode
class Workspace
def initialize(*projpaths)
@projpaths = projpaths
end
def self.new_from_xcworkspace(path)
begin
from_s(File.read(File.join(path, 'contents.xcworkspacedata')))
rescue Errno::ENOENT
new
end
end
def self.from_s(xml)
doc = NSXMLDocument.alloc.initWithXMLString(xml, options:0, error:nil)
projpaths = doc.nodesForXPath("/Workspace/FileRef", error:nil).map do |node|
node.attributeForName("location").stringValue.sub(/^group:/, '')
end
new(*projpaths)
end
attr_reader :projpaths
def <<(projpath)
@projpaths << projpath
end
def include?(projpath)
@projpaths.include?(projpath)
end
TEMPLATE = %q[<?xml version="1.0" encoding="UTF-8"?><Workspace version="1.0"></Workspace>]
def to_s
doc = NSXMLDocument.alloc.initWithXMLString(TEMPLATE, options:0, error:nil)
@projpaths.each do |projpath|
el = NSXMLNode.elementWithName("FileRef")
el.addAttribute(NSXMLNode.attributeWithName("location", stringValue:"group:#{projpath}"))
doc.rootElement.addChild(el)
end
NSString.alloc.initWithData(doc.XMLData, encoding:NSUTF8StringEncoding)
end
def save_as(path)
FileUtils.mkdir_p(path)
File.open(File.join(path, 'contents.xcworkspacedata'), 'w') do |out|
out << to_s
end
end
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Xcode::Config" do
extend SpecHelper::TemporaryDirectory
before do
@config = Pod::Xcode::Config.new('OTHER_LD_FLAGS' => '-framework Foundation')
end
it "merges another config hash in place" do
@config.merge!('HEADER_SEARCH_PATHS' => '/some/path')
@config.to_hash.should == {
'OTHER_LD_FLAGS' => '-framework Foundation',
'HEADER_SEARCH_PATHS' => '/some/path'
}
end
it "appends a value for the same key when merging" do
@config.merge!('OTHER_LD_FLAGS' => '-l xml2.2.7.3')
@config.to_hash.should == {
'OTHER_LD_FLAGS' => '-framework Foundation -l xml2.2.7.3'
}
end
it "creates the config file" do
@config.merge!('HEADER_SEARCH_PATHS' => '/some/path')
@config.merge!('OTHER_LD_FLAGS' => '-l xml2.2.7.3')
@config.save_as(temporary_directory + 'Pods.xcconfig')
(temporary_directory + 'Pods.xcconfig').read.split("\n").sort.should == [
"OTHER_LD_FLAGS = -framework Foundation -l xml2.2.7.3",
"HEADER_SEARCH_PATHS = /some/path"
].sort
end
end
This diff is collapsed.
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Xcode::Workspace" do
before do
@workspace = Pod::Xcode::Workspace.new('Pods/Pods.xcodeproj', 'App.xcodeproj')
end
it "accepts new projects" do
@workspace << 'Framework.xcodeproj'
@workspace.projpaths.should.include 'Framework.xcodeproj'
end
before do
@doc = NSXMLDocument.alloc.initWithXMLString(@workspace.to_s, options:0, error:nil)
end
it "is the right xml workspace version" do
@doc.rootElement.attributeForName("version").stringValue.should == "1.0"
end
it "refers to the projects in xml" do
@doc.nodesForXPath("/Workspace/FileRef", error:nil).map do |node|
node.attributeForName("location").stringValue.sub(/^group:/, '')
end.sort.should == ['App.xcodeproj', 'Pods/Pods.xcodeproj']
end
end
require File.expand_path('../../spec_helper', __FILE__)
describe 'Xcode::Project' do
before do
@project = Xcode::Project.new
end
def find_object(conditions)
@project.objects_hash.select do |_, object|
object.objectsForKeys(conditions.keys, notFoundMarker:Object.new) == conditions.values
end.first
end
it "adds a group to the `Pods' group" do
group = @project.add_pod_group('JSONKit')
@project.pods.childReferences.should.include group.uuid
find_object({
'isa' => 'PBXGroup',
'name' => 'JSONKit',
'sourceTree' => '<group>',
'children' => []
}).should.not == nil
end
it "creates a copy build header phase which will copy headers to a specified path" do
@project.targets.new
phase = @project.targets.first.copy_files_build_phases.new_pod_dir("SomePod", "Path/To/Source")
find_object({
'isa' => 'PBXCopyFilesBuildPhase',
'dstPath' => '$(PUBLIC_HEADERS_FOLDER_PATH)/Path/To/Source',
'name' => 'Copy SomePod Public Headers'
}).should.not == nil
@project.targets.first.buildPhases.should.include phase
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