forked from cms-sw/cms-git-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-cms-checkdeps
executable file
·282 lines (260 loc) · 8.87 KB
/
git-cms-checkdeps
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env perl
#
# $Id: git-checkdeps,v 1.8 2013/03/25 13:26:43 eulisse Exp $
#
# Created by: David Lange
# LLNL
# 12 September 207
#
use strict;
use warnings;
use Getopt::Long;
use Cwd;
#Idea: diff checked out packages.
# looking for changed headers
# find all packages that depend on those headers
# print that list.
#if any argument, print help and exit
my $poisondir="poison";
my $checkout=0;
my $checkpython=0;
my $checkheader=0;
my $checkbuildfile=0;
my $printFileNames=0;
my $poison_includes=undef;
my $poison_only=0;
my $jobs=4;
while (my $arg=shift) {
if ( $arg eq "-a" ) {
$checkout=1;
if (!defined $poison_includes) {$poison_includes=1;}
}
elsif ( $arg eq "-p" ) {
$checkpython=1;
}
elsif ( $arg eq "-h" ) {
$checkheader=1;
}
elsif ( $arg eq "-b" ) {
$checkbuildfile=1;
}
elsif ( $arg eq "-f" ) {
$printFileNames=1;
}
elsif ( $arg eq "-d" ) {
$poison_includes=0;
}
elsif ( $arg eq "-D" ) {
$poison_only=1;
}
elsif ( $arg eq "-j" ) {
$arg = shift;
if ($arg!~/^\d+$/){die "Error: Invalid value '$arg' use with -j command-line argument.\n";}
$jobs=int($arg);
if ($jobs<1){$jobs=1;}
}
elsif ( $arg eq "-A" ) {
$checkpython=1;
$checkheader=1;
$checkbuildfile=1;
}
else{
print "checkdeps:\n",
" Utility to check your local development area against the CMSSW release.\n",
" Any modified header files or python modules are found and the package\n",
" dependencies of these files will be returned. addpkg-ing these packages\n",
" and rebuilding them should provide a full and consistent build.\n",
"\nUsage: \n",
" -p look for python modules and their dependencies (ON by default)\n",
" -h look for header files and their dependencies (ON by default)\n",
" -b look for BuildFile files and their dependencies (OFF by default)\n",
" -f print name of changed file name instead of type of dependency (OFF by default)\n",
" -a will add/checkout the packages into your development area\n",
" -A will check all dependencies i.e. header (-h), python(-p) and BuildFile(-b)\n",
" -d do not create dummy copy of deleted files in ${poisondir} directory. Dummy copies\n",
" are useful to find out if deleted headers files are included by other source files.\n",
" -D only dummy copy of deleted files in ${poisondir} directory created.\n",
" NOTE: all other dependency check/add command-line args are ignored.\n",
" -j <N> Run N threads to checkout packages. Default is ${jobs}\n",
" -q will pass -Q option to cvs to make it quiet\n\n";
exit;
}
}
if ($poison_only) {
$checkpython=0;
$checkheader=0;
$checkbuildfile=0;
$checkout=0;
$poison_includes=1;
}
elsif ((!$checkpython) && (!$checkheader) && (!$checkbuildfile)) {
$checkpython=1;
$checkheader=1;
}
if(!defined $poison_includes) { $poison_includes = 0; }
my $localtop=$ENV{CMSSW_BASE};
die "ERROR: Could not find developer area base path. Please run \"cmsenv\" in a developer area.\n" if ($localtop eq "");
my $releasetop=$ENV{CMSSW_RELEASE_BASE};
die "ERROR: Could not find release base path. Please run this script from a developer area.\n" if ($releasetop eq "");
my %vals=();
if ($checkheader){
my $depfile = "${releasetop}/etc/dependencies/usedby.out.gz";
die "ERROR: This release appears not to support the functionality of this script (170pre4 and higher). Sorry\n" if (!-e "$depfile");
&readDependencyInfo("$depfile",\%vals);
}
if ($checkpython) {
my $depfile = "${releasetop}/etc/dependencies/pyusedby.out.gz";
&readDependencyInfo("$depfile",\%vals) if (-e "$depfile");
}
if ($checkbuildfile)
{
my $depfile = "${releasetop}/etc/dependencies/bfusedby.out.gz";
&readDependencyInfo("$depfile",\%vals) if (-e "$depfile");
}
chdir("${localtop}/src");
my @changedFiles;
my @deletedFiles;
my $reltag;
if ($ENV{CMSSW_GIT_HASH}) {
$reltag=$ENV{CMSSW_GIT_HASH};
} else {
$reltag=$ENV{CMSSW_VERSION};
}
my %upackages=();
foreach my $diff (`git diff -G '^([^\$]+\$|[^\$]*[\$][^\$]*\$|([^\$]*[\$])(\$|[^RAIDLNSH]|(R[^eC]|A[^u]|I[^d]|D[^a]|L[^o]|N[^a]|S[^o]|H[^e])|(Re[^v]|RC[^S]|Au[^t]|Id[^:]|Da[^t]|Lo[^g]|Na[^m]|So[^u]|He[^a])|(Rev[^i]|RCS[^f]|Aut[^h]|Dat[^e]|Log[^:]|Nam[^e]|Sou[^r]|Hea[^d])|(Revi[^s]|RCSf[^i]|Auth[^o]|Date[^:]|Name[^:]|Sour[^c]|Head[^e])|(Revis[^i]|RCSfi[^l]|Autho[^r]|Sourc[^e]|Heade[^r])|(Revisi[^o]|RCSfil[^e]|Author[^:]|Source[^:]|Header[^:])|(Revisio[^n]|RCSfile[^:])|(Revision[^:])))' --name-status -r $reltag | grep -v .gitignore | sed -e 's/[ \t]\+/ /'`)
{
chomp $diff;
if ($diff=~/^.\s+([^\/]+\/[^\/]+)\/[^\s]+$/o)
{
my $pack=$1;
if (!exists $upackages{$pack})
{
$upackages{$pack}=[];
if (!-e $pack){print ">> Package removed $pack\n";}
}
push @{$upackages{$pack}},$diff;
}
}
my @packages=sort keys %upackages;
foreach my $package (@packages) {
next if ($package =~/^UserCode.*/o);
print ">> Checking $package $reltag\n";
my %msgs=("-" => {}, "x" => {});
foreach my $diff (@{$upackages{$package}}) {
my $del = 0;
if ( ($diff =~/^(M)/o) || ($diff =~/^(U)/o) || ($diff =~/^(D)/o) ) {
if ($1 eq "D"){$del =1;}
my @sp2=split(' ', $diff);
$diff = $sp2[1];
}
else {$diff = "";}
if ($diff) {$msgs{"x"}{$diff}=1;}
if ($del) {$msgs{"-"}{$diff}=1;}
}
my @files=sort keys %{$msgs{"-"}};
push(@deletedFiles,@files);
push(@changedFiles,@files);
foreach my $diff (@files){print " - $diff\n"; delete $msgs{"x"}{$diff};}
@files=sort keys %{$msgs{"x"}};
push(@changedFiles,@files);
foreach my $diff (@files){print " x $diff\n";}
}
&poisonIncludes(\@deletedFiles,$localtop) if ($poison_includes);
if ($poison_only) {exit 0;}
my %recompileList;
my $big_bf="";
foreach my $file (@changedFiles) {
if ($file=~/^BigProducts\/[^\/]+\/BuildFile\.xml$/o){$big_bf="${big_bf} ${file}";}
next if (!(exists $vals{$file}));
foreach my $dep (@{$vals{$file}}) {
my @sp=split('/',$dep);
my $recompile="$sp[0]/$sp[1]";
if (!(grep {$_ eq $recompile} @packages)) {
my $scope="header";
if ($file=~/\.py$/o){$scope="python";}
elsif($file=~/\/BuildFile(\.xml|)$/o){$scope="buildfile";}
$recompileList{$recompile}{$scope}=$file;
}
}
}
if ($big_bf ne "")
{
foreach my $diff (`git diff -r $reltag -- $big_bf | sed -e 's/[ \t]\+/ /' | grep '^+' | grep -i '< *use *name *='`)
{
chomp $diff;
$diff=~s/^[+]//o;
foreach my $p (split(">",$diff))
{
if ($p=~/^\s*<\s*use\s+name\s*=\s*["]([^"]+)["]\s*/)
{
if (-e "${releasetop}/src/${1}"){$recompileList{$1}{biglib}="BigProducts";}
}
}
}
}
my @t=sort(keys %recompileList);
my $len=scalar(@t);
if ( $checkout == 0 ) {
print "Packages to check out and compile: $len\n";
}
else{
print "Checking out these packages: $len\n";
}
my $exitcode=0;
if ( $len > 0 ) {
foreach my $pk (@t) {
if ( $printFileNames == 1 ) {
print "$pk (",join(", ",sort values %{$recompileList{$pk}}),")\n";
} else {
print "$pk (",join(", ",sort keys %{$recompileList{$pk}}),")\n";
}
}
if ( $checkout == 1 ) {
chdir ($localtop);
use File::Temp qw(tempfile);
my ($fh,$fname) = tempfile($ENV{CMSSW_BASE} . '/tmp/checkdepsXXXXX', UNLINK => 1);;
foreach my $pk (@t) {
print $fh "$pk/\n";
}
system("cd $ENV{CMSSW_BASE}/src; cat $fname >> $ENV{CMSSW_BASE}/src/.git/info/sparse-checkout; git read-tree -mu HEAD");
$exitcode+=$?;
close($fh);
}
}
if ($exitcode>0){$exitcode=1;}
exit($exitcode);
sub readDependencyInfo()
{
my $file=shift;
my $cache=shift;
my $ref;
open($ref,"gunzip -c $file |") || die "Can not open file for reading: $file\n";
while (my $line=<$ref>) {
chomp($line);
my ($file1,$rest)=split(' ',$line,2);
if ($file1 ne "")
{
if (!exists $vals{$file1}){$vals{$file1}=[];}
push @{$vals{$file1}},split(' ',$rest);
}
}
close($ref);
}
sub poisonIncludes() {
my ($deletedFiles,$topdir)=@_;
use File::Path qw (mkpath rmtree);
use File::Basename qw(dirname);
my $poison="${topdir}/${poisondir}";
if (-d $poison){rmtree($poison);}
if (scalar(@$deletedFiles)>0) {print ">> Creating dummy files under $poison directory.\n";}
foreach my $file (@$deletedFiles) {
my $f="${poison}/${file}";
my $dir=dirname($f);
if (!-d $dir){mkpath($dir);}
my $ref;
if(!open($ref,">${f}")){die "ERROR: Can not open file for writing: $f\n";}
print $ref "#error THIS FILE HAS BEEN REMOVED FROM THE PACKAGE.\n";
close($ref);
print " $file\n";
}
}