cocoapods-bb-bin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +19 -0
- data/README.md +68 -0
- data/lib/cocoapods-bb-bin/command/bin/archive.rb +234 -0
- data/lib/cocoapods-bb-bin/command/bin/auto.rb +226 -0
- data/lib/cocoapods-bb-bin/command/bin/code.rb +295 -0
- data/lib/cocoapods-bb-bin/command/bin/dup.rb +78 -0
- data/lib/cocoapods-bb-bin/command/bin/imy.rb +46 -0
- data/lib/cocoapods-bb-bin/command/bin/init.rb +69 -0
- data/lib/cocoapods-bb-bin/command/bin/initHotKey.rb +70 -0
- data/lib/cocoapods-bb-bin/command/bin/install.rb +44 -0
- data/lib/cocoapods-bb-bin/command/bin/lib/lint.rb +69 -0
- data/lib/cocoapods-bb-bin/command/bin/repo/update.rb +43 -0
- data/lib/cocoapods-bb-bin/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-bb-bin/command/bin/spec/push.rb +114 -0
- data/lib/cocoapods-bb-bin/command/bin/update.rb +154 -0
- data/lib/cocoapods-bb-bin/command/bin.rb +59 -0
- data/lib/cocoapods-bb-bin/command.rb +2 -0
- data/lib/cocoapods-bb-bin/config/config.rb +136 -0
- data/lib/cocoapods-bb-bin/config/config_asker.rb +57 -0
- data/lib/cocoapods-bb-bin/config/config_builder.rb +234 -0
- data/lib/cocoapods-bb-bin/config/config_hot_key.rb +102 -0
- data/lib/cocoapods-bb-bin/config/config_hot_key_asker.rb +57 -0
- data/lib/cocoapods-bb-bin/gem_version.rb +10 -0
- data/lib/cocoapods-bb-bin/helpers/Info.plist +0 -0
- data/lib/cocoapods-bb-bin/helpers/build_helper.rb +217 -0
- data/lib/cocoapods-bb-bin/helpers/build_utils.rb +63 -0
- data/lib/cocoapods-bb-bin/helpers/framework.rb +85 -0
- data/lib/cocoapods-bb-bin/helpers/framework_builder.rb +446 -0
- data/lib/cocoapods-bb-bin/helpers/library.rb +54 -0
- data/lib/cocoapods-bb-bin/helpers/library_builder.rb +90 -0
- data/lib/cocoapods-bb-bin/helpers/sources_helper.rb +36 -0
- data/lib/cocoapods-bb-bin/helpers/spec_creator.rb +170 -0
- data/lib/cocoapods-bb-bin/helpers/spec_files_helper.rb +77 -0
- data/lib/cocoapods-bb-bin/helpers/spec_source_creator.rb +227 -0
- data/lib/cocoapods-bb-bin/helpers/upload_helper.rb +96 -0
- data/lib/cocoapods-bb-bin/helpers/xcframework_builder.rb +77 -0
- data/lib/cocoapods-bb-bin/helpers.rb +5 -0
- data/lib/cocoapods-bb-bin/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-bb-bin/native/analyzer.rb +55 -0
- data/lib/cocoapods-bb-bin/native/file_accessor.rb +28 -0
- data/lib/cocoapods-bb-bin/native/installation_options.rb +25 -0
- data/lib/cocoapods-bb-bin/native/installer.rb +135 -0
- data/lib/cocoapods-bb-bin/native/linter.rb +26 -0
- data/lib/cocoapods-bb-bin/native/path_source.rb +33 -0
- data/lib/cocoapods-bb-bin/native/pod_source_installer.rb +19 -0
- data/lib/cocoapods-bb-bin/native/pod_target_installer.rb +94 -0
- data/lib/cocoapods-bb-bin/native/podfile.rb +91 -0
- data/lib/cocoapods-bb-bin/native/podfile_env.rb +37 -0
- data/lib/cocoapods-bb-bin/native/podfile_generator.rb +199 -0
- data/lib/cocoapods-bb-bin/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-bb-bin/native/resolver.rb +230 -0
- data/lib/cocoapods-bb-bin/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-bb-bin/native/source.rb +35 -0
- data/lib/cocoapods-bb-bin/native/sources_manager.rb +20 -0
- data/lib/cocoapods-bb-bin/native/specification.rb +31 -0
- data/lib/cocoapods-bb-bin/native/target_validator.rb +41 -0
- data/lib/cocoapods-bb-bin/native/validator.rb +40 -0
- data/lib/cocoapods-bb-bin/native.rb +23 -0
- data/lib/cocoapods-bb-bin/source_provider_hook.rb +66 -0
- data/lib/cocoapods-bb-bin.rb +2 -0
- data/lib/cocoapods_plugin.rb +3 -0
- data/spec/command/bin_spec.rb +12 -0
- data/spec/spec_helper.rb +51 -0
- metadata +200 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
module CBin
|
4
|
+
class Framework
|
5
|
+
attr_reader :headers_path
|
6
|
+
attr_reader :module_map_path
|
7
|
+
attr_reader :resources_path
|
8
|
+
attr_reader :root_path
|
9
|
+
attr_reader :versions_path
|
10
|
+
attr_reader :swift_module_path
|
11
|
+
attr_reader :fwk_path
|
12
|
+
|
13
|
+
def initialize(name, platform)
|
14
|
+
@name = name
|
15
|
+
@platform = platform
|
16
|
+
end
|
17
|
+
|
18
|
+
def make
|
19
|
+
make_root
|
20
|
+
make_framework
|
21
|
+
make_headers
|
22
|
+
make_resources
|
23
|
+
make_current_version
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_resources
|
27
|
+
Pathname.new(@resources_path).rmtree if File.exist? (@resources_path)
|
28
|
+
(Pathname.new(@fwk_path) + Pathname.new('Resources')).delete if File.exist?(Pathname.new(@fwk_path) + Pathname.new('Resources'))
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_current_version
|
32
|
+
FileUtils.rm_f(File.join(@fwk_path,@name))
|
33
|
+
FileUtils.rm_f(File.join(@fwk_path,"Headers"))
|
34
|
+
FileUtils.rm_f(File.join(@fwk_path,"Resources"))
|
35
|
+
|
36
|
+
FileUtils.cp_r("#{@versions_path}/.", @fwk_path)
|
37
|
+
# FileUtils.remove_dir(@versions_path)
|
38
|
+
FileUtils.remove_dir("#{@fwk_path}/Versions")
|
39
|
+
|
40
|
+
# current_version_path = @versions_path + Pathname.new('../Current')
|
41
|
+
# `ln -sf A #{current_version_path}`
|
42
|
+
# `ln -sf Versions/Current/Headers #{@fwk_path}/`
|
43
|
+
# `ln -sf Versions/Current/Resources #{@fwk_path}/`
|
44
|
+
# `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def make_current_version
|
50
|
+
current_version_path = @versions_path + Pathname.new('../Current')
|
51
|
+
`ln -sf A #{current_version_path}`
|
52
|
+
`ln -sf Versions/Current/Headers #{@fwk_path}/`
|
53
|
+
`ln -sf Versions/Current/Resources #{@fwk_path}/`
|
54
|
+
`ln -sf Versions/Current/#{@name} #{@fwk_path}/`
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
def make_framework
|
60
|
+
@fwk_path = @root_path + Pathname.new(@name + '.framework')
|
61
|
+
@fwk_path.mkdir unless @fwk_path.exist?
|
62
|
+
|
63
|
+
@module_map_path = @fwk_path + Pathname.new('Modules')
|
64
|
+
@swift_module_path = @module_map_path + Pathname.new(@name + '.swiftmodule')
|
65
|
+
|
66
|
+
|
67
|
+
@versions_path = @fwk_path + Pathname.new('Versions/A')
|
68
|
+
end
|
69
|
+
|
70
|
+
def make_headers
|
71
|
+
@headers_path = @versions_path + Pathname.new('Headers')
|
72
|
+
@headers_path.mkpath unless @headers_path.exist?
|
73
|
+
end
|
74
|
+
|
75
|
+
def make_resources
|
76
|
+
@resources_path = @versions_path + Pathname.new('Resources')
|
77
|
+
@resources_path.mkpath unless @resources_path.exist?
|
78
|
+
end
|
79
|
+
|
80
|
+
def make_root
|
81
|
+
@root_path = Pathname.new(@platform)
|
82
|
+
@root_path.mkpath unless @root_path.exist?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,446 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
require 'cocoapods-bb-bin/helpers/framework.rb'
|
4
|
+
require 'English'
|
5
|
+
require 'cocoapods-bb-bin/config/config_builder'
|
6
|
+
require 'shellwords'
|
7
|
+
require 'cocoapods-bb-bin/helpers/build_utils'
|
8
|
+
|
9
|
+
module CBin
|
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
|
+
defines = compile
|
36
|
+
build_sim_libraries(defines)
|
37
|
+
|
38
|
+
defines
|
39
|
+
end
|
40
|
+
|
41
|
+
def lipo_build(defines)
|
42
|
+
|
43
|
+
UI.puts "framework lipo build"
|
44
|
+
|
45
|
+
if CBin::Build::Utils.is_swift_module(@spec) || !CBin::Build::Utils.uses_frameworks?
|
46
|
+
UI.section("Building static Library #{@spec}") do
|
47
|
+
# defines = compile
|
48
|
+
UI.puts "swift framework lipo build"
|
49
|
+
# build_sim_libraries(defines)
|
50
|
+
output = framework.versions_path + Pathname.new(@spec.name)
|
51
|
+
|
52
|
+
build_static_library_for_ios(output)
|
53
|
+
|
54
|
+
copy_headers
|
55
|
+
copy_license
|
56
|
+
copy_resources
|
57
|
+
|
58
|
+
cp_to_source_dir
|
59
|
+
end
|
60
|
+
else
|
61
|
+
# begin
|
62
|
+
UI.section("Building framework #{@spec}") do
|
63
|
+
# defines = compile
|
64
|
+
UI.puts "oc framework lipo build"
|
65
|
+
# build_sim_libraries(defines)
|
66
|
+
output = framework.fwk_path + Pathname.new(@spec.name)
|
67
|
+
|
68
|
+
copy_static_framework_dir_for_ios
|
69
|
+
|
70
|
+
build_static_framework_machO_for_ios(output)
|
71
|
+
|
72
|
+
# copy_license
|
73
|
+
copy_framework_resources
|
74
|
+
|
75
|
+
#cp_to_source_dir#
|
76
|
+
|
77
|
+
# rescue Object => exception
|
78
|
+
# UI.puts exception
|
79
|
+
# end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
framework
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def cp_to_source_dir
|
89
|
+
# 删除Versions 软链接
|
90
|
+
framework.remove_current_version if CBin::Build::Utils.is_swift_module(@spec)
|
91
|
+
|
92
|
+
framework_name = "#{@spec.name}.framework"
|
93
|
+
target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
|
94
|
+
FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
|
95
|
+
|
96
|
+
zip_dir = CBin::Config::Builder.instance.zip_dir
|
97
|
+
FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
|
98
|
+
|
99
|
+
`cp -fa #{@platform}/#{framework_name} #{target_dir}`
|
100
|
+
end
|
101
|
+
|
102
|
+
#模拟器,目前只支持 debug x86-64
|
103
|
+
def build_sim_libraries(defines)
|
104
|
+
UI.message 'Building simulator libraries'
|
105
|
+
|
106
|
+
# archs = %w[i386 x86_64]
|
107
|
+
archs = ios_architectures_sim
|
108
|
+
archs.map do |arch|
|
109
|
+
xcodebuild(defines, "-sdk iphonesimulator ARCHS=\'#{arch}\' ", "build-#{arch}",@build_model)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def static_libs_in_sandbox(build_dir = 'build')
|
116
|
+
file = Dir.glob("#{build_dir}/lib#{target_name}.a")
|
117
|
+
unless file
|
118
|
+
UI.warn "file no find = #{build_dir}/lib#{target_name}.a"
|
119
|
+
end
|
120
|
+
file
|
121
|
+
end
|
122
|
+
|
123
|
+
def build_static_library_for_ios(output)
|
124
|
+
UI.message "Building ios libraries with archs #{ios_architectures}"
|
125
|
+
static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-simulator') + @vendored_libraries
|
126
|
+
|
127
|
+
ios_architectures.map do |arch|
|
128
|
+
static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
129
|
+
end
|
130
|
+
ios_architectures_sim do |arch|
|
131
|
+
static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
132
|
+
end
|
133
|
+
|
134
|
+
build_path = Pathname("build")
|
135
|
+
build_path.mkpath unless build_path.exist?
|
136
|
+
|
137
|
+
libs = (ios_architectures + ios_architectures_sim) .map do |arch|
|
138
|
+
library = "build-#{arch}/lib#{@spec.name}.a"
|
139
|
+
library
|
140
|
+
end
|
141
|
+
|
142
|
+
UI.message "lipo -create -output #{output} #{libs.join(' ')}"
|
143
|
+
`lipo -create -output #{output} #{libs.join(' ')}`
|
144
|
+
end
|
145
|
+
|
146
|
+
def ios_build_options
|
147
|
+
"ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
|
148
|
+
end
|
149
|
+
|
150
|
+
def ios_architectures
|
151
|
+
# >armv7
|
152
|
+
# iPhone4
|
153
|
+
# iPhone4S
|
154
|
+
# >armv7s 去掉
|
155
|
+
# iPhone5
|
156
|
+
# iPhone5C
|
157
|
+
# >arm64
|
158
|
+
# iPhone5S(以上)
|
159
|
+
# >i386
|
160
|
+
# iphone5,iphone5s以下的模拟器
|
161
|
+
# >x86_64
|
162
|
+
# iphone6以上的模拟器
|
163
|
+
archs = %w[arm64 armv7]
|
164
|
+
# archs = %w[x86_64 arm64 armv7s i386]
|
165
|
+
# @vendored_libraries.each do |library|
|
166
|
+
# archs = `lipo -info #{library}`.split & archs
|
167
|
+
# end
|
168
|
+
archs
|
169
|
+
end
|
170
|
+
|
171
|
+
def ios_architectures_sim
|
172
|
+
|
173
|
+
archs = %w[x86_64]
|
174
|
+
# TODO 处理是否需要 i386
|
175
|
+
archs
|
176
|
+
end
|
177
|
+
|
178
|
+
def compile
|
179
|
+
defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)'"
|
180
|
+
defines += ' '
|
181
|
+
defines += @spec.consumer(@platform).compiler_flags.join(' ')
|
182
|
+
|
183
|
+
options = ios_build_options
|
184
|
+
# if is_debug_model
|
185
|
+
archs = ios_architectures
|
186
|
+
# archs = %w[arm64 armv7 armv7s]
|
187
|
+
archs.map do |arch|
|
188
|
+
xcodebuild(defines, "ARCHS=\'#{arch}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'","build-#{arch}",@build_model)
|
189
|
+
end
|
190
|
+
# else
|
191
|
+
# xcodebuild(defines,options)
|
192
|
+
# end
|
193
|
+
|
194
|
+
defines
|
195
|
+
end
|
196
|
+
|
197
|
+
def is_debug_model
|
198
|
+
@build_model == "Debug"
|
199
|
+
end
|
200
|
+
|
201
|
+
def target_name
|
202
|
+
#区分多平台,如配置了多平台,会带上平台的名字
|
203
|
+
# 如libwebp-iOS
|
204
|
+
if @spec.available_platforms.count > 1
|
205
|
+
"#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
|
206
|
+
else
|
207
|
+
@spec.name
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Debug')
|
212
|
+
|
213
|
+
unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
|
214
|
+
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"
|
215
|
+
else
|
216
|
+
command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{build_model} -target #{target_name} -project ./Pods.xcodeproj 2>&1"
|
217
|
+
end
|
218
|
+
|
219
|
+
UI.message "command = #{command}"
|
220
|
+
output = `#{command}`.lines.to_a
|
221
|
+
|
222
|
+
if $CHILD_STATUS.exitstatus != 0
|
223
|
+
raise <<~EOF
|
224
|
+
Build command failed: #{command}
|
225
|
+
Output:
|
226
|
+
#{output.map { |line| " #{line}" }.join}
|
227
|
+
EOF
|
228
|
+
|
229
|
+
Process.exit
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def copy_headers
|
234
|
+
#走 podsepc中的public_headers
|
235
|
+
public_headers = Array.new
|
236
|
+
|
237
|
+
#by slj 如果没有头文件,去 "Headers/Public"拿
|
238
|
+
# if public_headers.empty?
|
239
|
+
spec_header_dir = "./Headers/Public/#{@spec.name}"
|
240
|
+
unless File.exist?(spec_header_dir)
|
241
|
+
spec_header_dir = "./Pods/Headers/Public/#{@spec.name}"
|
242
|
+
end
|
243
|
+
raise "copy_headers #{spec_header_dir} no exist " unless File.exist?(spec_header_dir)
|
244
|
+
Dir.chdir(spec_header_dir) do
|
245
|
+
headers = Dir.glob('*.h')
|
246
|
+
headers.each do |h|
|
247
|
+
public_headers << Pathname.new(File.join(Dir.pwd,h))
|
248
|
+
end
|
249
|
+
end
|
250
|
+
# end
|
251
|
+
|
252
|
+
# UI.message "Copying public headers #{public_headers.map(&:basename).map(&:to_s)}"
|
253
|
+
|
254
|
+
public_headers.each do |h|
|
255
|
+
`ditto #{h} #{framework.headers_path}/#{h.basename}`
|
256
|
+
end
|
257
|
+
|
258
|
+
# If custom 'module_map' is specified add it to the framework distribution
|
259
|
+
# otherwise check if a header exists that is equal to 'spec.name', if so
|
260
|
+
# create a default 'module_map' one using it.
|
261
|
+
if !@spec.module_map.nil?
|
262
|
+
module_map_file = @file_accessor.module_map
|
263
|
+
if Pathname(module_map_file).exist?
|
264
|
+
module_map = File.read(module_map_file)
|
265
|
+
end
|
266
|
+
elsif public_headers.map(&:basename).map(&:to_s).include?("#{@spec.name}-umbrella.h")
|
267
|
+
module_map = <<-MAP
|
268
|
+
framework module #{@spec.name} {
|
269
|
+
umbrella header "#{@spec.name}-umbrella.h"
|
270
|
+
|
271
|
+
export *
|
272
|
+
module * { export * }
|
273
|
+
}
|
274
|
+
MAP
|
275
|
+
end
|
276
|
+
|
277
|
+
unless module_map.nil?
|
278
|
+
UI.message "Writing module map #{module_map}"
|
279
|
+
unless framework.module_map_path.exist?
|
280
|
+
framework.module_map_path.mkpath
|
281
|
+
end
|
282
|
+
File.write("#{framework.module_map_path}/module.modulemap", module_map)
|
283
|
+
|
284
|
+
# unless framework.swift_module_path.exist?
|
285
|
+
# framework.swift_module_path.mkpath
|
286
|
+
# end
|
287
|
+
# todo 所有架构的swiftModule拷贝到 framework.swift_module_path
|
288
|
+
archs = ios_architectures + ios_architectures_sim
|
289
|
+
archs.map do |arch|
|
290
|
+
swift_module = "build-#{arch}/#{@spec.name}.swiftmodule"
|
291
|
+
if File.directory?(swift_module)
|
292
|
+
FileUtils.cp_r("#{swift_module}/.", framework.swift_module_path)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
swift_Compatibility_Header = "build-#{archs.first}/Swift\ Compatibility\ Header/#{@spec.name}-Swift.h"
|
296
|
+
FileUtils.cp(swift_Compatibility_Header,framework.headers_path) if File.exist?(swift_Compatibility_Header)
|
297
|
+
info_plist_file = File.join(File.dirname(__FILE__),"info.plist")
|
298
|
+
FileUtils.cp(info_plist_file,framework.fwk_path)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def copy_swift_header
|
303
|
+
|
304
|
+
end
|
305
|
+
|
306
|
+
def copy_license
|
307
|
+
UI.message 'Copying license'
|
308
|
+
license_file = @spec.license[:file] || 'LICENSE'
|
309
|
+
`cp "#{license_file}" .` if Pathname(license_file).exist?
|
310
|
+
end
|
311
|
+
|
312
|
+
def copy_resources
|
313
|
+
resource_dir = './build/*.bundle'
|
314
|
+
resource_dir = './build-armv7/*.bundle' if File.exist?('./build-armv7')
|
315
|
+
resource_dir = './build-arm64/*.bundle' if File.exist?('./build-arm64')
|
316
|
+
|
317
|
+
bundles = Dir.glob(resource_dir)
|
318
|
+
|
319
|
+
bundle_names = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
320
|
+
consumer = spec.consumer(@platform)
|
321
|
+
consumer.resource_bundles.keys +
|
322
|
+
consumer.resources.map do |r|
|
323
|
+
File.basename(r, '.bundle') if File.extname(r) == 'bundle'
|
324
|
+
end
|
325
|
+
end.compact.uniq
|
326
|
+
|
327
|
+
bundles.select! do |bundle|
|
328
|
+
bundle_name = File.basename(bundle, '.bundle')
|
329
|
+
bundle_names.include?(bundle_name)
|
330
|
+
end
|
331
|
+
|
332
|
+
if bundles.count > 0
|
333
|
+
UI.message "Copying bundle files #{bundles}"
|
334
|
+
bundle_files = bundles.join(' ')
|
335
|
+
`cp -rp #{bundle_files} #{framework.resources_path} 2>&1`
|
336
|
+
end
|
337
|
+
|
338
|
+
real_source_dir = @source_dir
|
339
|
+
unless @isRootSpec
|
340
|
+
spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
|
341
|
+
unless File.exist?(spec_source_dir)
|
342
|
+
spec_source_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
|
343
|
+
end
|
344
|
+
raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
|
345
|
+
|
346
|
+
spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
|
347
|
+
real_source_dir = spec_source_dir
|
348
|
+
end
|
349
|
+
|
350
|
+
resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
351
|
+
expand_paths(real_source_dir, spec.consumer(@platform).resources)
|
352
|
+
end.compact.uniq
|
353
|
+
|
354
|
+
if resources.count == 0 && bundles.count == 0
|
355
|
+
framework.delete_resources
|
356
|
+
return
|
357
|
+
end
|
358
|
+
|
359
|
+
if resources.count > 0
|
360
|
+
#把 路径转义。 避免空格情况下拷贝失败
|
361
|
+
escape_resource = []
|
362
|
+
resources.each do |source|
|
363
|
+
escape_resource << Shellwords.join(source)
|
364
|
+
end
|
365
|
+
UI.message "Copying resources #{escape_resource}"
|
366
|
+
`cp -rp #{escape_resource.join(' ')} #{framework.resources_path}`
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
def expand_paths(source_dir, path_specs)
|
371
|
+
path_specs.map do |path_spec|
|
372
|
+
Dir.glob(File.join(source_dir, path_spec))
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
#---------------------------------swift--------------------------------------#
|
377
|
+
# lipo -create .a
|
378
|
+
def build_static_framework_machO_for_ios(output)
|
379
|
+
UI.message "Building ios framework with archs #{ios_architectures}"
|
380
|
+
|
381
|
+
static_libs = static_libs_in_sandbox('build') + @vendored_libraries
|
382
|
+
ios_architectures.map do |arch|
|
383
|
+
static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
384
|
+
end
|
385
|
+
|
386
|
+
ios_architectures_sim do |arch|
|
387
|
+
static_libs += static_libs_in_sandbox("build-#{arch}") + @vendored_libraries
|
388
|
+
end
|
389
|
+
|
390
|
+
build_path = Pathname("build")
|
391
|
+
build_path.mkpath unless build_path.exist?
|
392
|
+
|
393
|
+
libs = (ios_architectures + ios_architectures_sim) .map do |arch|
|
394
|
+
library = "build-#{arch}/#{@spec.name}.framework/#{@spec.name}"
|
395
|
+
library
|
396
|
+
end
|
397
|
+
|
398
|
+
UI.message "lipo -create -output #{output} #{libs.join(' ')}"
|
399
|
+
`lipo -create -output #{output} #{libs.join(' ')}`
|
400
|
+
end
|
401
|
+
|
402
|
+
def copy_static_framework_dir_for_ios
|
403
|
+
|
404
|
+
archs = ios_architectures + ios_architectures_sim
|
405
|
+
framework_dir = "build-#{ios_architectures_sim.first}/#{@spec.name}.framework"
|
406
|
+
framework_dir = "build-#{ios_architectures.first}/#{@spec.name}.framework" unless File.exist?(framework_dir)
|
407
|
+
unless File.exist?(framework_dir)
|
408
|
+
raise "#{framework_dir} path no exist"
|
409
|
+
end
|
410
|
+
File.join(Dir.pwd, "build-#{ios_architectures_sim.first}/#{@spec.name}.framework")
|
411
|
+
FileUtils.cp_r(framework_dir, framework.root_path)
|
412
|
+
|
413
|
+
# todo 所有架构的swiftModule拷贝到 framework.swift_module_path
|
414
|
+
archs.map do |arch|
|
415
|
+
swift_module = "build-#{arch}/#{@spec.name}.framework/Modules/#{@spec.name}.swiftmodule"
|
416
|
+
if File.directory?(swift_module)
|
417
|
+
FileUtils.cp_r("#{swift_module}/.", framework.swift_module_path)
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# 删除Versions 软链接
|
422
|
+
framework.remove_current_version
|
423
|
+
end
|
424
|
+
|
425
|
+
def copy_framework_resources
|
426
|
+
resources = Dir.glob("#{framework.fwk_path + Pathname.new('Resources')}/*")
|
427
|
+
if resources.count == 0
|
428
|
+
framework.delete_resources
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
|
433
|
+
#---------------------------------getter and setter--------------------------------------#
|
434
|
+
|
435
|
+
def framework
|
436
|
+
@framework ||= begin
|
437
|
+
framework = Framework.new(@spec.name, @platform.name.to_s)
|
438
|
+
framework.make
|
439
|
+
framework
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
|
444
|
+
end
|
445
|
+
end
|
446
|
+
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,90 @@
|
|
1
|
+
|
2
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
3
|
+
|
4
|
+
require 'cocoapods-bb-bin/helpers/framework.rb'
|
5
|
+
require 'cocoapods-bb-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,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
|