cocoapods-util 0.0.11
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/.gitignore +4 -0
- data/Gemfile +13 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +13 -0
- data/cocoapods-util.gemspec +25 -0
- data/lib/cocoapods-util/CocoapodsUtilHook.rb +18 -0
- data/lib/cocoapods-util/cocoapods-extend/extend.rb +2 -0
- data/lib/cocoapods-util/cocoapods-extend/install/list.rb +140 -0
- data/lib/cocoapods-util/cocoapods-extend/install.rb +15 -0
- data/lib/cocoapods-util/cocoapods-extend/repo/push.rb +40 -0
- data/lib/cocoapods-util/cocoapods-extend/repo/push_helper.rb +36 -0
- data/lib/cocoapods-util/cocoapods-extend/repo.rb +15 -0
- data/lib/cocoapods-util/command/util.rb +28 -0
- data/lib/cocoapods-util/command.rb +1 -0
- data/lib/cocoapods-util/gem_version.rb +3 -0
- data/lib/cocoapods-util/hooks/installer.rb +4 -0
- data/lib/cocoapods-util/libsource/source.rb +81 -0
- data/lib/cocoapods-util/libsource/source_linker.rb +184 -0
- data/lib/cocoapods-util/package/helper/builder.rb +194 -0
- data/lib/cocoapods-util/package/helper/framework.rb +61 -0
- data/lib/cocoapods-util/package/helper/framework_builder.rb +147 -0
- data/lib/cocoapods-util/package/helper/library_builder.rb +47 -0
- data/lib/cocoapods-util/package/helper/pod_utils.rb +126 -0
- data/lib/cocoapods-util/package/package.rb +177 -0
- data/lib/cocoapods-util/user_interface/build_failed_report.rb +15 -0
- data/lib/cocoapods-util/xcframework/xcframework.rb +66 -0
- data/lib/cocoapods-util/xcframework/xcramework_build.rb +133 -0
- data/lib/cocoapods-util.rb +1 -0
- data/lib/cocoapods_plugin.rb +3 -0
- data/spec/command/util_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +126 -0
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class SourceLinker
|
4
|
+
include Pod
|
5
|
+
attr_accessor :allow_ask_source_path, :source_path, :compile_path
|
6
|
+
|
7
|
+
def initialize(file_name, file_type, source_dir, link_type, force_link)
|
8
|
+
# 允许询问源码路径,默认为false
|
9
|
+
@allow_ask_source_path = false
|
10
|
+
@link_type = link_type
|
11
|
+
|
12
|
+
@file_name = file_name.gsub(/^lib/, '')
|
13
|
+
@file_type = file_type
|
14
|
+
@source_dir = source_dir
|
15
|
+
@force_link = force_link
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
compile_dir_path = if @compile_path
|
20
|
+
@compile_path
|
21
|
+
else
|
22
|
+
check_compile(get_libfile_path)
|
23
|
+
end
|
24
|
+
if compile_dir_path.nil? || compile_dir_path.empty?
|
25
|
+
UI.puts "没有获取到可执行文件的编译路径,链接结束。"
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
case @link_type
|
30
|
+
when :link
|
31
|
+
add_link(compile_dir_path)
|
32
|
+
when :unlink
|
33
|
+
remove_link(compile_dir_path)
|
34
|
+
when :checkcompile
|
35
|
+
user_check_compile
|
36
|
+
else
|
37
|
+
linked_path = get_linked_path(compile_dir_path)
|
38
|
+
check_linked(get_libfile_path, linked_path)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def islinked(compile_dir_path)
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def remove_link(compile_dir_path)
|
49
|
+
linked_path = get_linked_path(compile_dir_path)
|
50
|
+
if File.exist? linked_path
|
51
|
+
if File.symlink?(linked_path)
|
52
|
+
File.unlink(linked_path)
|
53
|
+
UI.puts "已移除可执行文件的源码映射关系。"
|
54
|
+
else
|
55
|
+
UI.puts "映射文件不是软链接。"
|
56
|
+
end
|
57
|
+
else
|
58
|
+
UI.puts "映射文件不存在。"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_link(compile_dir_path)
|
63
|
+
linked_path = get_linked_path(compile_dir_path)
|
64
|
+
if File.exist? linked_path
|
65
|
+
if File.symlink?(linked_path)
|
66
|
+
if @force_link
|
67
|
+
File.unlink(linked_path)
|
68
|
+
# Pathname.new(linked_path).rmtree
|
69
|
+
else
|
70
|
+
UI.puts "可执行文件的编译路径已经存在映射关系,您可以尝试使用`--force`。请检查路径:#{compile_dir_path}".red
|
71
|
+
return
|
72
|
+
end
|
73
|
+
else
|
74
|
+
UI.puts "文件编译路径已存在,并不是软链接。请检查路径:#{compile_dir_path}".red
|
75
|
+
return
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if @source_path.nil? && @allow_ask_source_path
|
80
|
+
@source_path = get_stdin("您没有设置将要映射的源码路径,请输入(或者拖动路径到终端)...")
|
81
|
+
end
|
82
|
+
if @source_path.nil? || @source_path.empty?
|
83
|
+
UI.puts "没有将要链接的源码路径,链接结束。"
|
84
|
+
return
|
85
|
+
else
|
86
|
+
@source_path = File.expand_path(@source_path)
|
87
|
+
unless File.exist?(@source_path) && File.directory?(@source_path)
|
88
|
+
UI.puts "将要链接的源码路径不存在或不是文件目录,链接结束。"
|
89
|
+
return
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
unless File.exist? compile_dir_path
|
94
|
+
begin
|
95
|
+
FileUtils.mkdir_p(compile_dir_path)
|
96
|
+
rescue Exception => e
|
97
|
+
# puts e.backtrace.inspect
|
98
|
+
UI.puts "创建可执行文件的编译路径失败,可能是因为权限问题,请检查`#{compile_dir_path}`\n\n错误信息:#{e.message}".red
|
99
|
+
UI.puts "您可以使用命令创建目录:`sudo mkdir -p #{compile_dir_path}`"
|
100
|
+
return
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# 链接
|
105
|
+
File.symlink(@source_path , linked_path)
|
106
|
+
check_linked(get_libfile_path, linked_path)
|
107
|
+
end
|
108
|
+
|
109
|
+
def check_linked(lib_file, linked_path)
|
110
|
+
file = `dwarfdump "#{lib_file}" | grep -E "DW_AT_decl_file.*\.(m|mm|c)" | head -1 | cut -d \\" -f2`.chomp!
|
111
|
+
if file.nil? || file.empty?
|
112
|
+
UI.puts "二进制中未搜索到#{@file_name}相关文件,请自行检查。"
|
113
|
+
return
|
114
|
+
end
|
115
|
+
unless File.exist?(file)
|
116
|
+
UI.puts "#{file}文件不存在,请检查源码的版本或存储位置。"
|
117
|
+
return
|
118
|
+
end
|
119
|
+
UI.puts "链接成功,链接路径#{linked_path}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_stdin(message)
|
123
|
+
UI.puts "#{message}".red
|
124
|
+
print "请输入--> ".green
|
125
|
+
val = STDIN.gets.chomp.strip
|
126
|
+
val
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_linked_path(compile_dir_path)
|
130
|
+
if @source_path.nil? || @source_path.empty?
|
131
|
+
linked_path = "#{compile_dir_path}/#{@file_name}"
|
132
|
+
else
|
133
|
+
basename = File.basename(@source_path)
|
134
|
+
linked_path = "#{compile_dir_path}/#{basename}"
|
135
|
+
end
|
136
|
+
linked_path
|
137
|
+
end
|
138
|
+
|
139
|
+
def get_libfile_path
|
140
|
+
if @lib_path
|
141
|
+
@lib_path
|
142
|
+
else
|
143
|
+
case @file_type
|
144
|
+
when 'a'
|
145
|
+
@lib_path = check_realpath("lib#{@file_name}.a", @source_dir)
|
146
|
+
when 'framework'
|
147
|
+
framework_path = "#{@source_dir}/#{@file_name}.framework"
|
148
|
+
@lib_path = check_realpath(@file_name, framework_path)
|
149
|
+
when 'xcframework'
|
150
|
+
xcframework_path = "#{@source_dir}/#{@file_name}.xcframework"
|
151
|
+
framework_path = Dir.glob("#{xcframework_path}/**/*.framework").first
|
152
|
+
raise "没有找到framework,请检查xcframework文件" unless framework_path
|
153
|
+
@lib_path = check_realpath(@file_name, framework_path)
|
154
|
+
end
|
155
|
+
@lib_path
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def check_realpath(lib_filename, dir_path)
|
160
|
+
lib_path = "#{dir_path}/#{lib_filename}"
|
161
|
+
if File.exist? lib_path
|
162
|
+
# 如果可执行文件为软链接类型,获取realpath
|
163
|
+
if File.ftype(lib_path) == 'link'
|
164
|
+
realpath = File.readlink(lib_path)
|
165
|
+
lib_path = "#{dir_path}/#{realpath}"
|
166
|
+
end
|
167
|
+
lib_path
|
168
|
+
else
|
169
|
+
raise "没有找到可执行文件,请检查输入的文件或路径"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def check_compile(lib_path)
|
174
|
+
compile_dir_path = `dwarfdump "#{lib_path}" | grep "AT_comp_dir" | head -1 | cut -d \\" -f2`.chomp!
|
175
|
+
compile_dir_path
|
176
|
+
end
|
177
|
+
|
178
|
+
def user_check_compile
|
179
|
+
compile_dir_path = `dwarfdump "#{get_libfile_path}" | grep "AT_comp_dir" | head -1 | cut -d \\" -f2`.chomp!
|
180
|
+
UI.puts "二进制文件的编译路径:#{compile_dir_path}"
|
181
|
+
file_path = `dwarfdump "#{get_libfile_path}" | grep -E "DW_AT_decl_file.*\.(m|mm|c)" | head -1 | cut -d \\" -f2`.chomp!
|
182
|
+
UI.puts "二进制文件中某个文件编译时的真实路径:#{file_path}"
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
module Pod
|
2
|
+
class Builder
|
3
|
+
def initialize(platform, static_installer, source_dir, static_sandbox_root, public_headers_root, spec, config, exclude_sim, framework_contains_resources, verbose)
|
4
|
+
@platform = platform
|
5
|
+
@static_installer = static_installer
|
6
|
+
@source_dir = source_dir
|
7
|
+
@static_sandbox_root = static_sandbox_root
|
8
|
+
@public_headers_root = public_headers_root
|
9
|
+
@spec = spec
|
10
|
+
@config = config
|
11
|
+
@exclude_sim = exclude_sim || @platform.name.to_s == 'osx'
|
12
|
+
@framework_contains_resources = framework_contains_resources
|
13
|
+
@verbose = verbose
|
14
|
+
|
15
|
+
@file_accessors = @static_installer.pod_targets.select { |t| t.pod_name == @spec.name }.flat_map(&:file_accessors)
|
16
|
+
end
|
17
|
+
|
18
|
+
def build(package_type)
|
19
|
+
require 'cocoapods-util/package/helper/framework_builder.rb'
|
20
|
+
require 'cocoapods-util/package/helper/library_builder.rb'
|
21
|
+
|
22
|
+
case package_type
|
23
|
+
when :static_library
|
24
|
+
build_static_library
|
25
|
+
when :static_framework
|
26
|
+
build_static_framework
|
27
|
+
when :static_xcframework
|
28
|
+
build_static_xcframework
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_static_library
|
33
|
+
UI.puts("Building #{@platform.name.to_s} static library #{@spec} with configuration #{@config}")
|
34
|
+
|
35
|
+
defines = compile
|
36
|
+
build_sim_libraries(defines) unless @exclude_sim
|
37
|
+
|
38
|
+
create_library
|
39
|
+
UI.puts("Building #{@platform.name.to_s} static library #{@spec} with configuration #{@config} success")
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_static_framework
|
43
|
+
UI.puts("Building #{@platform.name.to_s} static framework #{@spec} with configuration #{@config}")
|
44
|
+
|
45
|
+
defines = compile
|
46
|
+
build_sim_libraries(defines) unless @exclude_sim
|
47
|
+
|
48
|
+
frameworks = generate_frameworks
|
49
|
+
combine_frameworks(frameworks)
|
50
|
+
|
51
|
+
# delete framework
|
52
|
+
framework_paths = frameworks.map {|fwk| fwk.fwk_path }
|
53
|
+
framework_paths.each { |path| FileUtils.rm_rf(File.dirname(path)) }
|
54
|
+
|
55
|
+
UI.puts("Building #{@platform.name.to_s} static framework #{@spec} with configuration #{@config} success")
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_static_xcframework
|
59
|
+
require 'cocoapods-util/xcframework/xcramework_build.rb'
|
60
|
+
UI.puts("Building #{@platform.name.to_s} static framework #{@spec} with configuration #{@config}")
|
61
|
+
|
62
|
+
defines = compile
|
63
|
+
build_sim_libraries(defines) unless @exclude_sim
|
64
|
+
|
65
|
+
frameworks = generate_frameworks
|
66
|
+
framework_paths = frameworks.map {|fwk| fwk.fwk_path }
|
67
|
+
|
68
|
+
# gemerate xcframework
|
69
|
+
xcbuilder = XCFrameworkBuilder.new(
|
70
|
+
@spec.name,
|
71
|
+
@platform.name.to_s,
|
72
|
+
true
|
73
|
+
)
|
74
|
+
xcbuilder.generate_xcframework(framework_paths)
|
75
|
+
# delete framework
|
76
|
+
framework_paths.each { |path| FileUtils.rm_rf(File.dirname(path)) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_sim_libraries(defines)
|
80
|
+
options = build_options
|
81
|
+
case @platform.name
|
82
|
+
when :ios
|
83
|
+
options << ' -sdk iphonesimulator'
|
84
|
+
when :watchos
|
85
|
+
options << ' -sdk watchsimulator'
|
86
|
+
when :tvos
|
87
|
+
options << ' -sdk appletvsimulator'
|
88
|
+
else
|
89
|
+
return
|
90
|
+
end
|
91
|
+
xcodebuild(defines, options, 'build-sim')
|
92
|
+
end
|
93
|
+
|
94
|
+
def compile
|
95
|
+
defines = ("" << @spec.consumer(@platform).compiler_flags.join(' '))
|
96
|
+
|
97
|
+
options = build_options
|
98
|
+
case @platform.name
|
99
|
+
when :ios
|
100
|
+
options << ' -sdk iphoneos'
|
101
|
+
when :osx
|
102
|
+
options << ' -sdk macosx'
|
103
|
+
when :watchos
|
104
|
+
options << ' -sdk watchos'
|
105
|
+
when :tvos
|
106
|
+
options << ' -sdk appletvos'
|
107
|
+
end
|
108
|
+
xcodebuild(defines, options)
|
109
|
+
|
110
|
+
defines
|
111
|
+
end
|
112
|
+
|
113
|
+
def build_options
|
114
|
+
vendored_archs = []
|
115
|
+
vendored_libraries.each do |library|
|
116
|
+
vendored_archs = vendored_archs | `lipo -archs #{library}`.split
|
117
|
+
UI.puts "library at #{library}, archs: #{vendored_archs}" if @verbose
|
118
|
+
end
|
119
|
+
options = ("ARCHS=\'#{vendored_archs.join(' ')}\'" unless vendored_archs.empty?) || ""
|
120
|
+
options
|
121
|
+
end
|
122
|
+
|
123
|
+
def static_libs_in_sandbox(build_dir = 'build')
|
124
|
+
if build_dir == 'build'
|
125
|
+
Dir.glob("#{@static_sandbox_root}/#{build_dir}/**/#{@spec.name}/lib#{@spec.name}.a")
|
126
|
+
else
|
127
|
+
Dir.glob("#{@static_sandbox_root}/#{build_dir}/**/#{@spec.name}/lib#{@spec.name}.a")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def vendored_libraries
|
132
|
+
if @vendored_libraries
|
133
|
+
@vendored_libraries
|
134
|
+
end
|
135
|
+
file_accessors = @file_accessors
|
136
|
+
libs = file_accessors.flat_map(&:vendored_static_frameworks).map { |f| f + f.basename('.*') } || []
|
137
|
+
libs += file_accessors.flat_map(&:vendored_static_libraries)
|
138
|
+
@vendored_libraries = libs.compact.map(&:to_s)
|
139
|
+
@vendored_libraries
|
140
|
+
end
|
141
|
+
|
142
|
+
def expand_paths(path_specs)
|
143
|
+
path_specs.map do |path_spec|
|
144
|
+
Dir.glob(File.join(@source_dir, path_spec))
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def os_build_name(build_root)
|
149
|
+
build_name = "#{@config}"
|
150
|
+
case build_root
|
151
|
+
when 'build'
|
152
|
+
case @platform.name
|
153
|
+
when :ios
|
154
|
+
build_name += "-iphoneos"
|
155
|
+
when :watchos
|
156
|
+
build_name += '-watchos'
|
157
|
+
when :tvos
|
158
|
+
build_name += '-appletvos'
|
159
|
+
end
|
160
|
+
else
|
161
|
+
case @platform.name
|
162
|
+
when :ios
|
163
|
+
build_name += "-iphonesimulator"
|
164
|
+
when :watchos
|
165
|
+
build_name += '-watchsimulator'
|
166
|
+
when :tvos
|
167
|
+
build_name += '-appletvsimulator'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
build_name
|
171
|
+
end
|
172
|
+
|
173
|
+
def xcodebuild(defines = '', args = '', build_dir = 'build', target = 'Pods-packager', project_root = @static_sandbox_root, config = @config)
|
174
|
+
if defined?(Pod::DONT_CODESIGN)
|
175
|
+
args = "#{args} CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO"
|
176
|
+
end
|
177
|
+
|
178
|
+
command = "xcodebuild #{defines} #{args} BUILD_DIR=#{build_dir} clean build -configuration #{config} -target #{target} -project #{project_root}/Pods.xcodeproj 2>&1".gsub!(/\s+/, ' ')
|
179
|
+
UI.puts "#{command}" if @verbose
|
180
|
+
output = `#{command}`.lines.to_a
|
181
|
+
|
182
|
+
if $?.exitstatus != 0
|
183
|
+
puts UI::BuildFailedReport.report(command, output)
|
184
|
+
|
185
|
+
# Note: We use `Process.exit` here because it fires a `SystemExit`
|
186
|
+
# exception, which gives the caller a chance to clean up before the
|
187
|
+
# process terminates.
|
188
|
+
#
|
189
|
+
# See http://ruby-doc.org/core-1.9.3/Process.html#method-c-exit
|
190
|
+
Process.exit
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Framework
|
2
|
+
class Tree
|
3
|
+
attr_reader :headers_path
|
4
|
+
attr_reader :module_map_path
|
5
|
+
attr_reader :resources_path
|
6
|
+
attr_reader :root_path
|
7
|
+
attr_reader :versions_path
|
8
|
+
attr_reader :fwk_path
|
9
|
+
|
10
|
+
def delete_resources
|
11
|
+
Pathname.new(@resources_path).rmtree
|
12
|
+
(Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(name, platform)
|
16
|
+
@name = name
|
17
|
+
@platform = platform
|
18
|
+
end
|
19
|
+
|
20
|
+
def make
|
21
|
+
make_root
|
22
|
+
make_framework
|
23
|
+
make_headers
|
24
|
+
make_resources
|
25
|
+
make_current_version
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def make_current_version
|
31
|
+
current_version_path = @versions_path + Pathname.new('../Current')
|
32
|
+
`ln -sf A #{current_version_path}`
|
33
|
+
`ln -sf Versions/Current/Headers #{@fwk_path}/`
|
34
|
+
`ln -sf Versions/Current/Resources #{@fwk_path}/`
|
35
|
+
`ln -sf Versions/Current/#{@name} #{@fwk_path}/`
|
36
|
+
end
|
37
|
+
|
38
|
+
def make_framework
|
39
|
+
@fwk_path = @root_path + Pathname.new(@name + '.framework')
|
40
|
+
@fwk_path.mkdir unless @fwk_path.exist?
|
41
|
+
|
42
|
+
@module_map_path = @fwk_path + Pathname.new('Modules')
|
43
|
+
@versions_path = @fwk_path + Pathname.new('Versions/A')
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_headers
|
47
|
+
@headers_path = @versions_path + Pathname.new('Headers')
|
48
|
+
@headers_path.mkpath unless @headers_path.exist?
|
49
|
+
end
|
50
|
+
|
51
|
+
def make_resources
|
52
|
+
@resources_path = @versions_path + Pathname.new('Resources')
|
53
|
+
@resources_path.mkpath unless @resources_path.exist?
|
54
|
+
end
|
55
|
+
|
56
|
+
def make_root
|
57
|
+
@root_path = Pathname.new(@platform)
|
58
|
+
@root_path.mkpath unless @root_path.exist?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Pod
|
2
|
+
class Builder
|
3
|
+
private
|
4
|
+
def generate_frameworks
|
5
|
+
frameworks = []
|
6
|
+
os_names = ['build']
|
7
|
+
os_names += ['build-sim'] unless @exclude_sim
|
8
|
+
os_names.each do |os|
|
9
|
+
frameworks << create_framework(os)
|
10
|
+
framework_build_static_library(os)
|
11
|
+
framework_copy_headers(os)
|
12
|
+
framework_copy_license
|
13
|
+
if @framework_contains_resources
|
14
|
+
framework_copy_resources(os)
|
15
|
+
else
|
16
|
+
framework_copy_resources(os) if os = 'build'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
frameworks
|
20
|
+
end
|
21
|
+
|
22
|
+
def combine_frameworks(frameworks)
|
23
|
+
# combine frameworks
|
24
|
+
if (1..2) === frameworks.count
|
25
|
+
fwk = frameworks.first
|
26
|
+
fwk_lib = "#{fwk.versions_path}/#{@spec.name}"
|
27
|
+
if frameworks.count == 2
|
28
|
+
other_fwk = frameworks.last
|
29
|
+
other_fwk_lib = "#{other_fwk.versions_path}/#{@spec.name}"
|
30
|
+
|
31
|
+
# create Muti-architecture
|
32
|
+
`lipo -create #{fwk_lib} #{other_fwk_lib} -output #{fwk_lib}`
|
33
|
+
|
34
|
+
# copy swiftmodules
|
35
|
+
swiftmodule = Dir.glob("#{other_fwk.fwk_path}/**/#{@spec.name}.swiftmodule").first || ''
|
36
|
+
`cp -rp #{swiftmodule}/ #{fwk.module_map_path}/#{@spec.name}.swiftmodule/` unless swiftmodule.empty?
|
37
|
+
end
|
38
|
+
`cp -a #{fwk.fwk_path} #{@platform.name.to_s}/`
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_framework(os_name = '')
|
43
|
+
@fwk = Framework::Tree.new(@spec.name, "#{@platform.name.to_s}/#{os_name}")
|
44
|
+
@fwk.make
|
45
|
+
@fwk
|
46
|
+
end
|
47
|
+
|
48
|
+
def framework_build_static_library(build_root = 'build')
|
49
|
+
static_libs = static_libs_in_sandbox(build_root)
|
50
|
+
output = @fwk.versions_path + Pathname.new(@spec.name)
|
51
|
+
`lipo -create -output #{output} #{static_libs.join(' ')}`
|
52
|
+
end
|
53
|
+
|
54
|
+
def framework_copy_headers(build_root = 'build')
|
55
|
+
headers_source_root = "#{@public_headers_root}/#{@spec.name}"
|
56
|
+
|
57
|
+
Dir.glob("#{headers_source_root}/**/*.h").
|
58
|
+
each { |h| `ditto #{h} #{@fwk.headers_path}/#{h.sub(headers_source_root, '')}` }
|
59
|
+
|
60
|
+
# check swift headers
|
61
|
+
swift_headers = Dir.glob("#{@static_sandbox_root}/#{build_root}/#{os_build_name(build_root)}/#{@spec.name}/**/*-{Swift,umbrella}.h")
|
62
|
+
swift_headers.each { |h| `cp -rp #{h.gsub(/\s/, "\\ ")} #{@fwk.headers_path}/` }
|
63
|
+
|
64
|
+
# check swiftmodule files
|
65
|
+
swiftmodule_path = "#{@static_sandbox_root}/#{build_root}/#{os_build_name(build_root)}/#{@spec.name}/#{@spec.name}.swiftmodule"
|
66
|
+
if File.exist? swiftmodule_path
|
67
|
+
@fwk.module_map_path.mkpath unless @fwk.module_map_path.exist?
|
68
|
+
`cp -rp #{swiftmodule_path.to_s} #{@fwk.module_map_path}/`
|
69
|
+
end
|
70
|
+
|
71
|
+
# umbrella header name
|
72
|
+
header_name = "#{@spec.name}"
|
73
|
+
header_name = "#{@spec.name}-umbrella" if File.exist? "#{@fwk.headers_path}/#{@spec.name}-umbrella.h"
|
74
|
+
|
75
|
+
# If custom 'module_map' is specified add it to the framework distribution
|
76
|
+
# otherwise check if a header exists that is equal to 'spec.name', if so
|
77
|
+
# create a default 'module_map' one using it.
|
78
|
+
if !@spec.module_map.nil?
|
79
|
+
module_map_file = @file_accessors.flat_map(&:module_map).first
|
80
|
+
module_map = File.read(module_map_file) if Pathname(module_map_file).exist?
|
81
|
+
elsif File.exist?("#{@fwk.headers_path}/#{header_name}.h")
|
82
|
+
module_map = <<MAP
|
83
|
+
framework module #{@spec.name} {
|
84
|
+
umbrella header "#{header_name}.h"
|
85
|
+
|
86
|
+
export *
|
87
|
+
module * { export * }
|
88
|
+
}
|
89
|
+
MAP
|
90
|
+
unless swift_headers.empty?
|
91
|
+
module_map << swift_module_map = <<SWIFT_MAP
|
92
|
+
module #{@spec.name}.Swift {
|
93
|
+
header "#{@spec.name}-Swift.h"
|
94
|
+
requires objc
|
95
|
+
}
|
96
|
+
SWIFT_MAP
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
unless module_map.nil?
|
101
|
+
@fwk.module_map_path.mkpath unless @fwk.module_map_path.exist?
|
102
|
+
File.write("#{@fwk.module_map_path}/module.modulemap", module_map)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def framework_copy_license
|
107
|
+
license_file = @spec.license[:file] || 'LICENSE'
|
108
|
+
`cp "#{license_file}" .` if Pathname(license_file).exist?
|
109
|
+
end
|
110
|
+
|
111
|
+
def framework_copy_resources(build_root = 'build')
|
112
|
+
unless @framework_contains_resources
|
113
|
+
# copy resources
|
114
|
+
platform_path = Pathname.new(@platform.name.to_s)
|
115
|
+
platform_path.mkdir unless platform_path.exist?
|
116
|
+
|
117
|
+
bundles = Dir.glob("#{@static_sandbox_root}/#{build_root}/#{os_build_name(build_root)}/#{@spec.name}/*.bundle")
|
118
|
+
resources = expand_paths(@spec.consumer(@platform).resources)
|
119
|
+
if bundles.count > 0 || resources.count > 0
|
120
|
+
resources_path = platform_path + "Resources"
|
121
|
+
resources_path.mkdir unless resources_path.exist?
|
122
|
+
if bundles.count > 0
|
123
|
+
`cp -rp #{@static_sandbox_root}/#{build_root}/#{os_build_name(build_root)}/#{@spec.name}/*.bundle #{resources_path} 2>&1`
|
124
|
+
end
|
125
|
+
if resources.count > 0
|
126
|
+
`cp -rp #{resources.join(' ')} #{resources_path}`
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# delete framework resources
|
131
|
+
@fwk.delete_resources if @fwk
|
132
|
+
return
|
133
|
+
end
|
134
|
+
|
135
|
+
bundles = Dir.glob("#{@static_sandbox_root}/#{build_root}/#{os_build_name(build_root)}/#{@spec.name}/*.bundle")
|
136
|
+
`cp -rp #{@static_sandbox_root}/#{build_root}/#{os_build_name(build_root)}/#{@spec.name}/*.bundle #{@fwk.resources_path} 2>&1`
|
137
|
+
resources = expand_paths(@spec.consumer(@platform).resources)
|
138
|
+
if resources.count == 0 && bundles.count == 0
|
139
|
+
@fwk.delete_resources
|
140
|
+
return
|
141
|
+
end
|
142
|
+
if resources.count > 0
|
143
|
+
`cp -rp #{resources.join(' ')} #{@fwk.resources_path}`
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Pod
|
2
|
+
class Builder
|
3
|
+
private
|
4
|
+
def create_library
|
5
|
+
@library_platform_path = Pathname.new(@platform.name.to_s)
|
6
|
+
@library_platform_path.mkdir unless @library_platform_path.exist?
|
7
|
+
|
8
|
+
generate_static_library
|
9
|
+
library_copy_headers
|
10
|
+
library_copy_resources
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_static_library
|
14
|
+
static_libs = static_libs_in_sandbox('build')
|
15
|
+
static_libs += static_libs_in_sandbox('build-sim') unless @exclude_sim
|
16
|
+
|
17
|
+
# create Muti-architecture
|
18
|
+
output = @library_platform_path + "lib#{@spec.name}.a"
|
19
|
+
`lipo -create -output #{output} #{static_libs.join(' ')}`
|
20
|
+
end
|
21
|
+
|
22
|
+
def library_copy_headers
|
23
|
+
headers_source_root = "#{@public_headers_root}/#{@spec.name}"
|
24
|
+
headers = Dir.glob("#{headers_source_root}/**/*.h")
|
25
|
+
if headers.count > 0
|
26
|
+
headers_path = @library_platform_path + "Headers"
|
27
|
+
headers_path.mkdir unless headers_path.exist?
|
28
|
+
headers.each { |h| `ditto #{h} #{headers_path}/#{h.sub(headers_source_root, '')}` }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def library_copy_resources(build_root = 'build')
|
33
|
+
bundles = Dir.glob("#{@static_sandbox_root}/#{build_root}/#{os_build_name('build')}/#{@spec.name}/*.bundle")
|
34
|
+
resources = expand_paths(@spec.consumer(@platform).resources)
|
35
|
+
if bundles.count > 0 || resources.count > 0
|
36
|
+
resources_path = @library_platform_path + "Resources"
|
37
|
+
resources_path.mkdir unless resources_path.exist?
|
38
|
+
if bundles.count > 0
|
39
|
+
`cp -rp #{@static_sandbox_root}/#{build_root}/#{os_build_name('build')}/#{@spec.name}/*.bundle #{resources_path} 2>&1`
|
40
|
+
end
|
41
|
+
if resources.count > 0
|
42
|
+
`cp -rp #{resources.join(' ')} #{resources_path}`
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|