使用Perl查找VC工程依赖关系

大凡具有一定规模的系统都会分为多个子系统和模块,对应于软件开发工具的工程。在系统开发过程中,我们经常

以下是相应的Perl脚本,该脚本只在VC6的工程管理文件上使用过,对于其他版本的工程文件或许不能有效使用。

#!/usr/bin/perl
use strict;

my %prj2libs;
my %outLib2Prj;
while( <> ) {
   if( /<DIR>.*?(/w+)/ ) {
      chdir $1;
      my @files = <*.dsp>;
     
      foreach my $file ( @files ) {
         if($file =~ /(.*)/.dsp/) {
            my $prj = $1;
            #print "$prj/n";
            my $startEx = "";
            open DSPFILE,'<',$file;
            while(<DSPFILE>) {
               #print;
               if( $startEx ) {
                  if( /^# ADD LINK32|^# ADD LIB32/ ) {
                     #print;
                     my @allWords = split;
                     my @allDepLibs = ();
                     foreach my $word ( @allWords ) {
                        if( $word =~ /([^]*)/.lib/ ) {
                           push @allDepLibs,"/U${1}";
                        }
                     }
                     $prj2libs{$prj} = /@allDepLibs;
                     #/out.*//(w+)/.lib|out.*//(w+)/.dll/;
                     if( ///out.*?//([^//]+)/.dll/ or ///out.*?//([^//]+)/.lib/ ) {
                        $outLib2Prj{"/U${1}"} = $prj;
                     }
                     last;
                  }
               }elsif ( /^!ELSEIF.+Win32 Debug/ ) {
                  #print;
                  $startEx = "true";
               }else {
                  next;
               }
            }
            close DSPFILE;
         }
      }
      chdir "..";
   }
}

#foreach my $key ( sort keys %prj2libs ) {
#   print "key is:/t",$key,"/n";
#   print "prj is $key with", @{$prj2libs{$key}}," are depent!/n";
#}

my @allPrjs = sort keys %prj2libs;
my %prjDepPrjs;

#print "All the Projects:/t@allPrjs/n";

foreach my $prj ( @allPrjs ) {
   #print "$prj/n";
   my @depPrjs = ();
   foreach my $depLib ( @{$prj2libs{$prj}} ) {
      push @depPrjs, $outLib2Prj{$depLib} if( exists $outLib2Prj{$depLib} );
   }
   $prjDepPrjs{$prj} = /@depPrjs;
}
$, = " ";
foreach my $prj ( sort keys %prjDepPrjs ) {
   print "$prj depends on prjs:/t", (sort @{$prjDepPrjs{$prj}}),"/n";
}

#foreach my $outLib ( sort keys %outLib2Prj ) {
#   print "out lib of $outLib2Prj{$outLib} is $outLib/n";
#}

Windows上可以使用的Perl包括ActiveState(www.activestate.com)公司提供的ActivePerl以及cygwin中的Perl(http://sourceware.redhat.com/cygwin/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值