plasmo_xcodeproj 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +95 -0
- data/bin/xcodeproj +10 -0
- data/lib/xcodeproj/command/config_dump.rb +91 -0
- data/lib/xcodeproj/command/project_diff.rb +56 -0
- data/lib/xcodeproj/command/show.rb +60 -0
- data/lib/xcodeproj/command/sort.rb +44 -0
- data/lib/xcodeproj/command/target_diff.rb +43 -0
- data/lib/xcodeproj/command.rb +63 -0
- data/lib/xcodeproj/config/other_linker_flags_parser.rb +73 -0
- data/lib/xcodeproj/config.rb +386 -0
- data/lib/xcodeproj/constants.rb +465 -0
- data/lib/xcodeproj/differ.rb +239 -0
- data/lib/xcodeproj/gem_version.rb +5 -0
- data/lib/xcodeproj/helper.rb +30 -0
- data/lib/xcodeproj/plist.rb +94 -0
- data/lib/xcodeproj/project/case_converter.rb +90 -0
- data/lib/xcodeproj/project/object/build_configuration.rb +255 -0
- data/lib/xcodeproj/project/object/build_file.rb +84 -0
- data/lib/xcodeproj/project/object/build_phase.rb +369 -0
- data/lib/xcodeproj/project/object/build_rule.rb +109 -0
- data/lib/xcodeproj/project/object/configuration_list.rb +117 -0
- data/lib/xcodeproj/project/object/container_item_proxy.rb +116 -0
- data/lib/xcodeproj/project/object/file_reference.rb +338 -0
- data/lib/xcodeproj/project/object/group.rb +506 -0
- data/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb +72 -0
- data/lib/xcodeproj/project/object/helpers/file_references_factory.rb +245 -0
- data/lib/xcodeproj/project/object/helpers/groupable_helper.rb +260 -0
- data/lib/xcodeproj/project/object/native_target.rb +751 -0
- data/lib/xcodeproj/project/object/reference_proxy.rb +86 -0
- data/lib/xcodeproj/project/object/root_object.rb +100 -0
- data/lib/xcodeproj/project/object/swift_package_product_dependency.rb +29 -0
- data/lib/xcodeproj/project/object/swift_package_remote_reference.rb +33 -0
- data/lib/xcodeproj/project/object/target_dependency.rb +94 -0
- data/lib/xcodeproj/project/object.rb +534 -0
- data/lib/xcodeproj/project/object_attributes.rb +522 -0
- data/lib/xcodeproj/project/object_dictionary.rb +210 -0
- data/lib/xcodeproj/project/object_list.rb +223 -0
- data/lib/xcodeproj/project/project_helper.rb +341 -0
- data/lib/xcodeproj/project/uuid_generator.rb +132 -0
- data/lib/xcodeproj/project.rb +874 -0
- data/lib/xcodeproj/scheme/abstract_scheme_action.rb +100 -0
- data/lib/xcodeproj/scheme/analyze_action.rb +19 -0
- data/lib/xcodeproj/scheme/archive_action.rb +59 -0
- data/lib/xcodeproj/scheme/build_action.rb +298 -0
- data/lib/xcodeproj/scheme/buildable_product_runnable.rb +55 -0
- data/lib/xcodeproj/scheme/buildable_reference.rb +129 -0
- data/lib/xcodeproj/scheme/command_line_arguments.rb +162 -0
- data/lib/xcodeproj/scheme/environment_variables.rb +170 -0
- data/lib/xcodeproj/scheme/execution_action.rb +86 -0
- data/lib/xcodeproj/scheme/launch_action.rb +179 -0
- data/lib/xcodeproj/scheme/location_scenario_reference.rb +49 -0
- data/lib/xcodeproj/scheme/macro_expansion.rb +34 -0
- data/lib/xcodeproj/scheme/profile_action.rb +57 -0
- data/lib/xcodeproj/scheme/remote_runnable.rb +92 -0
- data/lib/xcodeproj/scheme/send_email_action_content.rb +84 -0
- data/lib/xcodeproj/scheme/shell_script_action_content.rb +77 -0
- data/lib/xcodeproj/scheme/test_action.rb +394 -0
- data/lib/xcodeproj/scheme/xml_element_wrapper.rb +82 -0
- data/lib/xcodeproj/scheme.rb +375 -0
- data/lib/xcodeproj/user_interface.rb +22 -0
- data/lib/xcodeproj/workspace/file_reference.rb +79 -0
- data/lib/xcodeproj/workspace/group_reference.rb +67 -0
- data/lib/xcodeproj/workspace/reference.rb +40 -0
- data/lib/xcodeproj/workspace.rb +277 -0
- data/lib/xcodeproj/xcodebuild_helper.rb +108 -0
- data/lib/xcodeproj.rb +29 -0
- metadata +208 -0
@@ -0,0 +1,245 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'xcodeproj/project/object/helpers/groupable_helper'
|
3
|
+
|
4
|
+
module Xcodeproj
|
5
|
+
class Project
|
6
|
+
module Object
|
7
|
+
class FileReferencesFactory
|
8
|
+
class << self
|
9
|
+
# Creates a new reference with the given path and adds it to the
|
10
|
+
# given group. The reference is configured according to the extension
|
11
|
+
# of the path.
|
12
|
+
#
|
13
|
+
# @param [PBXGroup] group
|
14
|
+
# The group to which to add the reference.
|
15
|
+
#
|
16
|
+
# @param [#to_s] path
|
17
|
+
# The, preferably absolute, path of the reference.
|
18
|
+
#
|
19
|
+
# @param [Symbol] source_tree
|
20
|
+
# The source tree key to use to configure the path (@see
|
21
|
+
# GroupableHelper::SOURCE_TREES_BY_KEY).
|
22
|
+
#
|
23
|
+
# @return [PBXFileReference, XCVersionGroup] The new reference.
|
24
|
+
#
|
25
|
+
def new_reference(group, path, source_tree)
|
26
|
+
ref = case File.extname(path).downcase
|
27
|
+
when '.xcdatamodeld'
|
28
|
+
new_xcdatamodeld(group, path, source_tree)
|
29
|
+
when '.xcodeproj'
|
30
|
+
new_subproject(group, path, source_tree)
|
31
|
+
else
|
32
|
+
new_file_reference(group, path, source_tree)
|
33
|
+
end
|
34
|
+
|
35
|
+
configure_defaults_for_file_reference(ref)
|
36
|
+
ref
|
37
|
+
end
|
38
|
+
|
39
|
+
# Creates a file reference to a static library and adds it to the
|
40
|
+
# given group.
|
41
|
+
#
|
42
|
+
# @param [PBXGroup] group
|
43
|
+
# The group to which to add the reference.
|
44
|
+
#
|
45
|
+
# @param [#to_s] product_basename
|
46
|
+
# The name of the static library.
|
47
|
+
#
|
48
|
+
# @return [PBXFileReference] The new file reference.
|
49
|
+
#
|
50
|
+
def new_product_ref_for_target(group, product_basename, product_type)
|
51
|
+
if product_type == :static_library
|
52
|
+
prefix = 'lib'
|
53
|
+
end
|
54
|
+
extension = Constants::PRODUCT_UTI_EXTENSIONS[product_type]
|
55
|
+
path = "#{prefix}#{product_basename}"
|
56
|
+
path += ".#{extension}" if extension
|
57
|
+
ref = new_reference(group, path, :built_products)
|
58
|
+
ref.include_in_index = '0'
|
59
|
+
ref.set_explicit_file_type
|
60
|
+
ref
|
61
|
+
end
|
62
|
+
|
63
|
+
# Creates a file reference to a new bundle and adds it to the given
|
64
|
+
# group.
|
65
|
+
#
|
66
|
+
# @param [PBXGroup] group
|
67
|
+
# The group to which to add the reference.
|
68
|
+
#
|
69
|
+
# @param [#to_s] product_basename
|
70
|
+
# The name of the bundle.
|
71
|
+
#
|
72
|
+
# @return [PBXFileReference] The new file reference.
|
73
|
+
#
|
74
|
+
def new_bundle(group, product_basename)
|
75
|
+
ref = new_reference(group, "#{product_basename}.bundle", :built_products)
|
76
|
+
ref.include_in_index = '0'
|
77
|
+
ref.set_explicit_file_type('wrapper.cfbundle')
|
78
|
+
ref
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
# @group Private Helpers
|
84
|
+
#-------------------------------------------------------------------#
|
85
|
+
|
86
|
+
# Creates a new file reference with the given path and adds it to the
|
87
|
+
# given group.
|
88
|
+
#
|
89
|
+
# @param [PBXGroup] group
|
90
|
+
# The group to which to add the reference.
|
91
|
+
#
|
92
|
+
# @param [#to_s] path
|
93
|
+
# The, preferably absolute, path of the reference.
|
94
|
+
#
|
95
|
+
# @param [Symbol] source_tree
|
96
|
+
# The source tree key to use to configure the path (@see
|
97
|
+
# GroupableHelper::SOURCE_TREES_BY_KEY).
|
98
|
+
#
|
99
|
+
# @return [PBXFileReference] The new file reference.
|
100
|
+
#
|
101
|
+
def new_file_reference(group, path, source_tree)
|
102
|
+
path = Pathname.new(path)
|
103
|
+
ref = group.project.new(PBXFileReference)
|
104
|
+
group.children << ref
|
105
|
+
GroupableHelper.set_path_with_source_tree(ref, path, source_tree)
|
106
|
+
ref.set_last_known_file_type
|
107
|
+
ref
|
108
|
+
end
|
109
|
+
|
110
|
+
# Creates a new version group reference to an xcdatamodeled adding
|
111
|
+
# the xcdatamodel files included in the wrapper as children file
|
112
|
+
# references.
|
113
|
+
#
|
114
|
+
# @param [PBXGroup] group
|
115
|
+
# The group to which to add the reference.
|
116
|
+
#
|
117
|
+
# @param [#to_s] path
|
118
|
+
# The, preferably absolute, path of the reference.
|
119
|
+
#
|
120
|
+
# @param [Symbol] source_tree
|
121
|
+
# The source tree key to use to configure the path (@see
|
122
|
+
# GroupableHelper::SOURCE_TREES_BY_KEY).
|
123
|
+
#
|
124
|
+
# @note To match Xcode behaviour the current version is read from
|
125
|
+
# the .xccurrentversion file, if it doesn't exist the last
|
126
|
+
# xcdatamodel according to its path is set as the current
|
127
|
+
# version.
|
128
|
+
#
|
129
|
+
# @return [XCVersionGroup] The new reference.
|
130
|
+
#
|
131
|
+
def new_xcdatamodeld(group, path, source_tree)
|
132
|
+
path = Pathname.new(path)
|
133
|
+
ref = group.project.new(XCVersionGroup)
|
134
|
+
group.children << ref
|
135
|
+
GroupableHelper.set_path_with_source_tree(ref, path, source_tree)
|
136
|
+
ref.version_group_type = 'wrapper.xcdatamodel'
|
137
|
+
|
138
|
+
real_path = group.real_path.join(path)
|
139
|
+
current_version_name = nil
|
140
|
+
if real_path.exist?
|
141
|
+
real_path.children.each do |child_path|
|
142
|
+
if File.extname(child_path) == '.xcdatamodel'
|
143
|
+
new_file_reference(ref, child_path, :group)
|
144
|
+
elsif File.basename(child_path) == '.xccurrentversion'
|
145
|
+
full_path = real_path + File.basename(child_path)
|
146
|
+
xccurrentversion = Plist.read_from_path(full_path)
|
147
|
+
current_version_name = xccurrentversion['_XCCurrentVersionName']
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
if current_version_name
|
152
|
+
ref.current_version = ref.children.find do |obj|
|
153
|
+
obj.path.split('/').last == current_version_name
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
ref
|
159
|
+
end
|
160
|
+
|
161
|
+
# Creates a file reference to another Xcode subproject and setups the
|
162
|
+
# proxies to the targets.
|
163
|
+
#
|
164
|
+
# @param [PBXGroup] group
|
165
|
+
# The group to which to add the reference.
|
166
|
+
#
|
167
|
+
# @param [#to_s] path
|
168
|
+
# The, preferably absolute, path of the reference.
|
169
|
+
#
|
170
|
+
# @param [Symbol] source_tree
|
171
|
+
# The source tree key to use to configure the path (@see
|
172
|
+
# GroupableHelper::SOURCE_TREES_BY_KEY).
|
173
|
+
#
|
174
|
+
# @note To analyze the targets the given project is read and thus
|
175
|
+
# it should already exist in the disk.
|
176
|
+
#
|
177
|
+
# @return [PBXFileReference] The new file reference.
|
178
|
+
#
|
179
|
+
def new_subproject(group, path, source_tree)
|
180
|
+
ref = new_file_reference(group, path, source_tree)
|
181
|
+
ref.include_in_index = nil
|
182
|
+
|
183
|
+
product_group_ref = find_products_group_ref(group, true)
|
184
|
+
|
185
|
+
subproj = Project.open(path)
|
186
|
+
subproj.products_group.files.each do |product_reference|
|
187
|
+
container_proxy = group.project.new(PBXContainerItemProxy)
|
188
|
+
container_proxy.container_portal = ref.uuid
|
189
|
+
container_proxy.proxy_type = Constants::PROXY_TYPES[:reference]
|
190
|
+
container_proxy.remote_global_id_string = product_reference.uuid
|
191
|
+
container_proxy.remote_info = 'Subproject'
|
192
|
+
|
193
|
+
reference_proxy = group.project.new(PBXReferenceProxy)
|
194
|
+
extension = File.extname(product_reference.path)[1..-1]
|
195
|
+
reference_proxy.file_type = Constants::FILE_TYPES_BY_EXTENSION[extension]
|
196
|
+
reference_proxy.path = product_reference.path
|
197
|
+
reference_proxy.remote_ref = container_proxy
|
198
|
+
reference_proxy.source_tree = 'BUILT_PRODUCTS_DIR'
|
199
|
+
|
200
|
+
product_group_ref << reference_proxy
|
201
|
+
end
|
202
|
+
|
203
|
+
attribute = PBXProject.references_by_keys_attributes.find { |attrb| attrb.name == :project_references }
|
204
|
+
project_reference = ObjectDictionary.new(attribute, group.project.root_object)
|
205
|
+
project_reference[:project_ref] = ref
|
206
|
+
project_reference[:product_group] = product_group_ref
|
207
|
+
group.project.root_object.project_references << project_reference
|
208
|
+
|
209
|
+
ref
|
210
|
+
end
|
211
|
+
|
212
|
+
# Configures a file reference according to the extension to math
|
213
|
+
# Xcode behaviour.
|
214
|
+
#
|
215
|
+
# @param [PBXFileReference] ref
|
216
|
+
# The file reference to configure.
|
217
|
+
#
|
218
|
+
# @note To closely match the Xcode behaviour the name attribute of
|
219
|
+
# the file reference is set only if the path of the file is
|
220
|
+
# not equal to the path of the group.
|
221
|
+
#
|
222
|
+
# @return [void]
|
223
|
+
#
|
224
|
+
def configure_defaults_for_file_reference(ref)
|
225
|
+
if ref.path.include?('/')
|
226
|
+
ref.name = ref.path.split('/').last
|
227
|
+
end
|
228
|
+
|
229
|
+
if File.extname(ref.path).downcase == '.framework'
|
230
|
+
ref.include_in_index = nil
|
231
|
+
end
|
232
|
+
end
|
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
|
+
|
240
|
+
#-------------------------------------------------------------------#
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
@@ -0,0 +1,260 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Xcodeproj
|
3
|
+
class Project
|
4
|
+
module Object
|
5
|
+
class GroupableHelper
|
6
|
+
class << self
|
7
|
+
# @param [PBXGroup, PBXFileReference] object
|
8
|
+
# The object to analyze.
|
9
|
+
#
|
10
|
+
# @return [PBXGroup, PBXProject] The parent of the object.
|
11
|
+
#
|
12
|
+
def parent(object)
|
13
|
+
referrers = object.referrers.uniq
|
14
|
+
if referrers.count > 1
|
15
|
+
referrers = referrers.grep(PBXGroup)
|
16
|
+
end
|
17
|
+
|
18
|
+
if referrers.count == 0
|
19
|
+
raise '[Xcodeproj] Consistency issue: no parent ' \
|
20
|
+
"for object `#{object.display_name}`: "\
|
21
|
+
"`#{object.referrers.join('`, `')}`"
|
22
|
+
elsif referrers.count > 1
|
23
|
+
raise '[Xcodeproj] Consistency issue: unexpected multiple parents ' \
|
24
|
+
"for object `#{object.display_name}`: "\
|
25
|
+
"#{object.referrers}"
|
26
|
+
end
|
27
|
+
referrers.first
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [PBXGroup, PBXFileReference] object
|
31
|
+
# The object to analyze.
|
32
|
+
#
|
33
|
+
# @return [Array<PBXGroup, PBXProject>] The parents of the object.
|
34
|
+
#
|
35
|
+
def parents(object)
|
36
|
+
if main_group?(object)
|
37
|
+
[]
|
38
|
+
else
|
39
|
+
parent = parent(object)
|
40
|
+
parents(parent).push(parent)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param [PBXGroup, PBXFileReference] object
|
45
|
+
# The object to analyze.
|
46
|
+
#
|
47
|
+
# @return [String] A representation of the group hierarchy.
|
48
|
+
#
|
49
|
+
def hierarchy_path(object)
|
50
|
+
unless main_group?(object)
|
51
|
+
parent = parent(object)
|
52
|
+
parent = parent.hierarchy_path if parent.respond_to?(:hierarchy_path)
|
53
|
+
"#{parent}/#{object.display_name}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [PBXGroup, PBXFileReference] object
|
58
|
+
# The object to analyze.
|
59
|
+
#
|
60
|
+
# @return [Bool] Wether the object is the main group of the project.
|
61
|
+
#
|
62
|
+
def main_group?(object)
|
63
|
+
object.equal?(object.project.main_group)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Moves the object to a new parent.
|
67
|
+
#
|
68
|
+
# @param [PBXGroup, PBXFileReference] object
|
69
|
+
# The object to move.
|
70
|
+
#
|
71
|
+
# @param [PBXGroup] new_parent
|
72
|
+
# The new parent.
|
73
|
+
#
|
74
|
+
# @return [void]
|
75
|
+
#
|
76
|
+
def move(object, new_parent)
|
77
|
+
unless object
|
78
|
+
raise "[Xcodeproj] Attempt to move nil object to `#{new_parent}`."
|
79
|
+
end
|
80
|
+
unless new_parent
|
81
|
+
raise "[Xcodeproj] Attempt to move object `#{object}` to nil parent."
|
82
|
+
end
|
83
|
+
if new_parent.equal?(object)
|
84
|
+
raise "[Xcodeproj] Attempt to move object `#{object}` to itself."
|
85
|
+
end
|
86
|
+
if parents(new_parent).include?(object)
|
87
|
+
raise "[Xcodeproj] Attempt to move object `#{object}` to a child object `#{new_parent}`."
|
88
|
+
end
|
89
|
+
|
90
|
+
object.parent.children.delete(object)
|
91
|
+
new_parent << object
|
92
|
+
end
|
93
|
+
|
94
|
+
# @param [PBXGroup, PBXFileReference] object
|
95
|
+
# The object to analyze.
|
96
|
+
#
|
97
|
+
# @return [Pathname] The absolute path of the object resolving the
|
98
|
+
# source tree.
|
99
|
+
#
|
100
|
+
def real_path(object)
|
101
|
+
source_tree = source_tree_real_path(object)
|
102
|
+
path = object.path || ''.freeze
|
103
|
+
if source_tree
|
104
|
+
source_tree + path
|
105
|
+
else
|
106
|
+
Pathname(path)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# @param [PBXGroup, PBXFileReference] object
|
111
|
+
# The object to analyze.
|
112
|
+
#
|
113
|
+
# @return [Pathname] The path of the object without resolving the
|
114
|
+
# source tree.
|
115
|
+
#
|
116
|
+
def full_path(object)
|
117
|
+
folder = case object.source_tree
|
118
|
+
when '<group>'
|
119
|
+
object_parent = parent(object)
|
120
|
+
if object_parent.isa == 'PBXProject'.freeze
|
121
|
+
nil
|
122
|
+
else
|
123
|
+
full_path(object_parent)
|
124
|
+
end
|
125
|
+
when 'SOURCE_ROOT'
|
126
|
+
nil
|
127
|
+
when '<absolute>'
|
128
|
+
Pathname.new('/'.freeze)
|
129
|
+
else
|
130
|
+
Pathname.new("${#{object.source_tree}}")
|
131
|
+
end
|
132
|
+
folder ||= Pathname.new('')
|
133
|
+
if object.path
|
134
|
+
folder + object.path
|
135
|
+
else
|
136
|
+
folder
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# @param [PBXGroup, PBXFileReference] object
|
141
|
+
# The object to analyze.
|
142
|
+
#
|
143
|
+
# @return [Pathname] The absolute path of the source tree of the
|
144
|
+
# object.
|
145
|
+
#
|
146
|
+
def source_tree_real_path(object)
|
147
|
+
case object.source_tree
|
148
|
+
when '<group>'
|
149
|
+
object_parent = parent(object)
|
150
|
+
if object_parent.isa == 'PBXProject'.freeze
|
151
|
+
object.project.project_dir + object.project.root_object.project_dir_path
|
152
|
+
else
|
153
|
+
real_path(object_parent)
|
154
|
+
end
|
155
|
+
when 'SOURCE_ROOT'
|
156
|
+
object.project.project_dir
|
157
|
+
when '<absolute>'
|
158
|
+
nil
|
159
|
+
else
|
160
|
+
Pathname.new("${#{object.source_tree}}")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# @return [Hash{Symbol => String}] The source tree values by they
|
165
|
+
# symbol representation.
|
166
|
+
#
|
167
|
+
SOURCE_TREES_BY_KEY = {
|
168
|
+
:absolute => '<absolute>',
|
169
|
+
:group => '<group>',
|
170
|
+
:project => 'SOURCE_ROOT',
|
171
|
+
:built_products => 'BUILT_PRODUCTS_DIR',
|
172
|
+
:developer_dir => 'DEVELOPER_DIR',
|
173
|
+
:sdk_root => 'SDKROOT',
|
174
|
+
}.freeze
|
175
|
+
|
176
|
+
# Sets the source tree of the given object.
|
177
|
+
#
|
178
|
+
# @param [Symbol, String] source_tree
|
179
|
+
# The source tree, either a string or a key for
|
180
|
+
# {SOURCE_TREES_BY_KEY}.
|
181
|
+
#
|
182
|
+
# @return [void]
|
183
|
+
#
|
184
|
+
def set_source_tree(object, source_tree)
|
185
|
+
source_tree = normalize_source_tree(source_tree)
|
186
|
+
object.source_tree = source_tree
|
187
|
+
end
|
188
|
+
|
189
|
+
# Sets the path of the given object according to the provided source
|
190
|
+
# tree key. The path is converted to relative according to the real
|
191
|
+
# path of the source tree for group and project source trees, if both
|
192
|
+
# paths are relative or absolute. Otherwise the path is set as
|
193
|
+
# provided.
|
194
|
+
#
|
195
|
+
# @param [PBXGroup, PBXFileReference] object
|
196
|
+
# The object whose path needs to be set.
|
197
|
+
#
|
198
|
+
# @param [#to_s] path
|
199
|
+
# The path.
|
200
|
+
#
|
201
|
+
# @param [Symbol, String] source_tree
|
202
|
+
# The source tree, either a string or a key for
|
203
|
+
# {SOURCE_TREES_BY_KEY}.
|
204
|
+
#
|
205
|
+
# @return [void]
|
206
|
+
#
|
207
|
+
def set_path_with_source_tree(object, path, source_tree)
|
208
|
+
path = Pathname(path)
|
209
|
+
source_tree = normalize_source_tree(source_tree)
|
210
|
+
object.source_tree = source_tree
|
211
|
+
|
212
|
+
if source_tree == SOURCE_TREES_BY_KEY[:absolute]
|
213
|
+
unless path.absolute?
|
214
|
+
raise '[Xcodeproj] Attempt to set a relative path with an ' \
|
215
|
+
"absolute source tree: `#{path}`"
|
216
|
+
end
|
217
|
+
object.path = path.to_s
|
218
|
+
elsif source_tree == SOURCE_TREES_BY_KEY[:group] || source_tree == SOURCE_TREES_BY_KEY[:project]
|
219
|
+
source_tree_real_path = GroupableHelper.source_tree_real_path(object)
|
220
|
+
if source_tree_real_path && source_tree_real_path.absolute? == path.absolute?
|
221
|
+
relative_path = path.relative_path_from(source_tree_real_path)
|
222
|
+
object.path = relative_path.to_s
|
223
|
+
else
|
224
|
+
object.path = path.to_s
|
225
|
+
end
|
226
|
+
else
|
227
|
+
object.path = path.to_s
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
private
|
232
|
+
|
233
|
+
# @group Helpers
|
234
|
+
#-------------------------------------------------------------------#
|
235
|
+
|
236
|
+
# Converts the given source tree to its string value.
|
237
|
+
#
|
238
|
+
# @param [Symbol, String] source_tree
|
239
|
+
# The source tree, either a string or a key for
|
240
|
+
# {SOURCE_TREES_BY_KEY}.
|
241
|
+
#
|
242
|
+
# @return [String] the string value of the source tree.
|
243
|
+
#
|
244
|
+
def normalize_source_tree(source_tree)
|
245
|
+
if source_tree.is_a?(Symbol)
|
246
|
+
source_tree = SOURCE_TREES_BY_KEY[source_tree]
|
247
|
+
end
|
248
|
+
|
249
|
+
unless SOURCE_TREES_BY_KEY.values.include?(source_tree)
|
250
|
+
raise "[Xcodeproj] Unrecognized source tree option `#{source_tree}`"
|
251
|
+
end
|
252
|
+
source_tree
|
253
|
+
end
|
254
|
+
|
255
|
+
#-------------------------------------------------------------------#
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|