-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
file_references_installer.rb
208 lines (182 loc) · 6.64 KB
/
file_references_installer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
module Pod
class Installer
# Controller class responsible of installing the file references of the
# specifications in the Pods project.
#
class FileReferencesInstaller
# @return [Sandbox] The sandbox of the installation.
#
attr_reader :sandbox
# @return [Array<Library>] The libraries of the installation.
#
attr_reader :libraries
# @return [Project] The Pods project.
#
attr_reader :pods_project
# @param [Sandbox] sandbox @see sandbox
# @param [Array<Library>] libraries @see libraries
# @param [Project] libraries @see libraries
#
def initialize(sandbox, libraries, pods_project)
@sandbox = sandbox
@libraries = libraries
@pods_project = pods_project
end
# Installs the file references.
#
# @return [void]
#
def install!
refresh_file_accessors
add_source_files_references
add_frameworks_bundles
add_vendored_libraries
add_resources
link_headers
end
#-----------------------------------------------------------------------#
private
# @!group Installation Steps
# Reads the file accessors contents from the file system.
#
# @note The contents of the file accessors are modified by the clean
# step of the #{PodSourceInstaller} and by the pre install hooks.
#
# @return [void]
#
def refresh_file_accessors
file_accessors.each do |fa|
fa.path_list.read_file_system
end
end
# Adds the source files of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively).
#
# @return [void]
#
def add_source_files_references
UI.message "- Adding source files to Pods project" do
add_file_accessors_paths_to_pods_group(:source_files)
end
end
# Adds the bundled frameworks to the Pods project
#
# @return [void]
#
def add_frameworks_bundles
UI.message "- Adding frameworks to Pods project" do
add_file_accessors_paths_to_pods_group(:vendored_frameworks, :frameworks)
end
end
# Adds the bundled libraries to the Pods project
#
# @return [void]
#
def add_vendored_libraries
UI.message "- Adding libraries to Pods project" do
add_file_accessors_paths_to_pods_group(:vendored_libraries, :frameworks)
end
end
# Adds the resources of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively) in the resources group.
#
# @return [void]
#
def add_resources
UI.message "- Adding resources to Pods project" do
add_file_accessors_paths_to_pods_group(:resources, :resources)
add_file_accessors_paths_to_pods_group(:resource_bundle_files, :resources)
end
end
# Creates the link to the headers of the Pod in the sandbox.
#
# @return [void]
#
def link_headers
UI.message "- Linking headers" do
libraries.each do |library|
library.file_accessors.each do |file_accessor|
headers_sandbox = Pathname.new(file_accessor.spec.root.name)
library.build_headers.add_search_path(headers_sandbox, library.platform)
sandbox.public_headers.add_search_path(headers_sandbox, library.platform)
header_mappings(headers_sandbox, file_accessor, file_accessor.headers).each do |namespaced_path, files|
library.build_headers.add_files(namespaced_path, files, library.platform)
end
header_mappings(headers_sandbox, file_accessor, file_accessor.public_headers).each do |namespaced_path, files|
sandbox.public_headers.add_files(namespaced_path, files, library.platform)
end
end
end
end
end
#-----------------------------------------------------------------------#
private
# @!group Private Helpers
# @return [Array<Sandbox::FileAccessor>] The file accessors for all the
# specs platform combinations.
#
def file_accessors
@file_accessors ||= libraries.map(&:file_accessors).flatten.compact
end
# Adds file references to the list of the paths returned by the file
# accessor with the given key to the given group of the Pods project.
#
# @param [Symbol] file_accessor_key
# The method of the file accessor which would return the list of
# the paths.
#
# @param [Symbol] group_key
# The key of the group of the Pods project.
#
# @return [void]
#
def add_file_accessors_paths_to_pods_group(file_accessor_key, group_key = nil)
file_accessors.each do |file_accessor|
paths = file_accessor.send(file_accessor_key)
paths.each do |path|
group = pods_project.group_for_spec(file_accessor.spec.name, group_key)
pods_project.add_file_reference(path, group)
end
end
end
# Computes the destination sub-directory in the sandbox
#
# @param [Pathname] headers_sandbox
# The sandbox where the headers links should be stored for this
# Pod.
#
# @param [Specification::Consumer] consumer
# The consumer for which the headers need to be linked.
#
# @param [Array<Pathname>] headers
# The absolute paths of the headers which need to be mapped.
#
# @return [Hash{Pathname => Array<Pathname>}] A hash containing the
# headers folders as the keys and the absolute paths of the
# header files as the values.
#
def header_mappings(headers_sandbox, file_accessor, headers)
consumer = file_accessor.spec_consumer
dir = headers_sandbox
dir = dir + consumer.header_dir if consumer.header_dir
mappings = {}
headers.each do |header|
sub_dir = dir
if consumer.header_mappings_dir
header_mappings_dir = file_accessor.path_list.root + consumer.header_mappings_dir
relative_path = header.relative_path_from(header_mappings_dir)
sub_dir = sub_dir + relative_path.dirname
end
mappings[sub_dir] ||= []
mappings[sub_dir] << header
end
mappings
end
#-----------------------------------------------------------------------#
end
end
end