podfileDep 2.4.0 → 2.4.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/cocoapods_plugin.rb +0 -3
- data/lib/podfileDep/check/item.rb +201 -8
- data/lib/podfileDep/check/podspec.rb +13 -1
- data/lib/podfileDep/check/project.rb +1 -202
- data/lib/podfileDep/check/xcodeproj.rb +0 -238
- data/lib/podfileDep/version.rb +1 -1
- metadata +1 -3
- data/lib/podfileDep/check/dep.rb +0 -183
- data/lib/podfileDep/check/module.rb +0 -178
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90b91a2988e18202add645f9dfb02623d018854b09ed5b3e1c7cfe52ca463fba
|
4
|
+
data.tar.gz: 1a7f61c0e7d35282204b055e3580bf4d78894fc6525a3b1f5d59bfea7d4f95d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d370629f905be0397b4e76f2c2198b800a8e7868882d1436ed3a8a9aa19c57d3ed0a775ce1947e9e8f345cc6f2a018fc9d30c4264d966b87da80bca97f5bed
|
7
|
+
data.tar.gz: dccea04f95d9d9d06db5a22424ebf02f360a465b18f2e4a07aa05af32e3bbc2423dc34b429b360acdab81c5abdd1a878ba2578ee3b32f1c867f52dbdae9969d8
|
data/CHANGELOG.md
CHANGED
data/lib/cocoapods_plugin.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'cocoapods'
|
2
2
|
require_relative 'podfileDep/command/quick'
|
3
3
|
require_relative 'podfileDep/check/project'
|
4
|
-
require_relative 'podfileDep/check/dep'
|
5
4
|
require_relative 'podfileDep/check/podspec'
|
6
5
|
require_relative 'podfileDep/modify/modify_code'
|
7
6
|
require_relative 'podfileDep/reference/project'
|
@@ -28,8 +27,6 @@ module CocoapodsPlugin
|
|
28
27
|
# end
|
29
28
|
|
30
29
|
Pod::HooksManager.register('podfileDep', :post_install) do |context|
|
31
|
-
# 检查依赖库
|
32
|
-
# Dep::DepChecker.dep_check
|
33
30
|
|
34
31
|
project = Xcodeproj::XCodeProject.new
|
35
32
|
|
@@ -1,11 +1,204 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
module Xcodeproj
|
3
|
+
class ImportItem
|
4
|
+
attr_accessor :import_name
|
5
|
+
attr_accessor :module_name
|
6
|
+
attr_accessor :file_path
|
7
|
+
attr_accessor :import_file_name
|
8
|
+
attr_accessor :line_index
|
9
|
+
attr_accessor :belong_module
|
10
|
+
def initialize
|
11
|
+
@import_name = nil
|
12
|
+
@module_name = nil
|
13
|
+
@file_path = nil
|
14
|
+
@import_file_name = nil
|
15
|
+
@line_index = nil
|
16
|
+
@belong_module = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class ModuleItem
|
22
|
+
|
23
|
+
public
|
24
|
+
# 组名名
|
25
|
+
attr_accessor :module_name
|
26
|
+
|
27
|
+
# 组件路径
|
28
|
+
attr_accessor :module_path
|
29
|
+
|
30
|
+
# podspec路径
|
31
|
+
attr_accessor :podspec_path
|
32
|
+
|
33
|
+
# 组件目录的所有被引用的文件数组
|
34
|
+
attr_accessor :header_files
|
35
|
+
|
36
|
+
# 组件目录的所有被引用的文件数组
|
37
|
+
attr_accessor :source_files
|
38
|
+
|
39
|
+
# 是否是开发模块
|
40
|
+
attr_accessor :is_development_module
|
41
|
+
|
42
|
+
# [ImportItem]
|
43
|
+
attr_accessor :import_items
|
44
|
+
|
45
|
+
# [ImportItem]
|
46
|
+
attr_accessor :absolute_import_items
|
47
|
+
|
48
|
+
# [String]
|
49
|
+
attr_accessor :frameworks
|
50
|
+
|
51
|
+
def initialize(module_name)
|
52
|
+
@module_name = module_name
|
53
|
+
@module_path = nil
|
54
|
+
@podspec_path = nil
|
55
|
+
@header_files = {}
|
56
|
+
@source_files = {}
|
57
|
+
@import_items = []
|
58
|
+
@absolute_import_items = []
|
59
|
+
@is_development_module = false
|
60
|
+
@frameworks = []
|
61
|
+
end
|
62
|
+
|
63
|
+
# 生成 import <XX/YY.h>的信息
|
64
|
+
# 生成 include <XX/YY.h>的信息
|
65
|
+
def init_absolute_import_info
|
66
|
+
source_files.each_value do |source_file_path|
|
67
|
+
if File.directory?(source_file_path)
|
68
|
+
next
|
69
|
+
end
|
70
|
+
|
71
|
+
line_array = IO.readlines(source_file_path)
|
72
|
+
line_array.each_with_index { |line, line_index|
|
73
|
+
line = line.gsub(" ", "")
|
74
|
+
|
75
|
+
# 处理特殊情况
|
76
|
+
if line.start_with?("#import\"NBSAppAgent.h\"")
|
77
|
+
line = "#import<tingyunApp/NBSAppAgent.h>"
|
78
|
+
end
|
79
|
+
|
80
|
+
if not line.start_with?("#import<") and not line.start_with?("#include<")
|
81
|
+
next
|
82
|
+
end
|
83
|
+
|
84
|
+
if line.start_with?("@implementation")
|
85
|
+
break
|
86
|
+
end
|
87
|
+
|
88
|
+
# 前一行的内容 这里不是检测,则不需要
|
89
|
+
pre_line = ""
|
90
|
+
|
91
|
+
import_item = other_module_import(line, source_file_path, line_index, @module_name, pre_line)
|
92
|
+
if import_item
|
93
|
+
absolute_import_items << import_item
|
94
|
+
end
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
absolute_import_items
|
99
|
+
end
|
100
|
+
|
101
|
+
# 生成 import "XXX.h"的信息
|
102
|
+
def init_import_info
|
103
|
+
source_files.each_value do |source_file_path|
|
104
|
+
if File.directory?(source_file_path)
|
105
|
+
next
|
106
|
+
end
|
107
|
+
|
108
|
+
line_array = IO.readlines(source_file_path)
|
109
|
+
line_array.each_with_index { |line, line_index|
|
110
|
+
line = line.gsub(" ", "")
|
111
|
+
|
112
|
+
unless line.start_with?("#import")
|
113
|
+
next
|
114
|
+
end
|
115
|
+
|
116
|
+
if line.start_with?("@implementation")
|
117
|
+
break
|
118
|
+
end
|
119
|
+
|
120
|
+
# 前一行的内容
|
121
|
+
pre_index = line_index-1 < 0 ? 0 : line_index-1
|
122
|
+
pre_line = line_array[pre_index]
|
123
|
+
|
124
|
+
if line.start_with?("#import\"") #本组件
|
125
|
+
import_item = own_module_import(line, source_file_path, line_index, @module_name, pre_line)
|
126
|
+
if import_item
|
127
|
+
import_items << import_item
|
128
|
+
end
|
129
|
+
elsif line.start_with?("#import<") #其他组件
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
import_items
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
# 生成自己模块的import item
|
141
|
+
# @param line 以 import" 开头
|
142
|
+
def own_module_import(line, file_path, line_index, module_name, pre_line)
|
143
|
+
line_split_array = line.split("\"")
|
144
|
+
if line_split_array.size <= 1
|
145
|
+
return nil
|
146
|
+
end
|
147
|
+
|
148
|
+
import_content = "#{line_split_array[0]}\"#{line_split_array[1]}\"" # import"XXX.h" 或import"XXX.AAA.h" 防止后边有其他内容
|
149
|
+
|
150
|
+
# 特殊处理
|
151
|
+
if import_content == "#import\"NBSAppAgent.h\""
|
152
|
+
return nil
|
153
|
+
end
|
154
|
+
|
155
|
+
pre_line = pre_line.gsub(" ", "").gsub("\n", "")
|
156
|
+
if pre_line.start_with?("#if") or pre_line == "#else"
|
157
|
+
return nil
|
158
|
+
end
|
159
|
+
|
160
|
+
import_file_name = import_content
|
161
|
+
import_file_name = import_file_name.gsub("#import\"", "")
|
162
|
+
import_file_name = import_file_name.gsub("\"", "") # 变成 XX.h
|
163
|
+
|
164
|
+
|
165
|
+
import_item = ImportItem.new # (import_name, module_name, file_name, line_index, podfile)
|
166
|
+
import_item.import_name = import_content.gsub("#import\"", "#import \"")
|
167
|
+
import_item.module_name = module_name
|
168
|
+
import_item.file_path = file_path
|
169
|
+
import_item.import_file_name = import_file_name
|
170
|
+
import_item.line_index = line_index + 1
|
171
|
+
|
172
|
+
import_item
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
def other_module_import(line, file_path, line_index, module_name, pre_line)
|
177
|
+
line = line.gsub("\n","")
|
178
|
+
line_split_array = line.split("/") #import<XX/YY.h> 或 #import<XX/YY/ZZ.h>
|
179
|
+
if line_split_array.size <= 1
|
180
|
+
return nil
|
181
|
+
end
|
182
|
+
|
183
|
+
pre_line = pre_line.gsub(" ", "").gsub("\n", "")
|
184
|
+
if pre_line.start_with?("#if") or pre_line == "#else"
|
185
|
+
return nil
|
186
|
+
end
|
187
|
+
|
188
|
+
import_file_name = line_split_array[line_split_array.size-1].gsub(">", "")
|
189
|
+
belong_module = line_split_array[0].gsub("#import<", "").gsub("#include<", "")
|
190
|
+
import_name = line.gsub("#import<", "#import <").gsub("#include<", "#include <")
|
191
|
+
|
192
|
+
import_item = ImportItem.new # (import_name, module_name, file_name, line_index, podfile)
|
193
|
+
import_item.import_name = import_name
|
194
|
+
import_item.module_name = module_name
|
195
|
+
import_item.file_path = file_path
|
196
|
+
import_item.import_file_name = import_file_name
|
197
|
+
import_item.line_index = line_index + 1
|
198
|
+
import_item.belong_module = belong_module
|
199
|
+
|
200
|
+
import_item
|
201
|
+
|
202
|
+
end
|
10
203
|
end
|
11
204
|
end
|
@@ -112,6 +112,11 @@ module Xcodeproj
|
|
112
112
|
next
|
113
113
|
end
|
114
114
|
|
115
|
+
# 过滤未被安装的依赖库
|
116
|
+
unless module_is_installed(import_item.belong_module)
|
117
|
+
next
|
118
|
+
end
|
119
|
+
|
115
120
|
result_dic[import_item.belong_module] = import_item
|
116
121
|
end
|
117
122
|
result_dic.keys
|
@@ -153,7 +158,14 @@ module Xcodeproj
|
|
153
158
|
result
|
154
159
|
end
|
155
160
|
|
156
|
-
|
161
|
+
# 判断某个库是否被安装
|
162
|
+
def module_is_installed(module_name)
|
163
|
+
all = project.lock_content["SPEC CHECKSUMS"]
|
164
|
+
unless all
|
165
|
+
return false
|
166
|
+
end
|
167
|
+
!!all[module_name]
|
168
|
+
end
|
157
169
|
# 系统级的依赖库
|
158
170
|
# @return [String]
|
159
171
|
def system_modules
|
@@ -1,211 +1,10 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'colored2'
|
3
3
|
require_relative 'util'
|
4
|
+
require_relative 'item'
|
4
5
|
|
5
6
|
module Xcodeproj
|
6
7
|
|
7
|
-
class ImportItem
|
8
|
-
attr_accessor :import_name
|
9
|
-
attr_accessor :module_name
|
10
|
-
attr_accessor :file_path
|
11
|
-
attr_accessor :import_file_name
|
12
|
-
attr_accessor :line_index
|
13
|
-
attr_accessor :belong_module
|
14
|
-
def initialize
|
15
|
-
@import_name = nil
|
16
|
-
@module_name = nil
|
17
|
-
@file_path = nil
|
18
|
-
@import_file_name = nil
|
19
|
-
@line_index = nil
|
20
|
-
@belong_module = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
class ModuleItem
|
26
|
-
|
27
|
-
public
|
28
|
-
# 组名名
|
29
|
-
attr_accessor :module_name
|
30
|
-
|
31
|
-
# 组件路径
|
32
|
-
attr_accessor :module_path
|
33
|
-
|
34
|
-
# podspec路径
|
35
|
-
attr_accessor :podspec_path
|
36
|
-
|
37
|
-
# 组件目录的所有被引用的文件数组
|
38
|
-
attr_accessor :header_files
|
39
|
-
|
40
|
-
# 组件目录的所有被引用的文件数组
|
41
|
-
attr_accessor :source_files
|
42
|
-
|
43
|
-
# 是否是开发模块
|
44
|
-
attr_accessor :is_development_module
|
45
|
-
|
46
|
-
# [ImportItem]
|
47
|
-
attr_accessor :import_items
|
48
|
-
|
49
|
-
# [ImportItem]
|
50
|
-
attr_accessor :absolute_import_items
|
51
|
-
|
52
|
-
# [String]
|
53
|
-
attr_accessor :frameworks
|
54
|
-
|
55
|
-
def initialize(module_name)
|
56
|
-
@module_name = module_name
|
57
|
-
@module_path = nil
|
58
|
-
@podspec_path = nil
|
59
|
-
@header_files = {}
|
60
|
-
@source_files = {}
|
61
|
-
@import_items = []
|
62
|
-
@absolute_import_items = []
|
63
|
-
@is_development_module = false
|
64
|
-
@frameworks = []
|
65
|
-
end
|
66
|
-
|
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
|
103
|
-
end
|
104
|
-
|
105
|
-
# 生成 import "XXX.h"的信息
|
106
|
-
def init_import_info
|
107
|
-
source_files.each_value do |source_file_path|
|
108
|
-
if File.directory?(source_file_path)
|
109
|
-
next
|
110
|
-
end
|
111
|
-
|
112
|
-
line_array = IO.readlines(source_file_path)
|
113
|
-
line_array.each_with_index { |line, line_index|
|
114
|
-
line = line.gsub(" ", "")
|
115
|
-
|
116
|
-
unless line.start_with?("#import")
|
117
|
-
next
|
118
|
-
end
|
119
|
-
|
120
|
-
if line.start_with?("@implementation")
|
121
|
-
break
|
122
|
-
end
|
123
|
-
|
124
|
-
# 前一行的内容
|
125
|
-
pre_index = line_index-1 < 0 ? 0 : line_index-1
|
126
|
-
pre_line = line_array[pre_index]
|
127
|
-
|
128
|
-
if line.start_with?("#import\"") #本组件
|
129
|
-
import_item = own_module_import(line, source_file_path, line_index, @module_name, pre_line)
|
130
|
-
if import_item
|
131
|
-
import_items << import_item
|
132
|
-
end
|
133
|
-
elsif line.start_with?("#import<") #其他组件
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
}
|
138
|
-
end
|
139
|
-
|
140
|
-
import_items
|
141
|
-
end
|
142
|
-
|
143
|
-
private
|
144
|
-
# 生成自己模块的import item
|
145
|
-
# @param line 以 import" 开头
|
146
|
-
def own_module_import(line, file_path, line_index, module_name, pre_line)
|
147
|
-
line_split_array = line.split("\"")
|
148
|
-
if line_split_array.size <= 1
|
149
|
-
return nil
|
150
|
-
end
|
151
|
-
|
152
|
-
import_content = "#{line_split_array[0]}\"#{line_split_array[1]}\"" # import"XXX.h" 或import"XXX.AAA.h" 防止后边有其他内容
|
153
|
-
|
154
|
-
# 特殊处理
|
155
|
-
if import_content == "#import\"NBSAppAgent.h\""
|
156
|
-
return nil
|
157
|
-
end
|
158
|
-
|
159
|
-
pre_line = pre_line.gsub(" ", "").gsub("\n", "")
|
160
|
-
if pre_line.start_with?("#if") or pre_line == "#else"
|
161
|
-
return nil
|
162
|
-
end
|
163
|
-
|
164
|
-
import_file_name = import_content
|
165
|
-
import_file_name = import_file_name.gsub("#import\"", "")
|
166
|
-
import_file_name = import_file_name.gsub("\"", "") # 变成 XX.h
|
167
|
-
|
168
|
-
|
169
|
-
import_item = ImportItem.new # (import_name, module_name, file_name, line_index, podfile)
|
170
|
-
import_item.import_name = import_content.gsub("#import\"", "#import \"")
|
171
|
-
import_item.module_name = module_name
|
172
|
-
import_item.file_path = file_path
|
173
|
-
import_item.import_file_name = import_file_name
|
174
|
-
import_item.line_index = line_index + 1
|
175
|
-
|
176
|
-
import_item
|
177
|
-
end
|
178
|
-
|
179
|
-
|
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
|
205
|
-
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
8
|
class XCodeProject
|
210
9
|
|
211
10
|
# 壳工程xcodeproj对象
|
@@ -2,38 +2,6 @@ require 'xcodeproj'
|
|
2
2
|
require 'pathname'
|
3
3
|
|
4
4
|
module XCProject
|
5
|
-
class ModuleItem
|
6
|
-
|
7
|
-
|
8
|
-
def initialize(module_name, module_path)
|
9
|
-
@module_name = module_name
|
10
|
-
@module_path = module_path
|
11
|
-
@podspec_path = nil
|
12
|
-
@source_files = []
|
13
|
-
end
|
14
|
-
|
15
|
-
# 组件名
|
16
|
-
attr_reader :module_name
|
17
|
-
|
18
|
-
# 组件路径
|
19
|
-
attr_reader :module_path
|
20
|
-
|
21
|
-
# 组件目录的所有被引用的文件数组
|
22
|
-
attr_reader :source_files
|
23
|
-
|
24
|
-
# podspec路径
|
25
|
-
attr_reader :podspec_path
|
26
|
-
|
27
|
-
# 添加一个文件路径进去
|
28
|
-
def add_source_file(source_file)
|
29
|
-
self.source_files << source_file
|
30
|
-
end
|
31
|
-
|
32
|
-
def update_podspec_path(podspec_path)
|
33
|
-
@podspec_path = podspec_path
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
5
|
|
38
6
|
class XcodeprojManager
|
39
7
|
|
@@ -99,57 +67,6 @@ module XCProject
|
|
99
67
|
results
|
100
68
|
end
|
101
69
|
|
102
|
-
# 获取壳工程的引用的文件列表
|
103
|
-
# @return Hash
|
104
|
-
def get_shell_module
|
105
|
-
project = self.get_shell_project
|
106
|
-
|
107
|
-
result_map = {}
|
108
|
-
self.reference_shell_code_file(project.root_object.main_group, result_map)
|
109
|
-
result_map
|
110
|
-
end
|
111
|
-
|
112
|
-
# 根据一个group获取其对应的引用代码文件和路径- 仅限壳工程
|
113
|
-
@private
|
114
|
-
def reference_shell_code_file(group, result_map)
|
115
|
-
# 文件引用
|
116
|
-
file_reference = Xcodeproj::Project::Object::PBXFileReference
|
117
|
-
|
118
|
-
group.children.each {|child|
|
119
|
-
|
120
|
-
if child.class != file_reference
|
121
|
-
self.reference_shell_code_file(child, result_map)
|
122
|
-
next
|
123
|
-
end
|
124
|
-
|
125
|
-
file_name = child.real_path.basename
|
126
|
-
extend_name = file_name.extname
|
127
|
-
if not extend_name == ".h" and
|
128
|
-
not extend_name == ".m" and
|
129
|
-
not extend_name == ".mm" and
|
130
|
-
not extend_name == ".pch" and
|
131
|
-
not extend_name == ".c" and
|
132
|
-
not extend_name == ".cc" and
|
133
|
-
not extend_name == ".hpp" and
|
134
|
-
not extend_name == ".cpp"
|
135
|
-
next
|
136
|
-
end
|
137
|
-
|
138
|
-
# 引用关系路径
|
139
|
-
hierarchy_path_array = child.hierarchy_path.split("/")
|
140
|
-
if hierarchy_path_array.size < 2
|
141
|
-
next
|
142
|
-
end
|
143
|
-
|
144
|
-
module_name = hierarchy_path_array[1]
|
145
|
-
module_item = result_map[module_name] ? result_map[module_name] : ModuleItem.new(module_name, child.real_path)
|
146
|
-
module_item.add_source_file(child.real_path)
|
147
|
-
|
148
|
-
result_map[module_name] = module_item
|
149
|
-
}
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
70
|
# 获取Pods下project对象
|
154
71
|
def get_pods_project
|
155
72
|
|
@@ -162,160 +79,5 @@ module XCProject
|
|
162
79
|
|
163
80
|
end
|
164
81
|
|
165
|
-
# 根据一个组件名获取其内部所有的framework名字 如果没有则返回自己
|
166
|
-
def frameworks_with_module_name(module_name)
|
167
|
-
if self.module_frameworks[module_name]
|
168
|
-
return self.module_frameworks[module_name]
|
169
|
-
end
|
170
|
-
|
171
|
-
module_path = self.real_path_with_module_name(module_name)
|
172
|
-
frameworks = [module_name]
|
173
|
-
self.get_framework(module_path, frameworks)
|
174
|
-
self.module_frameworks[module_name] = frameworks
|
175
|
-
frameworks
|
176
|
-
end
|
177
|
-
|
178
|
-
# 递归查找路径下的framework名字
|
179
|
-
@private
|
180
|
-
def get_framework(path, frameworks)
|
181
|
-
|
182
|
-
if File.directory?(path)
|
183
|
-
Dir.foreach(path) { |fileName|
|
184
|
-
child_path = "#{path}/#{fileName}"
|
185
|
-
if File.directory?(child_path) and not fileName.start_with?(".")
|
186
|
-
if fileName.end_with?(".framework") or fileName.end_with?(".xcframework")
|
187
|
-
framework_name = fileName.gsub(".xcframework","").gsub(".framework","")
|
188
|
-
unless frameworks.include?(framework_name)
|
189
|
-
frameworks << framework_name
|
190
|
-
end
|
191
|
-
else
|
192
|
-
self.get_framework(child_path, frameworks)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
}
|
196
|
-
end
|
197
|
-
frameworks
|
198
|
-
end
|
199
|
-
|
200
|
-
# 根据一个组件的名字,获取其绝对路径
|
201
|
-
def real_path_with_module_name(module_name)
|
202
|
-
project = self.get_pods_project
|
203
|
-
project.main_group.children.each {|child|
|
204
|
-
if child.name != "Development Pods" and child.name != "Pods"
|
205
|
-
next
|
206
|
-
end
|
207
|
-
|
208
|
-
child.children.each {|sun|
|
209
|
-
if sun.name == module_name
|
210
|
-
real_path = sun.real_path
|
211
|
-
return real_path
|
212
|
-
end
|
213
|
-
}
|
214
|
-
}
|
215
|
-
nil
|
216
|
-
end
|
217
|
-
|
218
|
-
# 获取本地依赖库
|
219
|
-
# @return 数组 [ModuleItem]
|
220
|
-
def get_development_module
|
221
|
-
project = self.get_pods_project
|
222
|
-
result_map = {}
|
223
|
-
self.reference_file(project.main_group, result_map)
|
224
|
-
result_map
|
225
|
-
end
|
226
|
-
|
227
|
-
# 根据一个group获取 其对应的引用文件和路径
|
228
|
-
@private
|
229
|
-
def reference_file(group, result_map)
|
230
|
-
# 文件引用
|
231
|
-
file_reference = Xcodeproj::Project::Object::PBXFileReference
|
232
|
-
|
233
|
-
group.children.each {|child|
|
234
|
-
if child.class == file_reference and child.name != "Podfile"
|
235
|
-
|
236
|
-
# 引用关系路径
|
237
|
-
hierarchy_path_array = child.hierarchy_path.split("/")
|
238
|
-
if hierarchy_path_array.size >= 3
|
239
|
-
module_name = hierarchy_path_array[2]
|
240
|
-
|
241
|
-
module_item = result_map[module_name] ? result_map[module_name] : ModuleItem.new(module_name, child.real_path)
|
242
|
-
|
243
|
-
file_name = child.real_path.basename
|
244
|
-
extend_name = file_name.extname
|
245
|
-
if extend_name == ".podspec" or extend_name == ".podspec.json"
|
246
|
-
module_item.update_podspec_path(child.real_path)
|
247
|
-
elsif extend_name == ".h" or extend_name == ".m" or
|
248
|
-
extend_name == ".mm" or extend_name == ".pch" or
|
249
|
-
extend_name == ".c" or extend_name == ".cc" or
|
250
|
-
extend_name == ".cpp" or extend_name == ".hpp"
|
251
|
-
module_item.add_source_file(child.real_path)
|
252
|
-
end
|
253
|
-
|
254
|
-
result_map[module_name] = module_item
|
255
|
-
end
|
256
|
-
# 无论加或着不加 都跳过
|
257
|
-
next
|
258
|
-
end
|
259
|
-
|
260
|
-
if child.name == "Podfile" or
|
261
|
-
child.name == "Frameworks" or
|
262
|
-
child.name == "Pods" or
|
263
|
-
child.name == "Products" or
|
264
|
-
child.name == "Targets Support Files" or
|
265
|
-
child.name == "Support Files"
|
266
|
-
next
|
267
|
-
end
|
268
|
-
|
269
|
-
self.reference_file(child, result_map)
|
270
|
-
}
|
271
|
-
end
|
272
|
-
|
273
|
-
# 获取已引用的所有库,仅包含头文件
|
274
|
-
def get_installed_headers_module
|
275
|
-
project = self.get_pods_project
|
276
|
-
|
277
|
-
result_map = {}
|
278
|
-
self.reference_header_file(project.main_group, result_map)
|
279
|
-
result_map
|
280
|
-
end
|
281
|
-
|
282
|
-
# 获取引用的头文件
|
283
|
-
@private
|
284
|
-
def reference_header_file(group, result_map)
|
285
|
-
# 文件引用
|
286
|
-
file_reference = Xcodeproj::Project::Object::PBXFileReference
|
287
|
-
|
288
|
-
group.children.each {|child|
|
289
|
-
if child.class == file_reference
|
290
|
-
|
291
|
-
# 引用关系路径
|
292
|
-
hierarchy_path_array = child.hierarchy_path.split("/")
|
293
|
-
if hierarchy_path_array.size >= 3
|
294
|
-
module_name = hierarchy_path_array[2]
|
295
|
-
|
296
|
-
module_item = result_map[module_name] ? result_map[module_name] : ModuleItem.new(module_name, child.real_path)
|
297
|
-
|
298
|
-
file_name = child.real_path.basename
|
299
|
-
if file_name.to_s.end_with?(".h") or file_name.to_s.end_with?(".hpp") or file_name.to_s.end_with?(".pch")
|
300
|
-
module_item.add_source_file(child.real_path)
|
301
|
-
end
|
302
|
-
result_map[module_name] = module_item
|
303
|
-
end
|
304
|
-
# 无论加或着不加 都跳过
|
305
|
-
next
|
306
|
-
end
|
307
|
-
|
308
|
-
if child.name == "Podfile" or
|
309
|
-
child.name == "Frameworks" or
|
310
|
-
child.name == "Products" or
|
311
|
-
child.name == "Targets Support Files" or
|
312
|
-
child.name == "Support Files"
|
313
|
-
next
|
314
|
-
end
|
315
|
-
|
316
|
-
self.reference_header_file(child, result_map)
|
317
|
-
}
|
318
|
-
end
|
319
|
-
|
320
82
|
end
|
321
83
|
end
|
data/lib/podfileDep/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: podfileDep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 王帅朋
|
@@ -65,10 +65,8 @@ files:
|
|
65
65
|
- Rakefile
|
66
66
|
- lib/cocoapods_plugin.rb
|
67
67
|
- lib/podfileDep.rb
|
68
|
-
- lib/podfileDep/check/dep.rb
|
69
68
|
- lib/podfileDep/check/import.rb
|
70
69
|
- lib/podfileDep/check/item.rb
|
71
|
-
- lib/podfileDep/check/module.rb
|
72
70
|
- lib/podfileDep/check/podspec.rb
|
73
71
|
- lib/podfileDep/check/project.rb
|
74
72
|
- lib/podfileDep/check/util.rb
|
data/lib/podfileDep/check/dep.rb
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'yaml'
|
3
|
-
require_relative '../podfilelock'
|
4
|
-
require_relative '../my_constants'
|
5
|
-
require_relative 'module'
|
6
|
-
require_relative 'item'
|
7
|
-
require_relative 'xcodeproj'
|
8
|
-
|
9
|
-
module Dep
|
10
|
-
class DepChecker
|
11
|
-
|
12
|
-
# 检查缺少的或着多的依赖
|
13
|
-
def self.dep_check
|
14
|
-
puts "\n依赖库关系检查中..."
|
15
|
-
start = (Time.now.to_f * 1000).to_i
|
16
|
-
|
17
|
-
podfile_lock_manager = PodfileLock::PodfileLockManager
|
18
|
-
module_manager = ModuleModule::ModuleManager.share_instance
|
19
|
-
project_manager = XCProject::XcodeprojManager.share_manager
|
20
|
-
|
21
|
-
# podfile.lock的内容
|
22
|
-
lock_content = podfile_lock_manager.podfile_lock_content
|
23
|
-
|
24
|
-
# 获取需要检查的模块名和路径
|
25
|
-
modules = project_manager.get_development_module
|
26
|
-
|
27
|
-
# 获取所有已安装的依赖库
|
28
|
-
installed_deps = module_manager.get_installed_deps(lock_content)
|
29
|
-
|
30
|
-
# 计数
|
31
|
-
check_count = 0
|
32
|
-
|
33
|
-
# 遍历需要被检查的模块
|
34
|
-
modules.each { |module_name, module_item|
|
35
|
-
|
36
|
-
#组件的的真实依赖包括间接依赖 依据podfile.lock递归读取
|
37
|
-
real_dependencies = module_manager.real_dependencies(module_name, lock_content)
|
38
|
-
|
39
|
-
substart = (Time.now.to_f * 1000).to_i
|
40
|
-
real_frameworks = self.module_frameworks(real_dependencies)
|
41
|
-
puts "#{module_name}打点0:#{((Time.now.to_f * 1000).to_i - substart).to_s}毫秒\n"
|
42
|
-
substart = (Time.now.to_f * 1000).to_i
|
43
|
-
|
44
|
-
#podspec写的直接依赖
|
45
|
-
podspec_dependencies = module_manager.podspec_dependencies(module_item.podspec_path)
|
46
|
-
|
47
|
-
# 某个模块从代码文件里读取的真实需要的依赖库 #import <XX/XX.h>
|
48
|
-
import_item_map = {}
|
49
|
-
module_item.source_files.each { |source_file|
|
50
|
-
self.update_import_item_map(source_file, module_name, import_item_map)
|
51
|
-
check_count += 1
|
52
|
-
}
|
53
|
-
|
54
|
-
if import_item_map.size == 0 and real_dependencies.size == 0
|
55
|
-
next
|
56
|
-
end
|
57
|
-
|
58
|
-
# real_dependencies指的是根据组件podspec的写法 解析出来的依赖库
|
59
|
-
# import_item_map指的是根据代码文件解析出来的依赖库
|
60
|
-
loss = []
|
61
|
-
import_item_map.each_key {|key|
|
62
|
-
if key != module_name
|
63
|
-
did_loss = true
|
64
|
-
|
65
|
-
real_frameworks.each { |dep, frameworks|
|
66
|
-
frameworks.each {|framework|
|
67
|
-
if key == framework
|
68
|
-
did_loss = false
|
69
|
-
break
|
70
|
-
end
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
if did_loss
|
75
|
-
loss << "#{key}"
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
}
|
80
|
-
|
81
|
-
puts "#{module_name}打点1:#{((Time.now.to_f * 1000).to_i - substart).to_s}毫秒\n"
|
82
|
-
substart = (Time.now.to_f * 1000).to_i
|
83
|
-
|
84
|
-
unused = []
|
85
|
-
real_frameworks.each { |dep, frameworks|
|
86
|
-
use = false
|
87
|
-
frameworks.each{|framework|
|
88
|
-
if import_item_map.keys.include?(framework)
|
89
|
-
use = true
|
90
|
-
break
|
91
|
-
end
|
92
|
-
}
|
93
|
-
if not use and podspec_dependencies.include?(dep)
|
94
|
-
unused << "# s.dependency '#{dep}'"
|
95
|
-
end
|
96
|
-
}
|
97
|
-
|
98
|
-
if loss.size >0
|
99
|
-
puts "⚠️ [#{module_name}] 请到#{module_name}.podspec文件中添加缺少的依赖库, 如下:"
|
100
|
-
puts loss
|
101
|
-
puts "\n"
|
102
|
-
end
|
103
|
-
|
104
|
-
if unused.size >0
|
105
|
-
puts "⚠️ [#{module_name}] 请到#{module_name}.podspec文件中移除未被引用的依赖库, 如下:"
|
106
|
-
puts unused
|
107
|
-
puts "\n"
|
108
|
-
end
|
109
|
-
|
110
|
-
puts "#{module_name}打点2:#{((Time.now.to_f * 1000).to_i - substart).to_s}毫秒\n"
|
111
|
-
}
|
112
|
-
|
113
|
-
duration = ((Time.now.to_f * 1000).to_i - start)*0.001
|
114
|
-
puts "依赖库关系检查完毕! 共检查#{modules.size.to_s}个组件(#{check_count}个文件) 耗时:#{duration.round(2)}秒"
|
115
|
-
end
|
116
|
-
|
117
|
-
# 将某个库的所有依赖转化为其对应的frameworks
|
118
|
-
def self.module_frameworks(dependencies)
|
119
|
-
project_manager = XCProject::XcodeprojManager.share_manager
|
120
|
-
result_map = {}
|
121
|
-
dependencies.each do |dependency|
|
122
|
-
frameworks = project_manager.frameworks_with_module_name(dependency)
|
123
|
-
result_map[dependency] = frameworks
|
124
|
-
end
|
125
|
-
result_map
|
126
|
-
end
|
127
|
-
|
128
|
-
# 获取某个文件内对应类型的import <XX/XX>
|
129
|
-
def self.update_import_item_map(file_path, module_name, import_item_map)
|
130
|
-
if File.directory?(file_path)
|
131
|
-
return
|
132
|
-
end
|
133
|
-
|
134
|
-
line_array = IO.readlines(file_path)
|
135
|
-
line_array.each_with_index { |line, index|
|
136
|
-
line = line.gsub(" ", "")
|
137
|
-
if not line.start_with?("#import<") and not line.start_with?("#include<")
|
138
|
-
next
|
139
|
-
end
|
140
|
-
|
141
|
-
line_split_array = line.split(">")
|
142
|
-
if line_split_array.size == 0
|
143
|
-
next
|
144
|
-
end
|
145
|
-
|
146
|
-
import_name = line_split_array[0]+">" # #import <XX/XX.h> 或者 #import <XX.h> 防止后边有其他的内容
|
147
|
-
if not import_name.include?(".h") and not import_name.include?(".H")
|
148
|
-
next
|
149
|
-
end
|
150
|
-
import_array = import_name.split("/")
|
151
|
-
if line_split_array.size == 0
|
152
|
-
next
|
153
|
-
end
|
154
|
-
|
155
|
-
pod = import_array[0].gsub("#import<", "").gsub("#include<", "")
|
156
|
-
pod = pod.gsub(".h>", "")
|
157
|
-
pod = pod.gsub(".H>", "")
|
158
|
-
|
159
|
-
# 已经包含
|
160
|
-
if import_item_map[pod]
|
161
|
-
next
|
162
|
-
end
|
163
|
-
|
164
|
-
# 系统级依赖库
|
165
|
-
if self.system_deps.include?(pod)
|
166
|
-
next
|
167
|
-
end
|
168
|
-
|
169
|
-
file_name = File.basename(file_path)
|
170
|
-
line_index = index+1
|
171
|
-
|
172
|
-
import_item_map[pod] = ImportItem.new(import_name, module_name, file_name, line_index, pod)
|
173
|
-
|
174
|
-
}
|
175
|
-
end
|
176
|
-
|
177
|
-
# 系统级的依赖库
|
178
|
-
def self.system_deps
|
179
|
-
return MyConstants::LIBLIBARYS + MyConstants::FRAMEWORKS
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'yaml'
|
3
|
-
require 'cocoapods'
|
4
|
-
require 'xcodeproj'
|
5
|
-
require_relative '../my_constants'
|
6
|
-
|
7
|
-
module ModuleModule
|
8
|
-
|
9
|
-
class ModuleDepObject
|
10
|
-
def initialize(module_name)
|
11
|
-
@module_name = module_name
|
12
|
-
@dependencies = []
|
13
|
-
@dependencies_expanded = false
|
14
|
-
end
|
15
|
-
|
16
|
-
# 组件名
|
17
|
-
attr_reader :module_name
|
18
|
-
|
19
|
-
# 组件所引用的依赖库
|
20
|
-
attr_reader :dependencies
|
21
|
-
|
22
|
-
# 组件的依赖是否被全部展开
|
23
|
-
attr_reader :dependencies_expanded
|
24
|
-
|
25
|
-
|
26
|
-
# 添加一个依赖库
|
27
|
-
def add_dependency(dependency)
|
28
|
-
self.dependencies << dependency
|
29
|
-
end
|
30
|
-
|
31
|
-
def did_expanded
|
32
|
-
@dependencies_expanded = true
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
class ModuleManager
|
38
|
-
|
39
|
-
# 缓存某个的依赖库
|
40
|
-
# {{"module_nameA":ModuleDepObject,{"module_nameB":ModuleDepObject}
|
41
|
-
attr_reader :all_module_dependencies
|
42
|
-
|
43
|
-
def initialize
|
44
|
-
@all_module_dependencies = {}
|
45
|
-
end
|
46
|
-
# 单例方法
|
47
|
-
@@instance = ModuleManager.new
|
48
|
-
|
49
|
-
# 获取单例
|
50
|
-
def self.share_instance
|
51
|
-
@@instance
|
52
|
-
end
|
53
|
-
|
54
|
-
private_class_method :new
|
55
|
-
|
56
|
-
def real_dependencies(module_name, lock_content)
|
57
|
-
|
58
|
-
lock_dependencies = lock_content["PODS"]
|
59
|
-
|
60
|
-
module_dep = ModuleDepObject.new(module_name)
|
61
|
-
|
62
|
-
# 可能是取的缓存 所以必须赋值
|
63
|
-
module_dep = self.get_module_dep(lock_dependencies, module_dep)
|
64
|
-
|
65
|
-
module_dep.dependencies
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
# 根据podfile.lock里内容递归获取某个库的依赖库
|
70
|
-
@private
|
71
|
-
def get_module_dep(lock_dependencies, module_dep)
|
72
|
-
|
73
|
-
module_dep_cache = self.all_module_dependencies[module_dep.module_name]
|
74
|
-
if module_dep_cache&.dependencies_expanded
|
75
|
-
return module_dep_cache
|
76
|
-
end
|
77
|
-
|
78
|
-
# 找出当前组件的依赖
|
79
|
-
lock_dependencies.each { |item|
|
80
|
-
|
81
|
-
item_name= item
|
82
|
-
if item.class == Hash
|
83
|
-
item_name = item.keys[0]
|
84
|
-
end
|
85
|
-
|
86
|
-
item_name = item_name.split(" (")[0]
|
87
|
-
item_name = item_name.split("/")[0] #解决子仓库的问题
|
88
|
-
|
89
|
-
# 非当前组件
|
90
|
-
if item_name != module_dep.module_name
|
91
|
-
next
|
92
|
-
end
|
93
|
-
|
94
|
-
# 当前组件无其他依赖
|
95
|
-
if item.class == String
|
96
|
-
break
|
97
|
-
end
|
98
|
-
|
99
|
-
# 当前组件有其他依赖
|
100
|
-
# item:{"A (99999)"=>["Masonry", "MJExtension"]
|
101
|
-
item.each {|name, child_names|
|
102
|
-
child_names.each { |child_name|
|
103
|
-
child_name = child_name.split(" (")[0]
|
104
|
-
child_name = child_name.split("/")[0] #解决子仓库的问题
|
105
|
-
|
106
|
-
if item_name == child_name #解决item_name = AFNetworking child_name=AFNetworking/NSURLSession
|
107
|
-
next
|
108
|
-
end
|
109
|
-
|
110
|
-
# 当前库的依赖加进去
|
111
|
-
unless module_dep.dependencies.include?(child_name)
|
112
|
-
module_dep.dependencies << child_name
|
113
|
-
end
|
114
|
-
|
115
|
-
# 当前库的依赖的子依赖
|
116
|
-
child = ModuleDepObject.new(child_name)
|
117
|
-
child_dep = self.get_module_dep(lock_dependencies, child)
|
118
|
-
|
119
|
-
child_dep.did_expanded
|
120
|
-
self.all_module_dependencies[child_dep.module_name] = child_dep
|
121
|
-
|
122
|
-
child_dep.dependencies.each { |sun_name|
|
123
|
-
# 孙子依赖加进去
|
124
|
-
unless module_dep.dependencies.include?(sun_name)
|
125
|
-
module_dep.dependencies << sun_name
|
126
|
-
end
|
127
|
-
}
|
128
|
-
}
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
module_dep.did_expanded
|
133
|
-
self.all_module_dependencies[module_dep.module_name] = module_dep
|
134
|
-
module_dep
|
135
|
-
end
|
136
|
-
|
137
|
-
# 获取某个库的podspec的直接依赖
|
138
|
-
def podspec_dependencies(podspec_path)
|
139
|
-
|
140
|
-
podspec_json_path = podspec_path.to_s.end_with?(".podspec.json") ? podspec_path : nil
|
141
|
-
|
142
|
-
podspec_content = nil
|
143
|
-
if podspec_json_path and File.exist?(podspec_json_path)
|
144
|
-
json = File.read(podspec_json_path)
|
145
|
-
podspec_content = JSON.parse(json)
|
146
|
-
elsif podspec_path and File.exist?(podspec_path)
|
147
|
-
json = self.get_podspec_content(podspec_path)
|
148
|
-
podspec_content = JSON.parse(json)
|
149
|
-
end
|
150
|
-
|
151
|
-
podspec_content["dependencies"] ? podspec_content["dependencies"].keys : []
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
# 获取已安装的依赖库
|
156
|
-
def get_installed_deps(lock_dependencies)
|
157
|
-
lock_dependencies["SPEC CHECKSUMS"] ? lock_dependencies["SPEC CHECKSUMS"].keys : {}
|
158
|
-
end
|
159
|
-
|
160
|
-
# 根据podspec路径把podspec转为json
|
161
|
-
@private
|
162
|
-
def get_podspec_content(podspec_path)
|
163
|
-
|
164
|
-
spec_contents = File.open(podspec_path, 'r:utf-8', &:read)
|
165
|
-
|
166
|
-
if spec_contents.respond_to?(:encoding) && spec_contents.encoding.name != 'UTF-8'
|
167
|
-
spec_contents.encode!('UTF-8')
|
168
|
-
end
|
169
|
-
|
170
|
-
path = Pathname.new(podspec_path)
|
171
|
-
|
172
|
-
spec = ::Pod._eval_podspec(spec_contents, path)
|
173
|
-
|
174
|
-
spec.to_json
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
end
|