xcodeproj 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,8 @@ module Xcodeproj
8
8
  #
9
9
  class XCBuildConfiguration < AbstractObject
10
10
 
11
+ # @!group Attributes
12
+
11
13
  # @return [String] the name of the Target.
12
14
  #
13
15
  attribute :name, String
@@ -7,6 +7,8 @@ module Xcodeproj
7
7
  #
8
8
  class PBXBuildFile < AbstractObject
9
9
 
10
+ # @!group Attributes
11
+
10
12
  # @return [Hash] the list of build settings for this file.
11
13
  #
12
14
  # The contents of this array depend on the phase of the build file.
@@ -8,6 +8,7 @@ module Xcodeproj
8
8
  #
9
9
  class AbstractBuildPhase < AbstractObject
10
10
 
11
+ # @!group Attributes
11
12
 
12
13
  # @return [ObjectList<PBXBuildFile>] the files processed by this build
13
14
  # configuration.
@@ -31,42 +32,60 @@ module Xcodeproj
31
32
 
32
33
  end
33
34
 
34
- ### Phases that can appear only once in a target. ########################
35
+ #-----------------------------------------------------------------------#
35
36
 
36
37
  # The phase responsible of copying headers (aka `Copy Headers`).
37
38
  #
39
+ # @note This phase can appear only once in a target.
40
+ #
38
41
  class PBXHeadersBuildPhase < AbstractBuildPhase
39
42
 
40
43
  end
41
44
 
45
+ #-----------------------------------------------------------------------#
46
+
42
47
  # The phase responsible of compiling the files (aka `Compile Sources`).
43
48
  #
49
+ # @note This phase can appear only once in a target.
50
+ #
44
51
  class PBXSourcesBuildPhase < AbstractBuildPhase
45
52
 
46
53
  end
47
54
 
55
+ #-----------------------------------------------------------------------#
56
+
48
57
  # The phase responsible on linking with frameworks (aka `Link Binary With
49
58
  # Libraries`).
50
59
  #
60
+ # @note This phase can appear only once in a target.
61
+ #
51
62
  class PBXFrameworksBuildPhase < AbstractBuildPhase
52
63
 
53
64
  end
54
65
 
66
+ #-----------------------------------------------------------------------#
67
+
55
68
  # The resources build phase apparently is a specialized copy build phase
56
69
  # for resources (aka `Copy Bundle Resources`). It is unclear if this is
57
70
  # the only one capable of optimize PNG.
58
71
  #
72
+ # @note This phase can appear only once in a target.
73
+ #
59
74
  class PBXResourcesBuildPhase < AbstractBuildPhase
60
75
 
61
76
  end
62
77
 
63
- ### Phases that can appear multiple times in a target. ###################
78
+ #-----------------------------------------------------------------------#
64
79
 
65
80
  # Phase that copies the files to the bundle of the target (aka `Copy
66
81
  # Files`).
67
82
  #
83
+ # @note This phase can appear multiple times in a target.
84
+ #
68
85
  class PBXCopyFilesBuildPhase < AbstractBuildPhase
69
86
 
87
+ # @!group Attributes
88
+
70
89
  # @return [String] the name of the build phase.
71
90
  #
72
91
  attribute :name, String
@@ -85,10 +104,16 @@ module Xcodeproj
85
104
 
86
105
  end
87
106
 
107
+ #-----------------------------------------------------------------------#
108
+
88
109
  # A phase responsible of running a shell script (aka `Run Script`).
89
110
  #
111
+ # @note This phase can appear multiple times in a target.
112
+ #
90
113
  class PBXShellScriptBuildPhase < AbstractBuildPhase
91
114
 
115
+ # @!group Attributes
116
+
92
117
  # @return [String] the name of the build phase.
93
118
  #
94
119
  attribute :name, String
@@ -119,7 +144,7 @@ module Xcodeproj
119
144
  #
120
145
  attribute :shell_script, String, ''
121
146
 
122
- # @return [String] wether or not the ENV variables should be shown in
147
+ # @return [String] whether or not the ENV variables should be shown in
123
148
  # the build log.
124
149
  #
125
150
  # Defaults to true (`1`).
@@ -127,17 +152,21 @@ module Xcodeproj
127
152
  attribute :show_env_vars_in_log, String, '1'
128
153
  end
129
154
 
155
+ #-----------------------------------------------------------------------#
156
+
130
157
  # Apparently a build phase named `Build Carbon Resources` (Observed for
131
158
  # kernel extensions targets).
132
159
  #
