perl对目录下rtl 包含rtc字符的替换-更新

1.根据版本管理软件sos的特性,每次大量check in 前需要先人工去check下是否有明显错误。

2.增加了GetOptions选项,方便只discard,只修改,只check in 和全套的discard-check out-check in

3.使用方法

./run_001.plx -m 

./run_001.plx -d

./run_001.plx -i 

./run_001.plx -full 或者 ./run_001.plx -f

#! /usr/bin/perl

use 5.010;
use strict;
#use warnings;
use Getopt::Long;
use File::Find;

GetOptions (
            "m"  => \&func_modify,
            "d"  => \&func_d,
            "i"  => \&func_in,
            "full"  => \&func_full,
) or &usage;

sub usage {
        say "d or m or i or full must be specified with option";
    }

sub func_full {
        say "full function is starting!!!";
        &pre_main_cal;
        &func_rtc_full;
    }

sub func_modify {
        say "modify function is starting!!!";
        &pre_main_cal;
        &func_rtc_modify;
    }

sub func_in {
        say "all good files function is starting!!!";
        &pre_main_cal;
        &func_checkin;
    }

sub func_d {
        say "force discard function is starting!!!";
        &pre_main_cal;
        &func_discard;
    }


sub pre_main_cal {
#my @all_files_1 = glob '/proj/../wa/../fblite/../units/*/src/*.v';
#my @all_files_2 = glob '/proj/../wa/../fblite/../units/*/src/*/*.v';
#my @all_files_3 = glob '/proj/../wa/../fblite/../units/../*.v';
#
#my @all_files = (@all_files_1,@all_files_2,@all_files_3);

if (-e "good_file.txt") {
say "good_file.txt is exists";
unlink "good_file.txt";
say "good_file.txt is delete";
}

if (-e "store_text_001.txt") {
say "store_text_001.txt is exists";
unlink "store_text_001.txt";
say "store_text_001.txt is delete";
}

my @dir = '/proj/../../../../../units';
my @all_files;

open my $good_file_fh,'>','good_file.f';

find(\&PrintName,@dir);

close $good_file_fh;

sub PrintName{
    my $path;
        $path = $File::Find::name;
    if ($path !~ /verif|(fb_top|m_hsdec_top)_4g|src\/(bak|mbist|non_mbist)/){
        if ($path =~ /\.v$/){
            say $good_file_fh "$path";
            push @all_files ,$path;
        }
    }
    }

foreach my $file_name (@all_files){
        my $flag = 0;
        my $cnt = 0;
    open my $file_text,'<',"$file_name";
    open my $good_file,'>>',"good_file.txt";
    open my $store_text_001,'>>',"store_text_001.txt";
    while(<$file_text>){
        chomp;
        $cnt++;
            if(/rf1p_rtc|rf2p_rtc|sr1p_rtc|sr2p_rtc|rom_rtc|rom_rtc_ref|rtc/i){
                $flag = 1;
                say $store_text_001 "$cnt     $_"; 
                }
        }
    if ($flag == 1){
        $cnt = 0;
        say $good_file "$file_name";
        say $store_text_001 "$file_name"; 
        $flag = 0;
    }else {
        $cnt = 0;
        $flag = 0;
        };
    close $file_text;
    close $good_file;
    close $store_text_001;
    }
}

sub func_rtc_modify{
open my $file,'<',"good_file.txt";
my $cnt;
while(<$file>){
        $cnt++;
#        if($cnt <= 3){
        my $file_name_store = $_;
        `soscmd discardco -F $file_name_store`;
        `soscmd co $_`;
        open my $new_file_text,"$_";
        open my $new_file,'>',"new_file.v";
        while(<$new_file_text>){
            chmod;
        if (s/input\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/input  [`NEW_MEM_CTRL-1:0]  $1/){
            printf $new_file "$_";
            }
        elsif (s/output\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/output  [`NEW_MEM_CTRL-1:0]   $1/){
            printf $new_file "$_";
            }
        elsif (s/wire\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/wire [`NEW_MEM_CTRL-1:0] $1/){
            printf $new_file "$_";
            }
        elsif (s/(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)\s*\[\d+:0\]/$1/){
            printf $new_file "$_";
            }
        elsif (s/input\s*\[\d+\:0\]\s*(\brom_rtc\b)/input  [`NEW_ROM_CTRL-1:0]  $1/){
            printf $new_file "$_";
            }
        elsif (s/output\s*\[\d+\:0\]\s*(\brom_rtc\b)/output  [`NEW_ROM_CTRL-1:0]   $1/){
            printf $new_file "$_";
            }
        elsif (s/wire\s*\[\d+\:0\]\s*(\brom_rtc\b)/wire [`NEW_ROM_CTRL-1:0] $1/){
            printf $new_file "$_";
            }
        elsif (s/(\brom_rtc\b)\s*\[\d+:0\]/$1/){
            printf $new_file "$_";
            }
        elsif (s/wire    \[1\:0\]       (rtc0, rtc1, rtc2, rtc3, rtc4, rtc5, rtc6)/wire [`NEW_MEM_CTRL-1:0] $1/){
            printf $new_file "$_";
            }
        elsif (s/(input|output|wire)\s*\[\d+\:0\]\s*RTC/$1 [`NEW_MEM_CTRL-1:0] RTC/){
            printf $new_file "$_";
            }
        elsif (s/RTC\[\d+\:0\]/RTC/){
            printf $new_file "$_";
            }
        elsif (s/input\s*\[\d+\:0\]\s*(txmod_rf_rtc|rf2p_txmod_rtc)/input  [`NEW_MEM_CTRL-1:0]  $1/){
            printf $new_file "$_";
            }
        elsif (s/rf2p_txmod_rtc\[\d+\:0\]/rf2p_txmod_rtc/){
            printf $new_file "$_";
            }
        elsif (s/input\s*\[\d+\:0\]\s*\brsd_rtc\b/input  [`NEW_ROM_CTRL-1:0] rsd_rtc/){
            printf $new_file "$_";
            }
        elsif (s/rsd_rtc\[\d+\:0\]/rsd_rtc/){
            #say "$file_name_store";
            #say "$_";
            printf $new_file "$_";
            }
        else{
            print $new_file "$_";
            }
        }
        close $new_file_text;
        close $new_file;
        system("cp new_file.v $file_name_store");
 #      }
    }
close $file;
}

