Commit 70858e8c authored by Nolan Waite's avatar Nolan Waite

Generate template projects in code

parent e08a67a6
...@@ -161,9 +161,6 @@ module Pod ...@@ -161,9 +161,6 @@ module Pod
build_specifications.each(&:install!) build_specifications.each(&:install!)
root = config.project_pods_root root = config.project_pods_root
puts " * Copying contents of template directory `#{template.path}' to `#{root}'" if config.verbose?
template.copy_to(root)
puts "==> Generating Xcode project and xcconfig" unless config.silent? puts "==> Generating Xcode project and xcconfig" unless config.silent?
targets.each do |target| targets.each do |target|
target.install! target.install!
......
...@@ -4,42 +4,110 @@ module Pod ...@@ -4,42 +4,110 @@ module Pod
class ProjectTemplate class ProjectTemplate
def initialize(platform) def initialize(platform)
@platform = platform @platform = platform
@project = Xcode::Project.new(File.join(path, 'Pods.xcodeproj')) generate_template_project!
end end
attr_reader :platform
attr_reader :project attr_reader :project
# TODO this is a workaround for an issue with MacRuby with compiled files def save_to(pods_root)
# that makes the use of __FILE__ impossible. @project.save_as(File.join(pods_root, 'Pods.xcodeproj'))
# end
#TEMPLATES_DIR = Pathname.new(File.expand_path('../../../xcode-project-templates', __FILE__))
# Rest of this is to handle sourcing template projects from standalone
# executable, for which even the $LOADED_FEATURES workaround fails.
possibilities = [
[
$LOADED_FEATURES.find { |file| file =~ %r{cocoapods/project_template\.rbo?$} },
'../../../xcode-project-templates'
],
[$0, '../xcode-project-templates']
]
TEMPLATES_DIR = possibilities.map do |base, relpath|
Pathname.new(File.expand_path(relpath, base))
end.find { |path| path && path.exist? }
def path def generate_template_project!
@path ||= case @platform @project = Xcode::Project.new
when :osx root = @project.objects.add(Xcode::Project::PBXProject, {
TEMPLATES_DIR + 'cocoa-static-library' 'attributes' => { 'LastUpgradeCheck' => '0420' },
when :ios 'compatibilityVersion' => 'Xcode 3.2',
TEMPLATES_DIR + 'cocoa-touch-static-library' 'developmentRegion' => 'English',
else 'hasScannedForEncodings' => '0',
raise "No Xcode project template exists for the platform `#{platform.inspect}'" 'knownRegions' => ['en'],
end 'mainGroup' => @project.groups.new({ 'sourceTree' => '<group>' }).uuid,
'projectDirPath' => '',
'projectRoot' => '',
'targets' => []
})
@project.root_object = root
@project.main_group << @project.groups.new({
'name' => 'Pods',
'sourceTree' => '<group>'
})
framework = @project.files.new({
'lastKnownFileType' => 'wrapper.framework',
'name' => platform == :ios ? 'Foundation.framework' : 'Cocoa.framework',
'path' => "System/Library/Frameworks/#{platform == :ios ? 'Framework' : 'Cocoa'}.framework",
'sourceTree' => 'SDKROOT'
})
framework.group = @project.groups.new({
'name' => 'Frameworks',
'sourceTree' => '<group>'
})
@project.main_group << framework.group
products = @project.groups.new({
'name' => 'Products',
'sourceTree' => '<group>'
})
@project.main_group << products
@project.root_object.products = products
@project.root_object.attributes['buildConfigurationList'] = @project.objects.add(Xcode::Project::XCConfigurationList, {
'defaultConfigurationIsVisible' => '0',
'defaultConfigurationName' => 'Release',
'buildConfigurations' => [
@project.objects.add(Xcode::Project::XCBuildConfiguration, {
'name' => 'Debug',
'buildSettings' => build_settings(:debug)
}),
@project.objects.add(Xcode::Project::XCBuildConfiguration, {
'name' => 'Release',
'buildSettings' => build_settings(:release)
})
].map(&:uuid)
}).uuid
end end
def copy_to(pods_root) COMMON_BUILD_SETTINGS = {
FileUtils.cp_r("#{path}/.", pods_root) :all => {
@project.save_as(File.join(pods_root, 'Pods.xcodeproj')) 'ALWAYS_SEARCH_USER_PATHS' => 'NO',
'GCC_C_LANGUAGE_STANDARD' => 'gnu99',
'INSTALL_PATH' => "$(BUILT_PRODUCTS_DIR)",
'GCC_WARN_ABOUT_MISSING_PROTOTYPES' => 'YES',
'GCC_WARN_ABOUT_RETURN_TYPE' => 'YES',
'GCC_WARN_UNUSED_VARIABLE' => 'YES'
},
:debug => {
'GCC_DYNAMIC_NO_PIC' => 'NO',
'GCC_PREPROCESSOR_DEFINITIONS' => ["DEBUG=1", "$(inherited)"],
'GCC_SYMBOLS_PRIVATE_EXTERN' => 'NO',
'GCC_OPTIMIZATION_LEVEL' => '0'
},
:ios => {
'ARCHS' => "$(ARCHS_STANDARD_32_BIT)",
'GCC_VERSION' => 'com.apple.compilers.llvmgcc42',
'IPHONEOS_DEPLOYMENT_TARGET' => '4.3',
'PUBLIC_HEADERS_FOLDER_PATH' => "$(TARGET_NAME)",
'SDKROOT' => 'iphoneos'
},
:osx => {
'ARCHS' => "$(ARCHS_STANDARD_64_BIT)",
'GCC_ENABLE_OBJC_EXCEPTIONS' => 'YES',
'GCC_WARN_64_TO_32_BIT_CONVERSION' => 'YES',
'GCC_VERSION' => 'com.apple.compilers.llvm.clang.1_0',
'MACOSX_DEPLOYMENT_TARGET' => '10.7',
'SDKROOT' => 'macosx'
}
}
def build_settings(scheme)
settings = COMMON_BUILD_SETTINGS[:all].merge(COMMON_BUILD_SETTINGS[platform])
settings['COPY_PHASE_STRIP'] = scheme == :debug ? 'NO' : 'YES'
if scheme == :debug
settings.merge!(COMMON_BUILD_SETTINGS[:debug])
settings['ONLY_ACTIVE_ARCH'] = 'YES' if platform == :osx
else
settings['VALIDATE_PRODUCT'] = 'YES' if platform == :ios
settings['DEBUG_INFORMATION_FORMAT'] = "dwarf-with-dsym" if platform == :osx
end
settings
end end
end end
end end
...@@ -541,9 +541,18 @@ module Pod ...@@ -541,9 +541,18 @@ module Pod
end end
end end
def initialize(xcodeproj) def initialize(xcodeproj = nil)
file = File.join(xcodeproj, 'project.pbxproj') if xcodeproj
@plist = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s) file = File.join(xcodeproj, 'project.pbxproj')
@plist = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
else
@plist = {
'archiveVersion' => '1',
'classes' => {},
'objectVersion' => '46',
'objects' => {}
}
end
end end
def to_hash def to_hash
...@@ -558,17 +567,20 @@ module Pod ...@@ -558,17 +567,20 @@ module Pod
@objects ||= PBXObjectList.new(PBXObject, self, objects_hash) @objects ||= PBXObjectList.new(PBXObject, self, objects_hash)
end end
# TODO This should probably be the actual Project class (PBXProject). def root_object
def project_object
objects[@plist['rootObject']] objects[@plist['rootObject']]
end end
def root_object=(object)
@plist['rootObject'] = object.uuid
end
def groups def groups
objects.select_by_class(PBXGroup) objects.select_by_class(PBXGroup)
end end
def main_group def main_group
objects[project_object.attributes['mainGroup']] objects[root_object.attributes['mainGroup']]
end end
# Shortcut access to the `Pods' PBXGroup. # Shortcut access to the `Pods' PBXGroup.
...@@ -592,11 +604,11 @@ module Pod ...@@ -592,11 +604,11 @@ module Pod
def targets def targets
# Better to check the project object for targets to ensure they are # Better to check the project object for targets to ensure they are
# actually there so the project will work # actually there so the project will work
project_object.targets root_object.targets
end end
def products def products
project_object.products root_object.products
end end
IGNORE_GROUPS = ['Pods', 'Frameworks', 'Products', 'Supporting Files'] IGNORE_GROUPS = ['Pods', 'Frameworks', 'Products', 'Supporting Files']
......
...@@ -17,11 +17,6 @@ describe "Pod::Xcode::Project" do ...@@ -17,11 +17,6 @@ describe "Pod::Xcode::Project" do
find_objects(conditions).first find_objects(conditions).first
end end
it "returns an instance initialized from the iOS static library template" do
template_file = File.join(@template.path, 'Pods.xcodeproj', 'project.pbxproj')
@template.project.to_hash.should == NSDictionary.dictionaryWithContentsOfFile(template_file)
end
before do before do
@target = @template.project.targets.new_static_library('Pods') @target = @template.project.targets.new_static_library('Pods')
end end
...@@ -321,8 +316,7 @@ describe "Pod::Xcode::Project" do ...@@ -321,8 +316,7 @@ describe "Pod::Xcode::Project" do
end end
it "saves the template with the adjusted project" do it "saves the template with the adjusted project" do
@template.copy_to(temporary_directory) @template.save_to(temporary_directory)
@template.project.save_as(temporary_directory + 'Pods.xcodeproj')
project_file = (temporary_directory + 'Pods.xcodeproj/project.pbxproj') project_file = (temporary_directory + 'Pods.xcodeproj/project.pbxproj')
NSDictionary.dictionaryWithContentsOfFile(project_file.to_s).should == @template.project.to_hash NSDictionary.dictionaryWithContentsOfFile(project_file.to_s).should == @template.project.to_hash
end end
......
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXFileReference section */
518ACD3E1446050200F6BE80 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXGroup section */
518ACD301446050100F6BE80 = {
isa = PBXGroup;
children = (
518ACD5B1446449B00F6BE80 /* Pods */,
518ACD3D1446050200F6BE80 /* Frameworks */,
518ACD3C1446050200F6BE80 /* Products */,
);
sourceTree = "<group>";
};
518ACD3C1446050200F6BE80 /* Products */ = {
isa = PBXGroup;
children = (
);
name = Products;
sourceTree = "<group>";
};
518ACD3D1446050200F6BE80 /* Frameworks */ = {
isa = PBXGroup;
children = (
518ACD3E1446050200F6BE80 /* Cocoa.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
518ACD5B1446449B00F6BE80 /* Pods */ = {
isa = PBXGroup;
children = (
);
name = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXProject section */
518ACD321446050100F6BE80 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = 518ACD351446050100F6BE80 /* Build configuration list for PBXProject "Pods" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 518ACD301446050100F6BE80;
productRefGroup = 518ACD3C1446050200F6BE80 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
);
};
/* End PBXProject section */
/* Begin XCBuildConfiguration section */
518ACD4A1446050200F6BE80 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)";
MACOSX_DEPLOYMENT_TARGET = 10.7;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
518ACD4B1446050200F6BE80 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)";
MACOSX_DEPLOYMENT_TARGET = 10.7;
SDKROOT = macosx;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
518ACD351446050100F6BE80 /* Build configuration list for PBXProject "Pods" */ = {
isa = XCConfigurationList;
buildConfigurations = (
518ACD4A1446050200F6BE80 /* Debug */,
518ACD4B1446050200F6BE80 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 518ACD321446050100F6BE80 /* Project object */;
}
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXFileReference section */
515B0FB8141D52E0001DC3E6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXGroup section */
515B0FAA141D52E0001DC3E6 = {
isa = PBXGroup;
children = (
515B0FC9141D5FBE001DC3E6 /* Pods */,
515B0FB7141D52E0001DC3E6 /* Frameworks */,
515B0FB6141D52E0001DC3E6 /* Products */,
);
sourceTree = "<group>";
};
515B0FB6141D52E0001DC3E6 /* Products */ = {
isa = PBXGroup;
children = (
);
name = Products;
sourceTree = "<group>";
};
515B0FB7141D52E0001DC3E6 /* Frameworks */ = {
isa = PBXGroup;
children = (
515B0FB8141D52E0001DC3E6 /* Foundation.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
515B0FC9141D5FBE001DC3E6 /* Pods */ = {
isa = PBXGroup;
children = (
);
name = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXProject section */
515B0FAC141D52E0001DC3E6 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = 515B0FAF141D52E0001DC3E6 /* Build configuration list for PBXProject "Pods" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 515B0FAA141D52E0001DC3E6;
productRefGroup = 515B0FB6141D52E0001DC3E6 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
);
};
/* End PBXProject section */
/* Begin XCBuildConfiguration section */
515B0FC0141D52E0001DC3E6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvmgcc42;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PUBLIC_HEADERS_FOLDER_PATH = "$(TARGET_NAME)";
SDKROOT = iphoneos;
};
name = Debug;
};
515B0FC1141D52E0001DC3E6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvmgcc42;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PUBLIC_HEADERS_FOLDER_PATH = "$(TARGET_NAME)";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
515B0FAF141D52E0001DC3E6 /* Build configuration list for PBXProject "Pods" */ = {
isa = XCConfigurationList;
buildConfigurations = (
515B0FC0141D52E0001DC3E6 /* Debug */,
515B0FC1141D52E0001DC3E6 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 515B0FAC141D52E0001DC3E6 /* Project object */;
}
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