xcode-archive-cache 0.0.9 → 0.0.11

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.
@@ -0,0 +1,58 @@
1
+ module TargetEqualityCheck
2
+ # @return [String]
3
+ #
4
+ def equatable_identifier
5
+ uuid + display_name
6
+ end
7
+ end
8
+
9
+ module BuildConfigurationSearch
10
+ # @param [String] configuration_name
11
+ #
12
+ # @return [Xcodeproj::Project::Object::XCBuildConfiguration]
13
+ #
14
+ def find_build_configuration(configuration_name, raise_if_not_found: true)
15
+ build_configuration = build_configurations
16
+ .select { |configuration| configuration.name == configuration_name }
17
+ .first
18
+ if raise_if_not_found && build_configuration == nil
19
+ raise XcodeArchiveCache::Informative, "#{configuration_name} build configuration not found on target #{display_name} #{project.path}"
20
+ end
21
+
22
+ build_configuration
23
+ end
24
+ end
25
+
26
+ module SchellScriptBuildPhaseSearch
27
+ # @param [XcodeArchiveCache::BuildSettings::StringInterpolator] build_settings_interpolator
28
+ # @param [XcodeArchiveCache::BuildSettings::Container] build_settings
29
+ # @param [String] script_name
30
+ #
31
+ # @return [String]
32
+ #
33
+ def find_script(build_settings_interpolator, build_settings, script_name)
34
+ shell_script_build_phases.each do |phase|
35
+ if phase.display_name == script_name
36
+ return build_settings_interpolator.interpolate(phase.shell_script, build_settings)
37
+ .gsub(/^"|"$/, "")
38
+ .strip
39
+ end
40
+ end
41
+
42
+ nil
43
+ end
44
+ end
45
+
46
+ class Xcodeproj::Project::Object::PBXAggregateTarget
47
+ include XcodeArchiveCache::Logs
48
+ include TargetEqualityCheck
49
+ include BuildConfigurationSearch
50
+ include SchellScriptBuildPhaseSearch
51
+ end
52
+
53
+ class Xcodeproj::Project::Object::PBXNativeTarget
54
+ include XcodeArchiveCache::Logs
55
+ include TargetEqualityCheck
56
+ include BuildConfigurationSearch
57
+ include SchellScriptBuildPhaseSearch
58
+ end
@@ -7,9 +7,9 @@ module XcodeArchiveCache
7
7
  # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
8
8
  # @param [String] path
9
9
  #
10
- def add_framework_search_path(build_configuration, path)
10
+ def replace_or_add_framework_search_path(build_configuration, target_name, path)
11
11
  debug("using framework search path #{path}")
12
- add_flag_to_configuration(build_configuration, FRAMEWORK_SEARCH_PATHS_KEY, path_to_search_path(path))
12
+ replace_or_add_flag(build_configuration, [FRAMEWORK_SEARCH_PATHS_KEY], nil, [target_name], path_to_search_path(path), true)
13
13
  end
14
14
 
15
15
  # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
@@ -26,6 +26,37 @@ module XcodeArchiveCache
26
26
  # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
27
27
  # @param [XcodeArchiveCache::BuildGraph::Node] node
28
28
  #
29
+ def add_static_lib_linker_flag(build_configuration, node)
30
+ flag = get_linker_flag(node)
31
+ if flag
32
+ debug("using ld flag #{flag}")
33
+ add_linker_flag(build_configuration, flag)
34
+ end
35
+ end
36
+
37
+ # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
38
+ # @param [XcodeArchiveCache::BuildGraph::Node] node
39
+ #
40
+ def add_static_lib_libtool_flag(build_configuration, node)
41
+ flag = get_linker_flag(node)
42
+ if flag
43
+ debug("using libtool flag #{flag}")
44
+ add_libtool_flag(build_configuration, flag)
45
+ end
46
+ end
47
+
48
+ # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
49
+ # @param [String] path
50
+ #
51
+ def add_swift_include_path(build_configuration, path)
52
+ debug("adding #{path} to SWIFT_INCLUDE_PATHS")
53
+ add_flag_to_configuration(build_configuration, SWIFT_INCLUDE_PATHS_KEY, path_to_search_path(path))
54
+ end
55
+
56
+ # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
57
+ # @param [String] artifact_location
58
+ # @param [XcodeArchiveCache::BuildGraph::Node] node
59
+ #
29
60
  def add_framework_headers_iquote(build_configuration, artifact_location, node)
