podfileDep 2.3.6 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b141be5a2d0872d97b87f3afbd0549bf6d65146f66d665432a71f82ec5da405
4
- data.tar.gz: bdd4ee72216e8929dad9c09c0bb79d487b3dfd3805026d44efbad9c2740e633b
3
+ metadata.gz: 8bf6db57ebcfb8e33ea60332704f396c50385bf2985cbc0756a51306f9875fa0
4
+ data.tar.gz: 06b8d0f2e4f832833c41ec97e7f767c557aeff2ad7f990f7fe40b5fe3d88fee0
5
5
  SHA512:
6
- metadata.gz: 8a0e1e6c178434c745cb3aece459458fe770ec2da2ca8e3d4efa742706f6078d5584232a94f6d22bc7d95bb8498e3eac4e97cb738767343f5be50690f89e5997
7
- data.tar.gz: 0d2cdac871d2c5ef04c13e6606bea7498a5b2d1e21662ede1ffb2abf088712d2bd2041e9eedf81a3cbab54d28976432cda1711db25dfddc88338f79ea465627c
6
+ metadata.gz: 2d884c5e32c44f00740e57fbd4fadb0c901b5aede86f3b6f79f4cf739c80ef8550ecbcb8d16877b2047f3aa07e3805c89abc4113c6c4b1ded84b388fe3bec09d
7
+ data.tar.gz: 2320c89b84cad270a46325a80f8909aba737f6fc477ffc19eadc009847357163dab889cbfbdc4d3d0c49ccfb6b4ebeaa6bbc3d93f2bf88c7d2809a247838550a
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## [Released]
2
+ ### [2.4.0] - 2023-7-29
3
+ - 依赖库关系检查
2
4
 
3
5
  ### [2.3.6] - 2023-7-25
4
6
  - 彩色打印
@@ -2,10 +2,12 @@ require 'cocoapods'
2
2
  require_relative 'podfileDep/command/quick'
3
3
  require_relative 'podfileDep/check/project'
4
4
  require_relative 'podfileDep/check/dep'
5
+ require_relative 'podfileDep/check/podspec'
5
6
  require_relative 'podfileDep/modify/modify_code'
6
7
  require_relative 'podfileDep/reference/project'
7
8
  require_relative 'podfileDep/indirect/indirect'
8
9
  require_relative 'podfileDep/reference/unused'
10
+ require_relative 'podfileDep/check/import'
9
11
 
10
12
  # 注册插件
11
13
  module CocoapodsPlugin
@@ -32,7 +34,12 @@ module CocoapodsPlugin
32
34
  project = Xcodeproj::XCodeProject.new
33
35
 
34
36
  # 检查import
35
- project.check_import
37
+ checker1 = Xcodeproj::ImportChecker.new(project)
38
+ checker1.check_import
39
+
40
+ # 检查podspec
41
+ checker2 = Xcodeproj::PodspecChecker.new(project)
42
+ checker2.check_podspec
36
43
 
37
44
  # 代码文件处理
38
45
  ModifyCode::Modify.modify_fb
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
  require 'yaml'
3
3
  require_relative '../podfilelock'
4
- require_relative '../constants'
4
+ require_relative '../my_constants'
5
5
  require_relative 'module'
6
6
  require_relative 'item'
7
7
  require_relative 'xcodeproj'
@@ -176,7 +176,7 @@ module Dep
176
176
 
177
177
  # 系统级的依赖库
178
178
  def self.system_deps
179
- return Constants::LIBLIBARYS + Constants::FRAMEWORKS
179
+ return MyConstants::LIBLIBARYS + MyConstants::FRAMEWORKS
180
180
  end
181
181
 
182
182
  end
