cocoapods-mtxx-bin 0.0.1
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 +11 -0
- data/lib/cocoapods-mtxx-bin/command/bin/archive.rb +206 -0
- data/lib/cocoapods-mtxx-bin/command/bin/auto.rb +212 -0
- data/lib/cocoapods-mtxx-bin/command/bin/code.rb +232 -0
- data/lib/cocoapods-mtxx-bin/command/bin/imy.rb +45 -0
- data/lib/cocoapods-mtxx-bin/command/bin/init.rb +94 -0
- data/lib/cocoapods-mtxx-bin/command/bin/initHotKey.rb +70 -0
- data/lib/cocoapods-mtxx-bin/command/bin/install.rb +44 -0
- data/lib/cocoapods-mtxx-bin/command/bin/lib/lint.rb +67 -0
- data/lib/cocoapods-mtxx-bin/command/bin/repo/push.rb +115 -0
- data/lib/cocoapods-mtxx-bin/command/bin/repo/update.rb +42 -0
- data/lib/cocoapods-mtxx-bin/command/bin/repo.rb +14 -0
- data/lib/cocoapods-mtxx-bin/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-mtxx-bin/command/bin/spec/lint.rb +109 -0
- data/lib/cocoapods-mtxx-bin/command/bin/spec.rb +13 -0
- data/lib/cocoapods-mtxx-bin/command/bin/update.rb +154 -0
- data/lib/cocoapods-mtxx-bin/command/bin.rb +65 -0
- data/lib/cocoapods-mtxx-bin/command.rb +1 -0
- data/lib/cocoapods-mtxx-bin/config/config.rb +166 -0
- data/lib/cocoapods-mtxx-bin/config/config_asker.rb +60 -0
- data/lib/cocoapods-mtxx-bin/config/config_builder.rb +216 -0
- data/lib/cocoapods-mtxx-bin/config/config_hot_key.rb +103 -0
- data/lib/cocoapods-mtxx-bin/config/config_hot_key_asker.rb +57 -0
- data/lib/cocoapods-mtxx-bin/gem_version.rb +9 -0
- data/lib/cocoapods-mtxx-bin/helpers/Info.plist +0 -0
- data/lib/cocoapods-mtxx-bin/helpers/build_helper.rb +167 -0
- data/lib/cocoapods-mtxx-bin/helpers/build_utils.rb +64 -0
- data/lib/cocoapods-mtxx-bin/helpers/framework.rb +86 -0
- data/lib/cocoapods-mtxx-bin/helpers/framework_builder.rb +551 -0
- data/lib/cocoapods-mtxx-bin/helpers/library.rb +54 -0
- data/lib/cocoapods-mtxx-bin/helpers/library_builder.rb +90 -0
- data/lib/cocoapods-mtxx-bin/helpers/sources_helper.rb +35 -0
- data/lib/cocoapods-mtxx-bin/helpers/spec_creator.rb +170 -0
- data/lib/cocoapods-mtxx-bin/helpers/spec_files_helper.rb +80 -0
- data/lib/cocoapods-mtxx-bin/helpers/spec_source_creator.rb +304 -0
- data/lib/cocoapods-mtxx-bin/helpers/upload_helper.rb +104 -0
- data/lib/cocoapods-mtxx-bin/helpers.rb +5 -0
- data/lib/cocoapods-mtxx-bin/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-mtxx-bin/native/analyzer.rb +85 -0
- data/lib/cocoapods-mtxx-bin/native/file_accessor.rb +28 -0
- data/lib/cocoapods-mtxx-bin/native/gen.rb +79 -0
- data/lib/cocoapods-mtxx-bin/native/installation_options.rb +25 -0
- data/lib/cocoapods-mtxx-bin/native/installer.rb +135 -0
- data/lib/cocoapods-mtxx-bin/native/linter.rb +26 -0
- data/lib/cocoapods-mtxx-bin/native/path_source.rb +33 -0
- data/lib/cocoapods-mtxx-bin/native/pod_source_installer.rb +19 -0
- data/lib/cocoapods-mtxx-bin/native/pod_target_installer.rb +94 -0
- data/lib/cocoapods-mtxx-bin/native/podfile.rb +91 -0
- data/lib/cocoapods-mtxx-bin/native/podfile_env.rb +37 -0
- data/lib/cocoapods-mtxx-bin/native/podfile_generator.rb +201 -0
- data/lib/cocoapods-mtxx-bin/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-mtxx-bin/native/resolver.rb +238 -0
- data/lib/cocoapods-mtxx-bin/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-mtxx-bin/native/source.rb +35 -0
- data/lib/cocoapods-mtxx-bin/native/sources_manager.rb +19 -0
- data/lib/cocoapods-mtxx-bin/native/specification.rb +31 -0
- data/lib/cocoapods-mtxx-bin/native/target_validator.rb +41 -0
- data/lib/cocoapods-mtxx-bin/native/validator.rb +40 -0
- data/lib/cocoapods-mtxx-bin/native.rb +25 -0
- data/lib/cocoapods-mtxx-bin/source_provider_hook.rb +53 -0
- data/lib/cocoapods-mtxx-bin.rb +2 -0
- data/lib/cocoapods_plugin.rb +2 -0
- data/spec/command/bin_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +182 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'cocoapods-mtxx-bin/native/sources_manager.rb'
|
4
|
+
|
5
|
+
module CBin
|
6
|
+
module SourcesHelper
|
7
|
+
def sources_manager
|
8
|
+
Pod::Config.instance.sources_manager
|
9
|
+
end
|
10
|
+
|
11
|
+
def binary_source
|
12
|
+
sources_manager.binary_source
|
13
|
+
end
|
14
|
+
|
15
|
+
def code_source_list
|
16
|
+
sources_manager.code_source_list
|
17
|
+
end
|
18
|
+
# 优先采用对应依赖的 source
|
19
|
+
# cocoapods 内部会先匹配前面符合的 specification
|
20
|
+
# 只允许二进制的 specification subspec 比源码的 specification subspec 多
|
21
|
+
#
|
22
|
+
def valid_sources(code_dependencies = false)
|
23
|
+
sources = code_source_list
|
24
|
+
unless code_dependencies
|
25
|
+
sources << binary_source
|
26
|
+
sources.reverse!
|
27
|
+
end
|
28
|
+
sources
|
29
|
+
end
|
30
|
+
|
31
|
+
def sources_option(code_dependencies, additional_sources)
|
32
|
+
(valid_sources(code_dependencies).map(&:url) + Array(additional_sources)).join(',')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'cocoapods'
|
4
|
+
require 'cocoapods-mtxx-bin/config/config'
|
5
|
+
|
6
|
+
module CBin
|
7
|
+
class Specification
|
8
|
+
class Creator
|
9
|
+
attr_reader :code_spec
|
10
|
+
attr_reader :template_spec
|
11
|
+
attr_reader :spec
|
12
|
+
|
13
|
+
def initialize(code_spec, template_spec, platforms = 'ios')
|
14
|
+
@code_spec = code_spec
|
15
|
+
@template_spec = template_spec
|
16
|
+
@platforms = Array(platforms)
|
17
|
+
validate!
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate!
|
21
|
+
raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
|
22
|
+
if code_spec.subspecs.any? && template_spec.nil?
|
23
|
+
raise Pod::Informative, "不支持自动生成存在 subspec 的二进制 podspec , 需要提供模版文件 #{code_spec.name}.binary.podspec.template ."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
spec = template_spec ? create_from_code_spec_and_template_spec : create_from_code_spec
|
29
|
+
|
30
|
+
Pod::UI.message '生成二进制 podspec 内容: '
|
31
|
+
spec.to_pretty_json.split("\n").each do |text|
|
32
|
+
Pod::UI.message text
|
33
|
+
end
|
34
|
+
|
35
|
+
spec
|
36
|
+
end
|
37
|
+
|
38
|
+
def write_spec_file(file = filename)
|
39
|
+
create unless spec
|
40
|
+
|
41
|
+
File.open(file, 'w+') do |f|
|
42
|
+
f.write(spec.to_pretty_json)
|
43
|
+
end
|
44
|
+
|
45
|
+
@filename = file
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear_spec_file
|
49
|
+
File.delete(filename) if File.exist?(filename)
|
50
|
+
end
|
51
|
+
|
52
|
+
def filename
|
53
|
+
@filename ||= "#{spec.name}.binary.podspec.json"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def create_from_code_spec
|
59
|
+
@spec = code_spec.dup
|
60
|
+
# vendored_frameworks | resources | source | source_files | public_header_files
|
61
|
+
# license | resource_bundles | vendored_libraries
|
62
|
+
|
63
|
+
# Project Linkin
|
64
|
+
@spec.vendored_frameworks = "#{code_spec.root.name}.framework"
|
65
|
+
|
66
|
+
# Resources
|
67
|
+
extnames = []
|
68
|
+
extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
|
69
|
+
if code_spec_consumer.resources.any?
|
70
|
+
extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
|
71
|
+
end
|
72
|
+
if extnames.any?
|
73
|
+
@spec.resources = framework_contents('Resources').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
|
74
|
+
end
|
75
|
+
|
76
|
+
# Source Location
|
77
|
+
@spec.source = binary_source
|
78
|
+
|
79
|
+
# Source Code
|
80
|
+
@spec.source_files = framework_contents('Headers/*')
|
81
|
+
@spec.public_header_files = framework_contents('Headers/*')
|
82
|
+
|
83
|
+
# Unused for binary
|
84
|
+
spec_hash = @spec.to_hash
|
85
|
+
# spec_hash.delete('license')
|
86
|
+
spec_hash.delete('resource_bundles')
|
87
|
+
spec_hash.delete('exclude_files')
|
88
|
+
spec_hash.delete('preserve_paths')
|
89
|
+
# 这里不确定 vendored_libraries 指定的时动态/静态库
|
90
|
+
# 如果是静态库的话,需要移除,否则就不移除
|
91
|
+
# 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
|
92
|
+
# 这里统一只对命名后缀 .a 文件做处理
|
93
|
+
# spec_hash.delete('vendored_libraries')
|
94
|
+
# libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
|
95
|
+
spec_hash.delete('vendored_libraries')
|
96
|
+
spec_hash['vendored_libraries'] = binary_vendored_libraries
|
97
|
+
|
98
|
+
# vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
|
99
|
+
# if vendored_libraries.any?
|
100
|
+
# spec_hash['vendored_libraries'] = vendored_libraries
|
101
|
+
# end
|
102
|
+
|
103
|
+
# Filter platforms
|
104
|
+
platforms = spec_hash['platforms']
|
105
|
+
selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
|
106
|
+
spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
|
107
|
+
|
108
|
+
@spec = Pod::Specification.from_hash(spec_hash)
|
109
|
+
@spec
|
110
|
+
end
|
111
|
+
|
112
|
+
def create_from_code_spec_and_template_spec
|
113
|
+
@spec = template_spec.dup
|
114
|
+
|
115
|
+
@spec.version = code_spec.version
|
116
|
+
@spec.source = binary_source
|
117
|
+
|
118
|
+
@spec.source_files = binary_source_files
|
119
|
+
@spec.public_header_files = binary_public_header_files
|
120
|
+
@spec.vendored_libraries = binary_vendored_libraries
|
121
|
+
|
122
|
+
@spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources")
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
@spec
|
127
|
+
end
|
128
|
+
|
129
|
+
def binary_source
|
130
|
+
{ http: format(CBin.config.binary_download_url), type: CBin.config.download_file_type }
|
131
|
+
end
|
132
|
+
|
133
|
+
def code_spec_consumer(_platform = :ios)
|
134
|
+
code_spec.consumer(:ios)
|
135
|
+
end
|
136
|
+
|
137
|
+
def framework_contents(name)
|
138
|
+
["#{code_spec.root.name}.framework"].map { |path| "#{path}/#{name}" }
|
139
|
+
end
|
140
|
+
|
141
|
+
def binary_source_files
|
142
|
+
{ http: format(CBin.config.binary_download_url), type: CBin.config.download_file_type }
|
143
|
+
end
|
144
|
+
|
145
|
+
def binary_source_files
|
146
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*"
|
147
|
+
end
|
148
|
+
|
149
|
+
def binary_public_header_files
|
150
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*.h"
|
151
|
+
end
|
152
|
+
|
153
|
+
def binary_vendored_libraries
|
154
|
+
"bin_#{code_spec.name}_#{code_spec.version}/*.a"
|
155
|
+
end
|
156
|
+
|
157
|
+
def binary_resources
|
158
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Resources/*"
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
#模板框架begin
|
165
|
+
# s.source_files = "bin_#{s.name}_#{s.version}/Headers/*"
|
166
|
+
# s.public_header_files = "bin_#{s.name}_#{s.version}/Headers/*.h"
|
167
|
+
# s.vendored_libraries = "bin_#{s.name}_#{s.version}/*.a"
|
168
|
+
#有图片资源的,要带上
|
169
|
+
#s.resources = 'bin_#{s.name}_#{s.version}/Resources/*.{json,png,jpg,gif,js,xib,eot,svg,ttf,woff,db,sqlite,mp3,bundle}'
|
170
|
+
#模板框架end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'cocoapods-mtxx-bin/native/sources_manager.rb'
|
4
|
+
require 'cocoapods-mtxx-bin/helpers/spec_creator'
|
5
|
+
|
6
|
+
module CBin
|
7
|
+
module SpecFilesHelper
|
8
|
+
def spec_files
|
9
|
+
@spec_files ||= Pathname.glob('*.podspec{,.json}')
|
10
|
+
end
|
11
|
+
|
12
|
+
def binary_spec_files
|
13
|
+
@binary_spec_files ||= Pathname.glob('*.binary.podspec{,.json}')
|
14
|
+
end
|
15
|
+
|
16
|
+
def binary_template_spec_files
|
17
|
+
@binary_spec_template_files ||= Pathname.glob('*.binary-template.podspec{,.json}')
|
18
|
+
end
|
19
|
+
|
20
|
+
def binary_template_spec_file
|
21
|
+
@binary_spec_template_file ||= binary_template_spec_files.first
|
22
|
+
end
|
23
|
+
|
24
|
+
def code_spec_files
|
25
|
+
@code_spec_files ||= spec_files - binary_spec_files - binary_template_spec_files
|
26
|
+
end
|
27
|
+
|
28
|
+
def code_spec
|
29
|
+
if code_spec_files.first
|
30
|
+
Pod::Specification.from_file(code_spec_files.first)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def binary_spec
|
35
|
+
if binary_spec_files.first
|
36
|
+
Pod::Specification.from_file(binary_spec_files.first)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def binary_template_spec
|
41
|
+
if binary_template_spec_file
|
42
|
+
Pod::Specification.from_file(binary_template_spec_file)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_spec_file(podspec)
|
47
|
+
path = Pathname(podspec)
|
48
|
+
raise Pod::Informative, "无法找到 #{podspec}" unless path.exist?
|
49
|
+
|
50
|
+
path
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_binary_spec_file(code_spec, template_spec)
|
54
|
+
# 1. code spec 是否有 subpsec
|
55
|
+
# 1.1 有,查找 template spec,并生成
|
56
|
+
# 1.2 没有,是否有 template spec
|
57
|
+
# 1.2.1 有,根据 template spec 生成
|
58
|
+
# 1.2.2 没有,根据 code spec 生成
|
59
|
+
|
60
|
+
unless code_spec
|
61
|
+
raise Pod::Informative, '没有二进制 podspec 的情况下,必须要提供源码 podspec.'
|
62
|
+
end
|
63
|
+
# if code_spec.subspecs.any? && template_spec.nil?
|
64
|
+
# raise Pod::Informative, '拥有 subspec 的组件,在生成二进制 podspec 时,必须要提供模版 podspec.'
|
65
|
+
# end
|
66
|
+
|
67
|
+
Dir.chdir(CBin::Config::Builder.instance.root_dir) do
|
68
|
+
@spec_creator = CBin::SpecificationSource::Creator.new(code_spec)
|
69
|
+
# @spec_creator = CBin::Specification::Creator.new(code_spec, template_spec)
|
70
|
+
@spec_creator.create
|
71
|
+
@spec_creator.write_spec_file
|
72
|
+
@spec_creator.filename
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def clear_binary_spec_file_if_needed
|
77
|
+
@spec_creator&.clear_spec_file
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,304 @@
|
|
1
|
+
require 'cocoapods'
|
2
|
+
require 'cocoapods-mtxx-bin/config/config'
|
3
|
+
|
4
|
+
module CBin
|
5
|
+
class SpecificationSource
|
6
|
+
class Creator
|
7
|
+
attr_reader :code_spec
|
8
|
+
attr_reader :spec
|
9
|
+
|
10
|
+
def initialize(code_spec, platforms = 'ios')
|
11
|
+
@code_spec = code_spec
|
12
|
+
@platforms = Array(platforms)
|
13
|
+
validate!
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate!
|
17
|
+
raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
|
18
|
+
end
|
19
|
+
|
20
|
+
# 创建二进制podspec
|
21
|
+
def create
|
22
|
+
# spec = nil
|
23
|
+
if CBin::Build::Utils.is_framework(@code_spec)
|
24
|
+
# .framework
|
25
|
+
spec = create_framework_from_code_spec
|
26
|
+
else
|
27
|
+
# .a
|
28
|
+
spec = create_from_code_spec
|
29
|
+
end
|
30
|
+
|
31
|
+
spec
|
32
|
+
end
|
33
|
+
|
34
|
+
# 将二进制podspec写入文件
|
35
|
+
def write_spec_file(file = filename)
|
36
|
+
create unless spec
|
37
|
+
|
38
|
+
FileUtils.mkdir_p(CBin::Config::Builder.instance.binary_json_dir) unless File.exist?(CBin::Config::Builder.instance.binary_json_dir)
|
39
|
+
FileUtils.rm_rf(file) if File.exist?(file)
|
40
|
+
|
41
|
+
File.open(file, 'w+') do |f|
|
42
|
+
# f.write("# MARK: converted automatically by plugin cocoapods-mtxx-bin @slj \r\n")
|
43
|
+
f.write(spec.to_pretty_json)
|
44
|
+
end
|
45
|
+
|
46
|
+
@filename = file
|
47
|
+
end
|
48
|
+
|
49
|
+
def clear_spec_file
|
50
|
+
File.delete(filename) if File.exist?(filename)
|
51
|
+
end
|
52
|
+
|
53
|
+
def filename
|
54
|
+
@filename ||= "#{CBin::Config::Builder.instance.binary_json_dir_name}/#{spec.name}.binary.podspec.json"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# 创建.a的二进制podspec
|
60
|
+
def create_from_code_spec
|
61
|
+
@spec = code_spec.dup
|
62
|
+
# vendored_frameworks | resources | source | source_files | public_header_files
|
63
|
+
# license | resource_bundles | vendored_libraries
|
64
|
+
|
65
|
+
# Project Linkin
|
66
|
+
# @spec.vendored_frameworks = "#{code_spec.root.name}.framework"
|
67
|
+
|
68
|
+
# Resources
|
69
|
+
extnames = []
|
70
|
+
extnames << '*.bundle' if code_spec_consumer.resource_bundles.any?
|
71
|
+
if code_spec_consumer.resources.any?
|
72
|
+
extnames += code_spec_consumer.resources.map { |r| File.basename(r) }
|
73
|
+
end
|
74
|
+
if extnames.any?
|
75
|
+
@spec.resources = framework_contents('').flat_map { |r| extnames.map { |e| "#{r}/#{e}" } }
|
76
|
+
end
|
77
|
+
|
78
|
+
# Source Location
|
79
|
+
@spec.source = binary_source
|
80
|
+
|
81
|
+
# Source Code
|
82
|
+
@spec.source_files = framework_contents('Headers/*')
|
83
|
+
@spec.public_header_files = framework_contents('Headers/*')
|
84
|
+
|
85
|
+
# Unused for binary
|
86
|
+
spec_hash = @spec.to_hash
|
87
|
+
# spec_hash.delete('license')
|
88
|
+
spec_hash.delete('source_files')
|
89
|
+
spec_hash.delete('resource_bundles')
|
90
|
+
spec_hash.delete('exclude_files')
|
91
|
+
spec_hash.delete('preserve_paths')
|
92
|
+
|
93
|
+
spec_hash.delete('subspecs')
|
94
|
+
spec_hash.delete('default_subspecs')
|
95
|
+
spec_hash.delete('default_subspec')
|
96
|
+
spec_hash.delete('vendored_frameworks')
|
97
|
+
spec_hash.delete('vendored_framework')
|
98
|
+
|
99
|
+
# 这里不确定 vendored_libraries 指定的时动态/静态库
|
100
|
+
# 如果是静态库的话,需要移除,否则就不移除
|
101
|
+
# 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
|
102
|
+
# 这里统一只对命名后缀 .a 文件做处理
|
103
|
+
# spec_hash.delete('vendored_libraries')
|
104
|
+
# libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
|
105
|
+
spec_hash.delete('vendored_libraries')
|
106
|
+
|
107
|
+
# vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
|
108
|
+
# if vendored_libraries.any?
|
109
|
+
# spec_hash['vendored_libraries'] = vendored_libraries
|
110
|
+
# end
|
111
|
+
|
112
|
+
# Filter platforms
|
113
|
+
platforms = spec_hash['platforms']
|
114
|
+
selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
|
115
|
+
spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
|
116
|
+
|
117
|
+
@spec = Pod::Specification.from_hash(spec_hash)
|
118
|
+
|
119
|
+
#把命令 prepare_command 移除掉,如ReactiveCocoa会执行修改重命令的脚步
|
120
|
+
@spec.prepare_command = "" if @spec.prepare_command
|
121
|
+
@spec.version = code_spec.version
|
122
|
+
@spec.source = binary_source
|
123
|
+
@spec.source_files = binary_source_files
|
124
|
+
@spec.public_header_files = binary_public_header_files
|
125
|
+
@spec.vendored_libraries = binary_vendored_libraries
|
126
|
+
@spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources")
|
127
|
+
@spec.description = <<-EOF
|
128
|
+
「converted automatically by plugin cocoapods-mtxx-bin @美图 - zys」
|
129
|
+
#{@spec.description}
|
130
|
+
EOF
|
131
|
+
@spec
|
132
|
+
end
|
133
|
+
|
134
|
+
# 创建.framework的二进制podspec
|
135
|
+
def create_framework_from_code_spec
|
136
|
+
@spec = code_spec.dup
|
137
|
+
# vendored_frameworks | resources | source | source_files | public_header_files
|
138
|
+
# license | resource_bundles | vendored_libraries
|
139
|
+
|
140
|
+
# framework绝对路径
|
141
|
+
fwk_abs_path = "#{CBin::Config::Builder.instance.gen_dir}/#{code_spec.root.name}/ios/#{code_spec.module_name}.framework"
|
142
|
+
|
143
|
+
# Project Linkin
|
144
|
+
fwks_path = "#{fwk_abs_path}/fwks"
|
145
|
+
fwks = ["#{code_spec.module_name}.framework"]
|
146
|
+
if File.exist?(fwks_path)
|
147
|
+
fwks << "#{code_spec.module_name}.framework/fwks/*"
|
148
|
+
end
|
149
|
+
@spec.vendored_frameworks = fwks
|
150
|
+
|
151
|
+
libs_path = "#{fwk_abs_path}/libs"
|
152
|
+
@spec.vendored_libraries = "#{code_spec.module_name}.framework/libs/*" if File.exist?(libs_path)
|
153
|
+
|
154
|
+
# Resources
|
155
|
+
special_resource_ext_str = special_resource_exts.join(',')
|
156
|
+
special_res = Dir.glob("#{fwk_abs_path}/*.{#{special_resource_ext_str}}")
|
157
|
+
resources = []
|
158
|
+
unless special_res.empty?
|
159
|
+
resources << "#{code_spec.module_name}.framework/*.{#{special_resource_ext_str}}"
|
160
|
+
end
|
161
|
+
resources_path = "#{fwk_abs_path}/resources"
|
162
|
+
if File.exist?(resources_path)
|
163
|
+
resources << "#{code_spec.module_name}.framework/resources/*"
|
164
|
+
end
|
165
|
+
@spec.resources = resources unless resources.empty?
|
166
|
+
|
167
|
+
# Source Location
|
168
|
+
@spec.source = binary_source
|
169
|
+
# Source Code
|
170
|
+
@spec.source_files = "#{code_spec.module_name}.framework/Headers/*"
|
171
|
+
@spec.public_header_files = "#{code_spec.module_name}.framework/Headers/*"
|
172
|
+
@spec.private_header_files = "#{code_spec.module_name}.framework/PrivateHeaders/*"
|
173
|
+
|
174
|
+
# Unused for binary
|
175
|
+
spec_hash = @spec.to_hash
|
176
|
+
# spec_hash.delete('license')
|
177
|
+
# spec_hash.delete('source_files')
|
178
|
+
spec_hash.delete('project_header_files')
|
179
|
+
spec_hash.delete('resource_bundles')
|
180
|
+
spec_hash.delete('exclude_files')
|
181
|
+
spec_hash.delete('preserve_paths')
|
182
|
+
spec_hash.delete('prepare_command')
|
183
|
+
# 这里不确定 vendored_libraries 指定的时动态/静态库
|
184
|
+
# 如果是静态库的话,需要移除,否则就不移除
|
185
|
+
# 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
|
186
|
+
# 这里统一只对命名后缀 .a 文件做处理
|
187
|
+
# spec_hash.delete('vendored_libraries')
|
188
|
+
# libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
|
189
|
+
# vendored_libraries = spec_hash.delete('vendored_libraries')
|
190
|
+
# vendored_libraries = Array(vendored_libraries).reject { |l| l.end_with?('.a') }
|
191
|
+
# if vendored_libraries.any?
|
192
|
+
# spec_hash['vendored_libraries'] = vendored_libraries
|
193
|
+
# end
|
194
|
+
|
195
|
+
# Filter platforms
|
196
|
+
platforms = spec_hash['platforms']
|
197
|
+
selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
|
198
|
+
spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
|
199
|
+
|
200
|
+
# subspecs
|
201
|
+
if spec_hash['subspecs'] && spec_hash['subspecs'].size > 0
|
202
|
+
bin_subspec = {
|
203
|
+
'name' => 'Binary',
|
204
|
+
'source_files' => spec_hash['source_files'],
|
205
|
+
'public_header_files' => spec_hash['public_header_files'],
|
206
|
+
'private_header_files' => spec_hash['private_header_files'],
|
207
|
+
'vendored_frameworks' => spec_hash['vendored_frameworks'],
|
208
|
+
'vendored_libraries' => spec_hash['vendored_libraries'],
|
209
|
+
'resources' => spec_hash['resources']
|
210
|
+
}
|
211
|
+
spec_hash['subspecs'] << bin_subspec
|
212
|
+
spec_hash['subspecs'].map do |subspec|
|
213
|
+
next if subspec['name'] == 'Binary'
|
214
|
+
# 处理单个subspec
|
215
|
+
handle_single_subspec(subspec)
|
216
|
+
# 递归处理subspec
|
217
|
+
handle_subspecs(subspec['subspecs'])
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
@spec = Pod::Specification.from_hash(spec_hash)
|
222
|
+
@spec.description = <<-EOF
|
223
|
+
「converted automatically by plugin cocoapods-mtxx-bin @美图 - zys」
|
224
|
+
#{@spec.description}
|
225
|
+
EOF
|
226
|
+
@spec
|
227
|
+
end
|
228
|
+
|
229
|
+
# 特殊的资源后缀
|
230
|
+
def special_resource_exts
|
231
|
+
%w[momd mom cdm nib storyboardc]
|
232
|
+
end
|
233
|
+
|
234
|
+
# 递归处理subspecs
|
235
|
+
def handle_subspecs(subspecs)
|
236
|
+
return unless subspecs && subspecs.size > 0
|
237
|
+
subspecs.map do |s|
|
238
|
+
# 处理单个subspec
|
239
|
+
handle_single_subspec(s)
|
240
|
+
# 递归处理
|
241
|
+
handle_subspecs(s['subspecs'])
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# 处理单个subspec
|
246
|
+
def handle_single_subspec(subspec)
|
247
|
+
subspec.delete('source_files')
|
248
|
+
subspec.delete('public_header_files')
|
249
|
+
subspec.delete('project_header_files')
|
250
|
+
subspec.delete('private_header_files')
|
251
|
+
subspec.delete('vendored_frameworks')
|
252
|
+
subspec.delete('vendored_libraries')
|
253
|
+
subspec.delete('resource_bundles')
|
254
|
+
subspec.delete('resources')
|
255
|
+
subspec.delete('exclude_files')
|
256
|
+
subspec.delete('preserve_paths')
|
257
|
+
if subspec['dependencies']
|
258
|
+
subspec['dependencies']["#{code_spec.root.name}/Binary"] = []
|
259
|
+
else
|
260
|
+
subspec['dependencies'] = {"#{code_spec.root.name}/Binary": []}
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
# "source"字段
|
265
|
+
def binary_source
|
266
|
+
url = "#{CBin.config.binary_download_url_str}/#{code_spec.root.module_name}/#{code_spec.version}/#{code_spec.root.module_name}.framework_#{code_spec.version}.zip"
|
267
|
+
{ http: url, type: CBin.config.download_file_type }
|
268
|
+
end
|
269
|
+
|
270
|
+
def code_spec_consumer(_platform = :ios)
|
271
|
+
code_spec.consumer(:ios)
|
272
|
+
end
|
273
|
+
|
274
|
+
def framework_contents(name)
|
275
|
+
# ["#{code_spec.root.name}.framework", "#{code_spec.root.name}.framework/Versions/A"].map { |path| "#{path}/#{name}" }
|
276
|
+
["#{code_spec.module_name}.framework"]
|
277
|
+
end
|
278
|
+
|
279
|
+
def binary_source_files
|
280
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*"
|
281
|
+
end
|
282
|
+
|
283
|
+
def binary_public_header_files
|
284
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Headers/*.h"
|
285
|
+
end
|
286
|
+
|
287
|
+
def binary_vendored_libraries
|
288
|
+
"bin_#{code_spec.name}_#{code_spec.version}/*.a"
|
289
|
+
end
|
290
|
+
|
291
|
+
def binary_resources
|
292
|
+
"bin_#{code_spec.name}_#{code_spec.version}/Resources/*"
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
#模板框架begin
|
299
|
+
# s.source_files = "bin_#{s.name}_#{s.version}/Headers/*"
|
300
|
+
# s.public_header_files = "bin_#{s.name}_#{s.version}/Headers/*.h"
|
301
|
+
# s.vendored_libraries = "bin_#{s.name}_#{s.version}/*.a"
|
302
|
+
#有图片资源的,要带上
|
303
|
+
#s.resources = 'bin_#{s.name}_#{s.version}/Resources/*.{json,png,jpg,gif,js,xib,eot,svg,ttf,woff,db,sqlite,mp3,bundle}'
|
304
|
+
#模板框架end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# copy from https://github.com/CocoaPods/cocoapods-packager
|
4
|
+
|
5
|
+
require 'cocoapods-mtxx-bin/native/podfile'
|
6
|
+
require 'cocoapods/command/gen'
|
7
|
+
require 'cocoapods/generate'
|
8
|
+
require 'cocoapods-mtxx-bin/helpers/framework_builder'
|
9
|
+
require 'cocoapods-mtxx-bin/helpers/library_builder'
|
10
|
+
require 'cocoapods-mtxx-bin/helpers/sources_helper'
|
11
|
+
require 'cocoapods-mtxx-bin/command/bin/repo/push'
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
module CBin
|
15
|
+
class Upload
|
16
|
+
class Helper
|
17
|
+
include CBin::SourcesHelper
|
18
|
+
|
19
|
+
def initialize(spec,code_dependencies,sources)
|
20
|
+
@spec = spec
|
21
|
+
@code_dependencies = code_dependencies
|
22
|
+
@sources = sources
|
23
|
+
end
|
24
|
+
|
25
|
+
# 创建binary-template.podsepc
|
26
|
+
# 上传二进制文件
|
27
|
+
# 上传二进制 podspec
|
28
|
+
def upload
|
29
|
+
Dir.chdir(CBin::Config::Builder.instance.root_dir) do
|
30
|
+
# 上传zip包
|
31
|
+
res_zip = curl_zip
|
32
|
+
if res_zip
|
33
|
+
# 创建二进制podspec
|
34
|
+
filename = spec_creator
|
35
|
+
# 上传二进制 podspec
|
36
|
+
push_binary_repo(filename)
|
37
|
+
end
|
38
|
+
res_zip
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# 创建二进制podspec
|
43
|
+
def spec_creator
|
44
|
+
spec_creator = CBin::SpecificationSource::Creator.new(@spec)
|
45
|
+
# 创建二进制podspec
|
46
|
+
spec_creator.create
|
47
|
+
# 将二进制podspec写入文件
|
48
|
+
spec_creator.write_spec_file
|
49
|
+
# 返回二进制podspec文件路径
|
50
|
+
spec_creator.filename
|
51
|
+
end
|
52
|
+
|
53
|
+
# 推送二进制
|
54
|
+
# curl http://ci.xxx:9192/frameworks -F "name=IMYFoundation" -F "version=7.7.4.2" -F "annotate=IMYFoundation_7.7.4.2_log" -F "file=@bin_zip/bin_IMYFoundation_7.7.4.2.zip"
|
55
|
+
def curl_zip
|
56
|
+
# output_name = File.join(CBin::Config::Builder.instance.zip_dir, CBin::Config::Builder.instance.framework_name_zip)
|
57
|
+
zip_file = "#{CBin::Config::Builder.instance.library_file(@spec)}.zip"
|
58
|
+
res = File.exist?(zip_file)
|
59
|
+
unless res
|
60
|
+
zip_file = CBin::Config::Builder.instance.framework_zip_file(@spec) + ".zip"
|
61
|
+
res = File.exist?(zip_file)
|
62
|
+
end
|
63
|
+
if res
|
64
|
+
Pod::UI.title "Uploading binary zip file #{@spec.name} (#{@spec.version})" do
|
65
|
+
command = "curl -F \"name=#{@spec.module_name}\" -F \"version=#{@spec.version}\" -F \"file=@#{zip_file}\" #{CBin.config.binary_upload_url_str}"
|
66
|
+
Pod::UI.info "#{command}"
|
67
|
+
json = `#{command}`
|
68
|
+
Pod::UI.info json
|
69
|
+
error_code = JSON.parse(json)["error_code"]
|
70
|
+
if error_code == 0
|
71
|
+
Pod::UI.info "#{@spec.name} (#{@spec.version}) 上传成功".green
|
72
|
+
else
|
73
|
+
Pod::UI.info "#{@spec.name} (#{@spec.version}) 上传失败".red
|
74
|
+
raise Informative, "#{@spec.name} (#{@spec.version}) 上传失败"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
res
|
79
|
+
end
|
80
|
+
|
81
|
+
# 上传二进制 podspec
|
82
|
+
def push_binary_repo(binary_podsepc_json)
|
83
|
+
argvs = [
|
84
|
+
"#{binary_podsepc_json}",
|
85
|
+
"--binary",
|
86
|
+
"--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
|
87
|
+
"--skip-import-validation",
|
88
|
+
"--use-libraries",
|
89
|
+
"--allow-warnings",
|
90
|
+
"--verbose",
|
91
|
+
"--code-dependencies"
|
92
|
+
]
|
93
|
+
if @verbose
|
94
|
+
argvs += ['--verbose']
|
95
|
+
end
|
96
|
+
|
97
|
+
push = Pod::Command::Bin::Repo::Push.new(CLAide::ARGV.new(argvs))
|
98
|
+
push.validate!
|
99
|
+
push.run
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|