xcodeproj 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,92 +18,103 @@ module Xcodeproj
18
18
 
19
19
  # @return [String] the source tree to which the file is relative.
20
20
  #
21
- # Common values are `SOURCE_ROOT`, `SDKROOT` and `BUILT_PRODUCTS_DIR`
21
+ # @note Common values are `SOURCE_ROOT`, `SDKROOT` and
22
+ # `BUILT_PRODUCTS_DIR`
22
23
  #
23
24
  attribute :source_tree, String, 'SOURCE_ROOT'
24
25
 
25
26
  # @return [String] the file type (apparently) used for products
26
- # generated by Xcode (i.e. applications, libraries).
27
+ # generated by Xcode (i.e. applications, libraries).
27
28
  #
28
29
  attribute :explicit_file_type, String
29
30
 
30
31
  # @return [String] the file type guessed by Xcode.
31
32
  #
32
- # This attribute is not present if there is an `explicit_file_type`.
33
+ # @note This attribute is not present if there is an
34
+ # `explicit_file_type`.
33
35
  #
34
36
  attribute :last_known_file_type, String
35
37
 
36
38
  # @return [String] whether this file should be indexed. It can
37
- # be either `0` or `1`.
39
+ # be either `0` or `1`.
38
40
  #
39
- # Apparently present only for products generated by Xcode with a value
40
- # of `0`.
41
+ # @note Apparently present only for products generated by Xcode with
42
+ # a value of `0`.
41
43
  #
42
44
  attribute :include_in_index, String, '1'
43
45
 
44
46
  # @return [String] a string containing a number which represents the
45
- # encoding format of the file.
47
+ # encoding format of the file.
46
48
  #
47
49
  attribute :fileEncoding, String
48
50
 
49
51
  # @return [String] a string that specifies the UTI for the syntax
50
- # highlighting.
52
+ # highlighting.
51
53
  #
52
- # E.g. `xcode.lang.ruby`
54
+ # @example
55
+ # `xcode.lang.ruby`
53
56
  #
54
57
  attribute :xc_language_specification_identifier, String
55
58
 
56
59
  # @return [String] a string that specifies the UTI for the structure of
57
- # a plist file.
60
+ # a plist file.
58
61
  #
59
- # E.g. `com.apple.xcode.plist.structure-definition.iphone.info-plist`
62
+ # @example
63
+ # `com.apple.xcode.plist.structure-definition.iphone.info-plist`
60
64
  #
61
65
  attribute :plist_structure_definition_identifier, String
62
66
 
63
67
  # @return [String] Whether Xcode should use tabs for text alignment.
64
68
  #
65
- # E.g. `1`
69
+ # @example
70
+ # `1`
66
71
  #
67
72
  attribute :uses_tabs, String
68
73
 
69
74
  # @return [String] The width of the indent.
70
75
  #
71
- # E.g. `2`
76
+ # @example
77
+ # `2`
72
78
  #
73
79
  attribute :indent_width, String
74
80
 
75
81
  # @return [String] The width of the tabs.
76
82
  #
77
- # E.g. `2`
83
+ # @example
84
+ # `2`
78
85
  #
79
86
  attribute :tab_width, String
80
87
 
81
88
  # @return [String] Whether Xcode should wrap lines.
82
89
  #
83
- # E.g. `1`
90
+ # @example
91
+ # `1`
84
92
  #
85
93
  attribute :wraps_lines, String
86
94
 
87
95
 
88
96
  # @return [String] Apparently whether Xcode should add, if needed, a
89
- # new line feed before saving the file.
97
+ # new line feed before saving the file.
90
98
  #
91
- # E.g. `0`
99
+ # @example
100
+ # `0`
92
101
  #
93
102
  attribute :line_ending, String
94
103
 
95
104
  # @return [String] Comments associated with this file.
96
105
  #
97
- # This is apparently no longer used by Xcode.
106
+ # @note This is apparently no longer used by Xcode.
98
107
  #
99
108
  attribute :comments, String
100
109
 
101
110
  #---------------------------------------------------------------------#
102
111
 
112
+ public
113
+
103
114
  # @!group Helpers
104
115
 
105
116
  # @return [String] the name of the file taking into account the path if
106
- # needed.
117
+ # needed.
107
118
  #
108
119
  def display_name
109
120
  name || File.basename(path)
@@ -122,7 +133,7 @@ module Xcodeproj
122
133
  end
123
134
 
124
135
  # @return [Array<PBXBuildFile>] the build files associated with the
125
- # current file reference.
136
+ # current file reference.
126
137
  #
