cocoapods 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Pod
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
 
4
4
  class Informative < StandardError
5
5
  end
@@ -12,6 +12,7 @@ module Pod
12
12
  autoload :Executable, 'cocoapods/executable'
13
13
  autoload :Installer, 'cocoapods/installer'
14
14
  autoload :Podfile, 'cocoapods/podfile'
15
+ autoload :ProjectTemplate, 'cocoapods/project_template'
15
16
  autoload :Resolver, 'cocoapods/resolver'
16
17
  autoload :Source, 'cocoapods/source'
17
18
  autoload :Spec, 'cocoapods/specification'
@@ -22,6 +23,7 @@ module Pod
22
23
  autoload :Config, 'cocoapods/xcode/config'
23
24
  autoload :CopyResourcesScript, 'cocoapods/xcode/copy_resources_script'
24
25
  autoload :Project, 'cocoapods/xcode/project'
26
+ autoload :Workspace, 'cocoapods/xcode/workspace'
25
27
  end
26
28
 
27
29
  autoload :Pathname, 'pathname'
@@ -4,10 +4,11 @@ module Pod
4
4
  def self.banner
5
5
  %{Installing dependencies of a pod spec:
6
6
 
7
- $ pod install [NAME]
7
+ $ pod install [NAME] [PROJECT]
8
8
 
9
- Downloads all dependencies of the specified podspec file `NAME' and
10
- creates an Xcode Pods library project in `./Pods'. In case `NAME' is
9
+ Downloads all dependencies of the specified podspec file `NAME',
10
+ creates an Xcode Pods library project in `./Pods', and sets up `PROJECT'
11
+ to use the specified pods (if `PROJECT' is given). In case `NAME' is
11
12
  omitted it defaults to either `Podfile' or `*.podspec' in the current
12
13
  working directory.
13
14
  }
@@ -20,9 +21,10 @@ module Pod
20
21
 
21
22
  def initialize(argv)
22
23
  config.clean = !argv.option('--no-clean')
23
- if podspec = argv.shift_argument
24
- @podspec = Pathname.new(podspec)
25
- end
24
+ projpath = argv.shift_argument
25
+ projpath =~ /\.xcodeproj\/?$/ ? @projpath = projpath : podspec = projpath
26
+ @podspec = Pathname.new(podspec) if podspec
27
+ @projpath ||= argv.shift_argument
26
28
  super unless argv.empty?
27
29
  end
28
30
 
@@ -39,7 +41,9 @@ module Pod
39
41
  raise Informative, "No `Podfile' or `.podspec' file found in the current working directory."
40
42
  end
41
43
  end
42
- Installer.new(spec).install!
44
+ installer = Installer.new(spec)
45
+ installer.install!
46
+ installer.configure_project(@projpath) if @projpath
43
47
  end
44
48
  end
45
49
  end
@@ -44,7 +44,7 @@ module Pod
44
44
  def add
45
45
  puts "==> Cloning spec repo `#{@name}' from `#{@url}'" unless config.silent?
46
46
  config.repos_dir.mkpath
47
- Dir.chdir(config.repos_dir) { git("clone #{@url} #{@name}") }
47
+ Dir.chdir(config.repos_dir) { git("clone '#{@url}' #{@name}") }
48
48
  end
49
49
 
50
50
  def update
@@ -29,8 +29,12 @@ module Pod
29
29
  })
30
30
  end
31
31
 
32
+ def template
33
+ @template ||= ProjectTemplate.new(@specification.platform)
34
+ end
35
+
32
36
  def xcodeproj
33
- @xcodeproj ||= Xcode::Project.static_library(@specification.platform)
37
+ @xcodeproj ||= Xcode::Project.new(template.xcodeproj_path)
34
38
  end
35
39
 
36
40
  # TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
@@ -79,7 +83,11 @@ module Pod
79
83
  generate_project
80
84
 
81
85
  root = config.project_pods_root
82
- xcodeproj.create_in(root)
86
+ puts " * Copying contents of template directory `#{template.path}' to `#{root}'" if config.verbose?
87
+ template.copy_to(root)
88
+ pbxproj = File.join(root, 'Pods.xcodeproj')
89
+ puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
90
+ xcodeproj.save_as(pbxproj)
83
91
  xcconfig.create_in(root)
84
92
  if @specification.generate_bridge_support?
85
93
  path = bridge_support_generator.create_in(root)
@@ -89,5 +97,57 @@ module Pod
89
97
 
90
98
  build_specifications.each(&:post_install)
91
99
  end