30
61
  headers_search_path = get_framework_headers_iquote(artifact_location, node)
31
62
  debug("using -iquote path #{headers_search_path}")
@@ -35,9 +66,9 @@ module XcodeArchiveCache
35
66
  # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
36
67
  # @param [String] path
37
68
  #
38
- def add_library_search_path(build_configuration, path)
69
+ def replace_or_add_library_search_path(build_configuration, target_name, path)
39
70
  debug("using library search path #{path}")
40
- add_flag_to_configuration(build_configuration, LIBRARY_SEARCH_PATHS_KEY, path_to_search_path(path))
71
+ replace_or_add_flag(build_configuration, [LIBRARY_SEARCH_PATHS_KEY], nil, [target_name], path_to_search_path(path), true)
41
72
  end
42
73
 
43
74
  # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
@@ -64,15 +95,32 @@ module XcodeArchiveCache
64
95
  add_cflag(build_configuration, path_to_capital_i(path))
65
96
  end
66
97
 
98
+ # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
99
+ # @param [Array<String>] old_modulemap_names
100
+ # @param [String] path
101
+ #
102
+ def fix_module_map_path(build_configuration, old_modulemap_names, path)
103
+ debug("using #{path}")
104
+
105
+ settings_with_modulemaps = [OTHER_CFLAGS_KEY, OTHER_CPLUSPLUSFLAGS_KEY, OTHER_SWIFT_FLAGS_KEY]
106
+ replace_or_add_flag(build_configuration, settings_with_modulemaps, MODULE_MAP_FLAG, old_modulemap_names, path_to_search_path(path), false)
107
+ end
108
+
67
109
  private
68
110
 
69
111
  FRAMEWORK_SEARCH_PATHS_KEY = "FRAMEWORK_SEARCH_PATHS"
70
112
  LIBRARY_SEARCH_PATHS_KEY = "LIBRARY_SEARCH_PATHS"
71
113
  HEADER_SEARCH_PATHS_KEY = "HEADER_SEARCH_PATHS"
72
114
  OTHER_CFLAGS_KEY = "OTHER_CFLAGS"
115
+ OTHER_CPLUSPLUSFLAGS_KEY = "OTHER_CPLUSPLUSFLAGS"
73
116
  OTHER_LDFLAGS_KEY = "OTHER_LDFLAGS"
117
+ OTHER_LIBTOOLFLAGS_KEY = "OTHER_LIBTOOLFLAGS"
118
+ OTHER_SWIFT_FLAGS_KEY = "OTHER_SWIFT_FLAGS"
119
+ SWIFT_INCLUDE_PATHS_KEY = "SWIFT_INCLUDE_PATHS"
74
120
  INHERITED_SETTINGS_VALUE = "$(inherited)"
75
121
 
122
+ MODULE_MAP_FLAG = "-fmodule-map-file="
123
+
76
124
  # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
77
125
  # @param [String] flag
78
126
  #
@@ -80,6 +128,13 @@ module XcodeArchiveCache
80
128
  add_flag_to_configuration(build_configuration, OTHER_LDFLAGS_KEY, flag)
81
129
  end
82
130
 
131
+ # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
132
+ # @param [String] flag
133
+ #
134
+ def add_libtool_flag(build_configuration, flag)
135
+ add_flag_to_configuration(build_configuration, OTHER_LIBTOOLFLAGS_KEY, flag)
136
+ end
137
+
83
138
  # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
84
139
  # @param [String] flag
85
140
  #
@@ -167,6 +222,123 @@ module XcodeArchiveCache
167
222
 
168
223
  "-framework \"#{framework_name}\""
169
224
  end