160
+ # @note This phase can appear multiple times in a target.
161
+ #
133
162
  class PBXRezBuildPhase < AbstractBuildPhase
134
163
  end
135
164
 
136
- class AbstractBuildPhase < AbstractObject
165
+ #-----------------------------------------------------------------------#
137
166
 
138
- ## CONVENIENCE METHODS #################################################
167
+ class AbstractBuildPhase < AbstractObject
139
168
 
140
- # @!group Convenience methods
169
+ # @!group Helpers
141
170
 
142
171
  # @return [Array<PBXFileReference>] the list of all the files
143
172
  # referenced by this build phase.
@@ -179,7 +208,7 @@ module Xcodeproj
179
208
  # Removes a build file from the phase and clears its relationship to
180
209
  # the file reference.
181
210
  #
182
- # @param [PBXBuildFile] file the file to remove
211
+ # @param [PBXBuildFile] build_file the file to remove
183
212
  #
184
213
  # @return [void]
185
214
  #
@@ -6,6 +6,8 @@ module Xcodeproj
6
6
  #
7
7
  class PBXBuildRule < AbstractObject
8
8
 
9
+ # @!group Attributes
10
+
9
11
  # @return [String] the name of the rule.
10
12
  #
11
13
  attribute :name, String
@@ -7,6 +7,8 @@ module Xcodeproj
7
7
  #
8
8
  class XCConfigurationList < AbstractObject
9
9
 
10
+ # @!group Attributes
11
+
10
12
  # @return [String] whether the default configuration is visible.
11
13
  #
12
14
  # Usually `0`.
@@ -24,9 +26,9 @@ module Xcodeproj
24
26
  #
25
27
  has_many :build_configurations, XCBuildConfiguration
26
28
 
27
- ## CONVENIENCE METHODS #################################################
29
+ #---------------------------------------------------------------------#
28
30
 
29
- # @!group Convenience methods
31
+ # @!group Helpers
30
32
 
31
33
  # Returns the build settings of the build configuration with
32
34
  # the given name.
@@ -20,6 +20,8 @@ module Xcodeproj
20
20
  #
21
21
  class PBXContainerItemProxy < AbstractObject
22
22
 
23
+ # @!group Attributes
24
+
23
25
  # @return [String] apparently the UUID of the root object
24
26
  # {PBXProject} of the project containing the represented object.
25
27
  #
@@ -6,6 +6,8 @@ module Xcodeproj
6
6
  #
7
7
  class PBXFileReference < AbstractObject
8
8
 
9
+ # @!group Attributes
10
+
9
11
  # @return [String] the name of the reference, often not present.
10
12
  #
11
13
  attribute :name, String
@@ -58,7 +60,7 @@ module Xcodeproj
58
60
  #
59
61
  attribute :plist_structure_definition_identifier, String
60
62
 
61
- # @return [String] Whether Xcode should use tabs for text aligment.
63
+ # @return [String] Whether Xcode should use tabs for text alignment.
62
64
  #
63
65
  # E.g. `1`
64
66
  #
@@ -92,13 +94,13 @@ module Xcodeproj
92
94
 
93
95
  # @return [String] Comments associated with this file.
94
96
  #
95
- # This is apperantly no longer used by Xcode.
97
+ # This is apparently no longer used by Xcode.
96
98
  #
97
99
  attribute :comments, String
98
100
 
99
- ## CONVENIENCE METHODS #################################################
101
+ #---------------------------------------------------------------------#
100
102
 
101
- # @!group Convenience methods
103
+ # @!group Helpers
102
104
 
103
105
  # @return [String] the name of the file taking into account the path if
104
106
  # needed.
@@ -134,7 +136,7 @@ module Xcodeproj
134
136
  self.last_known_file_type = Constants::FILE_TYPES_BY_EXTENSION[pathname.extname[1..-1]]
135
137
  end
136
138
 
137
- # Checks wheter the reference is a proxy.
139
+ # Checks whether the reference is a proxy.
138
140
  #
139
141
  # @return [Bool] always false for this ISA.
140
142
  #
@@ -7,6 +7,8 @@ module Xcodeproj
7
7
  #
8
8
  class PBXGroup < AbstractObject
9
9
 
10
+ # @!group Attributes
11
+
10
12
  # @return [ObjectList<PBXGroup, PBXFileReference>]
11
13
  # the objects contained by the group.
12
14
  #
@@ -31,7 +33,7 @@ module Xcodeproj
31
33
  #
32
34
  attribute :name, String
