cocoapods-framework-tj 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Example/Gemfile +11 -0
- data/Example/Gemfile.lock +331 -0
- data/Example/podfile.package +7 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +13 -0
- data/cocoapods-framework-tj.gemspec +24 -0
- data/lib/cocoapods-framework/command/framework.rb +66 -0
- data/lib/cocoapods-framework/command/muti_framework.rb +61 -0
- data/lib/cocoapods-framework/command.rb +2 -0
- data/lib/cocoapods-framework/config.rb +8 -0
- data/lib/cocoapods-framework/frameworker.rb +68 -0
- data/lib/cocoapods-framework/gem_version.rb +3 -0
- data/lib/cocoapods-framework/muti_frameworker.rb +57 -0
- data/lib/cocoapods-framework/util/cmd.rb +24 -0
- data/lib/cocoapods-framework/util/dir_util.rb +50 -0
- data/lib/cocoapods-framework/util/error_util.rb +13 -0
- data/lib/cocoapods-framework/util/git_util.rb +14 -0
- data/lib/cocoapods-framework/util/pod_util.rb +256 -0
- data/lib/cocoapods-framework/util.rb +5 -0
- data/lib/cocoapods-framework/xbuilder/xcode_xbuild.rb +20 -0
- data/lib/cocoapods-framework/xbuilder/xcodeproj_helper.rb +46 -0
- data/lib/cocoapods-framework/xbuilder.rb +266 -0
- data/lib/cocoapods-framework.rb +1 -0
- data/lib/cocoapods_plugin.rb +10 -0
- data/pkg/cocoapods-framework-tj-0.0.1.gem +0 -0
- data/spec/command/framework_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +31 -2
@@ -0,0 +1,266 @@
|
|
1
|
+
require 'cocoapods-framework/xbuilder/xcode_xbuild'
|
2
|
+
require 'cocoapods-framework/xbuilder/xcodeproj_helper'
|
3
|
+
module Pod
|
4
|
+
class XBuilder
|
5
|
+
include XcodeXBuilder
|
6
|
+
include XcodeProjHelper
|
7
|
+
include PodUtil
|
8
|
+
include Config::Mixin
|
9
|
+
def initialize(installer, source_dir, sandbox_root, spec, configuration)
|
10
|
+
# def initialize(platform, installer, source_dir, sandbox_root, spec, config)
|
11
|
+
# @platform = platform
|
12
|
+
@installer = installer
|
13
|
+
@source_dir = source_dir
|
14
|
+
@sandbox_root = sandbox_root
|
15
|
+
@spec = spec
|
16
|
+
@muti = @spec.is_a? Array
|
17
|
+
@configs = @spec if @muti
|
18
|
+
@spec = "muti" if @muti
|
19
|
+
|
20
|
+
@configuration = configuration
|
21
|
+
@outputs = Hash.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def build
|
25
|
+
UI.puts("Building framework #{@spec} with configuration #{@configuration}")
|
26
|
+
UI.puts "Work dir is :#{@sandbox_root}"
|
27
|
+
# defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) PodsDummy_Pods_#{@spec.name}=PodsDummy_PodPackage_#{@spec.name}'"
|
28
|
+
defines = ""
|
29
|
+
if @configuration == 'Debug'
|
30
|
+
defines << 'GCC_GENERATE_DEBUGGING_SYMBOLS=YES ONLY_ACTIVE_ARCH=NO'
|
31
|
+
else
|
32
|
+
defines << "GCC_GENERATE_DEBUGGING_SYMBOLS=NO"
|
33
|
+
end
|
34
|
+
|
35
|
+
build_all_device defines
|
36
|
+
|
37
|
+
collect_xc_frameworks
|
38
|
+
|
39
|
+
collect_bundles
|
40
|
+
end
|
41
|
+
|
42
|
+
def collect_xc_frameworks
|
43
|
+
if @muti
|
44
|
+
collect_muti_xcframworks
|
45
|
+
else
|
46
|
+
collect_single_xcframeworks
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def collect_muti_xcframworks
|
51
|
+
@outputs[:xcframework] = Hash.new
|
52
|
+
@configs.each do |cfg|
|
53
|
+
export_dir = "#{@sandbox_root}/export/**/#{cfg["name"]}.framework"
|
54
|
+
frameworks = Pathname.glob(export_dir)
|
55
|
+
@outputs[:xcframework][cfg["name"]] = create_xc_framework_by_frameworks frameworks, cfg["name"]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def collect_single_xcframeworks
|
60
|
+
export_dir = "#{@sandbox_root}/export/**/#{@spec.name}.framework"
|
61
|
+
frameworks = Pathname.glob(export_dir)
|
62
|
+
@outputs[:xcframework] = create_xc_framework_by_frameworks frameworks, @spec.name
|
63
|
+
end
|
64
|
+
|
65
|
+
def collect_bundles
|
66
|
+
if @muti
|
67
|
+
colelct_muti_bundles
|
68
|
+
else
|
69
|
+
collect_single_bundles
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def colelct_muti_bundles
|
74
|
+
@outputs[:bundle] = Hash.new
|
75
|
+
@configs.each do |cfg|
|
76
|
+
# "" 这个是用来代表mac os的 macos 没有后缀奇怪吧
|
77
|
+
["iphoneos","","appletvos","watchos"].each do |plat|
|
78
|
+
export_dir = "#{@sandbox_root}/export/*-#{plat}/**/#{cfg["name"]}.bundle/**"
|
79
|
+
Pathname.glob(export_dir).each do |bundle|
|
80
|
+
if bundle.to_s.include? "#{@spec.name}.bundle/Info.plist"
|
81
|
+
return
|
82
|
+
end
|
83
|
+
target_path = "#{@sandbox_root}/bundle/#{cfg["name"]}"
|
84
|
+
@outputs[:bundle][cfg["name"]] = target_path
|
85
|
+
native_platform = to_native_platform plat
|
86
|
+
path = Pathname.new "#{target_path}/#{native_platform}"
|
87
|
+
if not path.exist?
|
88
|
+
path.mkpath
|
89
|
+
end
|
90
|
+
FileUtils.cp_r(Dir["#{bundle}"],"#{path}")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def collect_single_bundles
|
97
|
+
# "" 这个是用来代表mac os的 macos 没有后缀奇怪吧
|
98
|
+
["iphoneos","","appletvos","watchos"].each do |plat|
|
99
|
+
export_dir = "#{@sandbox_root}/export/*-#{plat}/**/#{@spec.name}.bundle/**"
|
100
|
+
Pathname.glob(export_dir).each do |bundle|
|
101
|
+
if bundle.to_s.include? "#{@spec.name}.bundle/Info.plist"
|
102
|
+
return
|
103
|
+
end
|
104
|
+
@outputs[:bundle] = "#{@sandbox_root}/bundle"
|
105
|
+
native_platform = to_native_platform plat
|
106
|
+
path = Pathname.new "#{@sandbox_root}/bundle/#{native_platform}"
|
107
|
+
if not path.exist?
|
108
|
+
path.mkpath
|
109
|
+
end
|
110
|
+
FileUtils.cp_r(Dir["#{bundle}"],"#{path}")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_xc_framework_by_frameworks frameworks, spec_name
|
116
|
+
command = 'xcodebuild -create-xcframework '
|
117
|
+
frameworks.each do |framework|
|
118
|
+
command << "-framework #{framework} "
|
119
|
+
end
|
120
|
+
command << "-output #{@sandbox_root}/#{spec_name}.xcframework 2>&1"
|
121
|
+
output = `#{command}`.lines.to_a
|
122
|
+
if $?.exitstatus != 0
|
123
|
+
Pod::ErrorUtil.error_report command,output
|
124
|
+
Process.exit -1
|
125
|
+
end
|
126
|
+
"#{@sandbox_root}/#{spec_name}.xcframework"
|
127
|
+
end
|
128
|
+
|
129
|
+
def build_all_device defines
|
130
|
+
# build general first because simulator will exchange SDKROOT to simulat sdk
|
131
|
+
build_general_device defines
|
132
|
+
build_simulator_device defines
|
133
|
+
end
|
134
|
+
|
135
|
+
def build_general_device defines
|
136
|
+
UI.puts("--- Building framework #{@spec} with general device")
|
137
|
+
xcode_xbuild(
|
138
|
+
defines,
|
139
|
+
@configuration,
|
140
|
+
@sandbox_root
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
def build_simulator_device defines
|
145
|
+
UI.puts("--- Building framework #{@spec} with simulator device")
|
146
|
+
modify_xcode_project_sdk_to_simullator "#{@sandbox_root}/Pods.xcodeproj"
|
147
|
+
xcode_xbuild(
|
148
|
+
defines,
|
149
|
+
@configuration,
|
150
|
+
@sandbox_root
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
154
|
+
def outputs target_dir
|
155
|
+
if not File.exist? target_dir
|
156
|
+
Pathname.new(target_dir).mkdir
|
157
|
+
end
|
158
|
+
outputs_xcframework target_dir
|
159
|
+
outputs_bundle target_dir
|
160
|
+
new_spec_hash = generic_new_podspec_hash @spec
|
161
|
+
new_spec_hash[:vendored_frameworks] = "#{@spec.name}.xcframework"
|
162
|
+
new_spec_hash = fix_header_file new_spec_hash, "#{target_dir}/#{@spec.name}.xcframework"
|
163
|
+
find_bundles(target_dir).each do |plat, value|
|
164
|
+
if new_spec_hash[plat]
|
165
|
+
new_spec_hash[plat]["resource_bundles"] = value
|
166
|
+
else
|
167
|
+
new_spec_hash[plat] = {
|
168
|
+
"resource_bundles" => value
|
169
|
+
}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
require 'json'
|
173
|
+
spec_json = JSON.pretty_generate(new_spec_hash) << "\n"
|
174
|
+
File.open("#{target_dir}/#{@spec.name}.podspec.json",'wb+') do |f|
|
175
|
+
f.write(spec_json)
|
176
|
+
end
|
177
|
+
UI.puts "result export at :#{target_dir}"
|
178
|
+
target_dir
|
179
|
+
end
|
180
|
+
|
181
|
+
def find_bundles target_dir
|
182
|
+
bundle_root = "#{target_dir}/bundle/"
|
183
|
+
pattern = "#{bundle_root}*"
|
184
|
+
result = {}
|
185
|
+
Pathname.glob(pattern).each do |bundle|
|
186
|
+
bundle_relative_path = bundle.to_s.gsub(bundle_root, "")
|
187
|
+
plat = bundle_relative_path
|
188
|
+
result[plat] = {
|
189
|
+
"#{@spec.name}" => "bundle/" + bundle_relative_path + "/*"
|
190
|
+
}
|
191
|
+
end
|
192
|
+
result
|
193
|
+
end
|
194
|
+
|
195
|
+
def outputs_xcframework target_dir
|
196
|
+
command = "cp -rp #{@outputs[:xcframework]} #{target_dir} 2>&1"
|
197
|
+
output = `#{command}`.lines.to_a
|
198
|
+
if $?.exitstatus != 0
|
199
|
+
Pod::ErrorUtil.error_report command,output
|
200
|
+
Process.exit -1
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def outputs_bundle target_dir
|
205
|
+
if @outputs[:bundle]
|
206
|
+
FileUtils.cp_r(Dir[@outputs[:bundle]],target_dir)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def outputs_muti target_dir
|
211
|
+
if not File.exist? target_dir
|
212
|
+
Pathname.new(target_dir).mkdir
|
213
|
+
end
|
214
|
+
outputs_xcframework_muti target_dir
|
215
|
+
outputs_bundle_muti target_dir
|
216
|
+
generic_new_podspec_hash_muti target_dir
|
217
|
+
end
|
218
|
+
|
219
|
+
def generic_new_podspec_hash_muti target_dir
|
220
|
+
work_dir = config.installation_root
|
221
|
+
@configs.map do |cfg|
|
222
|
+
podspec_path = "#{work_dir}/#{cfg["name"]}/#{cfg["name"]}.podspec"
|
223
|
+
if not File.exist? podspec_path
|
224
|
+
podspec_path = "#{podspec_path}.json"
|
225
|
+
end
|
226
|
+
podspec = Pod::Specification.from_file podspec_path
|
227
|
+
new_spec_hash = generic_new_podspec_hash podspec
|
228
|
+
new_spec_hash[:vendored_frameworks] = "#{podspec.name}.xcframework"
|
229
|
+
new_spec_hash = fix_header_file new_spec_hash, "#{target_dir}/#{@spec.name}.xcframework"
|
230
|
+
find_bundles("#{target_dir}/#{podspec.name}").each do |plat, value|
|
231
|
+
if new_spec_hash[plat]
|
232
|
+
new_spec_hash[plat]["resource_bundles"] = value
|
233
|
+
else
|
234
|
+
new_spec_hash[plat] = {
|
235
|
+
"resource_bundles" => value
|
236
|
+
}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
require 'json'
|
240
|
+
spec_json = JSON.pretty_generate(new_spec_hash) << "\n"
|
241
|
+
File.open("#{target_dir}/#{podspec.name}/#{podspec.name}.podspec.json",'wb+') do |f|
|
242
|
+
f.write(spec_json)
|
243
|
+
end
|
244
|
+
UI.puts "result export at :#{target_dir}/#{podspec.name}"
|
245
|
+
"#{target_dir}/#{podspec.name}"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def outputs_xcframework_muti target_dir
|
250
|
+
@outputs[:xcframework].each do |name, path|
|
251
|
+
target_dir_path = "#{target_dir}/#{name}/"
|
252
|
+
Pathname.new(target_dir_path).mkpath
|
253
|
+
FileUtils.cp_r(path, target_dir_path)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def outputs_bundle_muti target_dir
|
258
|
+
@outputs[:bundle].each do |name, path|
|
259
|
+
target_dir_path = "#{target_dir}/#{name}/bundle/"
|
260
|
+
Pathname.new(target_dir_path).mkpath
|
261
|
+
FileUtils.cp_r(path, target_dir_path)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-framework/gem_version'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'cocoapods'
|
2
|
+
require 'cocoapods-framework/config'
|
3
|
+
require 'cocoapods-framework/util'
|
4
|
+
require 'cocoapods-framework/xbuilder'
|
5
|
+
require 'cocoapods-framework/frameworker'
|
6
|
+
require 'cocoapods-framework/muti_frameworker'
|
7
|
+
|
8
|
+
|
9
|
+
#这个放在最后一个
|
10
|
+
require 'cocoapods-framework/command/framework'
|
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
module Pod
|
4
|
+
describe Command::Framework do
|
5
|
+
describe 'CLAide' do
|
6
|
+
it 'registers it self' do
|
7
|
+
Command.parse(%w{ framework }).should.be.instance_of Command::Framework
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
|
3
|
+
$:.unshift((ROOT + 'lib').to_s)
|
4
|
+
$:.unshift((ROOT + 'spec').to_s)
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'bacon'
|
8
|
+
require 'mocha-on-bacon'
|
9
|
+
require 'pretty_bacon'
|
10
|
+
require 'pathname'
|
11
|
+
require 'cocoapods'
|
12
|
+
|
13
|
+
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
14
|
+
|
15
|
+
require 'cocoapods_plugin'
|
16
|
+
|
17
|
+
#-----------------------------------------------------------------------------#
|
18
|
+
|
19
|
+
module Pod
|
20
|
+
|
21
|
+
# Disable the wrapping so the output is deterministic in the tests.
|
22
|
+
#
|
23
|
+
UI.disable_wrap = true
|
24
|
+
|
25
|
+
# Redirects the messages to an internal store.
|
26
|
+
#
|
27
|
+
module UI
|
28
|
+
@output = ''
|
29
|
+
@warnings = ''
|
30
|
+
|
31
|
+
class << self
|
32
|
+
attr_accessor :output
|
33
|
+
attr_accessor :warnings
|
34
|
+
|
35
|
+
def puts(message = '')
|
36
|
+
@output << "#{message}\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def warn(message = '', actions = [])
|
40
|
+
@warnings << "#{message}\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def print(message)
|
44
|
+
@output << message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#-----------------------------------------------------------------------------#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-framework-tj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- song
|
@@ -65,7 +65,34 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
|
+
- Example/Gemfile
|
69
|
+
- Example/Gemfile.lock
|
70
|
+
- Example/podfile.package
|
71
|
+
- LICENSE.txt
|
68
72
|
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- cocoapods-framework-tj.gemspec
|
75
|
+
- lib/cocoapods-framework.rb
|
76
|
+
- lib/cocoapods-framework/command.rb
|
77
|
+
- lib/cocoapods-framework/command/framework.rb
|
78
|
+
- lib/cocoapods-framework/command/muti_framework.rb
|
79
|
+
- lib/cocoapods-framework/config.rb
|
80
|
+
- lib/cocoapods-framework/frameworker.rb
|
81
|
+
- lib/cocoapods-framework/gem_version.rb
|
82
|
+
- lib/cocoapods-framework/muti_frameworker.rb
|
83
|
+
- lib/cocoapods-framework/util.rb
|
84
|
+
- lib/cocoapods-framework/util/cmd.rb
|
85
|
+
- lib/cocoapods-framework/util/dir_util.rb
|
86
|
+
- lib/cocoapods-framework/util/error_util.rb
|
87
|
+
- lib/cocoapods-framework/util/git_util.rb
|
88
|
+
- lib/cocoapods-framework/util/pod_util.rb
|
89
|
+
- lib/cocoapods-framework/xbuilder.rb
|
90
|
+
- lib/cocoapods-framework/xbuilder/xcode_xbuild.rb
|
91
|
+
- lib/cocoapods-framework/xbuilder/xcodeproj_helper.rb
|
92
|
+
- lib/cocoapods_plugin.rb
|
93
|
+
- pkg/cocoapods-framework-tj-0.0.1.gem
|
94
|
+
- spec/command/framework_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
69
96
|
homepage: https://github.com/songpanfei/cocoapods-framework-tj
|
70
97
|
licenses:
|
71
98
|
- MIT
|
@@ -89,4 +116,6 @@ rubygems_version: 3.3.26
|
|
89
116
|
signing_key:
|
90
117
|
specification_version: 4
|
91
118
|
summary: A short description of cocoapods-framework-tj.
|
92
|
-
test_files:
|
119
|
+
test_files:
|
120
|
+
- spec/command/framework_spec.rb
|
121
|
+
- spec/spec_helper.rb
|