225
+
226
+ # @param [XcodeArchiveCache::BuildGraph::Node] node
227
+ #
228
+ # @return [String]
229
+ #
230
+ # libSomething.a -> -lSomething
231
+ #
232
+ def get_linker_flag(node)
233
+ return unless node.product_file_name
234
+
235
+ node.product_file_name.gsub(/^lib/, "-l").gsub(/\.a$/, "")
236
+ end
237
+
238
+ # @param [Xcodeproj::Project::Object::XCBuildConfiguration] build_configuration
239
+ # @param [Array<String>] setting_keys
240
+ # @param [String] flag_name
241
+ # @param [Array<String>] possible_old_values
242
+ # @param [String] new_value
243
+ #
244
+ def replace_or_add_flag(build_configuration, setting_keys, flag_name, possible_old_values, new_value, add_if_missing)
245
+ replaced = false
246
+
247
+ setting_keys.each do |setting|
248
+ replaced = replace_flag_value(build_configuration.build_settings, setting, flag_name, possible_old_values, new_value) || replaced
249
+ end
250
+
251
+ if build_configuration.has_xcconfig?
252
+ replaced = replace_flag_value_in_xcconfig_recursively(
253
+ build_configuration.get_xcconfig_path,
254
+ build_configuration.get_project_dir,
255
+ setting_keys,
256
+ flag_name,
257
+ possible_old_values,
258
+ new_value) || replaced
259
+ end
260
+
261
+ if !replaced && add_if_missing
262
+ full_value = get_full_flag_value(flag_name, new_value)
263
+
264
+ setting_keys.each do |setting|
265
+ add_flag_to_configuration(build_configuration, setting, full_value)
266
+ end
267
+ end
268
+ end
269
+
270
+ # @param [String] xcconfig_path
271
+ # @param [String] project_dir
272
+ # @param [Array<String>] setting_keys
273
+ # @param [String] flag_name
274
+ # @param [Array<String>] possible_old_values
275
+ # @param [String] new_value
276
+ #
277
+ def replace_flag_value_in_xcconfig_recursively(xcconfig_path, project_dir, setting_keys, flag_name, possible_old_values, new_value)
278
+ debug("changing #{possible_old_values} to #{new_value} in #{File.basename(xcconfig_path)}")
279
+ return unless File.exist?(xcconfig_path)
280
+
281
+ replaced = false
282
+ xcconfig = Xcodeproj::Config.new(xcconfig_path)
283
+
284
+ setting_keys.each do |key|
285
+ replaced = replace_flag_value(xcconfig.attributes, key, flag_name, possible_old_values, new_value) || replaced
286
+ end
287
+
288
+ xcconfig.save_as(Pathname.new(xcconfig_path))
289
+
290
+ xcconfig.includes.each do |included_xcconfig|
291
+ included_xcconfig_path = File.join(project_dir, included_xcconfig)
292
+ replaced = replace_flag_value_in_xcconfig_recursively(included_xcconfig_path, project_dir, setting_keys, flag_name, possible_old_values, new_value) || replaced
293
+ end
294
+
295
+ replaced
296
+ end
297
+
298
+ # @param [Hash] attributes
299
+ # @param [String] setting_key
300
+ # @param [String] flag_name
301
+ # @param [Array<String>] possible_old_values
302
+ # @param [String] new_value
303
+ #
304
+ def replace_flag_value(attributes, setting_key, flag_name, possible_old_values, new_value)
305
+ build_settings = attributes[setting_key]
306
+ return unless build_settings
307
+
308
+ replaced = false
309
+ is_string = build_settings.is_a?(String)
310
+ build_settings = build_settings.split(" ") if is_string
311
+ full_value = get_full_flag_value(flag_name, new_value)
312
+ old_value_regexps = possible_old_values.map { |value| Regexp.new("/#{value}\"*$") }
313
+
314
+ updated_settings = build_settings
315
+ .map { |line| line.split(" ") }
316
+ .flatten
317
+ .map do |line|
318
+ if flag_name
319
+ next line unless line.include?(flag_name)
320
+ end
321
+
322
+ updated_line = line
323
+
324
+ old_value_regexps.each do |regexp|
325
+ if regexp.match?(line)
326
+ replaced = true
327
+ updated_line = full_value
328
+ break
329
+ end
330
+ end
331
+
332
+ updated_line
333
+ end
334
+
335
+ attributes[setting_key] = is_string ? updated_settings.join(" ") : updated_settings
336
+ replaced
337
+ end
338
+
339
+ def get_full_flag_value(flag_name, value)
340
+ "#{flag_name}#{value}"
341
+ end
170
342
  end
