cocoapods-swordfish 0.1.6
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/README.md +35 -0
- data/lib/cocoapods_plugin.rb +86 -0
- data/lib/gem_version.rb +11 -0
- data/lib/swordfish/command/archive.rb +187 -0
- data/lib/swordfish/command/auto.rb +192 -0
- data/lib/swordfish/command/config.rb +70 -0
- data/lib/swordfish/command/repo/update.rb +42 -0
- data/lib/swordfish/command/spec/create.rb +78 -0
- data/lib/swordfish/command/spec/push.rb +114 -0
- data/lib/swordfish/command/swordfish.rb +41 -0
- data/lib/swordfish/command.rb +2 -0
- data/lib/swordfish/config/config.rb +137 -0
- data/lib/swordfish/config/config_asker.rb +57 -0
- data/lib/swordfish/config/config_builder.rb +216 -0
- data/lib/swordfish/helpers/build_helper.rb +160 -0
- data/lib/swordfish/helpers/build_utils.rb +94 -0
- data/lib/swordfish/helpers/framework.rb +85 -0
- data/lib/swordfish/helpers/framework_builder.rb +451 -0
- data/lib/swordfish/helpers/library.rb +54 -0
- data/lib/swordfish/helpers/library_builder.rb +90 -0
- data/lib/swordfish/helpers/sources_helper.rb +38 -0
- data/lib/swordfish/helpers/spec_creator.rb +167 -0
- data/lib/swordfish/helpers/spec_files_helper.rb +76 -0
- data/lib/swordfish/helpers/spec_source_creator.rb +266 -0
- data/lib/swordfish/helpers/upload_helper.rb +94 -0
- data/lib/swordfish/hmap/hmap_generator.rb +59 -0
- data/lib/swordfish/hmap/pod_target.rb +92 -0
- data/lib/swordfish/hmap/podfile_dsl.rb +36 -0
- data/lib/swordfish/hmap/post_install_hook_context.rb +41 -0
- data/lib/swordfish/hmap/xcconfig.rb +99 -0
- data/lib/swordfish/hmap.rb +4 -0
- data/lib/swordfish/native/acknowledgements.rb +27 -0
- data/lib/swordfish/native/analyzer.rb +55 -0
- data/lib/swordfish/native/file_accessor.rb +28 -0
- data/lib/swordfish/native/installation_options.rb +25 -0
- data/lib/swordfish/native/installer.rb +135 -0
- data/lib/swordfish/native/linter.rb +25 -0
- data/lib/swordfish/native/path_source.rb +33 -0
- data/lib/swordfish/native/pod_source_installer.rb +19 -0
- data/lib/swordfish/native/pod_target_installer.rb +94 -0
- data/lib/swordfish/native/podfile.rb +105 -0
- data/lib/swordfish/native/podfile_env.rb +36 -0
- data/lib/swordfish/native/podfile_generator.rb +195 -0
- data/lib/swordfish/native/podspec_finder.rb +24 -0
- data/lib/swordfish/native/resolver.rb +223 -0
- data/lib/swordfish/native/source.rb +35 -0
- data/lib/swordfish/native/sources_manager.rb +19 -0
- data/lib/swordfish/native/specification.rb +31 -0
- data/lib/swordfish/native/target_architectures.rb +79 -0
- data/lib/swordfish/native/target_validator.rb +41 -0
- data/lib/swordfish/native/validator.rb +39 -0
- data/lib/swordfish/native.rb +16 -0
- data/lib/swordfish.rb +2 -0
- metadata +167 -0
@@ -0,0 +1,451 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
require 'shellwords'
|
5
|
+
require 'swordfish/helpers/framework.rb'
|
6
|
+
require 'swordfish/config/config_builder'
|
7
|
+
require 'swordfish/helpers/build_utils'
|
8
|
+
|
9
|
+
module Ocean
|
10
|
+
class Framework
|
11
|
+
class Builder
|
12
|
+
include Pod
|
13
|
+
#Debug下还待完成
|
14
|
+
def initialize(spec, file_accessor, platform, source_dir, isRootSpec = true, build_model="Debug")
|
15
|
+
@spec = spec
|
16
|
+
@source_dir = source_dir
|
17
|
+
@file_accessor = file_accessor
|
18
|
+
@platform = platform
|
19
|
+
@build_model = build_model
|
20
|
+
@isRootSpec = isRootSpec
|
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
|
+
# # 编译真机
|
36
|
+
defines = compile
|
37
|
+
# # 编译模拟器
|
38
|
+
build_sim_libraries(defines)
|
39
|
+
|
40
|
+
defines
|
41
|
+
end
|
42
|
+
|
43
|
+
def lipo_build(defines)
|
44
|
+
UI.section("Building static Library #{@spec}") do
|
45
|
+
# defines = compile
|
46
|
+
|
47
|
+
# build_sim_libraries(defines)
|
48
|
+
output = framework.versions_path + Pathname.new(@spec.name)
|
49
|
+
|
50
|
+
build_static_library_for_ios(output)
|
51
|
+
|
52
|
+
copy_headers
|
53
|
+
copy_license
|
54
|
+
copy_resources
|
55
|
+
|
56
|
+
cp_to_source_dir
|
57
|
+
end
|
58
|
+
framework
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def cp_to_source_dir
|
64
|
+
framework_name = "#{@spec.name}.framework"
|
65
|
+
target_dir = File.join(Ocean::Config::Builder.instance.zip_dir,framework_name)
|
66
|
+
FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
|
67
|
+
|
68
|
+
zip_dir = Ocean::Config::Builder.instance.zip_dir
|
69
|
+
FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
|
70
|
+
|
71
|
+
`cp -fa #{@platform}/#{framework_name} #{target_dir}`
|
72
|
+
end
|
73
|
+
|
74
|
+
#模拟器,目前只支持 debug x86-64
|
75
|
+
def build_sim_libraries(defines)
|
76
|
+
UI.message 'Building simulator libraries'
|
77
|
+
|
78
|
+
# archs = %w[i386 x86_64]
|
79
|
+
archs = ios_architectures_sim
|
80
|
+
archs.map do |arch|
|
81
|
+
xcodebuild(defines, "-sdk iphonesimulator ARCHS=\'#{arch}\' ", "build-#{arch}",@build_model)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def static_libs_in_sandbox(build_dir = 'build')
|
88
|
+
file = Dir.glob("#{build_dir}/lib#{target_name}.a")
|
89
|
+
unless file
|
90
|
+
UI.warn "file no find = #{build_dir}/lib#{target_name}.a"
|
91
|
+
end
|
92
|
+
file
|
93
|
+
end
|
94
|
+
|
95
|
+
def build_static_library_for_ios(output)
|
96
|
+
UI.message "Building ios libraries with archs #{ios_architectures}"
|
97
|
+
static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-simulator') + @vendored_libraries
|
98
|
+
# if is_debug_model
|
99
|
+
ios_architectures.map do |arch|
|
100
|
+
static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
101
|
+
end
|
102
|
+
ios_architectures_sim do |arch|
|
103
|
+
static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
104
|
+
end
|
105
|
+
# end
|
106
|
+
|
107
|
+
build_path = Pathname("build")
|
108
|
+
build_path.mkpath unless build_path.exist?
|
109
|
+
|
110
|
+
# if is_debug_model
|
111
|
+
libs = (ios_architectures + ios_architectures_sim) .map do |arch|
|
112
|
+
library = "build-#{arch}/lib#{@spec.name}.a"
|
113
|
+
library
|
114
|
+
end
|
115
|
+
# else
|
116
|
+
# libs = ios_architectures.map do |arch|
|
117
|
+
# library = "build/package-#{@spec.name}-#{arch}.a"
|
118
|
+
# # libtool -arch_only arm64 -static -o build/package-armv64.a build/libIMYFoundation.a build-simulator/libIMYFoundation.a
|
119
|
+
# # 从liBFoundation.a 文件中,提取出 arm64 架构的文件,命名为build/package-armv64.a
|
120
|
+
# UI.message "libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}"
|
121
|
+
# `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
|
122
|
+
# library
|
123
|
+
# end
|
124
|
+
# end
|
125
|
+
|
126
|
+
# build_static_library_with_vendored_libraries(libs)
|
127
|
+
|
128
|
+
UI.message "lipo -create -output #{output} #{libs.join(' ')}"
|
129
|
+
`lipo -create -output #{output} #{libs.join(' ')}`
|
130
|
+
end
|
131
|
+
|
132
|
+
def build_static_library_with_vendored_libraries(libs)
|
133
|
+
lipo_libraries = Array.new
|
134
|
+
|
135
|
+
spec_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
|
136
|
+
Dir.chdir(spec_dir) do
|
137
|
+
libraries = Dir.glob('**/*.a')
|
138
|
+
libraries.each do |l|
|
139
|
+
libs << Pathname.new(File.join(Dir.pwd,l))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# if lipo_libraries.empty? == false
|
144
|
+
# UI.message "lipo -create -output #{output} #{lipo_libraries.join(' ')}"
|
145
|
+
# `lipo -create -output #{output} #{lipo_libraries.join(' ')}`
|
146
|
+
# end
|
147
|
+
end
|
148
|
+
|
149
|
+
def ios_build_options
|
150
|
+
"ARCHS=\'#{ios_architectures.join(' ')}\' "
|
151
|
+
end
|
152
|
+
|
153
|
+
def ios_architectures
|
154
|
+
# >armv7
|
155
|
+
# iPhone4
|
156
|
+
# iPhone4S
|
157
|
+
# >armv7s 去掉
|
158
|
+
# iPhone5
|
159
|
+
# iPhone5C
|
160
|
+
# >arm64
|
161
|
+
# iPhone5S(以上)
|
162
|
+
# >i386
|
163
|
+
# iphone5,iphone5s以下的模拟器
|
164
|
+
# >x86_64
|
165
|
+
# iphone6以上的模拟器
|
166
|
+
# archs = %w[x86_64 arm64 armv7s i386]
|
167
|
+
archs = %w[arm64]
|
168
|
+
# @vendored_libraries.each do |library|
|
169
|
+
# archs = `lipo -info #{library}`.split & archs
|
170
|
+
# end
|
171
|
+
archs
|
172
|
+
end
|
173
|
+
|
174
|
+
def ios_architectures_sim
|
175
|
+
|
176
|
+
archs = %w[x86_64]
|
177
|
+
# TODO 处理是否需要 i386
|
178
|
+
archs
|
179
|
+
end
|
180
|
+
|
181
|
+
def compile
|
182
|
+
defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)'"
|
183
|
+
defines += ' '
|
184
|
+
defines += @spec.consumer(@platform).compiler_flags.join(' ')
|
185
|
+
|
186
|
+
options = ios_build_options
|
187
|
+
# if is_debug_model
|
188
|
+
archs = ios_architectures
|
189
|
+
# archs = %w[arm64 armv7 armv7s]
|
190
|
+
archs.map do |arch|
|
191
|
+
xcodebuild(defines, "ARCHS=\'#{arch}\' ","build-#{arch}",@build_model)
|
192
|
+
end
|
193
|
+
# else
|
194
|
+
# xcodebuild(defines,options)
|
195
|
+
# end
|
196
|
+
|
197
|
+
defines
|
198
|
+
end
|
199
|
+
|
200
|
+
def is_debug_model
|
201
|
+
@build_model == "Debug"
|
202
|
+
end
|
203
|
+
|
204
|
+
def target_name
|
205
|
+
#区分多平台,如配置了多平台,会带上平台的名字
|
206
|
+
# 如libwebp-iOS
|
207
|
+
if @spec.available_platforms.count > 1
|
208
|
+
"#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
|
209
|
+
else
|
210
|
+
@spec.name
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Debug')
|
215
|
+
unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
|
216
|
+
command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{File.join(File.expand_path("..", build_dir), File.basename(build_dir))} clean build -configuration #{build_model} SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -target #{target_name} -project ./Pods/Pods.xcodeproj 2>&1"
|
217
|
+
else
|
218
|
+
command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{build_model} -target #{target_name} -project ./Pods.xcodeproj 2>&1"
|
219
|
+
end
|
220
|
+
|
221
|
+
UI.message "command = #{command}"
|
222
|
+
output_str = `#{command}`
|
223
|
+
output = output_str.lines.to_a
|
224
|
+
|
225
|
+
if $CHILD_STATUS.exitstatus != 0
|
226
|
+
raise <<~EOF
|
227
|
+
Build command failed: #{command}
|
228
|
+
Output:
|
229
|
+
#{output.map { |line| " #{line}" }.join}
|
230
|
+
EOF
|
231
|
+
|
232
|
+
Process.exit
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def copy_headers
|
237
|
+
#by slj 如果没有头文件,去 "Headers/Public"拿
|
238
|
+
# if public_headers.empty?
|
239
|
+
public_headers = Array.new
|
240
|
+
|
241
|
+
spec_header_dir = Ocean::Build::Utils.spec_header_dir(@spec)
|
242
|
+
raise "copy_headers #{spec_header_dir} no exist " unless File.exist?(spec_header_dir)
|
243
|
+
|
244
|
+
Dir.chdir(spec_header_dir) do
|
245
|
+
headers = Dir.glob('**/*.{hpp,h}')
|
246
|
+
headers.each do |h|
|
247
|
+
public_headers << Pathname.new(File.join(Dir.pwd,h))
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
# xxx-swift.h copy
|
252
|
+
swiftmodule_files = Array.new
|
253
|
+
is_swift_module = true
|
254
|
+
(ios_architectures + ios_architectures_sim) .map do |arch|
|
255
|
+
temp_path = "build-#{arch}/Swift Compatibility Header/#{@spec.name}-swift.h"
|
256
|
+
if File.exist?Pathname.new(File.join(Dir.pwd,temp_path))
|
257
|
+
is_swift_module &= true
|
258
|
+
else
|
259
|
+
is_swift_module = false
|
260
|
+
end
|
261
|
+
|
262
|
+
# swiftmodule
|
263
|
+
temp_path = "build-#{arch}/#{@spec.name}.swiftmodule"
|
264
|
+
if File.exist?Pathname.new(File.join(Dir.pwd,temp_path))
|
265
|
+
Dir.chdir(temp_path) do
|
266
|
+
headers = Dir.glob('**/*.{swiftdoc,swiftmodule,swiftinterface}')
|
267
|
+
headers.each do |h|
|
268
|
+
swiftmodule_files << Pathname.new(File.join(Dir.pwd,h))
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
# 取arm64 xxx-swift.h
|
276
|
+
if is_swift_module
|
277
|
+
temp_path = "build-arm64/Swift Compatibility Header/#{@spec.name}-swift.h"
|
278
|
+
public_headers << Pathname.new(File.join(Dir.pwd,temp_path))
|
279
|
+
end
|
280
|
+
|
281
|
+
module_name = @spec.module_name || @spec.name
|
282
|
+
|
283
|
+
# FileUtils.cp_r("#{spec_header_dir}/.",framework.headers_path, force: true)
|
284
|
+
has_umbrella_header = false
|
285
|
+
public_headers.each do |h|
|
286
|
+
`ditto "#{h}" "#{framework.headers_path}/#{h.basename}"`
|
287
|
+
if h.basename == "#{module_name}-"
|
288
|
+
has_umbrella_header = true
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
# swift 拷贝xxx.swiftmodule文件
|
293
|
+
swiftmodule_files.each do |h|
|
294
|
+
`ditto "#{h}" "#{framework.swift_module_path}/#{h.basename}"`
|
295
|
+
end
|
296
|
+
|
297
|
+
if !@spec.module_map.nil?
|
298
|
+
module_map_file = @file_accessor.module_map
|
299
|
+
if Pathname(module_map_file).exist?
|
300
|
+
module_map = File.read(module_map_file)
|
301
|
+
end
|
302
|
+
# elsif public_headers.map(&:basename).map(&:to_s).include?("#{@spec.name}.h")
|
303
|
+
# append_module_content = ""
|
304
|
+
# if is_swift_module
|
305
|
+
# append_module_content = <<-MAP
|
306
|
+
# module #{@spec.name}.Swift {
|
307
|
+
# header "#{@spec.name}-Swift.h"
|
308
|
+
# requires objc
|
309
|
+
# }
|
310
|
+
# MAP
|
311
|
+
# end
|
312
|
+
#
|
313
|
+
# module_map = <<-MAP
|
314
|
+
# framework module #{module_name} {
|
315
|
+
# umbrella header "#{@spec.name}.h"
|
316
|
+
#
|
317
|
+
# export *
|
318
|
+
# module * { export * }
|
319
|
+
# }
|
320
|
+
# #{append_module_content}
|
321
|
+
# MAP
|
322
|
+
else
|
323
|
+
# by ChildhoodAndy
|
324
|
+
# try to read modulemap file from module dir
|
325
|
+
# module_map_file = File.join(Ocean::Build::Utils.spec_module_dir(@spec), "#{@spec.name}.modulemap")
|
326
|
+
# if Pathname(module_map_file).exist?
|
327
|
+
# module_map = File.read(module_map_file)
|
328
|
+
# end
|
329
|
+
#
|
330
|
+
append_module_content = ""
|
331
|
+
if is_swift_module
|
332
|
+
append_module_content = <<-MAP
|
333
|
+
module #{module_name}.Swift {
|
334
|
+
header "#{@spec.name}-Swift.h"
|
335
|
+
requires objc
|
336
|
+
}
|
337
|
+
MAP
|
338
|
+
end
|
339
|
+
header_file = "#{module_name}-umbrella.h"
|
340
|
+
if File.exist?Pathname.new(File.join(Dir.pwd,"#{framework.headers_path}/#{header_file}"))
|
341
|
+
# 有modulemap的情况
|
342
|
+
module_map = <<-MAP
|
343
|
+
framework module #{module_name} {
|
344
|
+
umbrella header "#{header_file}"
|
345
|
+
|
346
|
+
export *
|
347
|
+
module * { export * }
|
348
|
+
}
|
349
|
+
#{append_module_content}
|
350
|
+
MAP
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
unless module_map.nil?
|
355
|
+
UI.message "Writing module map #{module_map}"
|
356
|
+
unless framework.module_map_path.exist?
|
357
|
+
framework.module_map_path.mkpath
|
358
|
+
end
|
359
|
+
File.write("#{framework.module_map_path}/module.modulemap", module_map)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def copy_license
|
364
|
+
UI.message 'Copying license'
|
365
|
+
license_file = @spec.license[:file] || 'LICENSE'
|
366
|
+
`cp "#{license_file}" .` if Pathname(license_file).exist?
|
367
|
+
end
|
368
|
+
|
369
|
+
def copy_resources
|
370
|
+
resource_dir = './build/*.bundle'
|
371
|
+
# resource_dir = './build-armv7/*.bundle' if File.exist?('./build-armv7')
|
372
|
+
resource_dir = './build-arm64/*.bundle' if File.exist?('./build-arm64')
|
373
|
+
|
374
|
+
bundles = Dir.glob(resource_dir)
|
375
|
+
|
376
|
+
bundle_names = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
377
|
+
begin
|
378
|
+
consumer = spec.consumer(@platform)
|
379
|
+
consumer.resource_bundles.keys + consumer.resources.map do |r|
|
380
|
+
File.basename(r, '.bundle') if File.extname(r) == 'bundle'
|
381
|
+
end
|
382
|
+
rescue Exception => e
|
383
|
+
UI.message "copy_resources error #{e}"
|
384
|
+
next
|
385
|
+
end
|
386
|
+
end.compact.uniq
|
387
|
+
|
388
|
+
bundles.select! do |bundle|
|
389
|
+
bundle_name = File.basename(bundle, '.bundle')
|
390
|
+
bundle_names.include?(bundle_name)
|
391
|
+
end
|
392
|
+
|
393
|
+
if bundles.count > 0
|
394
|
+
UI.message "Copying bundle files #{bundles}"
|
395
|
+
bundle_files = bundles.join(' ')
|
396
|
+
`cp -rp #{bundle_files} #{framework.resources_path} 2>&1`
|
397
|
+
end
|
398
|
+
|
399
|
+
real_source_dir = @source_dir
|
400
|
+
unless @isRootSpec
|
401
|
+
spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
|
402
|
+
unless File.exist?(spec_source_dir)
|
403
|
+
spec_source_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
|
404
|
+
end
|
405
|
+
raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
|
406
|
+
|
407
|
+
real_source_dir = spec_source_dir
|
408
|
+
end
|
409
|
+
resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
410
|
+
begin
|
411
|
+
expand_paths(real_source_dir, spec.consumer(@platform).resources)
|
412
|
+
rescue Exception => e
|
413
|
+
UI.message "copy_resources error #{e}"
|
414
|
+
next
|
415
|
+
end
|
416
|
+
end.compact.uniq
|
417
|
+
|
418
|
+
if resources.count == 0 && bundles.count == 0
|
419
|
+
framework.delete_resources
|
420
|
+
return
|
421
|
+
end
|
422
|
+
|
423
|
+
if resources.count > 0
|
424
|
+
#把 路径转义。 避免空格情况下拷贝失败
|
425
|
+
escape_resource = []
|
426
|
+
resources.each do |source|
|
427
|
+
escape_resource << Shellwords.join(source)
|
428
|
+
end
|
429
|
+
UI.message "Copying resources #{escape_resource}"
|
430
|
+
`cp -rp #{escape_resource.join(' ')} #{framework.resources_path}`
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def expand_paths(source_dir, path_specs)
|
435
|
+
path_specs.map do |path_spec|
|
436
|
+
Dir.glob(File.join(source_dir, path_spec))
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
def framework
|
441
|
+
@framework ||= begin
|
442
|
+
framework = Framework.new(@spec.name, @platform.name.to_s)
|
443
|
+
framework.make
|
444
|
+
framework
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
module Ocean
|
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 = Ocean::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,90 @@
|
|
1
|
+
|
2
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
3
|
+
|
4
|
+
require 'swordfish/helpers/framework.rb'
|
5
|
+
require 'swordfish/helpers/library.rb'
|
6
|
+
|
7
|
+
require 'English'
|
8
|
+
|
9
|
+
module Ocean
|
10
|
+
class Library
|
11
|
+
class Builder
|
12
|
+
include Pod
|
13
|
+
|
14
|
+
def initialize(spec, file_accessor, platform, source_dir,framework_path)
|
15
|
+
@spec = spec
|
16
|
+
@source_dir = source_dir
|
17
|
+
@file_accessor = file_accessor
|
18
|
+
@platform = platform
|
19
|
+
@framework = framework_path
|
20
|
+
@source_files = "#{@source_dir}/#{library.name_path}"
|
21
|
+
@source_zip_file = "#{@source_files}.zip"
|
22
|
+
end
|
23
|
+
|
24
|
+
def build
|
25
|
+
UI.section("Building static library #{@spec}") do
|
26
|
+
|
27
|
+
clean_source_dir
|
28
|
+
|
29
|
+
copy_headers
|
30
|
+
copy_library
|
31
|
+
copy_resources
|
32
|
+
|
33
|
+
cp_to_source_dir
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def clean_source_dir
|
40
|
+
FileUtils.rm_rf(@source_files) if File.exist?(@source_files)
|
41
|
+
FileUtils.rm_rf(@source_zip_file) if File.exist?(@source_zip_file)
|
42
|
+
end
|
43
|
+
|
44
|
+
def cp_to_source_dir
|
45
|
+
target_dir = library.versions_path
|
46
|
+
dest_file = "#{@source_dir}/#{library.name_path}"
|
47
|
+
FileUtils.rm_rf(dest_file) if File.exist?(dest_file)
|
48
|
+
|
49
|
+
`cp -fa #{target_dir} #{dest_file}/`
|
50
|
+
end
|
51
|
+
|
52
|
+
def copy_headers
|
53
|
+
FileUtils.cp_r(framework.headers_path,library.versions_path) if File.exist?(framework.headers_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def copy_library
|
57
|
+
src_file = "#{framework.versions_path}/#{@spec.name}"
|
58
|
+
unless File.exist?(src_file)
|
59
|
+
raise Informative, "framework没有文件:#{src_file}"
|
60
|
+
end
|
61
|
+
|
62
|
+
dest_file = "#{library.versions_path}/#{@spec.name}"
|
63
|
+
rename_dest_file = "#{library.versions_path}/lib#{@spec.name}.a"
|
64
|
+
FileUtils.cp_r(src_file,dest_file)
|
65
|
+
File.rename(dest_file, rename_dest_file ) if File.exist?(dest_file)
|
66
|
+
end
|
67
|
+
|
68
|
+
def copy_resources
|
69
|
+
FileUtils.cp_r(framework.resources_path,library.versions_path) if File.exist?(framework.resources_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def framework
|
74
|
+
@framework ||= begin
|
75
|
+
framework = Framework.new(@spec.name, @platform.name.to_s)
|
76
|
+
framework.make
|
77
|
+
framework
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def library
|
82
|
+
@library ||= begin
|
83
|
+
library = Library.new(@spec.name, @platform.name.to_s,@spec.version)
|
84
|
+
library.make
|
85
|
+
library
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require 'swordfish/native/sources_manager.rb'
|
3
|
+
|
4
|
+
module Ocean
|
5
|
+
module SourcesHelper
|
6
|
+
def sources_manager
|
7
|
+
Pod::Config.instance.sources_manager
|
8
|
+
end
|
9
|
+
|
10
|
+
def binary_source
|
11
|
+
sources_manager.binary_source
|
12
|
+
end
|
13
|
+
|
14
|
+
def code_source
|
15
|
+
sources_manager.code_source
|
16
|
+
end
|
17
|
+
|
18
|
+
# 优先采用对应依赖的 source
|
19
|
+
# cocoapods 内部会先匹配前面符合的 specification
|
20
|
+
# 只允许二进制的 specification subspec 比源码的 specification subspec 多
|
21
|
+
#
|
22
|
+
def valid_sources(code_dependencies = false)
|
23
|
+
# sources = [code_source]
|
24
|
+
sources = []
|
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
|
+
sources = valid_sources(code_dependencies).map(&:url) + Array(additional_sources)
|
34
|
+
sources.uniq.join(',')
|
35
|
+
# (valid_sources(code_dependencies).map(&:url) + Array(additional_sources)).join(',')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|