@@ -1,159 +1,76 @@
1
- # require 'pathname'
2
- # require 'yaml'
3
- # require_relative '../constants'
4
- # require_relative 'module'
5
- # require_relative 'item'
6
- # require_relative 'xcodeproj'
7
- #
8
- # module Import
9
- # class ImportManager
10
- #
11
- # # 检查import规范
12
- # def self.import_check
13
- # puts "\nimport规范检查中..."
14
- # start = (Time.now.to_f * 1000).to_i
15
- #
16
- # project_manager = XCProject::XcodeprojManager.share_manager
17
- #
18
- # # 获取需要检查的模块名和路径
19
- # modules = project_manager.get_development_module
20
- #
21
- # # 获取Pods和本地依赖库的 组件名和包含的头文件列表 map类型
22
- # module_headers = project_manager.get_installed_headers_module
23
- #
24
- # # 计数
25
- # check_count = 0
26
- #
27
- # # 遍历需要被检查的模块
28
- # modules.each_value { |module_item|
29
- #
30
- # # 某个模块从代码文件里读取的双引号依赖库 #import "XX/XX.h"
31
- # import_item_map = {}
32
- #
33
- # #头文件的文件名
34
- # header_file_names = []
35
- #
36
- # module_item.source_files.each { |source_file|
37
- #
38
- # header_file_name = File.basename(source_file)
39
- # if header_file_name.end_with?(".h") or header_file_name.end_with?(".hpp") or header_file_name.end_with?(".pch")
40
- # header_file_names << header_file_name
41
- # end
42
- #
43
- # self.update_import_dot_item_map(source_file, module_item, import_item_map)
44
- #
45
- # check_count += 1
46
- # }
47
- #
48
- # if import_item_map.size == 0 and header_file_names.size == 0
49
- # next
50
- # end
51
- #
52
- # messages = []
53
- # import_item_map.each {|key, value| #key是 xxx.h value是{ImportItem:}
54
- #
55
- # # 当前仓库的文件已包含
56
- # if header_file_names.include?(key)
57
- # next
58
- # end
59
- #
60
- # # 是否是导入的系统lib
61
- # if self.check_sys_libary(key)
62
- # next
63
- # end
64
- #
65
- # search_module_name = self.get_module_name(module_headers, key)
66
- #
67
- # unless search_module_name
68
- # next
69
- # end
70
- #
71
- # messages << "#{value.file_name} 第#{value.line_index}行 #{value.import_name} => #import <#{search_module_name}/#{value.pod}>"
72
- #
73
- # }
74
- #
75
- # if messages.size >0
76
- # puts "⚠️ 组件#{module_item.module_name}存在以下情况, 请检查:"
77
- # puts messages
78
- # puts "\n"
79
- # end
80
- #
81
- # }
82
- #
83
- # duration = ((Time.now.to_f * 1000).to_i - start)*0.001
84
- # puts "import规范检查完毕! 共检查#{modules.size.to_s}个组件(#{check_count}个文件) 耗时:#{duration.round(2)}秒"
85
- # end
86
- #
87
- # # 获取某个文件内对应类型的import "XXX.h"
88
- # def self.update_import_dot_item_map(file_path, module_name, import_item_map)
89
- # if File.directory?(file_path)
90
- # return
91
- # end
92
- #
93
- # line_array = IO.readlines(file_path)
94
- # line_array.each_with_index { |line, index|
95
- # line = line.gsub(" ", "")
96
- # unless line.start_with?("#import\"")
97
- # next
98
- # end
99
- #
100
- # if line.start_with?("@implementation")
101
- # break
102
- # end
103
- #
104
- # line_split_array = line.split("\"")
105
- # if line_split_array.size <= 1
106
- # next
107
- # end
108
- #
109
- # import_name = "#{line_split_array[0]}\"#{line_split_array[1]}\"" # import"XXX.h" 或import"XXX.AAA.h" 防止后边有其他内容
110
- #
111
- # # 特殊处理
112
- # if import_name == "#import\"NBSAppAgent.h\""
113
- # next
114
- # end
115
- #
116
- # podfile = import_name
117
- # podfile = podfile.gsub("#import\"", "")
118
- # podfile = podfile.gsub("\"", "") # 变成 XX.h
119
- #
120
- # # 已经包含
121
- # if import_item_map[podfile]
122
- # next
123
- # end
124
- # pre_index = index-1 < 0 ? 0 : index-1
125
- # pre_line = line_array[pre_index]
126
- # pre_line = pre_line.gsub(" ", "").gsub("\n", "")
127
- # if pre_line.start_with?("#if") or pre_line == "#else"
128
- # next
129
- # end
130
- #
131
- # file_name = File.basename(file_path)
132
- # line_index = index+1
133
- #
134
- # import_item_map[podfile] = ImportItem.new(import_name, module_name, file_name, line_index, podfile)
135
- #
136
- # }
137
- # end
138
- #
139
- # # 根据文件名反查出属于哪个组件
140
- # def self.get_module_name(module_headers, file_name)
141
- # module_headers.each do |module_name,module_item|
142
- # module_item.source_files.each {|source_file|
143
- # if source_file.basename.to_s == file_name
144
- # return module_name
145
- # end
146
- # }
147
- # end
148
- # return nil
149
- # end
150
- #
151
- # # 获取某库是否是系统级的依赖库
152
- # def self.check_sys_libary(name)
153
- # name = name.gsub(".h", "")
154
- # libs = Constants::LIBLIBARYS
155
- # return libs.include?(name)
156
- # end
157
- #
158
- # end
159
- # end
1
+ require_relative 'project'
2
+
3
+ module Xcodeproj
4
+ class ImportChecker
5
+
6
+ # @return [XCodeProject]
7
+ attr_accessor :project
8
+
9
+ # @param project::[XCodeProject]
10
+ def initialize(project)
11
+ @project = project
12
+ end
13
+
14
+ # 检查import规范
15
+ def check_import
16
+ puts "import检查中..."
17
+ start = (Time.now.to_f * 1000).to_i
18
+ module_count = 0
19
+ file_count = 0
20
+
21
+ project.module_items.each do |module_name, module_item|
22
+ unless module_item.is_development_module
23
+ next
24
+ end
25
+ module_count += 1
26
+
27
+ messages = []
28
+
29
+ did_check_imports = {}
30
+ module_item.init_import_info
31
+
32
+ module_item.import_items.each do |import_item|
33
+ file_count += 1
34
+ did_check_import = did_check_imports[import_item.import_file_name]
35
+ if did_check_import
36
+ next
37
+ end
38
+ need_module_item = project.module_items[import_item.module_name]
39
+ real_path = need_module_item.header_files[import_item.import_file_name]
40
+ did_check_imports[import_item.import_file_name] = !!(real_path)
41
+ unless real_path
42
+ # 去查找所属模块
43
+ expect_module_name = find_module_with_header_file(import_item.import_file_name)
44
+ if expect_module_name
45
+ messages << "#{import_item.file_path.basename} 第#{import_item.line_index}行 #{import_item.import_name} => #import <#{expect_module_name}/#{import_item.import_file_name}>"
46
+ end
47
+ end
48
+ end
49
+
50
+ if messages.size >0
51
+ puts "组件#{module_item.module_name}存在以下情况, 请检查:".yellow
52
+ puts messages
53
+ puts "\n"
54
+ end
55
+
56
+ end
57
+
58
+ duration = ((Time.now.to_f * 1000).to_i - start)*0.001
59
+ puts "import检查完毕! 共检查#{module_count}个组件(#{file_count}个import) 耗时:#{duration.round(2)}秒"
60
+ end
61
+
62
+ private
63
+ # 根据头文件名查找所属组件
64
+ # @return [String, nil]
65
+ def find_module_with_header_file(header_file_name)
66
+ project.module_items.each do |module_name, module_item|
67
+ file_path = module_item.header_files[header_file_name]
68
+ if file_path
69
+ return module_item.module_name
70
+ end
71
+ end
72
+ nil
73
+ end
74
+
75
+ end
76
+ end
@@ -2,7 +2,7 @@ require 'pathname'
2
2
  require 'yaml'
