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
209
|
# File 'lib/pod_builder/podspec.rb', line 19
def self.generate_spec_keys_for(item, name, all_buildable_items, install_using_frameworks)
podspec = ""
valid = false
slash_count = name.count("/") + 1
indentation = " " * slash_count
spec_var = "p#{slash_count}"
if spec_var == "p1" && item.default_subspecs.count > 0
podspec += "#{indentation}#{spec_var}.default_subspecs = '#{item.default_subspecs.join("', '")}'\n"
end
if item.name == name
if_exists = lambda { |t| File.exist?(PodBuilder::prebuiltpath("#{item.root_name}/#{t}") || "") }
vendored_frameworks = item.vendored_frameworks
if item.default_subspecs.reject { |t| "#{item.root_name}/#{t}" == item.name }.count == 0 && install_using_frameworks
vendored_frameworks += ["#{item.module_name}.framework", "#{item.module_name}.xcframework"].select(&if_exists)
end
existing_vendored_frameworks = vendored_frameworks.select(&if_exists)
existing_vendored_frameworks_basename = vendored_frameworks.map { |t| File.basename(t) }.select(&if_exists)
vendored_frameworks = (existing_vendored_frameworks + existing_vendored_frameworks_basename).uniq
vendored_libraries = item.vendored_libraries
if install_using_frameworks
existing_vendored_libraries = vendored_libraries.map { |t| "#{item.module_name}/#{t}" }.select(&if_exists)
existing_vendored_libraries_basename = vendored_libraries.map { |t| File.basename(t) }.select(&if_exists)
vendored_libraries = (existing_vendored_libraries + existing_vendored_libraries_basename).uniq
vendored_libraries.reject! { |t| t.end_with?(".a") }
= []
resources = []
exclude_files = []
vendored_frameworks.each do |vendored_framework|
if vendored_framework.end_with?(".xcframework")
binary_path = Dir.glob(PodBuilder::prebuiltpath("#{item.root_name}/#{vendored_framework}/**/#{File.basename(vendored_framework, ".*")}")).reject { |t| t.include?("simulator") }.first
else
binary_path = Dir.glob(PodBuilder::prebuiltpath("#{item.root_name}/#{vendored_framework}/**/#{File.basename(vendored_framework, ".*")}")).first
end
next if binary_path.nil?
is_static = `file '#{binary_path}'`.include?("current ar archive")
if is_static
parent_folder = File.expand_path("#{binary_path}/..")
rel_path = Pathname.new(parent_folder).relative_path_from(Pathname.new(PodBuilder::prebuiltpath(item.root_name))).to_s
resources.push("#{rel_path}/*.{nib,bundle,xcasset,strings,png,jpg,tif,tiff,otf,ttf,ttc,plist,json,caf,wav,p12,momd}")
exclude_files.push("#{rel_path}/Info.plist")
end
end
else
= Dir.glob(PodBuilder::prebuiltpath("#{item.root_name}/#{item.root_name}/Headers/**/*.h"))
vendored_libraries += ["#{item.root_name}/lib#{item.root_name}.a"]
vendored_libraries = vendored_libraries.select(&if_exists)
resources = ["#{item.root_name}/*.{nib,bundle,xcasset,strings,png,jpg,tif,tiff,otf,ttf,ttc,plist,json,caf,wav,p12,momd}"]
exclude_files = ["*.modulemap"]
unless item.swift_version.nil?
exclude_files += ["Swift Compatibility Header/*", "*.swiftmodule"]
end
exclude_files.map! { |t| "#{item.root_name}/#{t}" }
end
entries = lambda { |spec_key, spec_value|
key = "#{indentation}#{spec_var}.#{spec_key}"
joined_values = spec_value.map { |t| "#{t}" }.uniq.sort.join("', '")
"#{key} = '#{joined_values}'\n"
}
if vendored_frameworks.count > 0
podspec += entries.call("vendored_frameworks", vendored_frameworks)
end
if vendored_libraries.count > 0
podspec += entries.call("vendored_libraries", vendored_libraries)
end
if item.frameworks.count > 0
podspec += entries.call("frameworks", item.frameworks)
end
if item.libraries.count > 0
podspec += entries.call("libraries", item.libraries)
end
if resources.count > 0
podspec += entries.call("resources", resources)
end
if exclude_files.count > 0
podspec += entries.call("exclude_files", exclude_files)
end
if .count > 0
podspec += "#{indentation}#{spec_var}.public_header_files = '#{item.root_name}/Headers/**/*.h'\n"
end
if !item..nil? && !install_using_frameworks
podspec += "#{indentation}#{spec_var}.header_dir = '#{item.}'\n"
podspec += "#{indentation}#{spec_var}.header_mappings_dir = '#{item.root_name}/Headers/#{item.}'\n"
end
if item.xcconfig.keys.count > 0
xcconfig = Hash.new
item.xcconfig.each do |k, v|
unless v != "$(inherited)"
xcconfig[k] = item.xcconfig[k]
next
end
unless k == "OTHER_LDFLAGS"
next end
if podspec_values = item.xcconfig[k]
podspec_values_arr = podspec_values.split(" ")
podspec_values_arr.push(v)
v = podspec_values_arr.join(" ")
end
xcconfig[k] = item.xcconfig[k]
end
if xcconfig.keys.count > 0
podspec += "#{indentation}#{spec_var}.xcconfig = #{xcconfig.to_s}\n"
end
end
if !install_using_frameworks && spec_var == "p1" && vendored_libraries.map { |t| File.basename(t) }.include?("lib#{item.root_name}.a")
module_path_files = Dir.glob(PodBuilder.prebuiltpath("#{item.root_name}/**/#{item.root_name}.modulemap"))
raise "\n\nToo many module maps found for #{item.root_name}\n".red if module_path_files.count > 1
rel_path = Pathname.new(PodBuilder::prebuiltpath).relative_path_from(Pathname.new(PodBuilder::project_path("Pods"))).to_s
prebuilt_root_var = "#{item.root_name.upcase.gsub("-", "_")}_PREBUILT_ROOT"
static_cfg = Hash.new
if module_path_file = module_path_files.first
module_map_rel = module_path_file.gsub(PodBuilder::prebuiltpath("#{item.root_name}/#{item.root_name}/"), "")
static_cfg = { "SWIFT_INCLUDE_PATHS" => "$(inherited) \"$(#{prebuilt_root_var})/#{item.root_name}/#{item.root_name}\"",
"OTHER_CFLAGS" => "$(inherited) -fmodule-map-file=\"$(#{prebuilt_root_var})/#{item.root_name}/#{item.root_name}/#{module_map_rel}\"",
"OTHER_SWIFT_FLAGS" => "$(inherited) -Xcc -fmodule-map-file=\"$(#{prebuilt_root_var})/#{item.root_name}/#{item.root_name}/#{module_map_rel}\"" }
end
static_cfg[prebuilt_root_var] = "$(PODS_ROOT)/#{rel_path}"
podspec += "#{indentation}#{spec_var}.xcconfig = #{static_cfg.to_s}\n"
podspec += "#{indentation}#{spec_var}.user_target_xcconfig = { \"OTHER_LDFLAGS\" => \"$(inherited) -L\\\"$(#{prebuilt_root_var})/#{item.root_name}/#{item.root_name}\\\" -l\\\"#{item.root_name}\\\"\" }\n"
end
deps = item.dependency_names.sort
if name == item.root_name
deps.reject! { |t| t.split("/").first == item.root_name }
end
deps.reject! { |t| t == item.name }
all_buildable_items_name = all_buildable_items.map(&:name)
deps.select! { |t| all_buildable_items_name.include?(t) }
if deps.count > 0
if podspec.count("\n") > 1
podspec += "\n"
end
deps.each do |dependency|
podspec += "#{indentation}#{spec_var}.dependency '#{dependency}'\n"
end
end
valid = valid || (install_using_frameworks ? vendored_frameworks.count > 0 : vendored_libraries.count > 0)
end
subspec_base = name.split("/").first(slash_count).join("/")
subspec_items = all_buildable_items.select { |t| t.name.start_with?("#{subspec_base}/") }
subspec_names = subspec_items.map { |t| t.name.split("/").drop(slash_count).first }.uniq
subspec_names.map! { |t| "#{subspec_base}/#{t}" }
subspec_names.each do |subspec|
subspec_item = all_buildable_items.detect { |t| t.name == subspec } || item
if podspec.length > 0
podspec += "\n"
end
subspec_keys, subspec_valid = generate_spec_keys_for(subspec_item, subspec, all_buildable_items, install_using_frameworks)
valid = valid || subspec_valid
if subspec_keys.length > 0
podspec += "#{indentation}#{spec_var}.subspec '#{subspec.split("/").last}' do |p#{slash_count + 1}|\n"
podspec += subspec_keys
podspec += "#{indentation}end\n"
end
end
return podspec, valid
end
|