new perls v5.39.10
[andk-cpan-tools.git] / bin / parse-strace-output-for-perlincludes.pl
blob083e455bed103a91dfc7a9b6d361ad8d5e01fb53
1 #!/usr/bin/perl
3 # use 5.010;
4 use strict;
5 use warnings;
7 =head1 NAME
9 parse-strace-output-for-perlincludes.pl
11 =head1 SYNOPSIS
13 parse-strace-output-for-perlincludes.pl [OPTIONS] strace.out-file
15 =head1 OPTIONS
17 =over 8
19 =cut
21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
23 =item B<--help|h!>
25 This help
27 =item B<--perl=s>
29 Full path to a perl from which we can query the INC paths
31 =back
33 =head1 DESCRIPTION
35 =head1 HISTORY
37 Needed for perl bin/parse-strace-output-for-perlincludes.pl --perl /home/sand/src/perl/repoperls/installed-perls/host/k93jammy/v5.39.4/6567/bin/perl ~sand/tmp/strace-6567.out
39 =cut
42 use FindBin;
43 use lib "$FindBin::Bin/../lib";
44 BEGIN {
45 push @INC, qw( );
48 use ExtUtils::MakeMaker;
49 use File::Basename qw(dirname);
50 use File::Path qw(mkpath);
51 use File::Spec;
52 use File::Temp;
53 use Getopt::Long;
54 use Pod::Usage;
55 use Hash::Util qw(lock_keys);
56 use Digest::MD5 qw(md5_hex);
58 our %Opt;
59 lock_keys %Opt, map { /([^=|!]+)/ } @opt;
60 GetOptions(\%Opt,
61 @opt,
62 ) or pod2usage(1);
63 if ($Opt{help}) {
64 pod2usage(0);
66 $Opt{perl} //= $^X;
67 my $strace_out_file = shift @ARGV or die "missing argument for strace-out-file on commandline";
69 warn "perl=$Opt{perl}";
70 my $cmd = qq{$Opt{perl} -le 'my %seen; print join q{|}, grep { ! \$seen{\$_}++ } sort { length \$b <=> length \$a } \@INC'};
71 warn "cmd=$cmd";
72 my $inc_regexp = qx{$cmd};
73 warn "inc_regexp=$inc_regexp";
74 open my $fh, '<', $strace_out_file or die "Could not open $strace_out_file: $!";
75 my %S;
76 my $i = 0;
77 while (<$fh>) {
78 next if /ENOENT/;
79 next unless m{"($inc_regexp)/(.*?\.pm)"};
80 my($path,$mod) = ($1,$2);
81 unless ($S{$mod}++){
82 $i++;
83 my $abspath = "$path/$mod";
84 my $data = do { open my $fh2, "<", $abspath or die "Could not open $abspath: $!"; local $/; <$fh2> };
85 my $digest = md5_hex $data;
86 my $version = MM->parse_version($abspath);
87 printf "%5d %-48s %s %s\n", $i, $mod, $digest, $version;
93 # Local Variables:
94 # mode: cperl
95 # cperl-indent-level: 4
96 # End: