Permalink
Browse files

Generate template projects in code

  • Loading branch information...
1 parent e08a67a commit 70858e8cc0f8e1df232aa86bec8356d067707a43 @nolanw nolanw committed Nov 5, 2011
@@ -161,9 +161,6 @@ def install!
build_specifications.each(&:install!)
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?
targets.each do |target|
target.install!
@@ -4,42 +4,110 @@ module Pod
class ProjectTemplate
def initialize(platform)
@platform = platform
- @project = Xcode::Project.new(File.join(path, 'Pods.xcodeproj'))
+ generate_template_project!
end
+ attr_reader :platform
attr_reader :project
- # TODO this is a workaround for an issue with MacRuby with compiled files
- # that makes the use of __FILE__ impossible.
- #
- #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 save_to(pods_root)
+ @project.save_as(File.join(pods_root, 'Pods.xcodeproj'))
+ end
- def path
- @path ||= case @platform
- when :osx
- TEMPLATES_DIR + 'cocoa-static-library'
- when :ios
- TEMPLATES_DIR + 'cocoa-touch-static-library'
- else
- raise "No Xcode project template exists for the platform `#{platform.inspect}'"
- end
+ def generate_template_project!
+ @project = Xcode::Project.new
+ root = @project.objects.add(Xcode::Project::PBXProject, {
+ 'attributes' => { 'LastUpgradeCheck' => '0420' },
+ 'compatibilityVersion' => 'Xcode 3.2',
+ 'developmentRegion' => 'English',
+ 'hasScannedForEncodings' => '0',
+ 'knownRegions' => ['en'],
+ '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
- def copy_to(pods_root)
- FileUtils.cp_r("#{path}/.", pods_root)
- @project.save_as(File.join(pods_root, 'Pods.xcodeproj'))
+ COMMON_BUILD_SETTINGS = {
+ :all => {
+ '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
@@ -541,9 +541,18 @@ def method_missing(name, *args, &block)
end
end
- def initialize(xcodeproj)
- file = File.join(xcodeproj, 'project.pbxproj')
- @plist = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
+ def initialize(xcodeproj = nil)
+ if xcodeproj
+ file = File.join(xcodeproj, 'project.pbxproj')
+ @plist = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
+ else
+ @plist = {
+ 'archiveVersion' => '1',
+ 'classes' => {},
+ 'objectVersion' => '46',
+ 'objects' => {}
+ }
+ end
end
def to_hash
@@ -558,17 +567,20 @@ def objects
@objects ||= PBXObjectList.new(PBXObject, self, objects_hash)
end
- # TODO This should probably be the actual Project class (PBXProject).
- def project_object
+ def root_object
objects[@plist['rootObject']]
end
+ def root_object=(object)
+ @plist['rootObject'] = object.uuid
+ end
+
def groups
objects.select_by_class(PBXGroup)
end
def main_group
- objects[project_object.attributes['mainGroup']]
+ objects[root_object.attributes['mainGroup']]
end
# Shortcut access to the `Pods' PBXGroup.
@@ -592,11 +604,11 @@ def build_files
def targets
# Better to check the project object for targets to ensure they are
# actually there so the project will work
- project_object.targets
+ root_object.targets
end
def products
- project_object.products
+ root_object.products
end
IGNORE_GROUPS = ['Pods', 'Frameworks', 'Products', 'Supporting Files']
@@ -17,11 +17,6 @@ def find_object(conditions)
find_objects(conditions).first
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
@target = @template.project.targets.new_static_library('Pods')
end
@@ -321,8 +316,7 @@ def find_object(conditions)
end
it "saves the template with the adjusted project" do
- @template.copy_to(temporary_directory)
- @template.project.save_as(temporary_directory + 'Pods.xcodeproj')
+ @template.save_to(temporary_directory)
project_file = (temporary_directory + 'Pods.xcodeproj/project.pbxproj')
NSDictionary.dictionaryWithContentsOfFile(project_file.to_s).should == @template.project.to_hash
end
@@ -1,132 +0,0 @@
-// !$*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 */;
-}
Oops, something went wrong.

0 comments on commit 70858e8

Please sign in to comment.