3
3
  require 'cocoapods'
4
4
  require 'xcodeproj'
5
- require_relative '../constants'
5
+ require_relative '../my_constants'
6
6
 
7
7
  module ModuleModule
8
8
 
@@ -0,0 +1,163 @@
1
+ require_relative 'project'
2
+ require_relative 'util'
3
+ require_relative '../my_constants'
4
+
5
+ module Xcodeproj
6
+ class PodspecChecker
7
+
8
+ # @return [XCodeProject]
9
+ attr_accessor :project
10
+
11
+ # @param project::[XCodeProject]
12
+ def initialize(project)
13
+ @project = project
14
+ end
15
+
16
+ # 检查podspec文件
17
+ def check_podspec
18
+ puts "podspec文件检查中..."
19
+ start = (Time.now.to_f * 1000).to_i
20
+ module_count = 0
21
+
22
+ project.module_items.each do |module_name, module_item|
23
+ unless module_item.is_development_module
24
+ next
25
+ end
26
+ module_count += 1
27
+
28
+ module_item.init_absolute_import_info
29
+
30
+ # 代码里需要的模块
31
+ need_modules = get_code_need_modules(module_item)
32
+
33
+ # podspec直接依赖
34
+ podspec_modules = get_podspec_modules(module_item)
35
+
36
+ loss = loss_modules(need_modules, podspec_modules)
37
+ unused = unused_modules(need_modules, podspec_modules)
38
+
39
+ if loss.size >0
40
+ puts "组件#{module_item.module_name}可能缺少以下依赖, 请检查:".yellow
41
+ loss.each do |name|
42
+ puts " s.dependency '#{name}'"
43
+ end
44
+ end
45
+
46
+ if unused.size >0
47
+ puts "组件#{module_item.module_name}可能未使用以下依赖, 请检查:".yellow
48
+ puts unused
49
+ end
50
+
51
+ end
52
+
53
+ duration = ((Time.now.to_f * 1000).to_i - start)*0.001
54
+ puts "podspec检查完毕! 共检查#{module_count}个组件 耗时:#{duration.round(2)}秒"
55
+ end
56
+
57
+ private
58
+
59
+ # 获取缺失的模块
60
+ # @param need_modules::[String]
61
+ # @param podspec_modules::[Hash{String => [String]}]
62
+ def loss_modules(need_modules, podspec_modules)
63
+ # 展开
64
+ temp_array = []
65
+ podspec_modules.each do |podspec_module|
66
+ podspec_modules.values.each do |array|
67
+ temp_array = temp_array | array
68
+ end
69
+ end
70
+
71
+ res = []
72
+ need_modules.each do |name|
73
+ unless temp_array.include?(name)
74
+ res << name
75
+ end
76
+ end
77
+ res
78
+ end
79
+
80
+ # 获取多余的模块
81
+ # @param need_modules::[String]
82
+ # @param podspec_modules::[Hash{String => [String]}]
83
+ def unused_modules(need_modules, podspec_modules)
84
+ res = []
85
+ podspec_modules.each do |dep_name, array|
86
+ contain = false
87
+ array.each do |vendor|
88
+ if need_modules.include?(vendor)
89
+ contain = true
90
+ end
91
+ end
92
+
93
+ unless contain
94
+ res << dep_name
95
+ end
96
+ end
97
+ res
98
+ end
99
+
100
+ # @note 获取代码里需要的模块
101
+ def get_code_need_modules(module_item)
102
+ import_items = module_item.absolute_import_items
103
+ result_dic = {}
104
+ import_items.each do |import_item|
105
+ # 过滤系统库
106
+ if system_modules.include?(import_item.belong_module)
107
+ next
108
+ end
109
+
110
+ # 过滤当前库
111
+ if module_item.module_name == import_item.belong_module
112
+ next
113
+ end
114
+
115
+ result_dic[import_item.belong_module] = import_item
116
+ end
117
+ result_dic.keys
118
+ end
119
+
120
+ # 获取podspec文件里写的模块 直接依赖
121
+ # @return [Hash{String => [String]}]
122
+ def get_podspec_modules(module_item)
123
+
124
+ podspec_content = Util.get_podspec_content(module_item.podspec_path)
125
+
126
+ podspec_dependencies = podspec_content["dependencies"] ? podspec_content["dependencies"].keys : []
127
+
128
+ # 子模块
129
+ subspecs = podspec_content["subspecs"]
130
+ if subspecs and subspecs.class == Array
131
+ subspecs.each do |subspec|
132
+ subspec_deps = subspec["dependencies"] ? subspec["dependencies"].keys : []
133
+ podspec_dependencies = podspec_dependencies + subspec_deps
134
+ end
135
+ end
136
+
137
+ # 转成map
138
+ result = {}
139
+ podspec_dependencies.each do |podspec_dependency|
140
+ podspec_dependency = podspec_dependency.split("/")[0] #如果podspec里写的依赖是带/的,取/前第一个, 例如:s.dependency 'UMCShare/Social/ReducedQQ'
141
+ dependency_item = project.module_items[podspec_dependency]
142
+ if dependency_item
143
+ result[podspec_dependency] = dependency_item.frameworks
144
+ else #如果/都处理了,还是取不到,那就整个默认值,自身
145
+ frameworks = [podspec_dependency]
146
+ if podspec_dependency.include?("/") #处理依赖 s.dependency 'UMCShare/Social/ReducedQQ'
147
+ frameworks << podspec_dependency.split("/")[0]
148
+ end
149
+ result[podspec_dependency] = frameworks
150
+ end
151
+ end
152
+
153
+ result
154
+ end
155
+
156
+
157
+ # 系统级的依赖库
158
+ # @return [String]
159
+ def system_modules
160
+ MyConstants::LIBLIBARYS + MyConstants::FRAMEWORKS
161
+ end
162
+ end
163
+ end
@@ -1,5 +1,6 @@
1
1
  require 'pathname'
