xcodeproj 1.7.0 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/xcodeproj/command/config_dump.rb +5 -1
  3. data/lib/xcodeproj/config.rb +3 -1
  4. data/lib/xcodeproj/config/other_linker_flags_parser.rb +2 -2
  5. data/lib/xcodeproj/constants.rb +70 -44
  6. data/lib/xcodeproj/gem_version.rb +1 -1
  7. data/lib/xcodeproj/project.rb +23 -2
  8. data/lib/xcodeproj/project/object.rb +3 -1
  9. data/lib/xcodeproj/project/object/build_configuration.rb +96 -35
  10. data/lib/xcodeproj/project/object/build_file.rb +9 -1
  11. data/lib/xcodeproj/project/object/build_phase.rb +45 -4
  12. data/lib/xcodeproj/project/object/build_rule.rb +12 -0
  13. data/lib/xcodeproj/project/object/helpers/file_references_factory.rb +11 -4
  14. data/lib/xcodeproj/project/object/helpers/groupable_helper.rb +13 -6
  15. data/lib/xcodeproj/project/object/native_target.rb +52 -9
  16. data/lib/xcodeproj/project/object/root_object.rb +15 -2
  17. data/lib/xcodeproj/project/object/swift_package_product_dependency.rb +19 -0
  18. data/lib/xcodeproj/project/object/swift_package_remote_reference.rb +19 -0
  19. data/lib/xcodeproj/project/object/target_dependency.rb +9 -0
  20. data/lib/xcodeproj/project/project_helper.rb +2 -1
  21. data/lib/xcodeproj/project/uuid_generator.rb +41 -19
  22. data/lib/xcodeproj/scheme.rb +6 -4
  23. data/lib/xcodeproj/scheme/build_action.rb +21 -0
  24. data/lib/xcodeproj/scheme/buildable_reference.rb +3 -1
  25. data/lib/xcodeproj/scheme/launch_action.rb +50 -0
  26. data/lib/xcodeproj/scheme/test_action.rb +36 -1
  27. data/lib/xcodeproj/workspace.rb +16 -7
  28. data/lib/xcodeproj/workspace/file_reference.rb +7 -12
  29. data/lib/xcodeproj/workspace/group_reference.rb +18 -15
  30. data/lib/xcodeproj/workspace/reference.rb +40 -0
  31. metadata +11 -9
@@ -18,7 +18,7 @@ module Xcodeproj
18
18
  #
19
19
  attribute :settings, Hash
20
20
 
21
- # @return [PBXFileReference] the file that to build.
21
+ # @return [PBXFileReference] the file to build.
22
22
  #
23
23
  # @todo I think that is possible to add any kind of group (for
24
24
  # example folders linked to a path).
@@ -31,6 +31,14 @@ module Xcodeproj
31
31
  PBXReferenceProxy,
32
32
  ]
33
33
 
34
+ # @return [XCSwiftPackageProductDependency] the Swift Package file to build.
35
+ #
36
+ has_one :product_ref, XCSwiftPackageProductDependency
37
+
38
+ # @return [String] the platform filter for this build file.
39
+ #
40
+ attribute :platform_filter, String
41
+
34
42
  #---------------------------------------------------------------------#
35
43
 
36
44
  public
@@ -30,6 +30,16 @@ module Xcodeproj
30
30
  #
31
31
  attribute :run_only_for_deployment_postprocessing, String, '0'
32
32
 
33
+ # @return [String] whether or not this run script will be forced to
34
+ # run even on incremental builds. Can be either '1', or
35
+ # missing. By default this option is disabled in Xcode.
36
+ #
37
+ # @note This setting is exposed in Xcode in the UI of
38
+ # PBXShellScriptBuildPhase as `Based on
39
+ # dependency analysis` (selected by default).
40
+ #
41
+ attribute :always_out_of_date, String
42
+
33
43
  # @return [String] Comments associated with this build phase.
34
44
  #
35
45
  # @note This is apparently no longer used by Xcode.
@@ -204,6 +214,19 @@ module Xcodeproj
204
214
  #