127
138
  def build_files
128
139
  referrers.select { |r| r.class == PBXBuildFile }
@@ -144,6 +155,8 @@ module Xcodeproj
144
155
  false
145
156
  end
146
157
 
158
+ #---------------------------------------------------------------------#
159
+
147
160
  end
148
161
  end
149
162
  end
@@ -10,59 +10,71 @@ module Xcodeproj
10
10
  # @!group Attributes
11
11
 
12
12
  # @return [ObjectList<PBXGroup, PBXFileReference>]
13
- # the objects contained by the group.
13
+ # the objects contained by the group.
14
14
  #
15
15
  has_many :children, [PBXGroup, PBXFileReference, PBXReferenceProxy]
16
16
 
17
17
  # @return [String] the source tree to which this group is relative.
18
18
  #
19
- # Usually is group <group>.
19
+ # @note Usually is group <group>.
20
20
  #
21
21
  attribute :source_tree, String, '<group>'
22
22
 
23
23
  # @return [String] the path to a folder in the file system.
24
24
  #
25
- # This attribute is present for groups that are linked to a folder in
26
- # the file system.
25
+ # @note This attribute is present for groups that are linked to a
26
+ # folder in the file system.
27
27
  #
28
28
  attribute :path, String
29
29
 
30
30
  # @return [String] the name of the group.
31
31
  #
32
- # If path is specified this attribute is not present.
32
+ # @note If path is specified this attribute is not present.
33
33
  #
34
34
  attribute :name, String
35
35
 
36
36
  # @return [String] Whether Xcode should use tabs for text alignment.
37
37
  #
38
- # E.g. `1`
38
+ # @example
39
+ # `1`
39
40
  #
40
41
  attribute :uses_tabs, String
41
42
 
42
43
  # @return [String] The width of the indent.
43
44
  #
44
- # E.g. `2`
45
+ # @example
46
+ # `2`
45
47
  #
46
48
  attribute :indent_width, String
47
49
 
48
50
  # @return [String] The width of the tabs.
49
51
  #
50
- # E.g. `2`
52
+ # @example
53
+ # `2`
51
54
  #
52
55
  attribute :tab_width, String
53
56
 
54
57
  # @return [String] Whether Xcode should wrap lines.
55
58
  #
56
- # E.g. `1`
59
+ # @example
60
+ # `1`
57
61
  #
58
62
  attribute :wraps_lines, String
59
63
 
60
- #-----------------------------------------------------------------------#
64
+ # @return [String] Comments associated with this group.
65
+ #
66
+ # @note This is apparently no longer used by Xcode.
67
+ #
68
+ attribute :comments, String
69
+
70
+ #---------------------------------------------------------------------#
71
+
72
+ public
61
73
 
62
74
  # @!group Helpers
63
75
 
64
76
  # @return [String] the name of the group taking into account the path
65
- # or other factors if needed.
77
+ # or other factors if needed.
66
78
  #
67
79
  def display_name
68
80
  if name
@@ -75,21 +87,20 @@ module Xcodeproj
75
87
  end
76
88
 
77
89
  # @return [Array<PBXFileReference>] the files references in the group
78
- # children.
90
+ # children.
79
91
  #
80
92
  def files
81
93
  children.select { |obj| obj.class == PBXFileReference }
82
94
  end
83
95
 
84
- # @return [Array<PBXGroup>] the groups in the group
85
- # children.
96
+ # @return [Array<PBXGroup>] the groups in the group children.
86
97
  #
87
98
  def groups
88
99
  children.select { |obj| obj.class == PBXGroup }
89
100
  end
90
101
 
91
102
  # @return [Array<XCVersionGroup>] the version groups in the group
92
- # children.
103
+ # children.
93
104
  #
94
105
  def version_groups
95
106
  children.select { |obj| obj.class == XCVersionGroup }
@@ -98,13 +109,15 @@ module Xcodeproj
98
109
  # Creates a new file reference with the given path and adds it to the
99
110
  # group or to an optional subpath.
100
111
  #
101
- # @note The subpath is created if needed, similar to the UNIX command `mkdir -p`
112
+ # @note The subpath is created if needed, similar to the UNIX command
113
+ # `mkdir -p`
102
114
  #
103
- # @param [#to_s] path
104
- # the file system path of the file.
115
+ # @param [#to_s] path
116
+ # the file system path of the file.
105
117
  #
106
- # @param [String] sub_group_path
107
- # an optional subgroup path indicating the groups separated by a `/`.
118
+ # @param [String] sub_group_path
119
+ # an optional subgroup path indicating the groups separated by
120
+ # a `/`.
108
121
  #