171
343
  end
172
344
  end
@@ -12,11 +12,21 @@ module XcodeArchiveCache
12
12
  debug("removing #{prebuilt_target.name} from #{dependent_target.display_name}")
13
13
 
14
14
  remove_from_dependencies(prebuilt_target, dependent_target)
15
+ remove_from_linking(prebuilt_node, dependent_target)
15
16
  remove_from_schemes(prebuilt_target, dependent_target)
16
17
 
17
18
  debug("finished removing #{prebuilt_target.name} from #{dependent_target.display_name}")
18
19
  end
19
20
 
21
+ # @param [XcodeArchiveCache::BuildGraph::Node] prebuilt_node
22
+ # @param [Xcodeproj::Project::Object::PBXNativeTarget] dependent_target
23
+ #
24
+ # @return [Boolean]
25
+ #
26
+ def is_linked(prebuilt_node, dependent_target)
27
+ !find_linked(prebuilt_node, dependent_target).empty?
28
+ end
29
+
20
30
  private
21
31
 
22
32
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] prebuilt_target
@@ -46,7 +56,7 @@ module XcodeArchiveCache
46
56
  #
47
57
  def remove_from_linking(prebuilt_node, dependent_target)
48
58
  debug("product name is #{prebuilt_node.product_file_name}")
49
- frameworks = dependent_target.frameworks_build_phase.files.select {|file| file.display_name == prebuilt_node.product_file_name}
59
+ frameworks = find_linked(prebuilt_node, dependent_target)
50
60
  debug("found #{frameworks.length} linked products")
51
61
 
52
62
  frameworks.each do |framework|
@@ -67,6 +77,17 @@ module XcodeArchiveCache
67
77
  end
68
78
  end
69
79
 
80
+ # @param [Xcodeproj::Project::Object::PBXNativeTarget] dependent_target
81
+ # @param [XcodeArchiveCache::BuildGraph::Node] prebuilt_node
82
+ #
83
+ # @return [Array<PBXBuildFile>]
84
+ #
85
+ def find_linked(prebuilt_node, dependent_target)
86
+ return [] unless dependent_target.frameworks_build_phase
87
+
88
+ dependent_target.frameworks_build_phase.files.select {|file| file.display_name == prebuilt_node.product_file_name}
89
+ end
90
+
70
91
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] target
71
92
  #
72
93
  # @return [Array<Xcodeproj::XCScheme>]
@@ -9,6 +9,7 @@ module XcodeArchiveCache
9
9
  def initialize(storage)
10
10
  @storage = storage
11
11
  @build_settings_interpolator = XcodeArchiveCache::BuildSettings::StringInterpolator.new
12
+ @modulemap_header_path_extractor = XcodeArchiveCache::Modulemap::HeaderPathExtractor.new
12
13
  end
13
14
 
14
15
  # @param [XcodeArchiveCache::BuildGraph::Node] node
@@ -19,17 +20,36 @@ module XcodeArchiveCache
19
20
 
20
21
  node.native_target.copy_files_build_phases.each do |build_phase|
21
22
  file_paths = build_phase.files
22
- .map {|build_file| get_real_path(build_file)}
23
+ .map { |build_file| get_real_path(build_file) }
23
24
  .compact
24
25
  .uniq
25
- .select {|path| File.extname(path) == ".h"}
26
+ .select { |path| File.extname(path) == ".h" }
26
27
  destination_path = get_destination_dir_path(node, build_phase)
27
28
  storage.store_headers(node, destination_path, file_paths)
28
29
 
29
30
  header_count += file_paths.length
30
31
  end
31
32
 