205
215
  attribute :dst_subfolder_spec, String, Constants::COPY_FILES_BUILD_PHASE_DESTINATIONS[:resources]
206
216
 
217
+ # @return [Hash{String => Hash}] A hash suitable to display the build
218
+ # phase to the user.
219
+ #
220
+ def pretty_print
221
+ {
222
+ display_name => {
223
+ 'Destination Path' => dst_path,
224
+ 'Destination Subfolder' => Constants::COPY_FILES_BUILD_PHASE_DESTINATIONS.key(dst_subfolder_spec).to_s,
225
+ 'Files' => files.map(&:pretty_print),
226
+ },
227
+ }
228
+ end
229
+
207
230
  # Alias method for #dst_subfolder_spec=, which accepts symbol values
208
231
  # instead of numeric string values.
209
232
  #
@@ -279,16 +302,34 @@ module Xcodeproj
279
302
 
280
303
  # @return [String] the actual script to perform.
281
304
  #
282
- # @note Defaults to the empty string.
305
+ # @note Defaults to a comment string.
283
306
  #
284
- attribute :shell_script, String, ''
307
+ attribute :shell_script, String, "# Type a script or drag a script file from your workspace to insert its path.\n"
285
308
 
286
309
  # @return [String] whether or not the ENV variables should be shown in
287
310
  # the build log.
288
311
  #
289
- # @note Defaults to true (`1`).
312
+ attribute :show_env_vars_in_log, String
313
+
314
+ # @return [String] the discovered dependency file to use.
315
+ #
316
+ attribute :dependency_file, String
317
+
318
+ # @return [Hash{String => Hash}] A hash suitable to display the build
319
+ # phase to the user.
290
320
  #
291
- attribute :show_env_vars_in_log, String, '1'
321
+ def pretty_print
322
+ {
323
+ display_name => {
324
+ 'Input File List Paths' => input_file_list_paths || [],
325
+ 'Input Paths' => input_paths || [],
326
+ 'Output File List Paths' => output_file_list_paths || [],
327
+ 'Output Paths' => output_paths || [],
328
+ 'Shell Path' => shell_path,
329
+ 'Shell Script' => shell_script,
330
+ },
331
+ }
332
+ end
292
333
  end
293
334
 
294
335
  #-----------------------------------------------------------------------#
@@ -41,6 +41,11 @@ module Xcodeproj
41
41
  #
42
42
  attribute :is_editable, String, '1'
43
43
 
44
+ # @return [ObjectList<PBXFileReference>] the file references for the
45
+ # input files files.
46
+ #
47
+ attribute :input_files, Array
48
+
44
49
  # @return [ObjectList<PBXFileReference>] the file references for the
45
50
  # output files.
46
51
  #
@@ -51,6 +56,13 @@ module Xcodeproj
51
56
  #
52
57
  attribute :output_files_compiler_flags, Array
53
58
 
59
+ # @return [String] whether the rule should be run once per architecture.
60
+ #
61
+ # @example
62
+ # `0`.
63
+ #
64
+ attribute :run_once_per_architecture, String
65
+
54
66
  # @return [String] the content of the script to use for the build rule.
55
67
  #
56
68
  # @note This attribute is present if the #{#compiler_spec} is
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'xcodeproj/project/object/helpers/groupable_helper'
2
3
 
3
4
  module Xcodeproj
@@ -51,7 +52,9 @@ module Xcodeproj
51
52
  prefix = 'lib'
52
53
  end
53
54
  extension = Constants::PRODUCT_UTI_EXTENSIONS[product_type]
54
- ref = new_reference(group, "#{prefix}#{target_name}.#{extension}", :built_products)
55
+ path = "#{prefix}#{target_name}"
56
+ path += ".#{extension}" if extension
57
+ ref = new_reference(group, path, :built_products)
55
58
  ref.include_in_index = '0'
56
59
  ref.set_explicit_file_type
57
60
  ref
@@ -177,9 +180,7 @@ module Xcodeproj
177
180
  ref = new_file_reference(group, path, source_tree)