100
+
101
+ def configure_project(projpath)
102
+ root = File.dirname(projpath)
103
+ xcworkspace = File.join(root, File.basename(projpath, '.xcodeproj') + '.xcworkspace')
104
+ workspace = Xcode::Workspace.new_from_xcworkspace(xcworkspace)
105
+ pods_projpath = File.join(config.project_pods_root, 'Pods.xcodeproj')
106
+ root = Pathname.new(root).expand_path
107
+ [projpath, pods_projpath].each do |path|
108
+ path = Pathname.new(path).expand_path.relative_path_from(root).to_s
109
+ workspace << path unless workspace.include? path
110
+ end
111
+ workspace.save_as(xcworkspace)
112
+
113
+ app_project = Xcode::Project.new(projpath)
114
+ return if app_project.files.find { |file| file.path =~ /libPods\.a$/ }
115
+
116
+ configfile = app_project.files.new({
117
+ 'path' => 'Pods/Pods.xcconfig',
118
+ 'lastKnownFileType' => 'text.xcconfig'
119
+ })
120
+ app_project.targets.each do |target|
121
+ target.buildConfigurationList.buildConfigurations.each do |config|
122
+ config.baseConfigurationReference = configfile
123
+ end
124
+ end
125
+ app_project.main_group << configfile
126
+
127
+ libfile = app_project.files.new({
128
+ 'path' => 'libPods.a',
129
+ 'lastKnownFileType' => 'archive.ar',
130
+ 'includeInIndex' => '0',
131
+ 'sourceTree' => 'BUILT_PRODUCTS_DIR'
132
+ })
133
+ app_project.objects.select_by_class(Xcode::Project::PBXFrameworksBuildPhase).each do |build_phase|
134
+ build_phase.files << libfile.build_file
135
+ end
136
+ app_project.main_group << libfile
137
+
138
+ copy_resources = app_project.objects.add(Xcode::Project::PBXShellScriptBuildPhase, {
139
+ 'name' => 'Copy Pods Resources',
140
+ 'buildActionMask' => '2147483647',
141
+ 'files' => [],
142
+ 'inputPaths' => [],
143
+ 'outputPaths' => [],
144
+ 'runOnlyForDeploymentPostprocessing' => '0',
145
+ 'shellPath' => '/bin/sh',
146
+ 'shellScript' => "${SRCROOT}/Pods/PodsResources.sh\n"
147
+ })
148
+ app_project.targets.each { |target| target.buildPhases << copy_resources }
149
+
150
+ app_project.save_as(projpath)
151
+ end
92
152
  end
93
153
  end
@@ -0,0 +1,35 @@
1
+ require 'fileutils'
2
+
3
+ module Pod
4
+ class ProjectTemplate
5
+ def initialize(platform)
6
+ @platform = platform
7
+ end
8
+
9
+ # TODO this is a workaround for an issue with MacRuby with compiled files
10
+ # that makes the use of __FILE__ impossible.
11
+ #
12
+ #TEMPLATES_DIR = Pathname.new(File.expand_path('../../../xcode-project-templates', __FILE__))
13
+ file = $LOADED_FEATURES.find { |file| file =~ %r{cocoapods/project_template\.rbo?$} }
14
+ TEMPLATES_DIR = Pathname.new(File.expand_path('../../../xcode-project-templates', file))
15
+
16
+ def path
17
+ @path ||= case @platform
18
+ when :osx
19
+ TEMPLATES_DIR + 'cocoa-static-library'
20
+ when :ios
21
+ TEMPLATES_DIR + 'cocoa-touch-static-library'
22
+ else
23
+ raise "No Xcode project template exists for the platform `#{platform.inspect}'"
24
+ end
25
+ end
26
+
27
+ def xcodeproj_path
28
+ @xcodeproj_path = File.join(path, 'Pods.xcodeproj')
29
+ end
30
+
31
+ def copy_to(pods_root)
32
+ FileUtils.cp_r("#{path}/.", pods_root)
33
+ end
34
+ end
35
+ end
@@ -88,6 +88,10 @@ module Pod
88
88
  end
89
89
  file
90
90
  end
91
+
92
+ def <<(child)
93
+ children << child.uuid
94
+ end
91
95
  end
92
96
 
93
97
  class PBXFileReference < PBXObject
@@ -122,7 +126,7 @@ module Pod
122
126
 
123
127
  # Returns a PBXFileReference instance corresponding to the uuid in the fileRef attribute.
124
128
  def file
125
- project.objects[fileRef]
129
+ @project.objects[fileRef]
126
130
  end
127
131
  end
128
132
 
@@ -140,17 +144,60 @@ module Pod
140
144
  list_by_class(file_uuids, PBXBuildFile)
141
145
  end
142
146
  end