32
- debug("found #{header_count} headers")
33
+ if node.has_static_library_product?
34
+ headers_file_paths = node.native_target
35
+ .headers_build_phase
36
+ .files
37
+ .select { |file| file.settings && file.settings["ATTRIBUTES"].include?("Public") }
38
+ .map { |header| get_real_path(header) }
39
+ .uniq
40
+ storage.store_default_headers(node, headers_file_paths)
41
+
42
+ header_count += headers_file_paths.length
43
+ end
44
+
45
+ modulemap_file_path = node.original_modulemap_file_path
46
+ if modulemap_file_path && File.exist?(modulemap_file_path)
47
+ header_file_paths = modulemap_header_path_extractor.extract_all_paths(modulemap_file_path)
48
+ storage.store_modulemap_headers(node, header_file_paths)
49
+ header_count += header_file_paths.length
50
+ end
51
+
52
+ debug("found #{header_count} header(s)")
33
53
  end
34
54
 
35
55
  private
@@ -42,6 +62,10 @@ module XcodeArchiveCache
42
62
  #
43
63
  attr_reader :build_settings_interpolator
44
64
 
65
+ # @return [XcodeArchiveCache::Modulemap::HeaderPathExtractor]
66
+ #
67
+ attr_reader :modulemap_header_path_extractor
68
+
45
69
  # @param [Xcodeproj::Project::Object::PBXBuildFile] build_file
46
70
  #
47
71
  # @return [String]
@@ -14,13 +14,14 @@ module XcodeArchiveCache
14
14
  @dependency_remover = DependencyRemover.new
15
15
  @build_flags_changer = BuildFlagsChanger.new
16
16
  @pods_fixer = PodsScriptFixer.new
17
+ @modulemap_fixer = XcodeArchiveCache::Modulemap::HeaderPathFixer.new(storage)
17
18
  @framework_embedder = FrameworkEmbedder.new
18
19
  end
19
20
 
20
21
  # @param [XcodeArchiveCache::BuildGraph::Graph] graph
21
22
  #
22
23
  def perform_internal_injection(graph)
23
- inject_unpacked(graph.nodes)
24
+ inject_unpacked_and_rebuilt(graph.nodes)
24
25
  add_header_paths(graph.nodes)
25
26
  save_graph_projects(graph)
26
27
  end
@@ -34,9 +35,15 @@ module XcodeArchiveCache
34
35
  return
35
36
  end
36
37
 
38
+ no_rebuild_performed = root_node.state == :unpacked
39
+
37
40
  graph.nodes.each do |node|
38
- headers_mover.prepare_headers_for_injection(node)
39
- add_as_prebuilt_dependency(node, target, node.is_root)
41
+ if no_rebuild_performed || node.state == :rebuilt_and_cached
42
+ headers_mover.prepare_headers_for_injection(node)
43
+ modulemap_fixer.fix_modulemap(node)
44
+ end
45
+
46
+ add_as_prebuilt_dependency(node, target)
40
47
  remove_native_target_from_project(node)
41
48
  end
42
49
 
@@ -51,8 +58,8 @@ module XcodeArchiveCache
51
58
  pods_fixer.fix_embed_frameworks_script(target, graph, storage.container_dir_path)
52
59
  pods_fixer.fix_copy_resources_script(target, graph, storage.container_dir_path)
53
60
  else
54
- framework_nodes = graph.nodes.select {|node| node.has_framework_product?}
55
- framework_file_paths = framework_nodes.map {|node| File.join(storage.get_storage_path(node), node.product_file_name)}
61
+ framework_nodes = graph.nodes.select { |node| node.has_framework_product? }
62
+ framework_file_paths = framework_nodes.map { |node| File.join(storage.get_storage_path(node), node.product_file_name) }
56
63
  framework_embedder.embed(framework_file_paths, target)
57
64
  end
58
65
 
@@ -86,16 +93,26 @@ module XcodeArchiveCache
86
93
  #
87
94
  attr_reader :pods_fixer
88
95
 
96
+ # @return [ModulemapFixer]
97
+ #
98
+ attr_reader :modulemap_fixer
99
+
89
100
  # @return [FrameworkEmbedder]
90
101
  #
91
102
  attr_reader :framework_embedder
92
103
 
93
104
  # @param [Array<XcodeArchiveCache::BuildGraph::Node>] nodes
94
105
  #
