8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/cocoapods-util/command/xcframework/xcframework_build.rb', line 8
def build_static_xcframework
framework_path = "#{@source_dir}/#{@name}.framework"
lib_file = "#{@name}"
lib_path = "#{framework_path}/#{lib_file}"
unless File.exist? lib_path
UI.puts("没有找到可执行文件,请检查输入的framework")
return nil
end
if File.ftype(lib_path) == 'link'
lib_file = File.readlink(lib_path)
lib_path = "#{framework_path}/#{lib_file}"
end
framework_paths = Array.new
archs = `lipo -archs #{lib_path}`.split
os_archs = sim_archs = []
if archs.empty?
UI.puts "framework文件中没有检查到任何编译架构,请使用`lipo -info`或`lipo -archs`检查文件支持的架构。"
return
elsif archs.count == 1
framework_paths += [framework_path]
else
platform = `strings #{lib_path} | grep -E -i '/Platforms/.*\.platform/' | head -n 1`.chomp!
if platform =~ /iPhone[^\.]*\.platform/ os_archs = archs & ['arm64', 'armv7', 'armv7s']
sim_archs = archs & ['i386', 'x86_64']
elsif platform =~ /MacOSX.platform/ os_archs = ['arm64', 'x86_64']
elsif platform =~ /Watch[^\.]*\.platform/ os_archs = archs & ['armv7k', 'arm64_32']
sim_archs = archs & ['arm64', 'i386', 'x86_64']
elsif platform =~ /AppleTV[^\.]*\.platform/ os_archs = archs & ['arm64']
sim_archs = archs & ['x86_64'] else
os_archs = archs & ['arm64', 'armv7', 'armv7s']
sim_archs = archs & ['i386', 'x86_64']
end
end
clean_intermediate_path
if os_archs.count > 0
path = Pathname.new("#{@source_dir}/#{os_target_path}")
FileUtils.mkdir_p(path) unless path.exist?
`cp -a #{framework_path} #{path}/`
fwk_path = "#{path}/#{@name}.framework"
framework_paths += ["#{fwk_path}"]
`lipo -extract #{os_archs.join(' -extract ')} "#{fwk_path}/#{lib_file}" -output "#{fwk_path}/#{lib_file}"`
end
if sim_archs.count > 0
path = Pathname.new("#{@source_dir}/#{simulator_target_path}")
FileUtils.mkdir_p(path) unless path.exist?
`cp -a #{framework_path} #{path}/`
fwk_path = "#{path}/#{@name}.framework"
framework_paths += ["#{fwk_path}"]
`lipo -extract #{sim_archs.join(' -extract ')} "#{fwk_path}/#{lib_file}" -output "#{fwk_path}/#{lib_file}"`
end
begin
generate_xcframework(framework_paths)
ensure clean_intermediate_path
end
end
|