cocoapods-fy-bin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +1 -0
- data/lib/cocoapods-fy-bin/command/bin/archive.rb +202 -0
- data/lib/cocoapods-fy-bin/command/bin/auto.rb +204 -0
- data/lib/cocoapods-fy-bin/command/bin/code.rb +232 -0
- data/lib/cocoapods-fy-bin/command/bin/imy.rb +46 -0
- data/lib/cocoapods-fy-bin/command/bin/init.rb +69 -0
- data/lib/cocoapods-fy-bin/command/bin/initHotKey.rb +70 -0
- data/lib/cocoapods-fy-bin/command/bin/install.rb +44 -0
- data/lib/cocoapods-fy-bin/command/bin/lib/lint.rb +69 -0
- data/lib/cocoapods-fy-bin/command/bin/repo/update.rb +43 -0
- data/lib/cocoapods-fy-bin/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-fy-bin/command/bin/spec/push.rb +114 -0
- data/lib/cocoapods-fy-bin/command/bin/update.rb +154 -0
- data/lib/cocoapods-fy-bin/command/bin.rb +59 -0
- data/lib/cocoapods-fy-bin/command.rb +2 -0
- data/lib/cocoapods-fy-bin/config/config.rb +137 -0
- data/lib/cocoapods-fy-bin/config/config_asker.rb +57 -0
- data/lib/cocoapods-fy-bin/config/config_builder.rb +228 -0
- data/lib/cocoapods-fy-bin/config/config_hot_key.rb +103 -0
- data/lib/cocoapods-fy-bin/config/config_hot_key_asker.rb +57 -0
- data/lib/cocoapods-fy-bin/gem_version.rb +10 -0
- data/lib/cocoapods-fy-bin/helpers/build_helper.rb +164 -0
- data/lib/cocoapods-fy-bin/helpers/build_utils.rb +63 -0
- data/lib/cocoapods-fy-bin/helpers/framework.rb +94 -0
- data/lib/cocoapods-fy-bin/helpers/framework_builder.rb +419 -0
- data/lib/cocoapods-fy-bin/helpers/library.rb +54 -0
- data/lib/cocoapods-fy-bin/helpers/library_builder.rb +91 -0
- data/lib/cocoapods-fy-bin/helpers/sources_helper.rb +36 -0
- data/lib/cocoapods-fy-bin/helpers/spec_creator.rb +170 -0
- data/lib/cocoapods-fy-bin/helpers/spec_files_helper.rb +77 -0
- data/lib/cocoapods-fy-bin/helpers/spec_source_creator.rb +229 -0
- data/lib/cocoapods-fy-bin/helpers/upload_helper.rb +97 -0
- data/lib/cocoapods-fy-bin/helpers.rb +5 -0
- data/lib/cocoapods-fy-bin/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-fy-bin/native/analyzer.rb +55 -0
- data/lib/cocoapods-fy-bin/native/file_accessor.rb +28 -0
- data/lib/cocoapods-fy-bin/native/installation_options.rb +25 -0
- data/lib/cocoapods-fy-bin/native/installer.rb +204 -0
- data/lib/cocoapods-fy-bin/native/linter.rb +26 -0
- data/lib/cocoapods-fy-bin/native/path_source.rb +33 -0
- data/lib/cocoapods-fy-bin/native/pod_source_installer.rb +19 -0
- data/lib/cocoapods-fy-bin/native/pod_target_installer.rb +94 -0
- data/lib/cocoapods-fy-bin/native/podfile.rb +91 -0
- data/lib/cocoapods-fy-bin/native/podfile_env.rb +37 -0
- data/lib/cocoapods-fy-bin/native/podfile_generator.rb +199 -0
- data/lib/cocoapods-fy-bin/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-fy-bin/native/resolver.rb +238 -0
- data/lib/cocoapods-fy-bin/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-fy-bin/native/source.rb +35 -0
- data/lib/cocoapods-fy-bin/native/sources_manager.rb +20 -0
- data/lib/cocoapods-fy-bin/native/specification.rb +31 -0
- data/lib/cocoapods-fy-bin/native/target_validator.rb +41 -0
- data/lib/cocoapods-fy-bin/native/validator.rb +40 -0
- data/lib/cocoapods-fy-bin/native.rb +23 -0
- data/lib/cocoapods-fy-bin/source_provider_hook.rb +55 -0
- data/lib/cocoapods-fy-bin.rb +2 -0
- data/lib/cocoapods_plugin.rb +3 -0
- data/spec/command/bin_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +177 -0
@@ -0,0 +1,419 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
require 'cocoapods-fy-bin/helpers/framework.rb'
|
4
|
+
require 'English'
|
5
|
+
require 'cocoapods-fy-bin/config/config_builder'
|
6
|
+
require 'shellwords'
|
7
|
+
|
8
|
+
module CBin
|
9
|
+
class Framework
|
10
|
+
class Builder
|
11
|
+
include Pod
|
12
|
+
#Debug下还待完成
|
13
|
+
def initialize(spec, file_accessor, platform, source_dir, archs, isRootSpec = true, build_model="Debug")
|
14
|
+
@spec = spec
|
15
|
+
@source_dir = source_dir
|
16
|
+
@file_accessor = file_accessor
|
17
|
+
@platform = platform
|
18
|
+
@build_model = build_model
|
19
|
+
@isRootSpec = isRootSpec
|
20
|
+
@archs = archs
|
21
|
+
#vendored_static_frameworks 只有 xx.framework 需要拼接为 xx.framework/xx by slj
|
22
|
+
vendored_static_frameworks = file_accessor.vendored_static_frameworks.map do |framework|
|
23
|
+
path = framework
|
24
|
+
extn = File.extname path
|
25
|
+
if extn.downcase == '.framework'
|
26
|
+
path = File.join(path,File.basename(path, extn))
|
27
|
+
end
|
28
|
+
path
|
29
|
+
end
|
30
|
+
|
31
|
+
@vendored_libraries = (vendored_static_frameworks + file_accessor.vendored_static_libraries).map(&:to_s)
|
32
|
+
end
|
33
|
+
|
34
|
+
def build
|
35
|
+
defines = compile
|
36
|
+
# build_sim_libraries(defines)
|
37
|
+
|
38
|
+
defines
|
39
|
+
end
|
40
|
+
|
41
|
+
def lipo_build(defines)
|
42
|
+
UI.section("Building static Library #{@spec}") do
|
43
|
+
# defines = compile
|
44
|
+
|
45
|
+
# build_sim_libraries(defines)
|
46
|
+
output = framework.fwk_path + Pathname.new(treated_framework_name)
|
47
|
+
build_static_library_for_ios(output)
|
48
|
+
copy_private_headers
|
49
|
+
copy_headers
|
50
|
+
copy_license
|
51
|
+
copy_resources
|
52
|
+
copy_info_plist
|
53
|
+
copy_dsym
|
54
|
+
cp_to_source_dir
|
55
|
+
end
|
56
|
+
framework
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def cp_to_source_dir
|
62
|
+
framework_name = "#{treated_framework_name}.framework"
|
63
|
+
target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
|
64
|
+
FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
|
65
|
+
|
66
|
+
zip_dir = CBin::Config::Builder.instance.zip_dir
|
67
|
+
FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
|
68
|
+
`cp -fa #{@platform}/* #{target_dir}`
|
69
|
+
end
|
70
|
+
|
71
|
+
#模拟器,目前只支持 debug x86-64
|
72
|
+
def build_sim_libraries(defines)
|
73
|
+
UI.message 'Building simulator libraries'
|
74
|
+
|
75
|
+
# archs = %w[i386 x86_64]
|
76
|
+
archs = ios_architectures_sim
|
77
|
+
archs.map do |arch|
|
78
|
+
xcodebuild(defines, "-sdk iphonesimulator ARCHS=\'#{arch}\' ", "build-#{arch}",@build_model)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def static_libs_in_sandbox(build_dir = 'build')
|
85
|
+
file = Dir.glob("#{build_dir}/lib#{target_name}.a")
|
86
|
+
unless file
|
87
|
+
UI.warn "file no find = #{build_dir}/lib#{target_name}.a"
|
88
|
+
end
|
89
|
+
file
|
90
|
+
end
|
91
|
+
|
92
|
+
def build_static_library_for_ios(output)
|
93
|
+
UI.message "Building ios libraries with archs #{ios_architectures}"
|
94
|
+
static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-simulator') + @vendored_libraries
|
95
|
+
# if is_debug_model
|
96
|
+
ios_architectures.map do |arch|
|
97
|
+
static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
98
|
+
end
|
99
|
+
# ios_architectures_sim do |arch|
|
100
|
+
# static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
101
|
+
# end
|
102
|
+
# end
|
103
|
+
|
104
|
+
build_path = Pathname("build")
|
105
|
+
build_path.mkpath unless build_path.exist?
|
106
|
+
|
107
|
+
# if is_debug_model
|
108
|
+
# libs = (ios_architectures + ios_architectures_sim) .map do |arch|
|
109
|
+
# library = "build-#{arch}/#{@spec.name}.framework/#{@spec.name}"
|
110
|
+
# library
|
111
|
+
# end
|
112
|
+
libs = (ios_architectures) .map do |arch|
|
113
|
+
library = "build-#{arch}/#{treated_framework_name}.framework/#{treated_framework_name}"
|
114
|
+
library
|
115
|
+
end
|
116
|
+
# else
|
117
|
+
# libs = ios_architectures.map do |arch|
|
118
|
+
# library = "build/package-#{@spec.name}-#{arch}.a"
|
119
|
+
# # libtool -arch_only arm64 -static -o build/package-armv64.a build/libIMYFoundation.a build-simulator/libIMYFoundation.a
|
120
|
+
# # 从liBFoundation.a 文件中,提取出 arm64 架构的文件,命名为build/package-armv64.a
|
121
|
+
# UI.message "libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}"
|
122
|
+
# `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
|
123
|
+
# library
|
124
|
+
# end
|
125
|
+
# end
|
126
|
+
if libs.length == 1
|
127
|
+
UI.message "cp #{libs[0]} #{output}"
|
128
|
+
`cp #{libs[0]} #{output}`
|
129
|
+
else
|
130
|
+
UI.message "lipo -create -output #{output} #{libs.join(' ')}"
|
131
|
+
`lipo -create -output #{output} #{libs.join(' ')}`
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def ios_build_options
|
136
|
+
"ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
|
137
|
+
end
|
138
|
+
|
139
|
+
def ios_architectures
|
140
|
+
# >armv7
|
141
|
+
# iPhone4
|
142
|
+
# iPhone4S
|
143
|
+
# >armv7s 去掉
|
144
|
+
# iPhone5
|
145
|
+
# iPhone5C
|
146
|
+
# >arm64
|
147
|
+
# iPhone5S(以上)
|
148
|
+
# >i386
|
149
|
+
# iphone5,iphone5s以下的模拟器
|
150
|
+
# >x86_64
|
151
|
+
# iphone6以上的模拟器
|
152
|
+
# archs = %w[arm64 armv7]
|
153
|
+
# archs = %w[x86_64 arm64 armv7s i386]
|
154
|
+
# @vendored_libraries.each do |library|
|
155
|
+
# archs = `lipo -info #{library}`.split & archs
|
156
|
+
# end
|
157
|
+
archs = @archs.split(",")
|
158
|
+
archs
|
159
|
+
end
|
160
|
+
|
161
|
+
def ios_architectures_sim
|
162
|
+
|
163
|
+
archs = %w[x86_64]
|
164
|
+
# TODO 处理是否需要 i386
|
165
|
+
archs
|
166
|
+
end
|
167
|
+
|
168
|
+
def compile
|
169
|
+
defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)'"
|
170
|
+
defines += ' '
|
171
|
+
defines += @spec.consumer(@platform).compiler_flags.join(' ')
|
172
|
+
|
173
|
+
options = ios_build_options
|
174
|
+
# if is_debug_model
|
175
|
+
archs = ios_architectures
|
176
|
+
# archs = %w[arm64 armv7 armv7s]
|
177
|
+
archs.map do |arch|
|
178
|
+
# -fembed-bitcode支持bitcode BUILD_LIBRARY_FOR_DISTRIBUTION=YES 构建向后兼容的framework
|
179
|
+
xcodebuild(defines, "ARCHS=\'#{arch}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\' DEBUG_INFORMATION_FORMAT=\'dwarf-with-dsym\' BUILD_LIBRARY_FOR_DISTRIBUTION=YES","build-#{arch}",@build_model)
|
180
|
+
end
|
181
|
+
# else
|
182
|
+
# xcodebuild(defines,options)
|
183
|
+
# end
|
184
|
+
|
185
|
+
defines
|
186
|
+
end
|
187
|
+
|
188
|
+
def is_debug_model
|
189
|
+
@build_model == "Debug"
|
190
|
+
end
|
191
|
+
|
192
|
+
def target_name
|
193
|
+
#区分多平台,如配置了多平台,会带上平台的名字
|
194
|
+
# 如libwebp-iOS
|
195
|
+
if @spec.available_platforms.count > 1
|
196
|
+
"#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
|
197
|
+
else
|
198
|
+
@spec.name
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Debug')
|
203
|
+
|
204
|
+
unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
|
205
|
+
command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{File.join(File.expand_path("..", build_dir), File.basename(build_dir))} clean build -configuration #{build_model} -target #{target_name} -project ./Pods/Pods.xcodeproj 2>&1"
|
206
|
+
else
|
207
|
+
command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{build_model} -target #{target_name} -project ./Pods.xcodeproj 2>&1"
|
208
|
+
end
|
209
|
+
|
210
|
+
UI.message "command = #{command}"
|
211
|
+
output = `#{command}`.lines.to_a
|
212
|
+
|
213
|
+
if $CHILD_STATUS.exitstatus != 0
|
214
|
+
raise <<~EOF
|
215
|
+
Build command failed: #{command}
|
216
|
+
Output:
|
217
|
+
#{output.map { |line| " #{line}" }.join}
|
218
|
+
EOF
|
219
|
+
|
220
|
+
Process.exit
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def copy_private_headers
|
225
|
+
private_headers = Array.new
|
226
|
+
arch = ios_architectures[0]
|
227
|
+
spec_private_header_dir = "./build-#{arch}/#{treated_framework_name}.framework/PrivateHeaders"
|
228
|
+
if File.exist?(spec_private_header_dir)
|
229
|
+
Dir.chdir(spec_private_header_dir) do
|
230
|
+
headers = Dir.glob('*.h')
|
231
|
+
headers.each do |h|
|
232
|
+
private_headers << Pathname.new(File.join(Dir.pwd,h))
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
private_headers.each do |h|
|
237
|
+
`ditto #{h} #{framework.private_headers_path}/#{h.basename}`
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def copy_headers
|
243
|
+
#走 podsepc中的public_headers
|
244
|
+
public_headers = Array.new
|
245
|
+
arch = ios_architectures[0]
|
246
|
+
spec_header_dir = "./build-#{arch}/#{treated_framework_name}.framework/Headers"
|
247
|
+
if File.exist?(spec_header_dir)
|
248
|
+
Dir.chdir(spec_header_dir) do
|
249
|
+
headers = Dir.glob('*.h')
|
250
|
+
headers.each do |h|
|
251
|
+
public_headers << Pathname.new(File.join(Dir.pwd,h))
|
252
|
+
end
|
253
|
+
end
|
254
|
+
# end
|
255
|
+
|
256
|
+
# UI.message "Copying public headers #{public_headers.map(&:basename).map(&:to_s)}"
|
257
|
+
|
258
|
+
public_headers.each do |h|
|
259
|
+
`ditto #{h} #{framework.headers_path}/#{h.basename}`
|
260
|
+
end
|
261
|
+
end
|
262
|
+
# If custom 'module_map' is specified add it to the framework distribution
|
263
|
+
# otherwise check if a header exists that is equal to 'spec.name', if so
|
264
|
+
# create a default 'module_map' one using it.
|
265
|
+
module_map_dir = "./build-#{arch}/#{treated_framework_name}.framework/Modules/module.modulemap"
|
266
|
+
if !@spec.module_map.nil?
|
267
|
+
module_map_file = @file_accessor.module_map
|
268
|
+
if Pathname(module_map_file).exist?
|
269
|
+
module_map = File.read(module_map_file)
|
270
|
+
end
|
271
|
+
elsif File.exist?(module_map_dir)
|
272
|
+
module_map_path = Pathname.new(module_map_dir)
|
273
|
+
module_map = File.read(module_map_path)
|
274
|
+
elsif public_headers.map(&:basename).map(&:to_s).include?("#{treated_framework_name}.h")
|
275
|
+
module_map = <<-MAP
|
276
|
+
framework module #{treated_framework_name} {
|
277
|
+
umbrella header "#{treated_framework_name}.h"
|
278
|
+
|
279
|
+
export *
|
280
|
+
module * { export * }
|
281
|
+
}
|
282
|
+
MAP
|
283
|
+
end
|
284
|
+
|
285
|
+
unless module_map.nil?
|
286
|
+
UI.message "Writing module map #{module_map}"
|
287
|
+
unless framework.module_map_path.exist?
|
288
|
+
framework.module_map_path.mkpath
|
289
|
+
end
|
290
|
+
File.write("#{framework.module_map_path}/module.modulemap", module_map)
|
291
|
+
end
|
292
|
+
|
293
|
+
#swift module
|
294
|
+
swift_module_map_dir = "./build-#{arch}/#{treated_framework_name}.framework/Modules/#{treated_framework_name}.swiftmodule"
|
295
|
+
if File.exist?(swift_module_map_dir)
|
296
|
+
`ditto #{swift_module_map_dir} #{framework.swift_module_path}`
|
297
|
+
# 解决module与class名称冲突问题
|
298
|
+
swift_module_dir_path = File.expand_path(framework.swift_module_path)
|
299
|
+
|
300
|
+
exclude_frameworks = ["Foundation","Swift","UIKit","_Concurrency"]
|
301
|
+
Dir.chdir(swift_module_dir_path) {
|
302
|
+
arr = IO.readlines("arm64.swiftinterface")
|
303
|
+
arr.map { |item|
|
304
|
+
if item.include?("import ")
|
305
|
+
items = item.split(" ")
|
306
|
+
item_last = items.last
|
307
|
+
if !exclude_frameworks.include?(item_last)
|
308
|
+
`find . -name "*.swiftinterface" -exec sed -i -e 's/#{item_last}\\.Method/#{item_last}BDF\\.Method/g' {} \\;`
|
309
|
+
`find . -name "*.swiftinterface" -exec sed -i -e 's/#{item_last}\\.#{item_last}/#{item_last}ACE\\.#{item_last}BDF/g' {} \\;`
|
310
|
+
`find . -name "*.swiftinterface" -exec sed -i -e 's/#{item_last}\\./#{item_last}ACE\\./g' {} \\;`
|
311
|
+
`find . -name "*.swiftinterface" -exec sed -i -e 's/#{item_last}ACE\\.//g' {} \\;`
|
312
|
+
`find . -name "*.swiftinterface" -exec sed -i -e 's/#{item_last}BDF/#{item_last}/g' {} \\;`
|
313
|
+
`find . -name "*.swiftinterface-e" | xargs rm -rf`
|
314
|
+
end
|
315
|
+
end
|
316
|
+
}
|
317
|
+
}
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def copy_license
|
322
|
+
UI.message 'Copying license'
|
323
|
+
license_file = @spec.license[:file] || 'LICENSE'
|
324
|
+
`cp "#{license_file}" .` if Pathname(license_file).exist?
|
325
|
+
end
|
326
|
+
|
327
|
+
def copy_info_plist
|
328
|
+
UI.message 'Copying info.plist'
|
329
|
+
info_plist_dir = './build-armv7' if File.exist?('./build-armv7')
|
330
|
+
info_plist_dir = './build-arm64' if File.exist?('./build-arm64')
|
331
|
+
info_plist_file = "#{info_plist_dir}/#{treated_framework_name}.framework/Info.plist"
|
332
|
+
`cp "#{info_plist_file}" #{framework.fwk_path}` if Pathname(info_plist_file).exist?
|
333
|
+
end
|
334
|
+
|
335
|
+
def copy_resources
|
336
|
+
resource_dir = './build/*.bundle'
|
337
|
+
resource_dir = './build-armv7/*.bundle' if File.exist?('./build-armv7')
|
338
|
+
resource_dir = './build-arm64/*.bundle' if File.exist?('./build-arm64')
|
339
|
+
|
340
|
+
bundles = Dir.glob(resource_dir)
|
341
|
+
|
342
|
+
bundle_names = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
343
|
+
consumer = spec.consumer(@platform)
|
344
|
+
consumer.resource_bundles.keys +
|
345
|
+
consumer.resources.map do |r|
|
346
|
+
File.basename(r, '.bundle') if File.extname(r) == 'bundle'
|
347
|
+
end
|
348
|
+
end.compact.uniq
|
349
|
+
|
350
|
+
bundles.select! do |bundle|
|
351
|
+
bundle_name = File.basename(bundle, '.bundle')
|
352
|
+
bundle_names.include?(bundle_name)
|
353
|
+
end
|
354
|
+
|
355
|
+
if bundles.count > 0
|
356
|
+
UI.message "Copying bundle files #{bundles}"
|
357
|
+
bundle_files = bundles.join(' ')
|
358
|
+
`cp -rp #{bundle_files} #{framework.resources_path} 2>&1`
|
359
|
+
end
|
360
|
+
|
361
|
+
real_source_dir = @source_dir
|
362
|
+
unless @isRootSpec
|
363
|
+
spec_source_dir = File.join(Dir.pwd,"#{treated_framework_name}")
|
364
|
+
unless File.exist?(spec_source_dir)
|
365
|
+
spec_source_dir = File.join(Dir.pwd,"Pods/#{treated_framework_name}")
|
366
|
+
end
|
367
|
+
raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
|
368
|
+
|
369
|
+
real_source_dir = spec_source_dir
|
370
|
+
end
|
371
|
+
resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
372
|
+
expand_paths(real_source_dir, spec.consumer(@platform).resources)
|
373
|
+
end.compact.uniq
|
374
|
+
|
375
|
+
if resources.count == 0 && bundles.count == 0
|
376
|
+
# framework.delete_resources
|
377
|
+
return
|
378
|
+
end
|
379
|
+
|
380
|
+
if resources.count > 0
|
381
|
+
#把 路径转义。 避免空格情况下拷贝失败
|
382
|
+
escape_resource = []
|
383
|
+
resources.each do |source|
|
384
|
+
escape_resource << Shellwords.join(source)
|
385
|
+
end
|
386
|
+
UI.message "Copying resources #{escape_resource}"
|
387
|
+
`cp -rp #{escape_resource.join(' ')} #{framework.resources_path}`
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
def copy_dsym
|
392
|
+
arch = ios_architectures[0]
|
393
|
+
dsym_file = "./build-#{arch}/#{treated_framework_name}.framework.dSYM"
|
394
|
+
if File.exist?(dsym_file)
|
395
|
+
`ditto "./build-#{arch}/#{treated_framework_name}.framework.dSYM" "./ios/#{treated_framework_name}.framework.dSYM"`
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def expand_paths(source_dir, path_specs)
|
400
|
+
path_specs.map do |path_spec|
|
401
|
+
Dir.glob(File.join(source_dir, path_spec))
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
def framework
|
406
|
+
@framework ||= begin
|
407
|
+
framework = Framework.new(treated_framework_name, @platform.name.to_s)
|
408
|
+
framework.make
|
409
|
+
framework
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
def treated_framework_name
|
414
|
+
CBin::Config::Builder.instance.treated_framework_name(@spec)
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
module CBin
|
4
|
+
class Library
|
5
|
+
attr_reader :headers_path
|
6
|
+
attr_reader :resources_path
|
7
|
+
attr_reader :root_path
|
8
|
+
attr_reader :versions_path
|
9
|
+
attr_reader :name_path
|
10
|
+
|
11
|
+
def initialize(name, platform, version)
|
12
|
+
@name = name
|
13
|
+
@platform = platform
|
14
|
+
@version = version
|
15
|
+
end
|
16
|
+
|
17
|
+
def make
|
18
|
+
make_root
|
19
|
+
make_library
|
20
|
+
make_headers
|
21
|
+
make_resources
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_resources
|
25
|
+
Pathname.new(@resources_path).rmtree
|
26
|
+
(Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def make_library
|
32
|
+
@name_path = CBin::Config::Builder.instance.library_name_version(@name,@version)
|
33
|
+
@fwk_path = @root_path + Pathname.new(@name_path)
|
34
|
+
@fwk_path.mkdir unless @fwk_path.exist?
|
35
|
+
|
36
|
+
@versions_path = @fwk_path
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_headers
|
40
|
+
@headers_path = @versions_path + Pathname.new('Headers')
|
41
|
+
@headers_path.mkpath unless @headers_path.exist?
|
42
|
+
end
|
43
|
+
|
44
|
+
def make_resources
|
45
|
+
@resources_path = @versions_path + Pathname.new('Resources')
|
46
|
+
@resources_path.mkpath unless @resources_path.exist?
|
47
|
+
end
|
48
|
+
|
49
|
+
def make_root
|
50
|
+
@root_path = Pathname.new(@platform)
|
51
|
+
@root_path.mkpath unless @root_path.exist?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
3
|
+
|
4
|
+
require 'cocoapods-fy-bin/helpers/framework.rb'
|
5
|
+
require 'cocoapods-fy-bin/helpers/library.rb'
|
6
|
+
|
7
|
+
require 'English'
|
8
|
+
|
9
|
+
module CBin
|
10
|
+
class Library
|
11
|
+
class Builder
|
12
|
+
include Pod
|
13
|
+
|
14
|
+
def initialize(spec, file_accessor, platform, source_dir, archs, framework_path)
|
15
|
+
@spec = spec
|
16
|
+
@source_dir = source_dir
|
17
|
+
@file_accessor = file_accessor
|
18
|
+
@platform = platform
|
19
|
+
@framework = framework_path
|
20
|
+
@archs = archs
|
21
|
+
@source_files = "#{@source_dir}/#{library.name_path}"
|
22
|
+
@source_zip_file = "#{@source_files}.zip"
|
23
|
+
end
|
24
|
+
|
25
|
+
def build
|
26
|
+
UI.section("Building static library #{@spec}") do
|
27
|
+
|
28
|
+
clean_source_dir
|
29
|
+
|
30
|
+
copy_headers
|
31
|
+
copy_library
|
32
|
+
copy_resources
|
33
|
+
|
34
|
+
cp_to_source_dir
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def clean_source_dir
|
41
|
+
FileUtils.rm_rf(@source_files) if File.exist?(@source_files)
|
42
|
+
FileUtils.rm_rf(@source_zip_file) if File.exist?(@source_zip_file)
|
43
|
+
end
|
44
|
+
|
45
|
+
def cp_to_source_dir
|
46
|
+
target_dir = library.versions_path
|
47
|
+
dest_file = "#{@source_dir}/#{library.name_path}"
|
48
|
+
FileUtils.rm_rf(dest_file) if File.exist?(dest_file)
|
49
|
+
|
50
|
+
`cp -fa #{target_dir} #{dest_file}/`
|
51
|
+
end
|
52
|
+
|
53
|
+
def copy_headers
|
54
|
+
FileUtils.cp_r(framework.headers_path,library.versions_path) if File.exist?(framework.headers_path)
|
55
|
+
end
|
56
|
+
|
57
|
+
def copy_library
|
58
|
+
src_file = "#{framework.versions_path}/#{@spec.name}"
|
59
|
+
unless File.exist?(src_file)
|
60
|
+
raise Informative, "framework没有文件:#{src_file}"
|
61
|
+
end
|
62
|
+
|
63
|
+
dest_file = "#{library.versions_path}/#{@spec.name}"
|
64
|
+
rename_dest_file = "#{library.versions_path}/lib#{@spec.name}.a"
|
65
|
+
FileUtils.cp_r(src_file,dest_file)
|
66
|
+
File.rename(dest_file, rename_dest_file ) if File.exist?(dest_file)
|
67
|
+
end
|
68
|
+
|
69
|
+
def copy_resources
|
70
|
+
FileUtils.cp_r(framework.resources_path,library.versions_path) if File.exist?(framework.resources_path)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def framework
|
75
|
+
@framework ||= begin
|
76
|
+
framework = Framework.new(@spec.name, @platform.name.to_s)
|
77
|
+
framework.make
|
78
|
+
framework
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def library
|
83
|
+
@library ||= begin
|
84
|
+
library = Library.new(@spec.name, @platform.name.to_s,@spec.version)
|
85
|
+
library.make
|
86
|
+
library
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'cocoapods-fy-bin/native/sources_manager.rb'
|
4
|
+
|
5
|
+
module CBin
|
6
|
+
module SourcesHelper
|
7
|
+
def sources_manager
|
8
|
+
Pod::Config.instance.sources_manager
|
9
|
+
end
|
10
|
+
|
11
|
+
def binary_source
|
12
|
+
sources_manager.binary_source
|
13
|
+
end
|
14
|
+
|
15
|
+
def code_source
|
16
|
+
sources_manager.code_source
|
17
|
+
end
|
18
|
+
|
19
|
+
# 优先采用对应依赖的 source
|
20
|
+
# cocoapods 内部会先匹配前面符合的 specification
|
21
|
+
# 只允许二进制的 specification subspec 比源码的 specification subspec 多
|
22
|
+
#
|
23
|
+
def valid_sources(code_dependencies = false)
|
24
|
+
sources = [code_source]
|
25
|
+
unless code_dependencies
|
26
|
+
sources << binary_source
|
27
|
+
sources.reverse!
|
28
|
+
end
|
29
|
+
sources
|
30
|
+
end
|
31
|
+
|
32
|
+
def sources_option(code_dependencies, additional_sources)
|
33
|
+
(valid_sources(code_dependencies).map(&:url) + Array(additional_sources)).join(',')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|