2
2
  require 'colored2'
3
+ require_relative 'util'
3
4
 
4
5
  module Xcodeproj
5
6
 
@@ -9,12 +10,14 @@ module Xcodeproj
9
10
  attr_accessor :file_path
10
11
  attr_accessor :import_file_name
11
12
  attr_accessor :line_index
13
+ attr_accessor :belong_module
12
14
  def initialize
13
15
  @import_name = nil
14
16
  @module_name = nil
15
17
  @file_path = nil
16
18
  @import_file_name = nil
17
19
  @line_index = nil
20
+ @belong_module = nil
18
21
  end
19
22
 
20
23
  end
@@ -38,11 +41,17 @@ module Xcodeproj
38
41
  attr_accessor :source_files
39
42
 
40
43
  # 是否是开发模块
41
- attr_reader :is_development_module
44
+ attr_accessor :is_development_module
42
45
 
43
- # [Hash{String => ImportItem}]
46
+ # [ImportItem]
44
47
  attr_accessor :import_items
45
48
 
49
+ # [ImportItem]
50
+ attr_accessor :absolute_import_items
51
+
52
+ # [String]
53
+ attr_accessor :frameworks
54
+
46
55
  def initialize(module_name)
47
56
  @module_name = module_name
48
57
  @module_path = nil
@@ -50,12 +59,47 @@ module Xcodeproj
50
59
  @header_files = {}
51
60
  @source_files = {}
52
61
  @import_items = []
62
+ @absolute_import_items = []
63
+ @is_development_module = false
64
+ @frameworks = []
53
65
  end
54
66
 