143
- class PBXSourcesBuildPhase < PBXBuildPhase; end
144
- class PBXCopyFilesBuildPhase < PBXBuildPhase; end
147
+
148
+ class PBXSourcesBuildPhase < PBXBuildPhase; end
149
+ class PBXCopyFilesBuildPhase < PBXBuildPhase; end
150
+ class PBXFrameworksBuildPhase < PBXBuildPhase; end
151
+ class PBXShellScriptBuildPhase < PBXBuildPhase
152
+ attributes_accessor :shellScript
153
+ end
145
154
 
146
155
  class PBXNativeTarget < PBXObject
147
- attributes_accessor :buildPhases
156
+ attributes_accessor :buildPhases, :buildConfigurationList
148
157
  alias_method :build_phase_uuids, :buildPhases
149
158
  alias_method :build_phase_uuids=, :buildPhases=
159
+ alias_method :build_configuration_list_uuid, :buildConfigurationList
160
+ alias_method :build_configuration_list_uuid=, :buildConfigurationList=
150
161
 
151
162
  def buildPhases
152
163
  list_by_class(build_phase_uuids, PBXBuildPhase)
153
164
  end
165
+
166
+ def buildConfigurationList
167
+ @project.objects[build_configuration_list_uuid]
168
+ end
169
+
170
+ def buildConfigurationList=(config_list)
171
+ self.build_configuration_list_uuid = config_list.uuid
172
+ end
173
+ end
174
+
175
+ class XCBuildConfiguration < PBXObject
176
+ attributes_accessor :baseConfigurationReference
177
+ alias_method :base_configuration_reference_uuid, :baseConfigurationReference
178
+ alias_method :base_configuration_reference_uuid=, :baseConfigurationReference=
179
+
180
+ def baseConfigurationReference
181
+ @project.objects[base_configuration_reference_uuid]
182
+ end
183
+
184
+ def baseConfigurationReference=(config)
185
+ self.base_configuration_reference_uuid = config.uuid
186
+ end
187
+ end
188
+
189
+ class XCConfigurationList < PBXObject
190
+ attributes_accessor :buildConfigurations
191
+ alias_method :build_configuration_uuids, :buildConfigurations
192
+ alias_method :build_configuration_uuids=, :buildConfigurations=
193
+
194
+ def buildConfigurations
195
+ list_by_class(build_configuration_uuids, XCBuildConfiguration)
196
+ end
197
+
198
+ def buildConfigurations=(configs)
199
+ self.build_configuration_uuids = configs.map(&:uuid)
200
+ end
154
201
  end
155
202
 
156
203
  # Missing constants that begin with either `PBX' or `XC' are assumed to be
@@ -215,42 +262,17 @@ module Pod
215
262
  end
216
263
  end
217
264
 
218
- include Pod::Config::Mixin
219
-
220
- # TODO this is a workaround for an issue with MacRuby with compiled files
221
- # that makes the use of __FILE__ impossible.
222
- #
223
- #TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', __FILE__))
224
- file = $LOADED_FEATURES.find { |file| file =~ %r{cocoapods/xcode/project\.rbo?$} }
225
- TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', file))
226
-
227
- def self.static_library(platform)
228
- case platform
229
- when :osx
230
- new TEMPLATES_DIR + 'cocoa-static-library'
231
- when :ios
232
- new TEMPLATES_DIR + 'cocoa-touch-static-library'
233
- else
234
- raise "No Xcode project template exists for the platform `#{platform.inspect}'"
235
- end
236
- end
237
-
238
- def initialize(template_dir)
239
- @template_dir = template_dir
240
- file = template_dir + template_file
241
- @template = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
242
- end
243
-
244
- def template_file
245
- 'Pods.xcodeproj/project.pbxproj'
265
+ def initialize(xcodeproj)
266
+ file = File.join(xcodeproj, 'project.pbxproj')
267
+ @plist = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
246
268
  end
247
269
 
248
270
  def to_hash
249
- @template
271
+ @plist
250
272
  end
251
273
 
252
274
  def objects_hash
253
- @template['objects']
275
+ @plist['objects']
254
276
  end
255
277
 
256
278
  def objects
@@ -260,6 +282,11 @@ module Pod
260
282
  def groups
261
283
  objects.select_by_class(PBXGroup)
262
284
  end
285
+
286
+ def main_group
287
+ project = objects[@plist['rootObject']]
288
+ objects[project.attributes['mainGroup']]
289
+ end
263
290
 
264
291
  # Shortcut access to the `Pods' PBXGroup.
265
292
  def pods
@@ -301,12 +328,10 @@ module Pod
301
328
  source_files
302
329
  end
303
330
 