95
- def inject_unpacked(nodes)
96
- cached_nodes = nodes.select {|node| node.state == :unpacked}
106
+ def inject_unpacked_and_rebuilt(nodes)
107
+ cached_nodes = nodes.select { |node| node.state == :unpacked }
97
108
  cached_nodes.each do |node|
98
109
  headers_mover.prepare_headers_for_injection(node)
110
+ modulemap_fixer.fix_modulemap(node)
111
+ add_as_prebuilt_to_dependents(node)
112
+ end
113
+
114
+ built_nodes = nodes.select { |node| node.state == :rebuilt_and_cached }
115
+ built_nodes.each do |node|
99
116
  add_as_prebuilt_to_dependents(node)
100
117
  end
101
118
  end
@@ -108,7 +125,7 @@ module XcodeArchiveCache
108
125
 
109
126
  nodes
110
127
  .select(&:waiting_for_rebuild)
111
- .each {|node| add_header_paths_to_target(node.native_target, header_storage_paths)}
128
+ .each { |node| add_header_paths_to_target(node.native_target, header_storage_paths) }
112
129
  end
113
130
 
114
131
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] target
@@ -119,7 +136,7 @@ module XcodeArchiveCache
119
136
 
120
137
  debug("adding #{paths} to #{target.display_name}")
121
138
 
122
- build_configuration = find_build_configuration(target)
139
+ build_configuration = target.find_build_configuration(configuration_name)
123
140
  paths.each do |path|
124
141
  build_flags_changer.add_headers_search_path(build_configuration, path)
125
142
  build_flags_changer.add_iquote_path(build_configuration, path)
@@ -134,8 +151,7 @@ module XcodeArchiveCache
134
151
  .all_dependent_nodes
135
152
  .select(&:waiting_for_rebuild)
136
153
  dependent_to_rebuild.each do |dependent_node|
137
- should_link = prebuilt_node.dependent.include?(dependent_node)
138
- add_as_prebuilt_dependency(prebuilt_node, dependent_node.native_target, should_link)
154
+ add_as_prebuilt_dependency(prebuilt_node, dependent_node.native_target)
139
155
  end
140
156
 
141
157
  remove_native_target_from_project(prebuilt_node)
@@ -146,25 +162,30 @@ module XcodeArchiveCache
146
162
  def save_graph_projects(graph)
147
163
  projects = graph.nodes.map(&:native_target).map(&:project).uniq
148
164
  debug("updating #{projects.length} projects")
149
- projects.each {|project| project.save}
165
+ projects.each { |project| project.save }
150
166
  end
151
167
 
152
168
  # @param [XcodeArchiveCache::BuildGraph::Node] prebuilt_node
153
169
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] dependent_target
154
170
  #
155
- def add_as_prebuilt_dependency(prebuilt_node, dependent_target, should_link)
171
+ def add_as_prebuilt_dependency(prebuilt_node, dependent_target)
172
+ target_identifier = get_target_identifier(dependent_target)
173
+ return if prebuilt_node.targets_injected_to.include?(target_identifier)
174
+
156
175
  debug("adding #{prebuilt_node.name} as prebuilt to #{dependent_target.display_name}")
157
176
 
158
177
  unless prebuilt_node.has_acceptable_product?
159
- raise Informative, "#{prebuilt_node.name} has unsupported product type: #{prebuilt_node.native_target.product_type}"
178
+ raise XcodeArchiveCache::Informative, "#{prebuilt_node.name} has unsupported product type: #{prebuilt_node.native_target.product_type}"
160
179
  end
161
180
 
162
181
  if prebuilt_node.has_framework_product?
163
182
  add_as_prebuilt_framework(prebuilt_node, dependent_target)
164
183
  elsif prebuilt_node.has_static_library_product?
165
- add_as_prebuilt_static_lib(prebuilt_node, dependent_target, should_link)
184
+ add_as_prebuilt_static_lib(prebuilt_node, dependent_target)
166
185
  end
167
186
 
187
+ prebuilt_node.targets_injected_to.push(target_identifier)
188
+
168
189
  debug("done with #{prebuilt_node.name} for #{dependent_target.display_name}")
169
190
  end
170
191
 
@@ -172,39 +193,47 @@ module XcodeArchiveCache
172
193
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] dependent_target
173
194
  #
