Commit 813bdac9 authored by Luke Redpath's avatar Luke Redpath

In preparation for further refactoring, extract integration with the user's project into a class

of it's own, and cover it's functionality with some specs.
parent 4bd63675
Subproject commit c874b109de3523829ef234a0e53a8c7c0ab1fc33 Subproject commit 7a771d9cba7eeea0515ebeac84a9155a3d7c4988
...@@ -15,6 +15,7 @@ module Pod ...@@ -15,6 +15,7 @@ module Pod
autoload :Platform, 'cocoapods/platform' autoload :Platform, 'cocoapods/platform'
autoload :Podfile, 'cocoapods/podfile' autoload :Podfile, 'cocoapods/podfile'
autoload :Project, 'cocoapods/project' autoload :Project, 'cocoapods/project'
autoload :ProjectIntegration, 'cocoapods/project_integration'
autoload :Resolver, 'cocoapods/resolver' autoload :Resolver, 'cocoapods/resolver'
autoload :Sandbox, 'cocoapods/sandbox' autoload :Sandbox, 'cocoapods/sandbox'
autoload :Source, 'cocoapods/source' autoload :Source, 'cocoapods/source'
......
...@@ -123,56 +123,8 @@ module Pod ...@@ -123,56 +123,8 @@ module Pod
end end
end end
# For now this assumes just one pods target, i.e. only libPods.a.
# Not sure yet if we should try to be smart with apps that have multiple
# targets and try to map pod targets to those app targets.
#
# Possible options are:
# 1. Only cater to the most simple setup
# 2. Try to automagically figure it out by name. For example, a pod target
# called `:some_target' could map to an app target called `SomeTarget'.
# (A variation would be to not even camelize the target name, but simply
# let the user specify it with the proper case.)
# 3. Let the user specify the app target name as an extra argument, but this
# seems to be a less good version of the variation on #2.
def configure_project(projpath) def configure_project(projpath)
# TODO use more of Pathname’s API here ProjectIntegration.integrate_with_project(projpath)
root = File.dirname(projpath)
xcworkspace = File.join(root, File.basename(projpath, '.xcodeproj') + '.xcworkspace')
workspace = Xcodeproj::Workspace.new_from_xcworkspace(xcworkspace)
pods_projpath = File.join(config.project_pods_root, 'Pods.xcodeproj')
root = Pathname.new(root).expand_path
[projpath, pods_projpath].each do |path|
path = Pathname.new(path).expand_path.relative_path_from(root).to_s
workspace << path unless workspace.include? path
end
workspace.save_as(xcworkspace)
app_project = Pod::Project.new(projpath)
return if app_project.files.find { |file| file.path =~ /libPods\.a$/ }
configfile = app_project.files.new('path' => 'Pods/Pods.xcconfig')
app_project.targets.each do |target|
target.buildConfigurations.each do |config|
config.baseConfiguration = configfile
end
end
libfile = app_project.files.new_static_library('Pods')
libfile.group = app_project.main_group.groups.find { |g| g.name == 'Frameworks' }
app_project.objects.select_by_class(Xcodeproj::Project::PBXFrameworksBuildPhase).each do |build_phase|
build_phase.files << libfile.buildFiles.new
end
copy_resources = app_project.add_shell_script_build_phase('Copy Pods Resources',
%{"${SRCROOT}/Pods/Pods-resources.sh"\n})
app_project.targets.each { |target| target.buildPhases << copy_resources }
app_project.save_as(projpath)
unless config.silent?
puts "[!] From now on use `#{File.basename(xcworkspace)}' instead of `#{File.basename(projpath)}'."
end
end end
def dependent_specifications def dependent_specifications
......
require 'xcodeproj/workspace'
require 'xcodeproj/project'
module Pod
class ProjectIntegration
extend Pod::Config::Mixin
# For now this assumes just one pods target, i.e. only libPods.a.
# Not sure yet if we should try to be smart with apps that have multiple
# targets and try to map pod targets to those app targets.
#
# Possible options are:
# 1. Only cater to the most simple setup
# 2. Try to automagically figure it out by name. For example, a pod target
# called `:some_target' could map to an app target called `SomeTarget'.
# (A variation would be to not even camelize the target name, but simply
# let the user specify it with the proper case.)
# 3. Let the user specify the app target name as an extra argument, but this
# seems to be a less good version of the variation on #2.
def self.integrate_with_project(projpath)
# TODO use more of Pathname’s API here
root = File.dirname(projpath)
xcworkspace = File.join(root, File.basename(projpath, '.xcodeproj') + '.xcworkspace')
workspace = Xcodeproj::Workspace.new_from_xcworkspace(xcworkspace)
pods_projpath = File.join(config.project_pods_root, 'Pods.xcodeproj')
root = Pathname.new(root).expand_path
[projpath, pods_projpath].each do |path|
path = Pathname.new(path).expand_path.relative_path_from(root).to_s
workspace << path unless workspace.include? path
end
workspace.save_as(xcworkspace)
app_project = Xcodeproj::Project.new(projpath)
return if app_project.files.find { |file| file.path =~ /libPods\.a$/ }
configfile = app_project.files.new('path' => 'Pods/Pods.xcconfig')
app_project.targets.each do |target|
target.buildConfigurations.each do |config|
config.baseConfiguration = configfile
end
end
libfile = app_project.files.new_static_library('Pods')
libfile.group = app_project.main_group.groups.find { |g| g.name == 'Frameworks' }
app_project.objects.select_by_class(Xcodeproj::Project::Object::PBXFrameworksBuildPhase).each do |build_phase|
build_phase.files << libfile.buildFiles.new
end
copy_resources = app_project.add_shell_script_build_phase('Copy Pods Resources',
%{"${SRCROOT}/Pods/Pods-resources.sh"\n})
app_project.targets.each { |target| target.buildPhases << copy_resources }
app_project.save_as(projpath)
unless config.silent?
puts "[!] From now on use `#{File.basename(xcworkspace)}' instead of `#{File.basename(projpath)}'."
end
end
end
end
//
// AppDelegate.h
// SampleProject
//
// Created by Luke Redpath on 26/02/2012.
// Copyright (c) 2012 LJR Software Limited. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// SampleProject
//
// Created by Luke Redpath on 26/02/2012.
// Copyright (c) 2012 LJR Software Limited. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>co.uk.lukeredpath.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
//
// Prefix header for all source files of the 'SampleProject' target in the 'SampleProject' project
//
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
//
// main.m
// SampleProject
//
// Created by Luke Redpath on 26/02/2012.
// Copyright (c) 2012 LJR Software Limited. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
...@@ -3,6 +3,14 @@ module SpecHelper ...@@ -3,6 +3,14 @@ module SpecHelper
Fixture.fixture(name) Fixture.fixture(name)
end end
def self.create_sample_app_copy_from_fixture(fixture_name)
tmp_dir = Pathname.new(Dir.mktmpdir)
fixture_path = ROOT + "spec/fixtures/#{fixture_name}"
fixture_copy_path = tmp_dir + fixture_name
FileUtils.cp_r(fixture_path, tmp_dir)
fixture_copy_path + "#{fixture_name}.xcodeproj"
end
module Fixture module Fixture
ROOT = ::ROOT + 'spec/fixtures' ROOT = ::ROOT + 'spec/fixtures'
......
require File.expand_path('../../spec_helper', __FILE__)
describe Pod::ProjectIntegration do
before do
@sample_project_path = SpecHelper.create_sample_app_copy_from_fixture('SampleProject')
Pod::ProjectIntegration.integrate_with_project(@sample_project_path)
@sample_project = Xcodeproj::Project.new(@sample_project_path)
end
it 'creates a workspace with a name matching the project' do
workspace_path = @sample_project_path.dirname + "SampleProject.xcworkspace"
workspace_path.should.exist
end
it 'adds the project being integrated to the workspace' do
workspace = Xcodeproj::Workspace.new_from_xcworkspace(@sample_project_path.dirname + "SampleProject.xcworkspace")
workspace.should.include?("SampleProject.xcodeproj")
end
it 'adds the Pods project to the workspace' do
workspace = Xcodeproj::Workspace.new_from_xcworkspace(@sample_project_path.dirname + "SampleProject.xcworkspace")
workspace.projpaths.find { |path| path =~ /Pods.xcodeproj/ }.should.not.be.nil
end
it 'adds the Pods xcconfig file to the project' do
@sample_project.files.where(:path => "Pods/Pods.xcconfig").should.not.be.nil
end
it 'sets the Pods xcconfig as the base config for each build configuration' do
xcconfig_file = @sample_project.files.where(:path => "Pods/Pods.xcconfig")
@sample_project.targets.each do |target|
target.buildConfigurations.each do |config|
config.baseConfiguration.should == xcconfig_file
end
end
end
it 'adds a reference to the libPods static library' do
static_lib = @sample_project.files.where(:name => "libPods.a")
static_lib.should.not.be.nil
end
it 'adds the libPods static library to the "Link binary with libraries" build phase of each target' do
@sample_project.targets.each do |target|
framework_build_phase = target.frameworks_build_phases.first
framework_build_phase.files.where(:file => {:name => 'libPods.a'}).should.not.be.nil
end
end
it 'adds a Copy Pods Resources build phase to each target' do
@sample_project.targets.each do |target|
expected_phase = target.shell_script_build_phases.where(:name => "Copy Pods Resources")
expected_phase.shellScript.strip.should == "\"${SRCROOT}/Pods/Pods-resources.sh\"".strip
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