55
- # 是否是开发模块
56
- # @return bool
57
- def is_development_module
58
- !!(podspec_path)
67
+ # 生成 import <XX/YY.h>的信息
68
+ # 生成 include <XX/YY.h>的信息
69
+ def init_absolute_import_info
70
+ source_files.each_value do |source_file_path|
71
+ if File.directory?(source_file_path)
72
+ next
73
+ end
74
+
75
+ line_array = IO.readlines(source_file_path)
76
+ line_array.each_with_index { |line, line_index|
77
+ line = line.gsub(" ", "")
78
+
79
+ # 处理特殊情况
80
+ if line.start_with?("#import\"NBSAppAgent.h\"")
81
+ line = "#import<tingyunApp/NBSAppAgent.h>"
82
+ end
83
+
84
+ if not line.start_with?("#import<") and not line.start_with?("#include<")
85
+ next
86
+ end
87
+
88
+ if line.start_with?("@implementation")
89
+ break
90
+ end
91
+
92
+ # 前一行的内容 这里不是检测,则不需要
93
+ pre_line = ""
94
+
95
+ import_item = other_module_import(line, source_file_path, line_index, @module_name, pre_line)
96
+ if import_item
97
+ absolute_import_items << import_item
98
+ end
99
+ }
100
+ end
101
+
102
+ absolute_import_items
59
103
  end
60
104
 
61
105
  # 生成 import "XXX.h"的信息
@@ -133,7 +177,31 @@ module Xcodeproj
133
177
  end
134
178
 
135
179
 
136
- def other_module_import(line)
180
+ def other_module_import(line, file_path, line_index, module_name, pre_line)
181
+ line = line.gsub("\n","")
182
+ line_split_array = line.split("/") #import<XX/YY.h> 或 #import<XX/YY/ZZ.h>
183
+ if line_split_array.size <= 1
184
+ return nil
185
+ end
186
+
187
+ pre_line = pre_line.gsub(" ", "").gsub("\n", "")
188
+ if pre_line.start_with?("#if") or pre_line == "#else"
189
+ return nil
190
+ end
191
+
192
+ import_file_name = line_split_array[line_split_array.size-1].gsub(">", "")
193
+ belong_module = line_split_array[0].gsub("#import<", "").gsub("#include<", "")
194
+ import_name = line.gsub("#import<", "#import <").gsub("#include<", "#include <")
195
+
196
+ import_item = ImportItem.new # (import_name, module_name, file_name, line_index, podfile)
197
+ import_item.import_name = import_name
198
+ import_item.module_name = module_name
199
+ import_item.file_path = file_path
200
+ import_item.import_file_name = import_file_name
201
+ import_item.line_index = line_index + 1
202
+ import_item.belong_module = belong_module
203
+
204
+ import_item
137
205
 
138
206
  end
139
207
  end
@@ -151,6 +219,8 @@ module Xcodeproj
151
219
  # @return [Hash{String => ModuleItem}]
152
220
  attr_accessor :module_items
153
221
 
222
+ # @return [Hash]
223
+ attr_accessor :lock_content
154
224
 
155
225
  def initialize
156
226
  @shell_project = nil
@@ -158,9 +228,12 @@ module Xcodeproj
158
228
  @module_items = {}
159
229
  init_shell_project
160
230
  init_pod_project
231
+ init_lockfile
161
232
  expand_module
233
+ init_vendor_frameworks
162
234
  end
163
235
 
236
+ @private
164
237
  def init_shell_project
165
238
  xcodeproj_file = nil
166
239
  Dir.foreach(Dir.pwd) do |file|
@@ -187,6 +260,16 @@ module Xcodeproj
187
260
  @pod_project = Xcodeproj::Project.open(xcodeproj_path)
188
261
  end
189
262
 
263
+ def init_lockfile
264
+ lockfile_path = MyConstants::PODFILE_LOCK
265
+
266
+ unless File.exist?(lockfile_path)
267
+ return
268
+ end
269
+
270
+ @lock_content = YAML.load_file(lockfile_path)
271
+ end
272
+
190
273
  # 展开模块
191
274
  def expand_module
192
275
  self.expand_with_module(pod_project.main_group, nil)
@@ -208,6 +291,7 @@ module Xcodeproj
208
291
  source_file_item = @module_items[module_name]
209
292
  if module_name and not source_file_item
210
293
  source_file_item = ModuleItem.new(module_name)
294
+ source_file_item.podspec_path = get_podspec_path(module_name)
211
295
  @module_items[module_name] = source_file_item
212
296
  end
213
297
 
@@ -251,6 +335,7 @@ module Xcodeproj
251
335
  extend_name = child.real_path.basename.extname
252
336
  if extend_name == ".podspec" or extend_name == ".podspec.json"
253
337
  source_file_item.podspec_path = child.real_path
338
+ source_file_item.is_development_module = true
254
339
  elsif source_file_extension.include?(extend_name)
255
340
  source_file_item.source_files[child.real_path.basename.to_s] = child.real_path