109
122
  # @return [PBXFileReference] the new file reference.
110
123
  #
@@ -122,12 +135,12 @@ module Xcodeproj
122
135
  # Creates a new group with the given name and adds it to the children
123
136
  # of the group.
124
137
  #
125
- # @note (see #new_file)
138
+ # @note @see new_file
126
139
  #
127
- # @param [#to_s] name
128
- # the name of the new group.
140
+ # @param [#to_s] name
141
+ # the name of the new group.
129
142
  #
130
- # @param [String] sub_group_path (see #new_file)
143
+ # @param [String] sub_group_path @see new_file
131
144
  #
132
145
  # @return [PBXGroup] the new group.
133
146
  #
@@ -143,12 +156,13 @@ module Xcodeproj
143
156
  # Creates a file reference to a static library and adds it to the
144
157
  # children of the group.
145
158
  #
146
- # @note (see #new_file)
159
+ # @note @see new_file
147
160
  #
148
- # @param [#to_s] product_name
149
- # the name of the new static library.
161
+ # @param [#to_s] product_name
162
+ # the name of the new static library.
163
+ #
164
+ # @param [String] sub_group_path @see new_file
150
165
  #
151
- # @param [String] sub_group_path (see #new_file)#
152
166
  # @return [PBXFileReference] the new group.
153
167
  #
154
168
  def new_static_library(product_name, sub_group_path = nil)
@@ -174,14 +188,12 @@ module Xcodeproj
174
188
  end
175
189
 
176
190
  # Traverses the children groups and finds the group with the given
177
- # path, optionally, creating any needed group.
178
- #
179
- # @param path (see #find_subpath)
191
+ # path, if exists.
180
192
  #
181
- # @note (see #find_subpath)
193
+ # @see find_subpath
182
194
  #
183
195
  def [](path)
184
- find_subpath(path)
196
+ find_subpath(path, false)
185
197
  end
186
198
 
187
199
  # Removes children files and groups under this group.
@@ -211,13 +223,21 @@ module Xcodeproj
211
223
  # g.name #=> 'Frameworks'
212
224
  #
213
225
  # @return [PBXGroup] the group if found.
226
+ # @return [Nil] if the path could not be found and should create is
227
+ # false.
214
228
  #
215
229
  def find_subpath(path, should_create = false)
216
230
  return self unless path
217
231
  path = path.split('/') unless path.is_a?(Array)
218
232
  child_name = path.shift
219
233
  child = children.find{ |c| c.display_name == child_name }
220
- child = new_group(child_name) if child.nil? && should_create
234
+ if child.nil?
235
+ if should_create
236
+ child = new_group(child_name)
237
+ else
238
+ return nil
239
+ end
240
+ end
221
241
  if path.empty?
222
242
  child
223
243
  else
@@ -238,7 +258,7 @@ module Xcodeproj
238
258
  # @note This is safe to call in an object list because it modifies it
239
259
  # in C in Ruby MRI. In other Ruby implementation it can cause
240
260
  # issues if there is one call to the notification enabled
241
- # methods not compensated by the corespondent oposite (loss of
261
+ # methods not compensated by the corespondent opposite (loss of
242
262
  # UUIDs and objects from the project).
243
263
  #
244
264
  # @return [void]
@@ -292,6 +312,9 @@ module Xcodeproj
292
312
  attribute :version_group_type, String, 'wrapper.xcdatamodel'
293
313
 
294
314
  end
315
+
316
+ #-----------------------------------------------------------------------#
317
+
295
318
  end
296
319
  end
297
320
  end
@@ -14,6 +14,12 @@ module Xcodeproj
14
14
  #
15
15
  attribute :product_name, String
16
16
 
17
+ # @return [String] Comments associated with this target.
18
+ #
19
+ # This is apparently no longer used by Xcode.
20
+ #
21
+ attribute :comments, String
22
+
17
23
  # @return [XCConfigurationList] the list of the build configurations of
18
24
  # the target. This list commonly include two configurations
19
25
  # `Debug` and `Release`.
@@ -24,102 +30,9 @@ module Xcodeproj
24
30
  #
25
31
  has_many :dependencies, PBXTargetDependency
26
32
 