33
35
 
34
- # @return [String] Whether Xcode should use tabs for text aligment.
36
+ # @return [String] Whether Xcode should use tabs for text alignment.
35
37
  #
36
38
  # E.g. `1`
37
39
  #
@@ -55,38 +57,9 @@ module Xcodeproj
55
57
  #
56
58
  attribute :wraps_lines, String
57
59
 
58
- end
59
-
60
- # This class is used to gather localized files into one entry.
61
- #
62
- class PBXVariantGroup < PBXGroup
63
- # @return [String] the file type guessed by Xcode.
64
- #
65
- attribute :last_known_file_type, String
66
- end
67
-
68
- # A group that contains multiple files references to the different
69
- # versions of a resource.
70
- #
71
- # Used to contain the different versions of a `xcdatamodel`.
72
- #
73
- class XCVersionGroup < PBXGroup
74
-
75
- # @return [PBXFileReference] the reference to the current version.
76
- #
77
- has_one :current_version, PBXFileReference
78
-
79
- # @return [String] the type of the versioned resource.
80
- #
81
- attribute :version_group_type, String, 'wrapper.xcdatamodel'
82
-
83
- end
84
-
85
- class PBXGroup < AbstractObject
86
-
87
- ## CONVENIENCE METHODS #################################################
60
+ #-----------------------------------------------------------------------#
88
61
 
89
- # @!group Convenience methods
62
+ # @!group Helpers
90
63
 
91
64
  # @return [String] the name of the group taking into account the path
92
65
  # or other factors if needed.
@@ -262,10 +235,16 @@ module Xcodeproj
262
235
 
263
236
  # Sorts the children of the group by type and then by name.
264
237
  #
238
+ # @note This is safe to call in an object list because it modifies it
239
+ # in C in Ruby MRI. In other Ruby implementation it can cause
240
+ # issues if there is one call to the notification enabled
241
+ # methods not compensated by the corespondent oposite (loss of
242
+ # UUIDs and objects from the project).
243
+ #
265
244
  # @return [void]
266
245
  #
267
- def sort_by_type
268
- children.sort do |x, y|
246
+ def sort_by_type!
247
+ children.sort! do |x, y|
269
248
  if x.is_a?(PBXGroup) && y.is_a?(PBXFileReference)
270
249
  -1
271
250
  elsif x.is_a?(PBXFileReference) && y.is_a?(PBXGroup)
@@ -277,7 +256,42 @@ module Xcodeproj
277
256
  end
278
257
  end
279
258
  end
280
- end # PBXGroup
259
+
260
+ end
261
+
262
+ #-----------------------------------------------------------------------#
263
+
264
+ # This class is used to gather localized files into one entry.
265
+ #
266
+ class PBXVariantGroup < PBXGroup
267
+
268
+ # @!group Attributes
269
+
270
+ # @return [String] the file type guessed by Xcode.
271
+ #
272
+ attribute :last_known_file_type, String
273
+ end
274
+
275
+ #-----------------------------------------------------------------------#
276
+
277
+ # A group that contains multiple files references to the different
278
+ # versions of a resource.
279
+ #
280
+ # Used to contain the different versions of a `xcdatamodel`.
281
+ #
282
+ class XCVersionGroup < PBXGroup
283
+
284
+ # @!group Attributes
285
+
286
+ # @return [PBXFileReference] the reference to the current version.
287
+ #
288
+ has_one :current_version, PBXFileReference
289
+
290
+ # @return [String] the type of the versioned resource.
291
+ #
292
+ attribute :version_group_type, String, 'wrapper.xcdatamodel'
293
+
294
+ end
281
295
  end
282
296
  end
283
297
  end
@@ -4,6 +4,8 @@ module Xcodeproj
4
4
 
5
5
  class AbstractTarget < AbstractObject
6
6
 
7
+ # @!group Attributes
8
+
7
9
  # @return [String] The name of the Target.
8
10
  #
9
11
  attribute :name, String
@@ -13,8 +15,8 @@ module Xcodeproj
13
15
  attribute :product_name, String
14
16
 
15
17
  # @return [XCConfigurationList] the list of the build configurations of
16
- # the target. This list commonly include two configurations `Debug`
17
- # and `Release`.
18
+ # the target. This list commonly include two configurations
19
+ # `Debug` and `Release`.
18
20
  #
19
21
  has_one :build_configuration_list, XCConfigurationList
20
22
 
@@ -24,10 +26,14 @@ module Xcodeproj
24
26
 
25
27
  end