256
341
  if header_file_extension.include?(extend_name)
@@ -267,65 +352,94 @@ module Xcodeproj
267
352
 
268
353
  end
269
354
 
270
- # 检查import规范
271
- def check_import
272
- puts "import检查中..."
273
- start = (Time.now.to_f * 1000).to_i
274
- module_count = 0
275
- file_count = 0
355
+ # 读取某个模块的podspec路径
356
+ def get_podspec_path(module_name)
357
+ lock_content = @lock_content
358
+ local_spec = lock_content["EXTERNAL SOURCES"]
359
+ if local_spec and local_spec[module_name]
360
+ path = local_spec[module_name][:path]
361
+ return Pathname(path).expand_path
362
+ end
276
363
 
277
- module_items.each do |module_name, module_item|
278
- unless module_item.is_development_module
279
- next
280
- end
281
- module_count += 1
364
+ remote_dependencies = lock_content["DEPENDENCIES"]
365
+ version_map = {}
366
+ remote_dependencies.each do |dependency|
367
+ temp = dependency.split("(")
368
+ name = temp[0].split("/")[0] # UMCShare/Social/ReducedWeChat
369
+ name = name.gsub(" ", "").gsub(")", "")
370
+ version = temp[1].gsub("= ", "").gsub(")", "")
371
+ version_map[name] = version
372
+ end
373
+ version = version_map[module_name]
374
+
375
+ remote_spec = lock_content["SPEC CHECKSUMS"]
376
+ md5_to5 = ""
377
+ if remote_spec and remote_spec[module_name]
378
+ md5 = remote_spec[module_name]
379
+ md5_to5 = md5.slice(0,5)
380
+ end
381
+ # 4.0.1-24ee2.podspec.json
382
+ podspec_json_name = "#{version}-#{md5_to5}.podspec.json"
383
+ path = "~/Library/Caches/CocoaPods/Pods/Specs/Release/#{module_name}/#{podspec_json_name}"
384
+ Pathname(path).expand_path
385
+ end
282
386
 
283
- messages = []
284
387
 
285
- did_check_imports = {}
286
- module_item.init_import_info
388
+ # 初始化模块的vendor_frameworks
389
+ def init_vendor_frameworks
390
+ @module_items.each_value do |module_item|
391
+ module_item.frameworks << module_item.module_name
392
+ podspec_content = Util.get_podspec_content(module_item.podspec_path)
287
393
 
288
- module_item.import_items.each do |import_item|
289
- file_count += 1
290
- did_check_import = did_check_imports[import_item.import_file_name]
291
- if did_check_import
292
- next
293
- end
294
- need_module_item = module_items[import_item.module_name]
295
- real_path = need_module_item.header_files[import_item.import_file_name]
296
- did_check_imports[import_item.import_file_name] = !!(real_path)
297
- unless real_path
298
- # 去查找所属模块
299
- expect_module_name = find_module_with_header_file(import_item.import_file_name)
300
- if expect_module_name
301
- messages << "#{import_item.file_path.basename} 第#{import_item.line_index}行 #{import_item.import_name} => #import <#{expect_module_name}/#{import_item.import_file_name}>"
302
- end
303
- end
394
+ unless podspec_content
395
+ next
304
396
  end
305
397
 
306
- if messages.size >0
307
- puts "组件#{module_item.module_name}存在以下情况, 请检查:".yellow
308
- puts messages
309
- puts "\n"
310
- end
398
+ update_dep_frameworks(module_item.frameworks, podspec_content)
311
399
 
400
+ subspec_content = podspec_content["subspecs"]
401
+ if subspec_content and subspec_content.class == Array
402
+ subspec_content.each { |json_content|
403
+ update_dep_frameworks(module_item.frameworks, json_content)
404
+ }
405
+ end
312
406
  end
313
407
 
314
- duration = ((Time.now.to_f * 1000).to_i - start)*0.001
315
- puts "import检查完毕! 共检查#{module_count}个组件(#{file_count}个import) 耗时:#{duration.round(2)}秒"
316
408
  end
317
409
 
318
- private
319
- # 根据头文件名查找所属组件
320
- # @return [String, nil]
321
- def find_module_with_header_file(header_file_name)
322
- module_items.each do |module_name, module_item|
323
- file_path = module_item.header_files[header_file_name]
324
- if file_path
325
- return module_item.module_name
410
+ def update_dep_frameworks(item_frameworks, json_content)
411
+ vendor_frameworks = json_content["vendored_frameworks"]
412
+ unless vendor_frameworks
413
+ ios = json_content["ios"]
414
+ if ios and ios.class == Hash
415
+ vendor_frameworks = ios["vendored_frameworks"]
326
416
  end
327
417
  end