304
- def create_in(pods_root)
305
- puts " * Copying contents of template directory `#{@template_dir}' to `#{pods_root}'" if config.verbose?
306
- FileUtils.cp_r("#{@template_dir}/.", pods_root)
307
- pbxproj = pods_root + template_file
308
- puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
309
- @template.writeToFile(pbxproj.to_s, atomically:true)
331
+ def save_as(projpath)
332
+ projpath = projpath.to_s
333
+ FileUtils.mkdir_p(projpath)
334
+ @plist.writeToFile(File.join(projpath, 'project.pbxproj'), atomically:true)
310
335
  end
311
336
 
312
337
  # TODO add comments, or even constants, describing what these magic numbers are.
@@ -0,0 +1,56 @@
1
+ framework 'Foundation'
2
+ require 'fileutils'
3
+
4
+ module Pod
5
+ module Xcode
6
+ class Workspace
7
+ def initialize(*projpaths)
8
+ @projpaths = projpaths
9
+ end
10
+
11
+ def self.new_from_xcworkspace(path)
12
+ begin
13
+ from_s(File.read(File.join(path, 'contents.xcworkspacedata')))
14
+ rescue Errno::ENOENT
15
+ new
16
+ end
17
+ end
18
+
19
+ def self.from_s(xml)
20
+ doc = NSXMLDocument.alloc.initWithXMLString(xml, options:0, error:nil)
21
+ projpaths = doc.nodesForXPath("/Workspace/FileRef", error:nil).map do |node|
22
+ node.attributeForName("location").stringValue.sub(/^group:/, '')
23
+ end
24
+ new(*projpaths)
25
+ end
26
+
27
+ attr_reader :projpaths
28
+
29
+ def <<(projpath)
30
+ @projpaths << projpath
31
+ end
32
+
33
+ def include?(projpath)
34
+ @projpaths.include?(projpath)
35
+ end
36
+
37
+ TEMPLATE = %q[<?xml version="1.0" encoding="UTF-8"?><Workspace version="1.0"></Workspace>]
38
+ def to_s
39
+ doc = NSXMLDocument.alloc.initWithXMLString(TEMPLATE, options:0, error:nil)
40
+ @projpaths.each do |projpath|
41
+ el = NSXMLNode.elementWithName("FileRef")
42
+ el.addAttribute(NSXMLNode.attributeWithName("location", stringValue:"group:#{projpath}"))
43
+ doc.rootElement.addChild(el)
44
+ end
45
+ NSString.alloc.initWithData(doc.XMLData, encoding:NSUTF8StringEncoding)
46
+ end
47
+
48
+ def save_as(path)
49
+ FileUtils.mkdir_p(path)
50
+ File.open(File.join(path, 'contents.xcworkspacedata'), 'w') do |out|
51
+ out << to_s
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Eloy Duran
@@ -14,8 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-09-17 00:00:00 +02:00
18
- default_executable:
18
+ date: 2011-09-17 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: |-
@@ -42,6 +42,7 @@ files:
42
42
  - lib/cocoapods/executable.rb
43
43
  - lib/cocoapods/installer.rb
44
44
  - lib/cocoapods/podfile.rb
45
+ - lib/cocoapods/project_template.rb
45
46
  - lib/cocoapods/resolver.rb
46
47
  - lib/cocoapods/source.rb
47
48
  - lib/cocoapods/specification/set.rb
@@ -50,6 +51,7 @@ files:
50
51
  - lib/cocoapods/xcode/config.rb
51
52
  - lib/cocoapods/xcode/copy_resources_script.rb
52
53
  - lib/cocoapods/xcode/project.rb
54
+ - lib/cocoapods/xcode/workspace.rb
53
55
  - lib/cocoapods.rb
54
56
  - xcode-project-templates/cocoa-static-library/Pods-Prefix.pch
55
57
  - xcode-project-templates/cocoa-static-library/Pods.xcconfig
@@ -62,7 +64,6 @@ files:
62
64
  - bin/pod
63
65
  - README.md
64
66
  - LICENSE
65
- has_rdoc: true
66
67
  homepage: https://github.com/alloy/cocoapods
67
68
  licenses:
68
69
  - MIT
@@ -77,23 +78,27 @@ rdoc_options: []
77
78
  require_paths:
78
79
  - lib
79
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
85
+ hash: 3
83
86
  segments:
84
87
  - 0
85
88
  version: "0"
86
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
87
91
  requirements:
88
92
  - - ">="
89
93
  - !ruby/object:Gem::Version
94
+ hash: 3
90
95
  segments:
91
96
  - 0
92
97
  version: "0"
93
98
  requirements: []
94
99
 
95
100
  rubyforge_project:
96
- rubygems_version: 1.3.6
101
+ rubygems_version: 1.8.7
97
102
  signing_key:
98
103
  specification_version: 3
99
104
  summary: A simple Objective-C library package manager. (Requires MacRuby.)