178
181
  ref.include_in_index = nil
179
182
 
180
- product_group_ref = group.project.new(PBXGroup)
181
- product_group_ref.name = 'Products'
182
- product_group_ref.source_tree = '<group>'
183
+ product_group_ref = find_products_group_ref(group, true)
183
184
 
184
185
  subproj = Project.open(path)
185
186
  subproj.products_group.files.each do |product_reference|
@@ -230,6 +231,12 @@ module Xcodeproj
230
231
  end
231
232
  end
232
233
 
234
+ def find_products_group_ref(group, should_create = false)
235
+ product_group_ref =
236
+ (group.project.root_object.product_ref_group ||= group.project.main_group.find_subpath('Products', should_create))
237
+ product_group_ref
238
+ end
239
+
233
240
  #-------------------------------------------------------------------#
234
241
  end
235
242
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xcodeproj
2
3
  class Project
3
4
  module Object
@@ -98,7 +99,7 @@ module Xcodeproj
98
99
  #
99
100
  def real_path(object)
100
101
  source_tree = source_tree_real_path(object)
101
- path = object.path || ''
102
+ path = object.path || ''.freeze
102
103
  if source_tree
103
104
  source_tree + path
104
105
  else
@@ -115,11 +116,16 @@ module Xcodeproj
115
116
  def full_path(object)
116
117
  folder = case object.source_tree
117
118
  when '<group>'
118
- parent(object).isa != 'PBXProject' ? full_path(parent(object)) : nil
119
+ object_parent = parent(object)
120
+ if object_parent.isa == 'PBXProject'.freeze
121
+ nil
122
+ else
123
+ full_path(object_parent)
124
+ end
119
125
  when 'SOURCE_ROOT'
120
126
  nil
121
127
  when '<absolute>'
122
- Pathname.new('/')
128
+ Pathname.new('/'.freeze)
123
129
  else
124
130
  Pathname.new("${#{object.source_tree}}")
125
131
  end
@@ -140,10 +146,11 @@ module Xcodeproj
140
146
  def source_tree_real_path(object)
141
147
  case object.source_tree
142
148
  when '<group>'
143
- if parent(object).isa == 'PBXProject'
144
- object.project.project_dir
149
+ object_parent = parent(object)
150
+ if object_parent.isa == 'PBXProject'.freeze
151
+ object.project.project_dir + object.project.root_object.project_dir_path
145
152
  else
146
- real_path(parent(object))
153
+ real_path(object_parent)
147
154
  end
148
155
  when 'SOURCE_ROOT'
149
156
  object.project.project_dir
@@ -42,7 +42,7 @@ module Xcodeproj
42
42
  # the key of the build setting.
43
43
  #
44
44
  # @param [Bool] resolve_against_xcconfig
45
- # wether the resolved setting should take in consideration any
45
+ # whether the resolved setting should take in consideration any
46
46
  # configuration file present.
47
47
  #
48
48
  # @return [Hash{String => String}] The value of the build setting
@@ -60,7 +60,7 @@ module Xcodeproj
60
60
  if target_val.is_a? String
61
61
  target_val.gsub(Regexp.union(Constants::INHERITED_KEYWORDS), proj_val)
62
62
  else
63
- target_val.map { |value| Constants::INHERITED_KEYWORDS.include?(value) ? proj_val : value }.flatten
63
+ target_val.flat_map { |value| Constants::INHERITED_KEYWORDS.include?(value) ? proj_val : value }
64
64
  end
65
65
  else
66
66
  target_val || proj_val
@@ -74,6 +74,10 @@ module Xcodeproj
74
74
  # @param [String] key
75
75
  # the key of the build setting.
76
76
  #
77
+ # @param [Boolean] resolve_against_xcconfig
78
+ # whether the resolved setting should take in consideration any
79
+ # configuration file present.
80
+ #
77
81
  # @raise If the build setting has multiple values.
78
82
  #
79
83
  # @note As it is common not to have a setting with no value for