328
- nil
418
+
419
+ if vendor_frameworks
420
+ if vendor_frameworks.class == Array
421
+ vendor_frameworks.each do |framework|
422
+ frameworks = deal_frameworks(vendor_frameworks)
423
+ if frameworks != "*"
424
+ item_frameworks << frameworks
425
+ end
426
+ end
427
+ elsif vendor_frameworks.class == String
428
+ frameworks = deal_frameworks(vendor_frameworks)
429
+ if frameworks != "*"
430
+ item_frameworks << frameworks
431
+ end
432
+ end
433
+ end
434
+ end
435
+
436
+ def deal_frameworks(frameworks)
437
+ # "frameworks/WCDB/WCDB.framework",
438
+ # "openssl.xcframework"
439
+ temp_array = frameworks.split("/")
440
+ result = temp_array.last
441
+ result = result.gsub(".xcframework","")
442
+ result.gsub(".framework", "")
329
443
  end
330
444
 
331
445
  end
@@ -0,0 +1,38 @@
1
+ module Xcodeproj
2
+ class Util
3
+ #读取podspec内容
4
+ # @return [Hash]
5
+ # @param podspec_path::[Pathname]
6
+ def self.get_podspec_content(podspec_path)
7
+
8
+ podspec_json_path = podspec_path.to_s.end_with?(".podspec.json") ? podspec_path : nil
9
+
10
+ podspec_content = nil
11
+ if podspec_json_path and File.exist?(podspec_json_path)
12
+ json = File.read(podspec_json_path)
13
+ podspec_content = JSON.parse(json)
14
+ elsif podspec_path and File.exist?(podspec_path)
15
+ json = get_podspec_file_content(podspec_path)
16
+ podspec_content = JSON.parse(json)
17
+ end
18
+ podspec_content
19
+ end
20
+
21
+ @private
22
+ # 根据podspec路径把podspec转为json
23
+ def self.get_podspec_file_content(podspec_path)
24
+
25
+ spec_contents = File.open(podspec_path, 'r:utf-8', &:read)
26
+
27
+ if spec_contents.respond_to?(:encoding) && spec_contents.encoding.name != 'UTF-8'
28
+ spec_contents.encode!('UTF-8')
29
+ end
30
+
31
+ path = Pathname.new(podspec_path)
32
+
33
+ spec = ::Pod._eval_podspec(spec_contents, path)
34
+
35
+ spec.to_json
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- module Constants
2
+ module MyConstants
3
3
 
4
4
  PODFILE_LOCAL_YAML = 'PodfileLocal.yaml'
5
5
  PODFILE_MODULE_YAML = 'PodfileModule.yaml'
@@ -1,11 +1,11 @@
1
- require_relative 'constants'
1
+ require_relative 'my_constants'
2
2
  require 'yaml'
3
3
 
4
4
  module PodfileLock
5
5
  class PodfileLockManager
6
6
  # 读取podfile.lock
7
7
  def self.podfile_lock_content
8
- podfile_lock = Constants::PODFILE_LOCK
8
+ podfile_lock = MyConstants::PODFILE_LOCK
9
9
 
10
10
  unless File.exist?(podfile_lock)
11
11
  return {}
@@ -1,5 +1,5 @@
1
1
  require_relative '../check/xcodeproj'
2
- require_relative '../constants'
2
+ require_relative '../my_constants'
3
3
 
4
4
  module Project
5
5
  class ProjectManager
@@ -27,16 +27,16 @@ module Project
27
27
  content += line
28
28
  next_line = index<line_array.size ? line_array[index+1] : ""
29
29
  if line.include?("if [[ \"$CONFIGURATION\"") and next_line.include?("install_resource")
30
- if File.exist?(Constants::PODFILE_LOCAL_YAML)
31
- content += " install_resource \"${SRCROOT}/#{Constants::PODFILE_LOCAL_YAML}\"\n"
30
+ if File.exist?(MyConstants::PODFILE_LOCAL_YAML)
31
+ content += " install_resource \"${SRCROOT}/#{MyConstants::PODFILE_LOCAL_YAML}\"\n"
32
32
  end
33
33
 
34
- if File.exist?(Constants::PODFILE_MODULE_YAML)
35
- content += " install_resource \"${SRCROOT}/#{Constants::PODFILE_MODULE_YAML}\"\n"
34
+ if File.exist?(MyConstants::PODFILE_MODULE_YAML)
35
+ content += " install_resource \"${SRCROOT}/#{MyConstants::PODFILE_MODULE_YAML}\"\n"
36
36
  end
37
37
 
38
- if File.exist?(Constants::PODFILE_THIRD_PARTY_YAML)
39
- content += " install_resource \"${SRCROOT}/#{Constants::PODFILE_THIRD_PARTY_YAML}\"\n"
38
+ if File.exist?(MyConstants::PODFILE_THIRD_PARTY_YAML)
39
+ content += " install_resource \"${SRCROOT}/#{MyConstants::PODFILE_THIRD_PARTY_YAML}\"\n"
40
40
  end
41
41
  end
42
42
  }
