forked from sni/thruk_libs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorphaned_modules
More file actions
executable file
·78 lines (67 loc) · 2.38 KB
/
orphaned_modules
File metadata and controls
executable file
·78 lines (67 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
use lib 'lib';
use BuildHelper;
BEGIN {
for my $val (qw/PERL5LIB PERL_MB_OPT PERL_LOCAL_LIB_ROOT PERL_MM_OPT/) {
undef $ENV{$val} if defined $ENV{$val};
}
};
####################################
my $verbose = 0;
GetOptions ('v|verbose' => \$verbose);
####################################
my @packages = glob("../thruk/Makefile.PL");
my $more_modules = {
'File::Copy::Recursive' => '0', # required by Thruks inc::Module::Install
};
####################################
# get module dependencies
my($deps,$files) = BuildHelper::get_all_deps(1);
my $orphaned = BuildHelper::get_orphaned($deps, $files, $verbose);
####################################
# remove referenced modules
for my $p (@packages) {
my $meta = BuildHelper::get_meta($p);
my $rem_deps = BuildHelper::get_deps_from_meta($meta, 1);
for my $rem_dep (keys %{$rem_deps}) {
my $rdep = BuildHelper::module_to_file($rem_dep, $files, $rem_deps->{$rem_dep});
my $cv = BuildHelper::is_core_module($rem_dep, 5.008);
if(!$rdep and !BuildHelper::version_compare($cv, $rem_deps->{$rem_dep}) and $rem_dep !~ m/^(Test|Devel|WWW::Mechanize::Firefox)/mx) {
print "WARNING: ",$rem_dep, " does not resolve to a file\n";
} else {
delete $orphaned->{$rdep} if $rdep;
}
}
}
####################################
for my $f (keys %{$files}) {
my($m,$v) = BuildHelper::file_to_module($files->{$f});
my $cv = BuildHelper::is_core_module($m, 5.008);
if($cv and BuildHelper::version_compare($cv, $v)) {
print "WARNING: ",$m, " is a core module (".$cv.") and ",$files->{$m}," should be removed\n";
}
}
# check other modules
for my $m (keys %{$more_modules}) {
if(BuildHelper::is_core_module($m, 5.008)) {
print "WARNING: ",$m, " is a core module and should be removed\n";
next;
}
my $mdep = BuildHelper::module_to_file($m, $files, $more_modules->{$m});
if(!defined $mdep) {
print "WARNING: ",$m, " does not resolve to a file\n";
} else {
delete $orphaned->{$mdep};
}
}
####################################
# print result
for my $file (keys %{$orphaned}) {
my($m,$v) = BuildHelper::file_to_module($file);
if(!defined $more_modules->{$m}) {
print $file, " is orphaned and could probably removed\n";
}
}