174
195
  def add_as_prebuilt_framework(prebuilt_node, dependent_target)
175
- build_configuration = find_build_configuration(dependent_target)
196
+ build_configuration = dependent_target.find_build_configuration(configuration_name)
176
197
 
177
198
  artifact_location = storage.get_storage_path(prebuilt_node)
178
- build_flags_changer.add_framework_search_path(build_configuration, artifact_location)
199
+ build_flags_changer.replace_or_add_framework_search_path(build_configuration, prebuilt_node.native_target.name, artifact_location)
179
200
  build_flags_changer.add_framework_headers_iquote(build_configuration, artifact_location, prebuilt_node)
180
201
 
202
+ if dependency_remover.is_linked(prebuilt_node, dependent_target)
203
+ build_flags_changer.add_framework_linker_flag(build_configuration, prebuilt_node)
204
+ end
205
+
181
206
  dependency_remover.remove_dependency(prebuilt_node, dependent_target)
182
207
  end
183
208
 
184
209
  # @param [XcodeArchiveCache::BuildGraph::Node] prebuilt_node
185
210
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] dependent_target
186
- # @param [Boolean] should_link
187
211
  #
188
- def add_as_prebuilt_static_lib(prebuilt_node, dependent_target, should_link)
189
- build_configuration = find_build_configuration(dependent_target)
212
+ def add_as_prebuilt_static_lib(prebuilt_node, dependent_target)
213
+ build_configuration = dependent_target.find_build_configuration(configuration_name)
190
214
 
191
- if should_link
192
- artifact_location = storage.get_storage_path(prebuilt_node)
193
- build_flags_changer.add_library_search_path(build_configuration, artifact_location)
194
- end
215
+ injected_modulemap_file_path = storage.get_modulemap_path(prebuilt_node)
216
+ if injected_modulemap_file_path
217
+ modulemap_file_names = [prebuilt_node.resulting_modulemap_file_name]
218
+ build_flags_changer.fix_module_map_path(build_configuration, modulemap_file_names, injected_modulemap_file_path)
195
219
 
196
- dependency_remover.remove_dependency(prebuilt_node, dependent_target)
197
- end
220
+ original_modulemap_path = prebuilt_node.original_modulemap_file_path
221
+ add_header_paths_to_target(dependent_target, [File.dirname(original_modulemap_path)])
222
+ end
198
223
 
199
- # @param [Xcodeproj::Project::Object::PBXNativeTarget] target
200
- #
201
- def find_build_configuration(target)
202
- build_configuration = target.build_configurations.select {|configuration| configuration.name == configuration_name}.first
203
- unless build_configuration
204
- raise Informative, "#{configuration_name} build configuration not found on target #{node.name}"
224
+ artifact_location = storage.get_storage_path(prebuilt_node)
225
+ build_flags_changer.replace_or_add_library_search_path(build_configuration, prebuilt_node.native_target.name, artifact_location)
226
+ build_flags_changer.add_swift_include_path(build_configuration, artifact_location)
227
+
228
+ if dependency_remover.is_linked(prebuilt_node, dependent_target)
229
+ if dependent_target.product_type == Xcodeproj::Constants::PRODUCT_TYPE_UTI[:static_library]
230
+ build_flags_changer.add_static_lib_libtool_flag(build_configuration, prebuilt_node)
231
+ else
232
+ build_flags_changer.add_static_lib_linker_flag(build_configuration, prebuilt_node)
233
+ end
205
234
  end
206
235
 
207
- build_configuration
236
+ dependency_remover.remove_dependency(prebuilt_node, dependent_target)
208
237
  end
209
238
 
210
239
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] target
@@ -224,6 +253,14 @@ module XcodeArchiveCache
224
253
  debug("deleting #{node.name} target")
225
254
  node.native_target.project.targets.delete(node.native_target)
226
255
  end
256
+
257
+ # @param [Xcodeproj::Project::Object::PBXNativeTarget] target
258
+ #
259
+ # @return [String]
260
+ #
261
+ def get_target_identifier(target)
262
+ target.uuid + target.project.path.realpath.to_s
263
+ end
227
264
  end
228
265
  end
229
266
  end