@@ -57,9 +57,9 @@ module Project
57
57
 
58
58
  def self.add_yaml
59
59
 
60
- podfile_local_yaml = Constants::PODFILE_LOCAL_YAML
61
- podfile_module_yaml = Constants::PODFILE_MODULE_YAML
62
- podfile_third_party_yaml = Constants::PODFILE_THIRD_PARTY_YAML
60
+ podfile_local_yaml = MyConstants::PODFILE_LOCAL_YAML
61
+ podfile_module_yaml = MyConstants::PODFILE_MODULE_YAML
62
+ podfile_third_party_yaml = MyConstants::PODFILE_THIRD_PARTY_YAML
63
63
 
64
64
  project_manager = XCProject::XcodeprojManager.share_manager
65
65
  pods_project = project_manager.get_pods_project
@@ -93,7 +93,7 @@ module Project
93
93
  def self.add_local_yaml_ignore
94
94
 
95
95
  gitignore = ".gitignore"
96
- podfile_local_yaml = Constants::PODFILE_LOCAL_YAML
96
+ podfile_local_yaml = MyConstants::PODFILE_LOCAL_YAML
97
97
 
98
98
  contain = false
99
99
  gitignore_path= "#{Dir.pwd}/#{gitignore}"
@@ -1,5 +1,5 @@
1
1
  require 'colored2'
2
- require_relative '../constants'
2
+ require_relative '../my_constants'
3
3
  require_relative '../yaml/yaml_dep'
4
4
 
5
5
  module Unused
@@ -12,11 +12,11 @@ module Unused
12
12
 
13
13
  if yaml_dep.quick_build
14
14
  msg = "🔰已开启编译优化选项,请关注上方日志 '下载依赖...'部分内容"
15
- msg += "\n #{Constants::PODFILE_LOCAL_YAML}文件内的依赖库,将不会被优化忽略掉"
15
+ msg += "\n #{MyConstants::PODFILE_LOCAL_YAML}文件内的依赖库,将不会被优化忽略掉"
16
16
  puts msg.green
17
17
  else
18
18
  msg = "检测到你未开启编译优化选项,如你处于开发模式,可开启此功能,移除不被引用的依赖库来加速编译,有2种方式任选其一"
19
- msg += "\n1. 在#{Constants::PODFILE_LOCAL_YAML}中 最外层 QUICK_BUILD字段设置为true,然后重新pod install"
19
+ msg += "\n1. 在#{MyConstants::PODFILE_LOCAL_YAML}中 最外层 QUICK_BUILD字段设置为true,然后重新pod install"
20
20
  msg += "\n2. 执行 pod install quick 可单次开启"
21
21
  puts msg.yellow
22
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PodfileDep
4
- VERSION = "2.3.6"
4
+ VERSION = "2.4.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  require_relative 'yaml_pod'
2
2
  require_relative '../version'
3
- require_relative '../constants'
3
+ require_relative '../my_constants'
4
4
  require_relative '../check/xcodeproj'
5
5
  require_relative '../variable'
6
6
  require 'colored2'
@@ -34,9 +34,9 @@ module Pod
34
34
  @yaml_deps = {}
35
35
  @all_deps = {}
36
36
  @targets_dependencies = {}
37
- @podfile_local_yaml = Constants::PODFILE_LOCAL_YAML
38
- @podfile_module_yaml = Constants::PODFILE_MODULE_YAML
39
- @podfile_third_party_yaml = Constants::PODFILE_THIRD_PARTY_YAML
37
+ @podfile_local_yaml = MyConstants::PODFILE_LOCAL_YAML
38
+ @podfile_module_yaml = MyConstants::PODFILE_MODULE_YAML
39
+ @podfile_third_party_yaml = MyConstants::PODFILE_THIRD_PARTY_YAML
40
40
  end
41
41
 
42
42
  def install_yaml_dep(podfile)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: podfileDep
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.6
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 王帅朋
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-25 00:00:00.000000000 Z
11
+ date: 2023-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -69,12 +69,14 @@ files:
69
69
  - lib/podfileDep/check/import.rb
70
70
  - lib/podfileDep/check/item.rb
71
71
  - lib/podfileDep/check/module.rb
72
+ - lib/podfileDep/check/podspec.rb
72
73
  - lib/podfileDep/check/project.rb
74
+ - lib/podfileDep/check/util.rb
73
75
  - lib/podfileDep/check/xcodeproj.rb
74
76
  - lib/podfileDep/command/quick.rb
75
- - lib/podfileDep/constants.rb
76
77
  - lib/podfileDep/indirect/indirect.rb
77
78
  - lib/podfileDep/modify/modify_code.rb
79
+ - lib/podfileDep/my_constants.rb
78
80
  - lib/podfileDep/podfilelock.rb
79
81
  - lib/podfileDep/reference/project.rb
80
82
  - lib/podfileDep/reference/unused.rb