cocoapods-bin-forest 1.0.0
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/LICENSE.txt +22 -0
- data/README.md +1 -0
- data/lib/cocoapods-bin-forest/command/bin/archive.rb +198 -0
- data/lib/cocoapods-bin-forest/command/bin/auto.rb +199 -0
- data/lib/cocoapods-bin-forest/command/bin/code.rb +232 -0
- data/lib/cocoapods-bin-forest/command/bin/imy.rb +46 -0
- data/lib/cocoapods-bin-forest/command/bin/init.rb +69 -0
- data/lib/cocoapods-bin-forest/command/bin/initHotKey.rb +70 -0
- data/lib/cocoapods-bin-forest/command/bin/install.rb +44 -0
- data/lib/cocoapods-bin-forest/command/bin/lib/lint.rb +69 -0
- data/lib/cocoapods-bin-forest/command/bin/repo/update.rb +43 -0
- data/lib/cocoapods-bin-forest/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-bin-forest/command/bin/spec/push.rb +114 -0
- data/lib/cocoapods-bin-forest/command/bin/update.rb +157 -0
- data/lib/cocoapods-bin-forest/command/bin.rb +57 -0
- data/lib/cocoapods-bin-forest/command.rb +2 -0
- data/lib/cocoapods-bin-forest/config/config.rb +137 -0
- data/lib/cocoapods-bin-forest/config/config_asker.rb +57 -0
- data/lib/cocoapods-bin-forest/config/config_builder.rb +216 -0
- data/lib/cocoapods-bin-forest/config/config_hot_key.rb +103 -0
- data/lib/cocoapods-bin-forest/config/config_hot_key_asker.rb +57 -0
- data/lib/cocoapods-bin-forest/gem_version.rb +10 -0
- data/lib/cocoapods-bin-forest/helpers/Info.plist +0 -0
- data/lib/cocoapods-bin-forest/helpers/build_helper.rb +158 -0
- data/lib/cocoapods-bin-forest/helpers/build_utils.rb +94 -0
- data/lib/cocoapods-bin-forest/helpers/framework.rb +85 -0
- data/lib/cocoapods-bin-forest/helpers/framework_builder.rb +351 -0
- data/lib/cocoapods-bin-forest/helpers/library.rb +54 -0
- data/lib/cocoapods-bin-forest/helpers/library_builder.rb +90 -0
- data/lib/cocoapods-bin-forest/helpers/sources_helper.rb +36 -0
- data/lib/cocoapods-bin-forest/helpers/spec_creator.rb +170 -0
- data/lib/cocoapods-bin-forest/helpers/spec_files_helper.rb +77 -0
- data/lib/cocoapods-bin-forest/helpers/spec_source_creator.rb +234 -0
- data/lib/cocoapods-bin-forest/helpers/upload_helper.rb +91 -0
- data/lib/cocoapods-bin-forest/helpers.rb +5 -0
- data/lib/cocoapods-bin-forest/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-bin-forest/native/analyzer.rb +55 -0
- data/lib/cocoapods-bin-forest/native/file_accessor.rb +28 -0
- data/lib/cocoapods-bin-forest/native/installation_options.rb +25 -0
- data/lib/cocoapods-bin-forest/native/installer.rb +135 -0
- data/lib/cocoapods-bin-forest/native/linter.rb +26 -0
- data/lib/cocoapods-bin-forest/native/path_source.rb +33 -0
- data/lib/cocoapods-bin-forest/native/pod_source_installer.rb +22 -0
- data/lib/cocoapods-bin-forest/native/pod_target_installer.rb +94 -0
- data/lib/cocoapods-bin-forest/native/podfile.rb +91 -0
- data/lib/cocoapods-bin-forest/native/podfile_env.rb +37 -0
- data/lib/cocoapods-bin-forest/native/podfile_generator.rb +200 -0
- data/lib/cocoapods-bin-forest/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-bin-forest/native/resolver.rb +230 -0
- data/lib/cocoapods-bin-forest/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-bin-forest/native/source.rb +35 -0
- data/lib/cocoapods-bin-forest/native/sources_manager.rb +20 -0
- data/lib/cocoapods-bin-forest/native/specification.rb +31 -0
- data/lib/cocoapods-bin-forest/native/target_validator.rb +41 -0
- data/lib/cocoapods-bin-forest/native/validator.rb +40 -0
- data/lib/cocoapods-bin-forest/native.rb +23 -0
- data/lib/cocoapods-bin-forest/source_provider_hook.rb +54 -0
- data/lib/cocoapods-imy-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 +178 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
require 'cocoapods-bin-forest/native/podfile'
|
4
|
+
require 'cocoapods/command/gen'
|
5
|
+
require 'cocoapods/generate'
|
6
|
+
require 'cocoapods-bin-forest/helpers/framework_builder'
|
7
|
+
require 'cocoapods-bin-forest/helpers/library_builder'
|
8
|
+
require 'cocoapods-bin-forest/config/config_builder'
|
9
|
+
|
10
|
+
module CBin
|
11
|
+
class Build
|
12
|
+
class Helper
|
13
|
+
include Pod
|
14
|
+
#class var
|
15
|
+
@@build_defines = ""
|
16
|
+
#Debug下还待完成
|
17
|
+
def initialize(spec,
|
18
|
+
platform,
|
19
|
+
framework_output,
|
20
|
+
zip,
|
21
|
+
rootSpec,
|
22
|
+
skip_archive = false,
|
23
|
+
build_model="Release")
|
24
|
+
@spec = spec
|
25
|
+
@platform = platform
|
26
|
+
@build_model = build_model
|
27
|
+
@rootSpec = rootSpec
|
28
|
+
@isRootSpec = rootSpec.name == spec.name
|
29
|
+
@skip_archive = skip_archive
|
30
|
+
@framework_output = framework_output
|
31
|
+
@zip = zip
|
32
|
+
|
33
|
+
@framework_path
|
34
|
+
end
|
35
|
+
|
36
|
+
def build
|
37
|
+
UI.section("Building static framework #{@spec}") do
|
38
|
+
|
39
|
+
build_static_framework
|
40
|
+
unless @skip_archive
|
41
|
+
unless CBin::Build::Utils.is_framework(@spec)
|
42
|
+
build_static_library
|
43
|
+
zip_static_library
|
44
|
+
else
|
45
|
+
zip_static_framework
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_static_framework
|
54
|
+
source_dir = Dir.pwd
|
55
|
+
file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
|
56
|
+
Dir.chdir(workspace_directory) do
|
57
|
+
builder = CBin::Framework::Builder.new(@spec, file_accessor, @platform, source_dir, @isRootSpec, @build_model )
|
58
|
+
@@build_defines = builder.build if @isRootSpec
|
59
|
+
begin
|
60
|
+
@framework_path = builder.lipo_build(@@build_defines) unless @skip_archive
|
61
|
+
rescue
|
62
|
+
@skip_archive = true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_static_library
|
68
|
+
source_dir = zip_dir
|
69
|
+
file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
|
70
|
+
Dir.chdir(workspace_directory) do
|
71
|
+
builder = CBin::Library::Builder.new(@spec, file_accessor, @platform, source_dir,@framework_path)
|
72
|
+
builder.build
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def zip_static_framework
|
77
|
+
Dir.chdir(File.join(workspace_directory,@framework_path.root_path)) do
|
78
|
+
output_name = File.join(zip_dir, framework_name_zip)
|
79
|
+
unless File.exist?(framework_name)
|
80
|
+
UI.puts "没有需要压缩的 framework 文件:#{framework_name}"
|
81
|
+
return
|
82
|
+
end
|
83
|
+
|
84
|
+
UI.puts "Compressing #{framework_name} into #{output_name}"
|
85
|
+
`zip --symlinks -r #{output_name} #{framework_name}`
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def zip_static_library
|
90
|
+
Dir.chdir(zip_dir) do
|
91
|
+
output_library = "#{library_name}.zip"
|
92
|
+
unless File.exist?(library_name)
|
93
|
+
raise Informative, "没有需要压缩的 library 文件:#{library_name}"
|
94
|
+
end
|
95
|
+
|
96
|
+
UI.puts "Compressing #{library_name} into #{output_library}"
|
97
|
+
|
98
|
+
`zip --symlinks -r #{output_library} #{library_name}`
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def clean_workspace
|
105
|
+
UI.puts 'Cleaning workspace'
|
106
|
+
|
107
|
+
FileUtils.rm_rf(gen_name)
|
108
|
+
Dir.chdir(zip_dir) do
|
109
|
+
FileUtils.rm_rf(framework_name) if @zip
|
110
|
+
FileUtils.rm_rf(library_name)
|
111
|
+
FileUtils.rm_rf(framework_name) unless @framework_output
|
112
|
+
FileUtils.rm_rf("#{framework_name}.zip") unless @framework_output
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def framework_name
|
117
|
+
CBin::Config::Builder.instance.framework_name(@spec)
|
118
|
+
end
|
119
|
+
|
120
|
+
def framework_name_zip
|
121
|
+
CBin::Config::Builder.instance.framework_name_version(@spec) + ".zip"
|
122
|
+
end
|
123
|
+
|
124
|
+
def library_name
|
125
|
+
CBin::Config::Builder.instance.library_name(@spec)
|
126
|
+
end
|
127
|
+
|
128
|
+
def workspace_directory
|
129
|
+
File.expand_path("#{gen_name}/#{@rootSpec.name}")
|
130
|
+
end
|
131
|
+
|
132
|
+
def zip_dir
|
133
|
+
CBin::Config::Builder.instance.zip_dir
|
134
|
+
end
|
135
|
+
|
136
|
+
def gen_name
|
137
|
+
CBin::Config::Builder.instance.gen_dir
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def spec_file
|
142
|
+
@spec_file ||= begin
|
143
|
+
if @podspec
|
144
|
+
find_spec_file(@podspec)
|
145
|
+
else
|
146
|
+
if code_spec_files.empty?
|
147
|
+
raise Informative, '当前目录下没有找到可用源码 podspec.'
|
148
|
+
end
|
149
|
+
|
150
|
+
spec_file = code_spec_files.first
|
151
|
+
spec_file
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'cocoapods-bin-forest/config/config'
|
3
|
+
|
4
|
+
module CBin
|
5
|
+
class Build
|
6
|
+
|
7
|
+
class Utils
|
8
|
+
|
9
|
+
def Utils.is_framework(spec)
|
10
|
+
if Utils.uses_frameworks?
|
11
|
+
return true
|
12
|
+
end
|
13
|
+
|
14
|
+
return Utils.is_swift_module(spec)
|
15
|
+
end
|
16
|
+
|
17
|
+
def Utils.spec_header_dir(spec)
|
18
|
+
|
19
|
+
header_dir = "./Headers/Public/#{spec.name}"
|
20
|
+
header_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(header_dir)
|
21
|
+
|
22
|
+
unless File.exist?(header_dir)
|
23
|
+
# 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
|
24
|
+
module_name = spec.name.gsub("-", "_")
|
25
|
+
header_dir = "./Pods/Headers/Public/#{module_name}"
|
26
|
+
end
|
27
|
+
|
28
|
+
# 暂时只支持:ios
|
29
|
+
consumer = Pod::Specification::Consumer.new(spec, :ios)
|
30
|
+
unless consumer.header_dir.nil?
|
31
|
+
header_dir = File.join(header_dir, consumer.header_dir)
|
32
|
+
end
|
33
|
+
|
34
|
+
header_dir
|
35
|
+
end
|
36
|
+
|
37
|
+
def Utils.spec_module_dir(spec)
|
38
|
+
if spec.module_name.nil?
|
39
|
+
module_dir = "./Headers/Public/#{spec.name}"
|
40
|
+
module_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(module_dir)
|
41
|
+
unless File.exist?(module_dir)
|
42
|
+
# 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
|
43
|
+
module_name = spec.name.gsub("-", "_")
|
44
|
+
module_dir = "./Pods/Headers/Public/#{module_name}"
|
45
|
+
end
|
46
|
+
else
|
47
|
+
module_dir = "./Headers/Public/#{spec.module_name}"
|
48
|
+
module_dir = "./Pods/Headers/Public/#{spec.module_name}" unless File.exist?(module_dir)
|
49
|
+
end
|
50
|
+
|
51
|
+
module_dir
|
52
|
+
end
|
53
|
+
|
54
|
+
def Utils.is_swift_module(spec)
|
55
|
+
|
56
|
+
is_framework = false
|
57
|
+
dir = File.join(CBin::Config::Builder.instance.gen_dir, CBin::Config::Builder.instance.target_name)
|
58
|
+
#auto 走这里
|
59
|
+
if File.exist?(dir)
|
60
|
+
Dir.chdir(dir) do
|
61
|
+
spec_module_dir = Utils.spec_module_dir(spec)
|
62
|
+
return false unless File.exist?(spec_module_dir)
|
63
|
+
is_framework = File.exist?(File.join(spec_module_dir, "#{spec.name}-umbrella.h"))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if $ARGV[1] == "local"
|
68
|
+
is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
|
69
|
+
unless is_framework
|
70
|
+
is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
is_framework
|
75
|
+
end
|
76
|
+
|
77
|
+
def Utils.uses_frameworks?
|
78
|
+
uses_frameworks = false
|
79
|
+
Pod::Config.instance.podfile.target_definitions.each do |key,value|
|
80
|
+
if key != "Pods"
|
81
|
+
uses_frameworks = value.uses_frameworks?
|
82
|
+
if uses_frameworks
|
83
|
+
break ;
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
return uses_frameworks
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -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,351 @@
|
|
1
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
2
|
+
|
3
|
+
require 'cocoapods-bin-forest/helpers/framework.rb'
|
4
|
+
require 'English'
|
5
|
+
require 'cocoapods-bin-forest/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, 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
|
+
#vendored_static_frameworks 只有 xx.framework 需要拼接为 xx.framework/xx by slj
|
21
|
+
vendored_static_frameworks = file_accessor.vendored_static_frameworks.map do |framework|
|
22
|
+
path = framework
|
23
|
+
extn = File.extname path
|
24
|
+
if extn.downcase == '.framework'
|
25
|
+
path = File.join(path,File.basename(path, extn))
|
26
|
+
end
|
27
|
+
path
|
28
|
+
end
|
29
|
+
|
30
|
+
@vendored_libraries = (vendored_static_frameworks + file_accessor.vendored_static_libraries).map(&:to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
def build
|
34
|
+
defines = compile
|
35
|
+
build_sim_libraries(defines)
|
36
|
+
|
37
|
+
defines
|
38
|
+
end
|
39
|
+
|
40
|
+
def lipo_build(defines)
|
41
|
+
UI.section("Building static Library #{@spec}") do
|
42
|
+
# defines = compile
|
43
|
+
|
44
|
+
# build_sim_libraries(defines)
|
45
|
+
output = framework.versions_path + Pathname.new(@spec.name)
|
46
|
+
|
47
|
+
build_static_library_for_ios(output)
|
48
|
+
|
49
|
+
copy_headers
|
50
|
+
copy_license
|
51
|
+
copy_resources
|
52
|
+
|
53
|
+
cp_to_source_dir
|
54
|
+
end
|
55
|
+
framework
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def cp_to_source_dir
|
61
|
+
framework_name = "#{@spec.name}.framework"
|
62
|
+
target_dir = File.join(CBin::Config::Builder.instance.zip_dir,framework_name)
|
63
|
+
FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
|
64
|
+
|
65
|
+
zip_dir = CBin::Config::Builder.instance.zip_dir
|
66
|
+
FileUtils.mkdir_p(zip_dir) unless File.exist?(zip_dir)
|
67
|
+
|
68
|
+
`cp -fa #{@platform}/#{framework_name} #{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}/lib#{@spec.name}.a"
|
110
|
+
library
|
111
|
+
end
|
112
|
+
# else
|
113
|
+
# libs = ios_architectures.map do |arch|
|
114
|
+
# library = "build/package-#{@spec.name}-#{arch}.a"
|
115
|
+
# # libtool -arch_only arm64 -static -o build/package-armv64.a build/libIMYFoundation.a build-simulator/libIMYFoundation.a
|
116
|
+
# # 从liBFoundation.a 文件中,提取出 arm64 架构的文件,命名为build/package-armv64.a
|
117
|
+
# UI.message "libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}"
|
118
|
+
# `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
|
119
|
+
# library
|
120
|
+
# end
|
121
|
+
# end
|
122
|
+
|
123
|
+
UI.message "lipo -create -output #{output} #{libs.join(' ')}"
|
124
|
+
`lipo -create -output #{output} #{libs.join(' ')}`
|
125
|
+
end
|
126
|
+
|
127
|
+
def ios_build_options
|
128
|
+
"ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
|
129
|
+
end
|
130
|
+
|
131
|
+
def ios_architectures
|
132
|
+
# >armv7
|
133
|
+
# iPhone4
|
134
|
+
# iPhone4S
|
135
|
+
# >armv7s 去掉
|
136
|
+
# iPhone5
|
137
|
+
# iPhone5C
|
138
|
+
# >arm64
|
139
|
+
# iPhone5S(以上)
|
140
|
+
# >i386
|
141
|
+
# iphone5,iphone5s以下的模拟器
|
142
|
+
# >x86_64
|
143
|
+
# iphone6以上的模拟器
|
144
|
+
archs = %w[arm64 armv7]
|
145
|
+
# archs = %w[x86_64 arm64 armv7s i386]
|
146
|
+
# @vendored_libraries.each do |library|
|
147
|
+
# archs = `lipo -info #{library}`.split & archs
|
148
|
+
# end
|
149
|
+
archs
|
150
|
+
end
|
151
|
+
|
152
|
+
def ios_architectures_sim
|
153
|
+
|
154
|
+
archs = %w[x86_64]
|
155
|
+
# TODO 处理是否需要 i386
|
156
|
+
archs
|
157
|
+
end
|
158
|
+
|
159
|
+
def compile
|
160
|
+
defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited)'"
|
161
|
+
defines += ' '
|
162
|
+
defines += @spec.consumer(@platform).compiler_flags.join(' ')
|
163
|
+
|
164
|
+
options = ios_build_options
|
165
|
+
# if is_debug_model
|
166
|
+
archs = ios_architectures
|
167
|
+
# archs = %w[arm64 armv7 armv7s]
|
168
|
+
archs.map do |arch|
|
169
|
+
xcodebuild(defines, "ARCHS=\'#{arch}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'","build-#{arch}",@build_model)
|
170
|
+
end
|
171
|
+
# else
|
172
|
+
# xcodebuild(defines,options)
|
173
|
+
# end
|
174
|
+
|
175
|
+
defines
|
176
|
+
end
|
177
|
+
|
178
|
+
def is_debug_model
|
179
|
+
@build_model == "Debug"
|
180
|
+
end
|
181
|
+
|
182
|
+
def target_name
|
183
|
+
#区分多平台,如配置了多平台,会带上平台的名字
|
184
|
+
# 如libwebp-iOS
|
185
|
+
if @spec.available_platforms.count > 1
|
186
|
+
"#{@spec.name}-#{Platform.string_name(@spec.consumer(@platform).platform_name)}"
|
187
|
+
else
|
188
|
+
@spec.name
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def xcodebuild(defines = '', args = '', build_dir = 'build', build_model = 'Debug')
|
193
|
+
|
194
|
+
unless File.exist?("Pods.xcodeproj") #cocoapods-generate v2.0.0
|
195
|
+
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"
|
196
|
+
else
|
197
|
+
command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{build_model} -target #{target_name} -project ./Pods.xcodeproj 2>&1"
|
198
|
+
end
|
199
|
+
|
200
|
+
UI.message "command = #{command}"
|
201
|
+
output = `#{command}`.lines.to_a
|
202
|
+
|
203
|
+
if $CHILD_STATUS.exitstatus != 0
|
204
|
+
raise <<~EOF
|
205
|
+
Build command failed: #{command}
|
206
|
+
Output:
|
207
|
+
#{output.map { |line| " #{line}" }.join}
|
208
|
+
EOF
|
209
|
+
|
210
|
+
Process.exit
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def copy_headers
|
215
|
+
#走 podsepc中的public_headers
|
216
|
+
public_headers = Array.new
|
217
|
+
|
218
|
+
#by slj 如果没有头文件,去 "Headers/Public"拿
|
219
|
+
# if public_headers.empty?
|
220
|
+
spec_header_dir = CBin::Build::Utils.spec_header_dir(@spec)
|
221
|
+
raise "copy_headers #{spec_header_dir} no exist " unless File.exist?(spec_header_dir)
|
222
|
+
|
223
|
+
Dir.chdir(spec_header_dir) do
|
224
|
+
headers = Dir.glob('**/*.h')
|
225
|
+
headers.each do |h|
|
226
|
+
public_headers << Pathname.new(File.join(Dir.pwd,h))
|
227
|
+
end
|
228
|
+
end
|
229
|
+
# end
|
230
|
+
|
231
|
+
# UI.message "Copying public headers #{public_headers.map(&:basename).map(&:to_s)}"
|
232
|
+
|
233
|
+
public_headers.each do |h|
|
234
|
+
`ditto #{h} #{framework.headers_path}/#{h.basename}`
|
235
|
+
end
|
236
|
+
|
237
|
+
# If custom 'module_map' is specified add it to the framework distribution
|
238
|
+
# otherwise check if a header exists that is equal to 'spec.name', if so
|
239
|
+
# create a default 'module_map' one using it.
|
240
|
+
if !@spec.module_map.nil?
|
241
|
+
module_map_file = @file_accessor.module_map
|
242
|
+
if Pathname(module_map_file).exist?
|
243
|
+
module_map = File.read(module_map_file)
|
244
|
+
end
|
245
|
+
elsif public_headers.map(&:basename).map(&:to_s).include?("#{@spec.name}.h")
|
246
|
+
module_map = <<-MAP
|
247
|
+
framework module #{@spec.name} {
|
248
|
+
umbrella header "#{@spec.name}.h"
|
249
|
+
|
250
|
+
export *
|
251
|
+
module * { export * }
|
252
|
+
}
|
253
|
+
MAP
|
254
|
+
else
|
255
|
+
# by ChildhoodAndy
|
256
|
+
# try to read modulemap file from module dir
|
257
|
+
module_map_file = File.join(CBin::Build::Utils.spec_module_dir(@spec), "#{@spec.name}.modulemap")
|
258
|
+
if Pathname(module_map_file).exist?
|
259
|
+
module_map = File.read(module_map_file)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
unless module_map.nil?
|
264
|
+
UI.message "Writing module map #{module_map}"
|
265
|
+
unless framework.module_map_path.exist?
|
266
|
+
framework.module_map_path.mkpath
|
267
|
+
end
|
268
|
+
File.write("#{framework.module_map_path}/module.modulemap", module_map)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def copy_license
|
273
|
+
UI.message 'Copying license'
|
274
|
+
license_file = @spec.license[:file] || 'LICENSE'
|
275
|
+
`cp "#{license_file}" .` if Pathname(license_file).exist?
|
276
|
+
end
|
277
|
+
|
278
|
+
def copy_resources
|
279
|
+
resource_dir = './build/*.bundle'
|
280
|
+
resource_dir = './build-armv7/*.bundle' if File.exist?('./build-armv7')
|
281
|
+
resource_dir = './build-arm64/*.bundle' if File.exist?('./build-arm64')
|
282
|
+
|
283
|
+
bundles = Dir.glob(resource_dir)
|
284
|
+
|
285
|
+
bundle_names = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
286
|
+
consumer = spec.consumer(@platform)
|
287
|
+
consumer.resource_bundles.keys +
|
288
|
+
consumer.resources.map do |r|
|
289
|
+
File.basename(r, '.bundle') if File.extname(r) == 'bundle'
|
290
|
+
end
|
291
|
+
end.compact.uniq
|
292
|
+
|
293
|
+
bundles.select! do |bundle|
|
294
|
+
bundle_name = File.basename(bundle, '.bundle')
|
295
|
+
bundle_names.include?(bundle_name)
|
296
|
+
end
|
297
|
+
|
298
|
+
if bundles.count > 0
|
299
|
+
UI.message "Copying bundle files #{bundles}"
|
300
|
+
bundle_files = bundles.join(' ')
|
301
|
+
`cp -rp #{bundle_files} #{framework.resources_path} 2>&1`
|
302
|
+
end
|
303
|
+
|
304
|
+
real_source_dir = @source_dir
|
305
|
+
unless @isRootSpec
|
306
|
+
spec_source_dir = File.join(Dir.pwd,"#{@spec.name}")
|
307
|
+
unless File.exist?(spec_source_dir)
|
308
|
+
spec_source_dir = File.join(Dir.pwd,"Pods/#{@spec.name}")
|
309
|
+
end
|
310
|
+
raise "copy_resources #{spec_source_dir} no exist " unless File.exist?(spec_source_dir)
|
311
|
+
|
312
|
+
real_source_dir = spec_source_dir
|
313
|
+
end
|
314
|
+
resources = [@spec, *@spec.recursive_subspecs].flat_map do |spec|
|
315
|
+
expand_paths(real_source_dir, spec.consumer(@platform).resources)
|
316
|
+
end.compact.uniq
|
317
|
+
|
318
|
+
if resources.count == 0 && bundles.count == 0
|
319
|
+
framework.delete_resources
|
320
|
+
return
|
321
|
+
end
|
322
|
+
|
323
|
+
if resources.count > 0
|
324
|
+
#把 路径转义。 避免空格情况下拷贝失败
|
325
|
+
escape_resource = []
|
326
|
+
resources.each do |source|
|
327
|
+
escape_resource << Shellwords.join(source)
|
328
|
+
end
|
329
|
+
UI.message "Copying resources #{escape_resource}"
|
330
|
+
`cp -rp #{escape_resource.join(' ')} #{framework.resources_path}`
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
def expand_paths(source_dir, path_specs)
|
335
|
+
path_specs.map do |path_spec|
|
336
|
+
Dir.glob(File.join(source_dir, path_spec))
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def framework
|
341
|
+
@framework ||= begin
|
342
|
+
framework = Framework.new(@spec.name, @platform.name.to_s)
|
343
|
+
framework.make
|
344
|
+
framework
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|