27
- end
28
-
29
- #-----------------------------------------------------------------------#
30
-
31
- # Represents a target handled by Xcode.
32
- #
33
- class PBXNativeTarget < AbstractTarget
34
-
35
- # @!group Attributes
36
-
37
- # @return [PBXBuildRule] the build rules of this target.
38
- #
39
- has_many :build_rules, PBXBuildRule
40
-
41
- # @return [String] the build product type identifier.
42
- #
43
- attribute :product_type, String, 'com.apple.product-type.library.static'
44
-
45
- # @return [PBXFileReference] the reference to the product file.
46
- #
47
- has_one :product_reference, PBXFileReference
48
-
49
- # @return [String] the install path of the product.
50
- #
51
- attribute :product_install_path, String
52
-
53
- # @return [PBXBuildRule] the build phases of the target.
54
- #
55
- # @note Apparently only PBXCopyFilesBuildPhase and
56
- # PBXShellScriptBuildPhase can appear multiple times in a
57
- # target.
58
- #
59
- has_many :build_phases, AbstractBuildPhase
60
-
61
- end
62
-
63
- #-----------------------------------------------------------------------#
64
-
65
- # Represents a target that only consists in a aggregate of targets.
66
- #
67
- # @todo apparently it can't have build rules.
68
- #
69
- class PBXAggregateTarget < AbstractTarget
70
-
71
- # @!group Attributes
72
-
73
- # @return [PBXBuildRule] the build phases of the target.
74
- #
75
- # @note Apparently only PBXCopyFilesBuildPhase and
76
- # PBXShellScriptBuildPhase can appear multiple times in a
77
- # target.
78
- #
79
- has_many :build_phases, [ PBXCopyFilesBuildPhase, PBXShellScriptBuildPhase ]
80
-
81
- end
82
-
83
- #-----------------------------------------------------------------------#
84
-
85
- # Represents a legacy target which uses an external build tool.
86
- #
87
- # Apparently it can't have any build phase but the attribute can be
88
- # present.
89
- #
90
- class PBXLegacyTarget < AbstractTarget
91
-
92
- # @!group Attributes
93
-
94
- # @return [String] e.g "Dir"
95
- #
96
- attribute :build_working_directory, String
97
-
98
- # @return [String] e.g "$(ACTION)"
99
- #
100
- attribute :build_arguments_string, String
101
-
102
- # @return [String] e.g "1"
103
- #
104
- attribute :pass_build_settings_in_environment, String
105
-
106
- # @return [String] e.g "/usr/bin/make"
107
- #
108
- attribute :build_tool_path, String
109
-
110
- # @return [PBXBuildRule] the build phases of the target.
111
- #
112
- # @note Apparently only PBXCopyFilesBuildPhase and
113
- # PBXShellScriptBuildPhase can appear multiple times in a
114
- # target.
115
- #
116
- has_many :build_phases, AbstractBuildPhase
117
-
118
- end
119
-
120
- #----------------------------------------------------------------------#
33
+ #--------------------------------------#
121
34
 
122
- class AbstractTarget < AbstractObject
35
+ public
123
36
 
124
37
  # @!group Helpers
125
38
 
@@ -149,8 +62,6 @@ module Xcodeproj
149
62
  end
150
63
  end
151
64
 
152
- #--------------------------------------#
153
-
154
65
  # @return [ObjectList<XCBuildConfiguration>] the build
155
66
  # configurations of the target.
156
67
  #
@@ -219,12 +130,62 @@ module Xcodeproj
219
130
  phase
220
131
  end
221
132
 
133
+ #--------------------------------------#
134
+
135
+ public
136
+
137
+ # @!group AbstractObject Hooks
138
+
139
+ # @return [Hash{String => Hash}] A hash suitable to display the object
140
+ # to the user.
141
+ #
142
+ def pretty_print
143
+ {
144
+ display_name => {
145
+ 'Build Phases' => build_phases.map(&:pretty_print),
146
+ 'Build Configurations' => build_configurations.map(&:pretty_print)
147
+ }
148
+ }
149
+ end
150
+
222
151
  end
223
152
 
224
153
  #-----------------------------------------------------------------------#
225
154
 
155
+ # Represents a target handled by Xcode.
156
+ #
226
157
  class PBXNativeTarget < AbstractTarget
227
158
 
159
+ # @!group Attributes
160
+
161
+ # @return [PBXBuildRule] the build rules of this target.
162
+ #
163
+ has_many :build_rules, PBXBuildRule
164
+
165
+ # @return [String] the build product type identifier.
166
+ #
167
+ attribute :product_type, String, 'com.apple.product-type.library.static'
168
+
169
+ # @return [PBXFileReference] the reference to the product file.
170
+ #
171
+ has_one :product_reference, PBXFileReference
172
+
173
+ # @return [String] the install path of the product.
174
+ #
175
+ attribute :product_install_path, String
176
+
177
+ # @return [PBXBuildRule] the build phases of the target.
178
+ #
179
+ # @note Apparently only PBXCopyFilesBuildPhase and
180
+ # PBXShellScriptBuildPhase can appear multiple times in a
181
+ # target.
182
+ #
183
+ has_many :build_phases, AbstractBuildPhase
184
+
185
+ #--------------------------------------#
186
+
187
+ public
188
+
228
189
  # @!group Helpers