26
28
 
29
+ #-----------------------------------------------------------------------#
30
+
27
31
  # Represents a target handled by Xcode.
28
32
  #
29
33
  class PBXNativeTarget < AbstractTarget
30
34
 
35
+ # @!group Attributes
36
+
31
37
  # @return [PBXBuildRule] the build rules of this target.
32
38
  #
33
39
  has_many :build_rules, PBXBuildRule
@@ -46,28 +52,36 @@ module Xcodeproj
46
52
 
47
53
  # @return [PBXBuildRule] the build phases of the target.
48
54
  #
49
- # @note Apparently only PBXCopyFilesBuildPhase and
50
- # PBXShellScriptBuildPhase can appear multiple times in a target.
55
+ # @note Apparently only PBXCopyFilesBuildPhase and
56
+ # PBXShellScriptBuildPhase can appear multiple times in a
57
+ # target.
51
58
  #
52
59
  has_many :build_phases, AbstractBuildPhase
53
60
 
54
61
  end
55
62
 
63
+ #-----------------------------------------------------------------------#
64
+
56
65
  # Represents a target that only consists in a aggregate of targets.
57
66
  #
58
67
  # @todo apparently it can't have build rules.
59
68
  #
60
69
  class PBXAggregateTarget < AbstractTarget
61
70
 
71
+ # @!group Attributes
72
+
62
73
  # @return [PBXBuildRule] the build phases of the target.
63
74
  #
64
- # @note Apparently only PBXCopyFilesBuildPhase and
65
- # PBXShellScriptBuildPhase can appear multiple times in a target.
75
+ # @note Apparently only PBXCopyFilesBuildPhase and
76
+ # PBXShellScriptBuildPhase can appear multiple times in a
77
+ # target.
66
78
  #
67
79
  has_many :build_phases, [ PBXCopyFilesBuildPhase, PBXShellScriptBuildPhase ]
68
80
 
69
81
  end
70
82
 
83
+ #-----------------------------------------------------------------------#
84
+
71
85
  # Represents a legacy target which uses an external build tool.
72
86
  #
73
87
  # Apparently it can't have any build phase but the attribute can be
@@ -75,6 +89,8 @@ module Xcodeproj
75
89
  #
76
90
  class PBXLegacyTarget < AbstractTarget
77
91
 
92
+ # @!group Attributes
93
+
78
94
  # @return [String] e.g "Dir"
79
95
  #
80
96
  attribute :build_working_directory, String
@@ -93,8 +109,9 @@ module Xcodeproj
93
109
 
94
110
  # @return [PBXBuildRule] the build phases of the target.
95
111
  #
96
- # @note Apparently only PBXCopyFilesBuildPhase and
97
- # PBXShellScriptBuildPhase can appear multiple times in a target.
112
+ # @note Apparently only PBXCopyFilesBuildPhase and
113
+ # PBXShellScriptBuildPhase can appear multiple times in a
114
+ # target.
98
115
  #
99
116
  has_many :build_phases, AbstractBuildPhase
100
117
 
@@ -104,35 +121,72 @@ module Xcodeproj
104
121
 
105
122
  class AbstractTarget < AbstractObject
106
123
 
107
- # @!group Convenience methods
124
+ # @!group Helpers
125
+
126
+ def sdk
127
+ build_configurations.first.build_settings['SDKROOT'] \
128
+ || project.build_configurations.first.build_settings['SDKROOT']
129
+ end
130
+
131
+ # @return [Symbol] the name of the platform of the target.
132
+ #
133
+ def platform_name
134
+ if sdk.include? 'iphoneos' then :ios
135
+ elsif sdk.include? 'macosx' then :osx
136
+ end
137
+ end
138
+
139
+ # @return [String] the deployment target of the target according to its
140
+ # platform.
141
+ #
142
+ def deployment_target
143
+ if platform_name == :ios
144
+ build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] ||
145
+ project.build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
146
+ else
147
+ build_configurations.first.build_settings['MACOSX_DEPLOYMENT_TARGET'] ||
148
+ project.build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
149
+ end
150
+ end
151
+
152
+ #--------------------------------------#
108
153
 
109
154
  # @return [ObjectList<XCBuildConfiguration>] the build
110
- # configurations of the target.
155
+ # configurations of the target.
111
156
  #
112
157
  def build_configurations
113
158
  build_configuration_list.build_configurations
114
159
  end
115
160
 
161
+ # @param [String] build_configuration_name
162
+ # the name of a build configuration.
163
+ #
116
164
  # @return [Hash] the build settings of the build configuration with the
