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.
@@ -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,50 @@
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
+ target_dir
14
+ end
15
+
16
+ def create_working_directory_by_spec spec,force
17
+ if spec.is_a? String
18
+ return create_working_directory_by_name spec,force
19
+ end
20
+ target_dir = create_target_directory_path_by_spec spec,force
21
+ # Pathname.new(target_dir).mkdir
22
+ work_dir = Dir.tmpdir + '/frameworks-' + Array.new(8) { rand(36).to_s(36) }.join
23
+
24
+ Pathname.new(work_dir).mkdir
25
+ [target_dir, work_dir]
26
+ end
27
+
28
+ def create_target_directory_path_by_name name, force
29
+ target_dir = "#{Dir.pwd}/#{name}-muti"
30
+
31
+ if File.exist? target_dir
32
+ if @force
33
+ Pathname.new(target_dir).rmtree
34
+ else
35
+ UI.warn "Target directory '#{target_dir}' already exists."
36
+ end
37
+ end
38
+ target_dir
39
+ end
40
+
41
+ def create_working_directory_by_name name, force
42
+ target_dir = create_target_directory_path_by_name name,force
43
+ # Pathname.new(target_dir).mkdir
44
+ work_dir = Dir.tmpdir + '/frameworks-' + Array.new(8) { rand(36).to_s(36) }.join
45
+
46
+ Pathname.new(work_dir).mkdir
47
+ [target_dir, work_dir]
48
+ end
49
+ end
50
+ 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,256 @@
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
+ installer.repo_update = true
78
+ installer.install!
79
+
80
+ unless installer.nil?
81
+ installer.pods_project.targets.each do |target|
82
+ target.build_configurations.each do |configuration|
83
+ if enable_bitcode && configuration.name == "Release"
84
+ configuration.build_settings['ENABLE_BITCODE'] = 'YES'
85
+ configuration.build_settings['BITCODE_GENERATION_MODE'] = 'bitcode'
86
+ end
87
+ end
88
+ if target.name == spec.name
89
+ target.build_configurations.each do |configuration|
90
+ configuration.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
91
+ end
92
+ end
93
+ end
94
+ installer.pods_project.save
95
+ end
96
+ installer
97
+ end
98
+
99
+ def installation_root_muti sandbox, configs, sources, use_frameworks = true, use_modular_headers = true, enable_bitcode = false
100
+ podfile = podfile_from_muti_configs(
101
+ configs,
102
+ sources,
103
+ use_frameworks,
104
+ use_modular_headers
105
+ )
106
+ installer = Installer.new(sandbox, podfile)
107
+ installer.repo_update = true
108
+ installer.install!
109
+
110
+ specs = configs.map do |cfg|
111
+ cfg["name"]
112
+ end
113
+ unless installer.nil?
114
+ installer.pods_project.targets.each do |target|
115
+ target.build_configurations.each do |configuration|
116
+ if enable_bitcode && configuration.name == "Release"
117
+ configuration.build_settings['ENABLE_BITCODE'] = 'YES'
118
+ configuration.build_settings['BITCODE_GENERATION_MODE'] = 'bitcode'
119
+ end
120
+ end
121
+ if specs.include? target.name
122
+ target.build_configurations.each do |configuration|
123
+ configuration.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
124
+ end
125
+ end
126
+ end
127
+ installer.pods_project.save
128
+ end
129
+ installer
130
+ end
131
+
132
+ def podfile_from_spec path, spec, subspecs, sources, use_frameworks = true, use_modular_headers=true
133
+ options = Hash.new
134
+ options[:podspec] = path.to_s
135
+ options[:subspecs] = spec.subspecs.map do |sub|
136
+ sub.base_name
137
+ end
138
+ options[:subspecs] = subspecs if subspecs
139
+ # 非常奇怪,如果传一个空的数组过去就会出问题!!
140
+ if options[:subspecs].length == 0
141
+ options[:subspecs] = nil
142
+ end
143
+ static_library_enable = config.static_library_enable?
144
+ Pod::Podfile.new do
145
+ sources.each {|s| source s}
146
+ spec.available_platforms.each do |plt|
147
+ target "#{spec.name}-#{plt.name}" do
148
+ platform(plt.name, spec.deployment_target(plt.name))
149
+ pod(spec.name, options)
150
+ end
151
+ end
152
+
153
+ install!('cocoapods',:integrate_targets => false,:deterministic_uuids => false)
154
+ if static_library_enable
155
+ use_frameworks! :linkage => :static if use_frameworks
156
+ else
157
+ use_frameworks! if use_frameworks
158
+ end
159
+ use_modular_headers! if use_modular_headers
160
+ end
161
+ end
162
+
163
+ def podfile_from_muti_configs configs, sources, use_frameworks = true, use_modular_headers = true
164
+ installation_root = config.installation_root.to_s
165
+ static_library_enable = config.static_library_enable?
166
+ Pod::Podfile.new do
167
+ sources.each {|s| source s}
168
+ configs.each do |cfg|
169
+ pod_spec_path = installation_root + "/#{cfg["name"]}/#{cfg["name"]}.podspec"
170
+ pod_spec_json_path = pod_spec_path + ".json"
171
+ (Pathname.glob(pod_spec_path) + Pathname.glob(pod_spec_json_path)).each do |real_path|
172
+ spec = Pod::Specification.from_file real_path.to_s
173
+ options = Hash.new
174
+ options[:podspec] = real_path.to_s
175
+ if cfg["subspecs"]
176
+ options[:subspecs] = cfg["subspecs"]
177
+ else
178
+ options[:subspecs] = spec.subspecs.map do |sub|
179
+ sub.base_name
180
+ end
181
+ end
182
+ # 非常奇怪,如果传一个空的数组过去就会出问题!!
183
+ if options[:subspecs].length == 0
184
+ options[:subspecs] = nil
185
+ end
186
+ spec.available_platforms.each do |plt|
187
+ target "#{spec.name}-#{plt.name}" do
188
+ puts "#{plt.name} #{spec.name} #{options}"
189
+ platform(plt.name, spec.deployment_target(plt.name))
190
+ pod(spec.name, options)
191
+ end
192
+ end
193
+ end
194
+ end
195
+ install!('cocoapods',
196
+ :integrate_targets => false,
197
+ :deterministic_uuids => false)
198
+
199
+ if static_library_enable
200
+ use_frameworks! :linkage => :static if use_frameworks
201
+ else
202
+ use_frameworks! if use_frameworks
203
+ end
204
+ use_modular_headers! if use_modular_headers
205
+ end
206
+ end
207
+
208
+ def generic_new_podspec_hash spec
209
+ spec_hash = spec.to_hash
210
+ [
211
+ "source_files",
212
+ "resources",
213
+ "resource_bundles",
214
+ "prefix_header_contents",
215
+ "prefix_header_file",
216
+ "header_dir",
217
+ "header_mappings_dir",
218
+ "script_phase",
219
+ "public_header_files",
220
+ "private_header_files",
221
+ "vendored_frameworks",
222
+ "vendored_libraries",
223
+ "exclude_files",
224
+ "preserve_paths",
225
+ "module_map",
226
+ "subspec"
227
+ ].each do |key|
228
+ spec_hash.delete "#{key}"
229
+ end
230
+ spec_hash
231
+ end
232
+
233
+ def fix_header_file spec_hash, xcframework_path
234
+ puts "Dir.glob(#{xcframework_path}/*/) : #{Dir.glob("#{xcframework_path}/*/")}"
235
+ Dir.glob("#{xcframework_path}/*/").each do |file|
236
+ ['ios','macos','tvos', 'watchos'].each do |prefix|
237
+ last_path = file.split("/").last
238
+ if last_path =~ /#{prefix}/ and not last_path =~ /simulator/
239
+ platform = to_native_platform prefix
240
+ if spec_hash[platform]
241
+ spec_hash[platform]["public_header_files"] = "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h"
242
+ spec_hash[platform]["source_files"] = "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h"
243
+ else
244
+ spec_hash[platform] = {
245
+ "public_header_files" => "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h",
246
+ "source_files" => "#{spec_hash[:vendored_frameworks]}/#{last_path}/*/Headers/*.h"
247
+ }
248
+ end
249
+ end
250
+ end
251
+ end
252
+ puts spec_hash.to_json
253
+ spec_hash
254
+ end
255
+ end
256
+ 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