@@ -83,8 +87,8 @@ module Xcodeproj
83
87
  #
84
88
  # @return [String] The value of the build setting.
85
89
  #
86
- def common_resolved_build_setting(key)
87
- values = resolved_build_setting(key).values.compact.uniq
90
+ def common_resolved_build_setting(key, resolve_against_xcconfig: false)
91
+ values = resolved_build_setting(key, resolve_against_xcconfig).values.compact.uniq
88
92
  if values.count <= 1
89
93
  values.first
90
94
  else
@@ -309,7 +313,7 @@ module Xcodeproj
309
313
  # Adds a file reference for one or more system framework to the project
310
314
  # if needed and adds them to the Frameworks build phases.
311
315
  #
312
- # @param [Array<String>, String] name
316
+ # @param [Array<String>, String] names
313
317
  # The name or the list of the names of the framework.
314
318
  #
315
319
  # @note Xcode behaviour is following: if the target has the same SDK
@@ -356,17 +360,22 @@ module Xcodeproj
356
360
  end
357
361
  alias_method :add_system_frameworks, :add_system_framework
358
362
 
359
- # Adds a file reference for one or more system libraries to the project
363
+ # Adds a file reference for one or more system dylib libraries to the project
360
364
  # if needed and adds them to the Frameworks build phases.
361
365
  #
362
- # @param [Array<String>, String] name
366
+ # @param [Array<String>, String] names
363
367
  # The name or the list of the names of the libraries.
364
368
  #
365
369
  # @return [void]
366
370
  #
367
371
  def add_system_library(names)
372
+ add_system_library_extension(names, 'dylib')
373
+ end
374
+ alias_method :add_system_libraries, :add_system_library
375
+
376
+ def add_system_library_extension(names, extension)
368
377
  Array(names).each do |name|
369
- path = "usr/lib/lib#{name}.dylib"
378
+ path = "usr/lib/lib#{name}.#{extension}"
370
379
  files = project.frameworks_group.files
371
380
  unless reference = files.find { |ref| ref.path == path }
372
381
  reference = project.frameworks_group.new_file(path, :sdk_root)
@@ -375,7 +384,20 @@ module Xcodeproj
375
384
  reference
376
385
  end
377
386
  end
378
- alias_method :add_system_libraries, :add_system_library
387
+ private :add_system_library_extension
388
+
389
+ # Adds a file reference for one or more system tbd libraries to the project
390
+ # if needed and adds them to the Frameworks build phases.
391
+ #
392
+ # @param [Array<String>, String] names
393
+ # The name or the list of the names of the libraries.
394
+ #
395
+ # @return [void]
396
+ #
397
+ def add_system_library_tbd(names)
398
+ add_system_library_extension(names, 'tbd')
399
+ end
400
+ alias_method :add_system_libraries_tbd, :add_system_library_tbd
379
401
 
380
402
  public
381
403
 
@@ -414,6 +436,11 @@ module Xcodeproj
414
436
  #
415
437
  has_one :product_reference, PBXFileReference
416
438
 
439
+ # @return [ObjectList<XCSwiftPackageProductDependency>] the Swift package products necessary to
440
+ # build this target.
441
+ #
442
+ has_many :package_product_dependencies, XCSwiftPackageProductDependency
443
+
417
444
  # @return [String] the install path of the product.
418
445
  #
419
446
  attribute :product_install_path, String
@@ -604,6 +631,22 @@ module Xcodeproj
604
631
  end
605
632
  end
606
633
  end
634
+
635
+ def to_hash_as(method = :to_hash)
636
+ hash_as = super
637
+ if !hash_as['packageProductDependencies'].nil? && hash_as['packageProductDependencies'].empty?
638
+ hash_as.delete('packageProductDependencies')
639
+ end
640
+ hash_as
641
+ end
642
+
643
+ def to_ascii_plist
644
+ plist = super
645
+ if !plist.value['packageProductDependencies'].nil? && plist.value['packageProductDependencies'].empty?
646
+ plist.value.delete('packageProductDependencies')
647
+ end
648
+ plist
649
+ end
607
650
  end