117
- # given name.
165
+ # given name.
118
166
  #
119
- # @param [String] build_configuration_name
120
- # the name of a build configuration.
121
167
  #
122
168
  def build_settings(build_configuration_name)
123
169
  build_configuration_list.build_settings(build_configuration_name)
124
170
  end
125
171
 
172
+ # @!group Build Phases Helpers
173
+
174
+ # @return [PBXFrameworksBuildPhase]
175
+ # the copy files build phases of the target.
176
+ #
177
+ def frameworks_build_phases
178
+ build_phases.find { |bp| bp.class == PBXFrameworksBuildPhase }
179
+ end
126
180
 
127
181
  # @return [Array<PBXCopyFilesBuildPhase>]
128
- # the copy files build phases of the target.
182
+ # the copy files build phases of the target.
129
183
  #
130
184
  def copy_files_build_phases
131
185
  build_phases.select { |bp| bp.class == PBXCopyFilesBuildPhase }
132
186
  end
133
187
 
134
188
  # @return [Array<PBXShellScriptBuildPhase>]
135
- # the copy files build phases of the target.
189
+ # the copy files build phases of the target.
136
190
  #
137
191
  def shell_script_build_phases
138
192
  build_phases.select { |bp| bp.class == PBXShellScriptBuildPhase }
@@ -140,8 +194,8 @@ module Xcodeproj
140
194
 
141
195
  # Creates a new copy files build phase.
142
196
  #
143
- # @param [String] name
144
- # an optional name for the phase.
197
+ # @param [String] name
198
+ # an optional name for the phase.
145
199
  #
146
200
  # @return [PBXCopyFilesBuildPhase] the new phase.
147
201
  #
@@ -154,7 +208,7 @@ module Xcodeproj
154
208
 
155
209
  # Creates a new shell script build phase.
156
210
  #
157
- # @param (see #new_copy_files_build_phase)
211
+ # @param (see #new_copy_files_build_phase)
158
212
  #
159
213
  # @return [PBXShellScriptBuildPhase] the new phase.
160
214
  #
@@ -167,18 +221,20 @@ module Xcodeproj
167
221
 
168
222
  end
169
223
 
224
+ #-----------------------------------------------------------------------#
225
+
170
226
  class PBXNativeTarget < AbstractTarget
171
227
 
172
- # @!group Convenience methods
228
+ # @!group Helpers
173
229
 
174
230
  # Adds source files to the target.
175
231
  #
176
- # @param [Array<PBXFileReference>] file_references
177
- # The files references of the source files that should be added to
178
- # the target.
232
+ # @param [Array<PBXFileReference>] file_references
233
+ # the files references of the source files that should be added
234
+ # to the target.
179
235
  #
180
- # @param [Hash{String=>String}] compiler_flags
181
- # The compiler flags for the source files.
236
+ # @param [Hash{String=>String}] compiler_flags
237
+ # the compiler flags for the source files.
182
238
  #
183
239
  # @return [void]
184
240
  #
@@ -201,7 +257,7 @@ module Xcodeproj
201
257
 
202
258
  # Finds or creates the headers build phase of the target.
203
259
  #
204
- # @note A target should have only one headers build phase.
260
+ # @note A target should have only one headers build phase.
205
261
  #
206
262
  # @return [PBXHeadersBuildPhase] the headers build phase.
207
263
  #
@@ -223,7 +279,7 @@ module Xcodeproj
223
279
 
224
280
  # Finds or creates the source build phase of the target.
225
281
  #
226
- # @note A target should have only one source build phase.
282
+ # @note A target should have only one source build phase.
227
283
  #
228
284
  # @return [PBXSourcesBuildPhase] the source build phase.
229
285
  #
@@ -241,7 +297,7 @@ module Xcodeproj
241
297
 
242
298
  # Finds or creates the frameworks build phase of the target.
243
299
  #
244
- # @note A target should have only one frameworks build phase.
300
+ # @note A target should have only one frameworks build phase.
245
301
  #
246
302
  # @return [PBXFrameworksBuildPhase] the frameworks build phase.
247
303
  #
@@ -256,7 +312,7 @@ module Xcodeproj
256
312
 
257
313
  # Finds or creates the resources build phase of the target.
258
314
  #
259
- # @note A target should have only one resources build phase.
315
+ # @note A target should have only one resources build phase.
260
316
  #
261
317
  # @return [PBXResourcesBuildPhase] the resources build phase.
262
318
  #