1 | ###########################################################################
|
---|
2 | # A module to filter API symbols
|
---|
3 | #
|
---|
4 | # Copyright (C) 2016-2018 Andrey Ponomarenko's ABI Laboratory
|
---|
5 | #
|
---|
6 | # Written by Andrey Ponomarenko
|
---|
7 | #
|
---|
8 | # This library is free software; you can redistribute it and/or
|
---|
9 | # modify it under the terms of the GNU Lesser General Public
|
---|
10 | # License as published by the Free Software Foundation; either
|
---|
11 | # version 2.1 of the License, or (at your option) any later version.
|
---|
12 | #
|
---|
13 | # This library is distributed in the hope that it will be useful,
|
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | # Lesser General Public License for more details.
|
---|
17 | #
|
---|
18 | # You should have received a copy of the GNU Lesser General Public
|
---|
19 | # License along with this library; if not, write to the Free Software
|
---|
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
---|
21 | # MA 02110-1301 USA.
|
---|
22 | ###########################################################################
|
---|
23 | use strict;
|
---|
24 |
|
---|
25 | my %SkippedPackage;
|
---|
26 |
|
---|
27 | sub classFilter($$$)
|
---|
28 | {
|
---|
29 | my ($Class, $LVer, $ClassContext) = @_;
|
---|
30 |
|
---|
31 | if(defined $Class->{"Dep"}) {
|
---|
32 | return 0;
|
---|
33 | }
|
---|
34 |
|
---|
35 | my $CName = $Class->{"Name"};
|
---|
36 | my $Package = $Class->{"Package"};
|
---|
37 |
|
---|
38 | if(defined $In::Opt{"ClassListPath"}
|
---|
39 | and not defined $In::Opt{"ClassList_User"}{$CName})
|
---|
40 | { # user defined classes
|
---|
41 | return 0;
|
---|
42 | }
|
---|
43 |
|
---|
44 | if(defined $In::Opt{"SkipClassesList"})
|
---|
45 | { # user defined classes
|
---|
46 | if(defined $In::Opt{"SkipClasses"}{$CName}) {
|
---|
47 | return 0;
|
---|
48 | }
|
---|
49 | else
|
---|
50 | {
|
---|
51 | my $SClass = $CName;
|
---|
52 |
|
---|
53 | while($SClass=~s/\.[^\.]+?\Z//)
|
---|
54 | {
|
---|
55 | if(defined $In::Opt{"SkipClasses"}{$SClass}) {
|
---|
56 | return 0;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | if(skipPackage($Package, $LVer))
|
---|
63 | { # internal packages
|
---|
64 | return 0;
|
---|
65 | }
|
---|
66 |
|
---|
67 | if(skipType($CName))
|
---|
68 | { # internal types
|
---|
69 | return 0;
|
---|
70 | }
|
---|
71 |
|
---|
72 | if($ClassContext)
|
---|
73 | {
|
---|
74 | my @Ann = ();
|
---|
75 |
|
---|
76 | if(defined $Class->{"Annotations"}) {
|
---|
77 | @Ann = keys(%{$Class->{"Annotations"}});
|
---|
78 | }
|
---|
79 |
|
---|
80 | if(not annotationFilter(\@Ann, $LVer)) {
|
---|
81 | return 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 | if($In::Opt{"ClientPath"})
|
---|
85 | {
|
---|
86 | if(not defined $In::Opt{"UsedClasses_Client"}{$CName}) {
|
---|
87 | return 0;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | return 1;
|
---|
93 | }
|
---|
94 |
|
---|
95 | sub nonImplClass($)
|
---|
96 | {
|
---|
97 | my $Class = $_[0];
|
---|
98 |
|
---|
99 | if(defined $In::Opt{"NonImplAll"}) {
|
---|
100 | return 1;
|
---|
101 | }
|
---|
102 |
|
---|
103 | if(defined $In::Opt{"NonImplClassesList"})
|
---|
104 | { # user defined classes
|
---|
105 | if(defined $In::Opt{"NonImplClasses"}{$Class->{"Name"}}) {
|
---|
106 | return 1;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | return 0;
|
---|
111 | }
|
---|
112 |
|
---|
113 | sub methodFilter($$)
|
---|
114 | {
|
---|
115 | my ($Method, $LVer) = @_;
|
---|
116 |
|
---|
117 | my $MAttr = $In::API{$LVer}{"MethodInfo"}{$Method};
|
---|
118 | my $MName = $MAttr->{"Name"};
|
---|
119 |
|
---|
120 | if(defined $MAttr->{"Dep"}) {
|
---|
121 | return 0;
|
---|
122 | }
|
---|
123 |
|
---|
124 | if($MAttr->{"Access"}=~/private/)
|
---|
125 | { # non-public
|
---|
126 | return 0;
|
---|
127 | }
|
---|
128 |
|
---|
129 | my $ClassId = $MAttr->{"Class"};
|
---|
130 | my $Class = getType($ClassId, $LVer);
|
---|
131 |
|
---|
132 | if($Class->{"Access"}=~/private/)
|
---|
133 | { # skip private classes
|
---|
134 | return 0;
|
---|
135 | }
|
---|
136 |
|
---|
137 | my $Package = $MAttr->{"Package"};
|
---|
138 |
|
---|
139 | my @Ann = ();
|
---|
140 |
|
---|
141 | if(defined $Class->{"Annotations"}) {
|
---|
142 | @Ann = (@Ann, keys(%{$Class->{"Annotations"}}));
|
---|
143 | }
|
---|
144 |
|
---|
145 | if(defined $MAttr->{"Annotations"}) {
|
---|
146 | @Ann = (@Ann, keys(%{$MAttr->{"Annotations"}}));
|
---|
147 | }
|
---|
148 |
|
---|
149 | if(not annotationFilter(\@Ann, $LVer)) {
|
---|
150 | return 0;
|
---|
151 | }
|
---|
152 |
|
---|
153 | if($In::Opt{"ClientPath"})
|
---|
154 | { # user defined application
|
---|
155 | if(not defined $In::Opt{"UsedMethods_Client"}{$MName}
|
---|
156 | and not defined $In::Opt{"UsedClasses_Client"}{$Class->{"Name"}}) {
|
---|
157 | return 0;
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | if(skipPackage($Package, $LVer))
|
---|
162 | { # internal packages
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 |
|
---|
166 | if(not classFilter($Class, $LVer, 0)) {
|
---|
167 | return 0;
|
---|
168 | }
|
---|
169 |
|
---|
170 | if(defined $In::Opt{"SkipDeprecated"})
|
---|
171 | {
|
---|
172 | if($Class->{"Deprecated"})
|
---|
173 | { # deprecated class
|
---|
174 | return 0;
|
---|
175 | }
|
---|
176 | if($MAttr->{"Deprecated"})
|
---|
177 | { # deprecated method
|
---|
178 | return 0;
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | return 1;
|
---|
183 | }
|
---|
184 |
|
---|
185 | sub annotationFilter($$)
|
---|
186 | {
|
---|
187 | my ($Ann, $LVer) = @_;
|
---|
188 |
|
---|
189 | if(not defined $In::Opt{"CountMethods"})
|
---|
190 | {
|
---|
191 | if(defined $In::Opt{"AddedAnnotations"} and $LVer==1) {
|
---|
192 | return 1;
|
---|
193 | }
|
---|
194 |
|
---|
195 | if(defined $In::Opt{"RemovedAnnotations"} and $LVer==2) {
|
---|
196 | return 1;
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | if($In::Opt{"SkipAnnotationsListPath"})
|
---|
201 | {
|
---|
202 | foreach my $Aid (@{$Ann})
|
---|
203 | {
|
---|
204 | my $AName = $In::API{$LVer}{"TypeInfo"}{$Aid}{"Name"};
|
---|
205 |
|
---|
206 | if(defined $In::Opt{"SkipAnnotationList_User"}{$AName}) {
|
---|
207 | return 0;
|
---|
208 | }
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | if($In::Opt{"AnnotationsListPath"})
|
---|
213 | {
|
---|
214 | my $Annotated = 0;
|
---|
215 |
|
---|
216 | foreach my $Aid (@{$Ann})
|
---|
217 | {
|
---|
218 | my $AName = $In::API{$LVer}{"TypeInfo"}{$Aid}{"Name"};
|
---|
219 |
|
---|
220 | if(defined $In::Opt{"AnnotationList_User"}{$AName})
|
---|
221 | {
|
---|
222 | $Annotated = 1;
|
---|
223 | last;
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | if(not $Annotated) {
|
---|
228 | return 0;
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | return 1;
|
---|
233 | }
|
---|
234 |
|
---|
235 | sub skipType($)
|
---|
236 | {
|
---|
237 | my $TName = $_[0];
|
---|
238 |
|
---|
239 | if(my $SkipInternalTypes = $In::Opt{"SkipInternalTypes"})
|
---|
240 | {
|
---|
241 | if($TName=~/($SkipInternalTypes)/) {
|
---|
242 | return 1;
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | return 0;
|
---|
247 | }
|
---|
248 |
|
---|
249 | sub skipPackage($$)
|
---|
250 | {
|
---|
251 | my ($Package, $LVer) = @_;
|
---|
252 |
|
---|
253 | if(my $SkipInternalPackages = $In::Opt{"SkipInternalPackages"})
|
---|
254 | {
|
---|
255 | if($Package=~/($SkipInternalPackages)/) {
|
---|
256 | return 1;
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | if(defined $In::Desc{$LVer}{"SkipPackages"})
|
---|
261 | {
|
---|
262 | foreach my $P (keys(%{$In::Desc{$LVer}{"SkipPackages"}}))
|
---|
263 | {
|
---|
264 | if($Package=~/\A\Q$P\E(\.|\Z)/)
|
---|
265 | { # user skipped packages
|
---|
266 | return 1;
|
---|
267 | }
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | if(not defined $In::Opt{"KeepInternal"})
|
---|
272 | {
|
---|
273 | my $Note = (not keys(%SkippedPackage));
|
---|
274 |
|
---|
275 | if($Package=~/(\A|\.)(internal|impl|examples)(\.|\Z)/)
|
---|
276 | { # internal packages
|
---|
277 | my $P = $2;
|
---|
278 | if(not $SkippedPackage{$LVer}{$P})
|
---|
279 | {
|
---|
280 | $SkippedPackage{$LVer}{$P} = 1;
|
---|
281 | printMsg("WARNING", "skipping \"$P\" packages");
|
---|
282 |
|
---|
283 | if($Note) {
|
---|
284 | printMsg("NOTE", "use --keep-internal option to check them");
|
---|
285 | }
|
---|
286 | }
|
---|
287 | return 1;
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | if(defined $In::Desc{$LVer}{"KeepPackages"}
|
---|
292 | and my @Keeped = keys(%{$In::Desc{$LVer}{"KeepPackages"}}))
|
---|
293 | {
|
---|
294 | my $UserKeeped = 0;
|
---|
295 | foreach my $P (@Keeped)
|
---|
296 | {
|
---|
297 | if($Package=~/\A\Q$P\E(\.|\Z)/)
|
---|
298 | { # user keeped packages
|
---|
299 | $UserKeeped = 1;
|
---|
300 | last;
|
---|
301 | }
|
---|
302 | }
|
---|
303 | if(not $UserKeeped) {
|
---|
304 | return 1;
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | if(my $Check = $In::Opt{"CheckPackages"})
|
---|
309 | {
|
---|
310 | if($Package!~/$Check/) {
|
---|
311 | return 1;
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | return 0;
|
---|
316 | }
|
---|
317 |
|
---|
318 | sub ignorePath($$)
|
---|
319 | {
|
---|
320 | my ($Path, $Prefix) = @_;
|
---|
321 |
|
---|
322 | if($Path=~/\~\Z/)
|
---|
323 | { # skipping system backup files
|
---|
324 | return 1;
|
---|
325 | }
|
---|
326 |
|
---|
327 | # skipping hidden .svn, .git, .bzr, .hg and CVS directories
|
---|
328 | if(cutPrefix($Path, $Prefix)=~/(\A|[\/\\]+)(\.(svn|git|bzr|hg)|CVS)([\/\\]+|\Z)/)
|
---|
329 | {
|
---|
330 | return 1;
|
---|
331 | }
|
---|
332 |
|
---|
333 | return 0;
|
---|
334 | }
|
---|
335 |
|
---|
336 | return 1;
|
---|