cocoapods-framework-tj 0.0.1 → 0.0.3

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.
@@ -0,0 +1,57 @@
1
+ module Pod
2
+ class MutiFrameworker
3
+ include Pod::PodUtil
4
+ include Pod::GitUtil
5
+ include Pod::DirUtil
6
+ include Config::Mixin
7
+ def initialize(name, source, spec_sources, configuration, force, use_modular_headers)
8
+ @name = name
9
+ @source = source
10
+ @spec_sources = spec_sources
11
+ @configuration = configuration
12
+ @force = force
13
+ @use_modular_headers = use_modular_headers
14
+ end
15
+
16
+ def run
17
+ configs = muti_config_with_file @name
18
+ target_dir, work_dir = create_working_directory_by_spec "xcframeworks", @force
19
+ prepare_git_with_configs configs, work_dir
20
+ build_frameworks configs, work_dir, target_dir
21
+ end
22
+
23
+ def build_frameworks configs, work_dir, target_dir
24
+ config.installation_root = Pathname.new work_dir
25
+ config.sandbox_root = "#{work_dir}/Pods"
26
+ sandbox = build_static_sandbox
27
+
28
+ sandbox_installer = installation_root_muti(
29
+ sandbox,
30
+ configs,
31
+ @spec_sources,
32
+ @use_modular_headers
33
+ )
34
+ perform_build(
35
+ sandbox,
36
+ sandbox_installer,
37
+ configs,
38
+ target_dir
39
+ )
40
+ end
41
+
42
+ def perform_build sandbox, installer, configs, target_dir
43
+ sandbox_root = config.sandbox_root.to_s
44
+ builder = Pod::XBuilder.new(
45
+ installer,
46
+ Dir.pwd,
47
+ sandbox_root,
48
+ configs,
49
+ @configuration
50
+ )
51
+ builder.build
52
+ builder.outputs_muti target_dir
53
+ end
54
+
55
+
56
+ end
57
+ end
@@ -0,0 +1,24 @@
1
+ module Pod
2
+ class Cmmd
3
+ class << self
4
+ def sh! command
5
+ UI.puts command
6
+ output = `#{command}`.lines.to_a
7
+ if $?.exitstatus != 0
8
+ Pod::ErrorUtil.error_report command,output
9
+ Process.exit -1
10
+ end
11
+ output
12
+ end
13
+
14
+ def sh? command
15
+ UI.puts command
16
+ output = `#{command}`.lines.to_a
17
+ if $?.exitstatus != 0
18
+ Pod::ErrorUtil.error_report command,output
19
+ end
20
+ output
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,52 @@
1
+ module Pod
2
+ module DirUtil
3
+ def create_target_directory_path_by_spec spec,force
4
+ target_dir = "#{Dir.pwd}/#{spec.name}-#{spec.version}"
5
+
6
+ if File.exist? target_dir
7
+ if @force
8
+ Pathname.new(target_dir).rmtree
9
+ else
10
+ UI.warn "Target directory '#{target_dir}' already exists."
11
+ end
12
+ end
13
+ #/Users/songpanfei/Desktop/PodDemo/module_MessageCenter/code/MessageCenter-0.0.412-MessageCenter-beta.676
14
+ target_dir
15
+ end
16
+
17
+ def create_working_directory_by_spec spec,force
18
+ if spec.is_a? String
19
+ return create_working_directory_by_name spec,force
20
+ end
21
+ target_dir = create_target_directory_path_by_spec spec,force
22
+ # Pathname.new(target_dir).mkdir
23
+ # /var/folders/d5/t7p1sj2d33g_8k82sq3ycfsm0000gn/T/frameworks-ra6jjpmq
24
+ work_dir = Dir.tmpdir + '/frameworks-' + Array.new(8) { rand(36).to_s(36) }.join
25
+
26
+ Pathname.new(work_dir).mkdir
27
+ [target_dir, work_dir]
28
+ end
29
+
30
+ def create_target_directory_path_by_name name, force
31
+ target_dir = "#{Dir.pwd}/#{name}-muti"
32
+
33
+ if File.exist? target_dir
34
+ if @force
35
+ Pathname.new(target_dir).rmtree
36
+ else
37
+ UI.warn "Target directory '#{target_dir}' already exists."
38
+ end
39
+ end
40
+ target_dir
41
+ end
42
+
43
+ def create_working_directory_by_name name, force
44
+ target_dir = create_target_directory_path_by_name name,force
45
+ # Pathname.new(target_dir).mkdir
46
+ work_dir = Dir.tmpdir + '/frameworks-' + Array.new(8) { rand(36).to_s(36) }.join
47
+
48
+ Pathname.new(work_dir).mkdir
49
+ [target_dir, work_dir]
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,13 @@
1
+ module Pod
2
+ module ErrorUtil
3
+ class << self
4
+ def error_report(command, output)
5
+ UI.puts "<<-EOF
6
+ Build command failed: #{command}
7
+ Output:
8
+ #{output.map { |line| " #{line}" }.join}
9
+ EOF"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Pod
2
+ module GitUtil
3
+ def prepare_git_with_configs configs, work_dir
4
+ index = 0
5
+ configs.each do |config|
6
+ name = config["name"]
7
+ git_url = config["git_url"]
8
+ git_branch = config["git_branch"]
9
+ command = "git clone #{git_url} -b #{git_branch} #{work_dir}/#{name}"
10
+ Cmmd.sh! command
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,262 @@
1
+ module Pod
2
+ module PodUtil
3
+ include Config::Mixin
4
+
5
+ def to_native_platform name
6
+ case name
7
+ when 'iphoneos' then 'ios'
8
+ when 'macOS' then 'osx'
9
+ when 'appletvos' then 'tvos'
10
+ when 'watchos' then 'watchos'
11
+ when 'ios' then 'ios'
12
+ when 'macos' then 'osx'
13
+ when 'tvos' then 'tvos'
14
+ else
15
+ name
16
+ end
17
+ end
18
+
19
+ def muti_config_with_file(path)
20
+ return nil if path.nil?
21
+ path = Pathname.new(path)
22
+ path = Pathname.new(Dir.pwd).join(path) unless path.absolute?
23
+ @path = path.expand_path
24
+ content = File.open(path, 'rb').read
25
+ result = JSON.parse content
26
+ if not result.is_a? Array
27
+ UI.error "#{path} format not support"
28
+ exit -1
29
+ end
30
+ result
31
+ end
32
+
33
+ def spec_with_path(path)
34
+ return if path.nil?
35
+ path = Pathname.new(path)
36
+ path = Pathname.new(Dir.pwd).join(path) unless path.absolute?
37
+ return unless path.exist?
38
+ @path = path.expand_path
39
+
40
+ if @path.directory?
41
+ raise @path + ': is a directory.'
42
+ return
43
+ end
44
+
45
+ unless ['.podspec', '.json'].include? @path.extname
46
+ raise @path + ': is not a podspec.'
47
+ return
48
+ end
49
+
50
+ Specification.from_file(@path)
51
+ end
52
+
53
+ def spec_with_name(name)
54
+ return if name.nil?
55
+
56
+ set = Pod::Config.instance.sources_manager.search(Dependency.new(name))
57
+ return nil if set.nil?
58
+
59
+ set.specification.root
60
+ end
61
+
62
+ def build_static_sandbox
63
+ Sandbox.new(config.sandbox_root)
64
+ end
65
+
66
+ def installation_root sandbox, spec, subspecs, sources,use_frameworks = true,use_modular_headers = true, enable_bitcode = false
67
+ podfile = podfile_from_spec(
68
+ @path,
69
+ spec,
70
+ subspecs,
71
+ sources,
72
+ use_frameworks,
73
+ use_modular_headers
74
+ )
75
+
76
+ installer = Installer.new(sandbox, podfile)
77
+
78
+ Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
79
+
80
+ installer.repo_update = true
81
+ installer.install!
82
+
83
+
84
+
85
+
86
+ unless installer.nil?
87
+ installer.pods_project.targets.each do |target|
88
+ target.build_configurations.each do |configuration|
89
+ if enable_bitcode && configuration.name == "Release"
90
+ configuration.build_settings['ENABLE_BITCODE'] = 'YES'
91
+ configuration.build_settings['BITCODE_GENERATION_MODE'] = 'bitcode'
92
+ end
93
+ end
94
+ if target.name == spec.name
95
+ target.build_configurations.each do |configuration|
96
+ configuration.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
97
+ end
98
+ end
99
+ end
100
+ installer.pods_project.save
101
+ end
102
+ installer
103
+ end
104
+
105
+ def installation_root_muti sandbox, configs, sources, use_frameworks = true, use_modular_headers = true, enable_bitcode = false
106
+ podfile = podfile_from_muti_configs(
107
+ configs,
108
+ sources,
109
+ use_frameworks,
110
+ use_modular_headers
111
+ )
112
+ installer = Installer.new(sandbox, podfile)
113
+ installer.repo_update = true
114
+ installer.install!
115
+
116
+ specs = configs.map do |cfg|
117
+ cfg["name"]
118
+ end
119
+ unless installer.nil?
120
+ installer.pods_project.targets.each do |target|
121
+ target.build_configurations.each do |configuration|
122
+ if enable_bitcode && configuration.name == "Release"
123
+ configuration.build_settings['ENABLE_BITCODE'] = 'YES'
124
+ configuration.build_settings['BITCODE_GENERATION_MODE'] = 'bitcode'
125
+ end
126
+ end
127
+ if specs.include? target.name
128
+ target.build_configurations.each do |configuration|
129
+ configuration.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
130
+ end
131
+ end
132
+ end
133
+ installer.pods_project.save
134
+ end
135
+ installer
136
+ end
137
+
138
+ def podfile_from_spec path, spec, subspecs, sources, use_frameworks = true, use_modular_headers=true
139
+ options = Hash.new
140
+ options[:podspec] = path.to_s
141
+ options[:subspecs] = spec.subspecs.map do |sub|
142
+ sub.base_name
143
+ end
144
+ options[:subspecs] = subspecs if subspecs
145
+ # 非常奇怪,如果传一个空的数组过去就会出问题!!
146
+ if options[:subspecs].length == 0
147
+ options[:subspecs] = nil
148
+ end
149
+ static_library_enable = config.static_library_enable?
150
+ Pod::Podfile.new do
151
+ sources.each {|s| source s}
152
+ spec.available_platforms.each do |plt|
153
+ target "#{spec.name}-#{plt.name}" do
154
+ platform(plt.name, spec.deployment_target(plt.name))
155
+ pod(spec.name, options)
156
+ end
157
+ end
158
+
159
+ install!('cocoapods',:integrate_targets => false,:deterministic_uuids => false)
160
+ if static_library_enable
161
+ use_frameworks! :linkage => :static if use_frameworks
162
+ else
163
+ use_frameworks! if use_frameworks
164
+ end
165
+ use_modular_headers! if use_modular_headers
166
+ end
167
+ end
168
+
169
+ def podfile_from_muti_configs configs, sources, use_frameworks = true, use_modular_headers = true
170
+ installation_root = config.installation_root.to_s
171
+ static_library_enable = config.static_library_enable?
172
+ Pod::Podfile.new do
173
+ sources.each {|s| source s}
174
+ configs.each do |cfg|
175
+ pod_spec_path = installation_root + "/#{cfg["name"]}/#{cfg["name"]}.podspec"
176
+ pod_spec_json_path = pod_spec_path + ".json"
177
+ (Pathname.glob(pod_spec_path) + Pathname.glob(pod_spec_json_path)).each do |real_path|
178
+ spec = Pod::Specification.from_file real_path.to_s
179
+ options = Hash.new
180
+ options[:podspec] = real_path.to_s
181
+ if cfg["subspecs"]
182
+ options[:subspecs] = cfg["subspecs"]
183
+ else
184
+ options[:subspecs] = spec.subspecs.map do |sub|
185
+ sub.base_name
186
+ end
187
+ end
188
+ # 非常奇怪,如果传一个空的数组过去就会出问题!!
189
+ if options[:subspecs].length == 0
190
+ options[:subspecs] = nil
191
+ end
192
+ spec.available_platforms.each do |plt|
193
+ target "#{spec.name}-#{plt.name}" do
194
+ puts "#{plt.name} #{spec.name} #{options}"
195
+ platform(plt.name, spec.deployment_target(plt.name))
196
+ pod(spec.name, options)
197
+ end
198
+ end
199
+ end
200
+ end
201
+ install!('cocoapods',
202
+ :integrate_targets => false,
203
+ :deterministic_uuids => false)
204
+
205
+ if static_library_enable
206
+ use_frameworks! :linkage => :static if use_frameworks
207
+ else
208
+ use_frameworks! if use_frameworks
209
+ end
210
+ use_modular_headers! if use_modular_headers
211
+ end
212
+ end
213
+
214
+ def generic_new_podspec_hash spec
215
+ spec_hash = spec.to_hash
216
+ [
217
+ "source_files",
218
+ "resources",
219
+ "resource_bundles",
220
+ "prefix_header_contents",
221
+ "prefix_header_file",
222
+ "header_dir",
223
+ "header_mappings_dir",
224
+ "script_phase",
225
+ "public_header_files",
226
+ "private_header_files",
227
+ "vendored_frameworks",
228
+ "vendored_libraries",
229
+ "exclude_files",
230
+ "preserve_paths",
231
+ "module_map",
232
+ "subspec"
233
+ ].each do |key|
234
+ spec_hash.delete "#{key}"
235
+ end
236
+ spec_hash
237
+ end
238
+
239
+ def fix_header_file spec_hash, xcframework_path
240
+ puts "Dir.glob(#{xcframework_path}/*/) : #{Dir.glob("#{xcframework_path}/*/")}"
241
+ Dir.glob("#{xcframework_path}/*/").each do |file|
242
+ ['ios','macos','tvos', 'watchos'].each do |prefix|
243
+ last_path = file.split("/").last
244
+ if last_path =~ /#{prefix}/ and not last_path =~ /simulator/
245
+ platform = to_native_platform prefix
246
+ if spec_hash[platform]
247
+ spec_hash[platform]["public_header_files"] = "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h"
248
+ spec_hash[platform]["source_files"] = "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h"
249
+ else
250
+ spec_hash[platform] = {
251
+ "public_header_files" => "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h",
252
+ "source_files" => "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h"
253
+ }
254
+ end
255
+ end
256
+ end
257
+ end
258
+ puts spec_hash.to_json
259
+ spec_hash
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,5 @@
1
+ require 'cocoapods-framework/util/error_util'
2
+ require 'cocoapods-framework/util/cmd'
3
+ require 'cocoapods-framework/util/git_util'
4
+ require 'cocoapods-framework/util/pod_util'
5
+ require 'cocoapods-framework/util/dir_util'
@@ -0,0 +1,20 @@
1
+ module Pod
2
+ class XBuilder
3
+ module XcodeXBuilder
4
+ def xcode_xbuild(defines, configuration, work_dir, build_dir = 'export')
5
+ if defined?(Pod::DONT_CODESIGN)
6
+ defines = "#{defines} CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO"
7
+ end
8
+ pwd = Pathname.pwd
9
+ Dir.chdir work_dir
10
+ command = "xcodebuild #{defines} BUILD_DIR=#{build_dir} BUILD_LIBRARY_FOR_DISTRIBUTION=YES clean build -configuration #{configuration} -alltargets 2>&1"
11
+ output = `#{command}`.lines.to_a
12
+ Dir.chdir pwd
13
+ if $?.exitstatus != 0
14
+ Pod::ErrorUtil.error_report command,output
15
+ Process.exit -1
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ require 'xcodeproj'
2
+ module Pod
3
+ class XBuilder
4
+ module XcodeProjHelper
5
+ include PodUtil
6
+ def modify_xcode_project_sdk_to_simullator path
7
+ sdks = xcode_sdks
8
+ project = Xcodeproj::Project.open path
9
+
10
+ project.targets.each do |target|
11
+ simulator_sdk = to_native_simulator_platform target.sdk
12
+ if not simulator_sdk.nil?
13
+ canonicalName = sdks[simulator_sdk]["canonicalName"]
14
+ target.build_configurations.each do |configuration|
15
+ configuration.build_settings["SDKROOT"] = canonicalName
16
+ end
17
+ end
18
+ end
19
+ project.save
20
+ end
21
+
22
+ private
23
+ def xcode_sdks
24
+ return @x_sdks if @x_sdks
25
+ outputs = `xcodebuild -showsdks -json`
26
+ sdks = JSON.parse outputs
27
+ @x_sdks = {}
28
+ sdks.each do |sdk|
29
+ @x_sdks[sdk["platform"]] = sdk
30
+ end
31
+ @x_sdks
32
+ end
33
+
34
+ def to_native_simulator_platform name
35
+ case name
36
+ when 'iphoneos' then 'iphonesimulator'
37
+ when 'macOS' then nil
38
+ when 'appletvos' then 'appletvsimulator'
39
+ when 'watchos' then 'watchsimulator'
40
+ else
41
+ name
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end