608
651
 
609
652
  #-----------------------------------------------------------------------#
@@ -34,7 +34,7 @@ module Xcodeproj
34
34
 
35
35
  # @return [String] the development region of the project.
36
36
  #
37
- attribute :development_region, String, 'English'
37
+ attribute :development_region, String, 'en'
38
38
 
39
39
  # @return [String] whether the project has scanned for encodings.
40
40
  #
@@ -42,7 +42,7 @@ module Xcodeproj
42
42
 
43
43
  # @return [Array<String>] the list of known regions.
44
44
  #
45
- attribute :known_regions, Array, ['en']
45
+ attribute :known_regions, Array, %w(en Base)
46
46
 
47
47
  # @return [PBXGroup] the main group of the project. The one displayed
48
48
  # by Xcode in the Project Navigator.
@@ -62,6 +62,10 @@ module Xcodeproj
62
62
  #
63
63
  attribute :project_root, String, ''
64
64
 
65
+ # @return [Array<XCRemoteSwiftPackageReference>] the list of Swift package references.
66
+ #
67
+ has_many :package_references, XCRemoteSwiftPackageReference
68
+
65
69
  # @return [Array<ObjectDictionary>] any reference to other projects.
66
70
  #
67
71
  has_many_references_by_keys :project_references,
@@ -76,9 +80,18 @@ module Xcodeproj
76
80
  ' Project object '
77
81
  end
78
82
 
83
+ def to_hash_as(method = :to_hash)
84
+ hash_as = super
85
+ if !hash_as['packageReferences'].nil? && hash_as['packageReferences'].empty?
86
+ hash_as.delete('packageReferences') if !hash_as['packageReferences'].nil? && hash_as['packageReferences'].empty?
87
+ end
88
+ hash_as
89
+ end
90
+
79
91
  def to_ascii_plist
80
92
  plist = super
81
93
  plist.value.delete('projectReferences') if plist.value['projectReferences'].empty?
94
+ plist.value.delete('packageReferences') if !plist.value['packageReferences'].nil? && plist.value['packageReferences'].empty?
82
95
  plist
83
96
  end
84
97
  end
@@ -0,0 +1,19 @@
1
+ module Xcodeproj
2
+ class Project
3
+ module Object
4
+ # This class represents a Swift package product dependency.
5
+ #
6
+ class XCSwiftPackageProductDependency < AbstractObject
7
+ # @!group Attributes
8
+
9
+ # @return [XCRemoteSwiftPackageReference] the Swift package reference.
10
+ #
11
+ has_one :package, XCRemoteSwiftPackageReference
12
+
13
+ # @return [String] the product name of this Swift package.
14
+ #
15
+ attribute :product_name, String
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Xcodeproj
2
+ class Project
3
+ module Object
4
+ # This class represents a Swift package reference.
5
+ #
6
+ class XCRemoteSwiftPackageReference < AbstractObject
7
+ # @!group Attributes
8
+
9
+ # @return [String] the repository url this Swift package was installed from.
10
+ #
11
+ attribute :repositoryURL, String
12
+
13
+ # @return [Hash] the version requirements for this Swift package.
14
+ #
15
+ attribute :requirement, Hash
16
+ end
17
+ end
18
+ end
19
+ end
@@ -26,6 +26,14 @@ module Xcodeproj
26
26
  #
27
27
  attribute :name, String
28
28
 
29
+ # @return [String] the platform filter for this target dependency.
30
+ #
31
+ attribute :platform_filter, String
32
+
33
+ # @return [String] the product reference for this target dependency.
34
+ #
35
+ attribute :product_ref, String
36
+
29
37
  public
30
38
 
31
39
  # @!group AbstractObject Hooks
@@ -65,6 +73,7 @@ module Xcodeproj
65
73
  hash = {}
66
74
  hash['displayName'] = display_name
67
75
  hash['isa'] = isa
76
+ hash['targetProxy'] = target_proxy.to_tree_hash
68
77
  hash
69
78
  end
70
79