sub func_discard{
    open my $file,'<',"good_file.txt";
         while(<$file>){
            my $file_name_store = $_;
            `soscmd discardco -F $file_name_store`;
        }
    close $file;
}

sub func_checkin{
    open my $file,'<',"good_file.txt";
         while(<$file>){
                    my $file_name_store = $_;
                    `soscmd ci -F -aLog="replace rtc in all falcon rtl file-20191009-release v1" $file_name_store`;
        }
    close $file;
}


sub func_rtc_full{
open my $file,'<',"good_file.txt";
my $cnt;
while(<$file>){
        $cnt++;
#        if($cnt <= 3){
        my $file_name_store = $_;
        `soscmd discardco -F $file_name_store`;
        `soscmd co $_`;
        open my $new_file_text,"$_";
        open my $new_file,'>',"new_file.v";
        while(<$new_file_text>){
            chmod;
        if (s/input\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/input  [`NEW_MEM_CTRL-1:0]  $1/){
            printf $new_file "$_";
            }
        elsif (s/output\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/output  [`NEW_MEM_CTRL-1:0]   $1/){
            printf $new_file "$_";
            }
        elsif (s/wire\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/wire [`NEW_MEM_CTRL-1:0] $1/){
            printf $new_file "$_";
            }
        elsif (s/(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)\s*\[\d+:0\]/$1/){
            printf $new_file "$_";
            }
        elsif (s/input\s*\[\d+\:0\]\s*(\brom_rtc\b)/input  [`NEW_ROM_CTRL-1:0]  $1/){
            printf $new_file "$_";
            }
        elsif (s/output\s*\[\d+\:0\]\s*(\brom_rtc\b)/output  [`NEW_ROM_CTRL-1:0]   $1/){
            printf $new_file "$_";
            }
        elsif (s/wire\s*\[\d+\:0\]\s*(\brom_rtc\b)/wire [`NEW_ROM_CTRL-1:0] $1/){
            printf $new_file "$_";
            }
        elsif (s/(\brom_rtc\b)\s*\[\d+:0\]/$1/){
            printf $new_file "$_";
            }
        elsif (s/wire    \[1\:0\]       (rtc0, rtc1, rtc2, rtc3, rtc4, rtc5, rtc6)/wire [`NEW_MEM_CTRL-1:0] $1/){
            printf $new_file "$_";
            }
        elsif (s/(input|output|wire)\s*\[\d+\:0\]\s*RTC/$1 [`NEW_MEM_CTRL-1:0] RTC/){
            printf $new_file "$_";
            }
        elsif (s/RTC\[\d+\:0\]/RTC/){
            printf $new_file "$_";
            }
        elsif (s/input\s*\[\d+\:0\]\s*(txmod_rf_rtc|rf2p_txmod_rtc)/input  [`NEW_MEM_CTRL-1:0]  $1/){
            printf $new_file "$_";
            }
        elsif (s/rf2p_txmod_rtc\[\d+\:0\]/rf2p_txmod_rtc/){
            printf $new_file "$_";
            }
        elsif (s/input\s*\[\d+\:0\]\s*\brsd_rtc\b/input  [`NEW_ROM_CTRL-1:0] rsd_rtc/){
            printf $new_file "$_";
            }
        elsif (s/rsd_rtc\[\d+\:0\]/rsd_rtc/){
            #say "$file_name_store";
            #say "$_";
            printf $new_file "$_";
            }
        else{
            print $new_file "$_";
            }
        }
        close $new_file_text;
        close $new_file;
        system("cp new_file.v $file_name_store");
#        `soscmd discardco -F $file_name_store`;
       # `soscmd ci $file_name_store`;
        `soscmd ci -F -aLog="replace rtc in all falcon rtl file-20191009" $file_name_store`;
 #      }
    }
close $file;
}

 

你可能感兴趣的:(PERL)