229
190
 
230
191
  # Adds source files to the target.
@@ -248,7 +209,9 @@ module Xcodeproj
248
209
  if (header_extensions.include?(extension))
249
210
  headers_build_phase.files << build_file
250
211
  else
251
- build_file.settings = { 'COMPILER_FLAGS' => compiler_flags } if compiler_flags && !compiler_flags.empty?
212
+ if compiler_flags && !compiler_flags.empty?
213
+ build_file.settings = { 'COMPILER_FLAGS' => compiler_flags }
214
+ end
252
215
  source_build_phase.files << build_file
253
216
  end
254
217
  end
@@ -301,12 +264,12 @@ module Xcodeproj
301
264
  # @return [PBXFrameworksBuildPhase] the frameworks build phase.
302
265
  #
303
266
  def frameworks_build_phase
304
- bp = build_phases.find { |bp| bp.class == PBXFrameworksBuildPhase }
305
- unless bp
306
- bp = project.new(PBXFrameworksBuildPhase)
307
- build_phases << bp
267
+ phase = build_phases.find { |bp| bp.class == PBXFrameworksBuildPhase }
268
+ unless phase
269
+ phase= project.new(PBXFrameworksBuildPhase)
270
+ build_phases << phase
308
271
  end
309
- bp
272
+ phase
310
273
  end
311
274
 
312
275
  # Finds or creates the resources build phase of the target.
@@ -316,14 +279,75 @@ module Xcodeproj
316
279
  # @return [PBXResourcesBuildPhase] the resources build phase.
317
280
  #
318
281
  def resources_build_phase
319
- bp = build_phases.find { |bp| bp.class == PBXResourcesBuildPhase }
320
- unless bp
321
- bp = project.new(PBXResourcesBuildPhase)
322
- build_phases << bp
282
+ phase = build_phases.find { |bp| bp.class == PBXResourcesBuildPhase }
283
+ unless phase
284
+ phase = project.new(PBXResourcesBuildPhase)
285
+ build_phases << phase
323
286
  end
324
- bp
287
+ phase
325
288
  end
289
+
326
290
  end
291
+
292
+ #-----------------------------------------------------------------------#
293
+
294
+ # Represents a target that only consists in a aggregate of targets.
295
+ #
296
+ # @todo Apparently it can't have build rules.
297
+ #
298
+ class PBXAggregateTarget < AbstractTarget
299
+
300
+ # @!group Attributes
301
+
302
+ # @return [PBXBuildRule] the build phases of the target.
303
+ #
304
+ # @note Apparently only PBXCopyFilesBuildPhase and
305
+ # PBXShellScriptBuildPhase can appear multiple times in a
306
+ # target.
307
+ #
308
+ has_many :build_phases, [ PBXCopyFilesBuildPhase, PBXShellScriptBuildPhase ]
309
+
310
+ end
311
+
312
+ #-----------------------------------------------------------------------#
313
+
314
+ # Represents a legacy target which uses an external build tool.
315
+ #
316
+ # Apparently it can't have any build phase but the attribute can be
317
+ # present.
318
+ #
319
+ class PBXLegacyTarget < AbstractTarget
320
+
321
+ # @!group Attributes
322
+
323
+ # @return [String] e.g "Dir"
324
+ #
325
+ attribute :build_working_directory, String
326
+
327
+ # @return [String] e.g "$(ACTION)"
328
+ #
329
+ attribute :build_arguments_string, String
330
+
331
+ # @return [String] e.g "1"
332
+ #
333
+ attribute :pass_build_settings_in_environment, String
334
+
335
+ # @return [String] e.g "/usr/bin/make"
336
+ #
337
+ attribute :build_tool_path, String
338
+
339
+ # @return [PBXBuildRule] the build phases of the target.
340
+ #
341
+ # @note Apparently only PBXCopyFilesBuildPhase and
342
+ # PBXShellScriptBuildPhase can appear multiple times in a
343
+ # target.
344
+ #
345
+ has_many :build_phases, AbstractBuildPhase
346
+
347
+ end
348
+
349
+ #-----------------------------------------------------------------------#
350
+
327
351
  end
328
352
  end
329
353
  end