Permalink
Browse files

Stash work on project creation.

  • Loading branch information...
1 parent edd1888 commit cca8cdfb4d9d49916340a1e8e515d6e0c190308f @alloy alloy committed Sep 11, 2011
@@ -122,13 +122,18 @@ def create_static_library!
spec = set.podspec
spec.read(:source_files).each do |pattern|
pattern = spec.pod_destroot + pattern
- pattern = pattern + '*.{m,mm,c,cpp}' if pattern.directory?
- source_files.concat(Dir.glob(pattern.to_s))
+ pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
+ source_files.concat(Dir.glob(pattern.to_s).map { |f| Pathname.new(f) })
end
end
project = XcodeProject.static_library
- project.source_files = source_files
+ source_files.each do |file|
+ file = file.relative_path_from(config.project_pods_root)
+ project.add_source_file(file)
+ end
+ #project.pretty_print
+ project.create_at(config.project_pods_root + 'Pods.xcodeproj')
end
include Config::Mixin
@@ -6,17 +6,95 @@ class XcodeProject
# TODO see if we really need different templates for iOS and OS X
def self.static_library
- new TEMPLATES_DIR + 'cocoa-touch-static-library.pbxproj'
+ new TEMPLATES_DIR + 'cocoa-touch-static-library/Pods.xcodeproj/project.pbxproj'
end
def initialize(template)
- @template = NSDictionary.dictionaryWithContentsOfFile(template.to_s)
- p @template
+ @template = NSMutableDictionary.dictionaryWithContentsOfFile(template.to_s)
+ #pretty_print
end
- def source_files=(files)
- @source_files = files
- @load_paths = files.map { |file| File.dirname(file) }.uniq
+ def add_source_file(file)
+ file_ref_uuid = generate_uuid
+ objects[file_ref_uuid] = {
+ "name" => file.basename.to_s,
+ "isa" => "PBXFileReference",
+ "sourceTree" => "SOURCE_ROOT",
+ "path" => file.to_s,
+ }
+ add_file_to_files_group(file_ref_uuid)
+
+ if file.extname == '.h'
+ add_header(file, file_ref_uuid)
+ else
+ build_file_uuid = generate_uuid
+ objects[build_file_uuid] = {
+ "isa" => "PBXBuildFile",
+ "fileRef" => file_ref_uuid
+ }
+ add_file_to_list('PBXSourcesBuildPhase', build_file_uuid)
+ end
+ end
+
+ def add_header(file, file_ref_uuid)
+ build_file_uuid = generate_uuid
+ objects[build_file_uuid] = {
+ "isa" => "PBXBuildFile",
+ "fileRef" => file_ref_uuid,
+ "settings"=> { "ATTRIBUTES" => ["Public"] }
+ }
+ add_file_to_list('PBXHeadersBuildPhase', build_file_uuid)
+ end
+
+ def to_hash
+ @template
+ end
+
+ def create_at(xcodeproj)
+ xcodeproj.mkpath
+ pbxproj = xcodeproj + 'project.pbxproj'
+ @template.writeToFile(pbxproj.to_s, atomically:true)
+ end
+
+ private
+
+ def add_file_to_list(isa, build_file_uuid)
+ object_uuid, object = object_by_isa(isa)
+ #object['files'] ||= []
+ object['files'] << build_file_uuid
+ objects[object_uuid] = object
+ end
+
+ def add_file_to_files_group(file_ref_uuid)
+ object_uuid, object = objects.find do |_, object|
+ object['isa'] == 'PBXGroup' && object['name'] == 'Files'
+ end
+ #object['children'] ||= []
+ object['children'] << file_ref_uuid
+ objects[object_uuid] = object
+ end
+
+ def objects
+ @template['objects']
+ end
+
+ def object_by_isa(isa)
+ objects.find { |_, object| object['isa'] == isa }
+ end
+
+ def generate_uuid
+ _uuid = CFUUIDCreate(nil)
+ uuid = CFUUIDCreateString(nil, _uuid)
+ CFRelease(_uuid)
+ CFMakeCollectable(uuid)
+ # Xcode's version is actually shorter, not worrying about collisions too much right now.
+ uuid.gsub('-', '')[0..23]
+ end
+
+ public
+
+ def pretty_print
+ puts `ruby -r pp -e 'pp(#{@template.inspect})'`
end
end
end
@@ -7,130 +7,138 @@
objects = {
/* Begin PBXBuildFile section */
- 515B0F8E141D3E3A001DC3E6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 515B0F8D141D3E3A001DC3E6 /* Foundation.framework */; };
- 515B0FA1141D3FB7001DC3E6 /* Pods.h in Headers */ = {isa = PBXBuildFile; fileRef = 515B0F9F141D3FB7001DC3E6 /* Pods.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 515B0FA2141D3FB7001DC3E6 /* Pods.m in Sources */ = {isa = PBXBuildFile; fileRef = 515B0FA0141D3FB7001DC3E6 /* Pods.m */; };
+ 515B0FB9141D52E0001DC3E6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 515B0FB8141D52E0001DC3E6 /* Foundation.framework */; };
+ 515B0FBF141D52E0001DC3E6 /* Pods.m in Sources */ = {isa = PBXBuildFile; fileRef = 515B0FBE141D52E0001DC3E6 /* Pods.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
- 515B0F8A141D3E3A001DC3E6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
- 515B0F8D141D3E3A001DC3E6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
- 515B0F9F141D3FB7001DC3E6 /* Pods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Pods.h; path = nested/files/Pods.h; sourceTree = SOURCE_ROOT; };
- 515B0FA0141D3FB7001DC3E6 /* Pods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Pods.m; path = nested/files/Pods.m; sourceTree = SOURCE_ROOT; };
+ 515B0FB5141D52E0001DC3E6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ 515B0FB8141D52E0001DC3E6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 515B0FBC141D52E0001DC3E6 /* Pods-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Pods-Prefix.pch"; sourceTree = "<group>"; };
+ 515B0FBD141D52E0001DC3E6 /* Pods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Pods.h; sourceTree = "<group>"; };
+ 515B0FBE141D52E0001DC3E6 /* Pods.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Pods.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
- 515B0F87141D3E3A001DC3E6 /* Frameworks */ = {
+ 515B0FB2141D52E0001DC3E6 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- 515B0F8E141D3E3A001DC3E6 /* Foundation.framework in Frameworks */,
+ 515B0FB9141D52E0001DC3E6 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
- 515B0F7F141D3E3A001DC3E6 = {
+ 515B0FAA141D52E0001DC3E6 = {
isa = PBXGroup;
children = (
- 515B0F9E141D3FA0001DC3E6 /* Files */,
- 515B0F8C141D3E3A001DC3E6 /* Frameworks */,
- 515B0F8B141D3E3A001DC3E6 /* Products */,
+ 515B0FBA141D52E0001DC3E6 /* Pods */,
+ 515B0FB7141D52E0001DC3E6 /* Frameworks */,
+ 515B0FB6141D52E0001DC3E6 /* Products */,
);
sourceTree = "<group>";
};
- 515B0F8B141D3E3A001DC3E6 /* Products */ = {
+ 515B0FB6141D52E0001DC3E6 /* Products */ = {
isa = PBXGroup;
children = (
- 515B0F8A141D3E3A001DC3E6 /* libPods.a */,
+ 515B0FB5141D52E0001DC3E6 /* libPods.a */,
);
name = Products;
sourceTree = "<group>";
};
- 515B0F8C141D3E3A001DC3E6 /* Frameworks */ = {
+ 515B0FB7141D52E0001DC3E6 /* Frameworks */ = {
isa = PBXGroup;
children = (
- 515B0F8D141D3E3A001DC3E6 /* Foundation.framework */,
+ 515B0FB8141D52E0001DC3E6 /* Foundation.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
- 515B0F9E141D3FA0001DC3E6 /* Files */ = {
+ 515B0FBA141D52E0001DC3E6 /* Pods */ = {
isa = PBXGroup;
children = (
- 515B0F9F141D3FB7001DC3E6 /* Pods.h */,
- 515B0FA0141D3FB7001DC3E6 /* Pods.m */,
+ 515B0FBD141D52E0001DC3E6 /* Pods.h */,
+ 515B0FBE141D52E0001DC3E6 /* Pods.m */,
+ 515B0FBB141D52E0001DC3E6 /* Supporting Files */,
);
- name = Files;
+ path = Pods;
+ sourceTree = "<group>";
+ };
+ 515B0FBB141D52E0001DC3E6 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 515B0FBC141D52E0001DC3E6 /* Pods-Prefix.pch */,
+ );
+ name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
- 515B0F88141D3E3A001DC3E6 /* Headers */ = {
+ 515B0FB3141D52E0001DC3E6 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
- 515B0FA1141D3FB7001DC3E6 /* Pods.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
- 515B0F89141D3E3A001DC3E6 /* Pods */ = {
+ 515B0FB4141D52E0001DC3E6 /* Pods */ = {
isa = PBXNativeTarget;
- buildConfigurationList = 515B0F97141D3E3A001DC3E6 /* Build configuration list for PBXNativeTarget "Pods" */;
+ buildConfigurationList = 515B0FC2141D52E0001DC3E6 /* Build configuration list for PBXNativeTarget "Pods" */;
buildPhases = (
- 515B0F86141D3E3A001DC3E6 /* Sources */,
- 515B0F87141D3E3A001DC3E6 /* Frameworks */,
- 515B0F88141D3E3A001DC3E6 /* Headers */,
+ 515B0FB1141D52E0001DC3E6 /* Sources */,
+ 515B0FB2141D52E0001DC3E6 /* Frameworks */,
+ 515B0FB3141D52E0001DC3E6 /* Headers */,
);
buildRules = (
);
dependencies = (
);
name = Pods;
productName = Pods;
- productReference = 515B0F8A141D3E3A001DC3E6 /* libPods.a */;
+ productReference = 515B0FB5141D52E0001DC3E6 /* libPods.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
- 515B0F81141D3E3A001DC3E6 /* Project object */ = {
+ 515B0FAC141D52E0001DC3E6 /* Project object */ = {
isa = PBXProject;
- buildConfigurationList = 515B0F84141D3E3A001DC3E6 /* Build configuration list for PBXProject "Pods" */;
+ buildConfigurationList = 515B0FAF141D52E0001DC3E6 /* Build configuration list for PBXProject "Pods" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
- mainGroup = 515B0F7F141D3E3A001DC3E6;
- productRefGroup = 515B0F8B141D3E3A001DC3E6 /* Products */;
+ mainGroup = 515B0FAA141D52E0001DC3E6;
+ productRefGroup = 515B0FB6141D52E0001DC3E6 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
- 515B0F89141D3E3A001DC3E6 /* Pods */,
+ 515B0FB4141D52E0001DC3E6 /* Pods */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
- 515B0F86141D3E3A001DC3E6 /* Sources */ = {
+ 515B0FB1141D52E0001DC3E6 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 515B0FA2141D3FB7001DC3E6 /* Pods.m in Sources */,
+ 515B0FBF141D52E0001DC3E6 /* Pods.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
- 515B0F95141D3E3A001DC3E6 /* Debug */ = {
+ 515B0FC0141D52E0001DC3E6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
@@ -153,7 +161,7 @@
};
name = Debug;
};
- 515B0F96141D3E3A001DC3E6 /* Release */ = {
+ 515B0FC1141D52E0001DC3E6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
@@ -170,7 +178,7 @@
};
name = Release;
};
- 515B0F98141D3E3A001DC3E6 /* Debug */ = {
+ 515B0FC3141D52E0001DC3E6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DSTROOT = /tmp/Pods.dst;
@@ -182,7 +190,7 @@
};
name = Debug;
};
- 515B0F99141D3E3A001DC3E6 /* Release */ = {
+ 515B0FC4141D52E0001DC3E6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DSTROOT = /tmp/Pods.dst;
@@ -197,25 +205,24 @@
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
- 515B0F84141D3E3A001DC3E6 /* Build configuration list for PBXProject "Pods" */ = {
+ 515B0FAF141D52E0001DC3E6 /* Build configuration list for PBXProject "Pods" */ = {
isa = XCConfigurationList;
buildConfigurations = (
- 515B0F95141D3E3A001DC3E6 /* Debug */,
- 515B0F96141D3E3A001DC3E6 /* Release */,
+ 515B0FC0141D52E0001DC3E6 /* Debug */,
+ 515B0FC1141D52E0001DC3E6 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
- 515B0F97141D3E3A001DC3E6 /* Build configuration list for PBXNativeTarget "Pods" */ = {
+ 515B0FC2141D52E0001DC3E6 /* Build configuration list for PBXNativeTarget "Pods" */ = {
isa = XCConfigurationList;
buildConfigurations = (
- 515B0F98141D3E3A001DC3E6 /* Debug */,
- 515B0F99141D3E3A001DC3E6 /* Release */,
+ 515B0FC3141D52E0001DC3E6 /* Debug */,
+ 515B0FC4141D52E0001DC3E6 /* Release */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
- rootObject = 515B0F81141D3E3A001DC3E6 /* Project object */;
+ rootObject = 515B0FAC141D52E0001DC3E6 /* Project object */;
}
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'Pods' target in the 'Pods' project
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+#endif

0 comments on commit cca8cdf

Please sign in to comment.