rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | #!/usr/bin/perl -w
|
| 2 | #use strict;
|
| 3 | use File::Basename;
|
| 4 | use Cwd;
|
| 5 |
|
| 6 | &Usage() if ($#ARGV < 3);
|
| 7 |
|
| 8 | my $DEBUG = 0; # debug for normal info.
|
| 9 | my $DEBUG1 = 0; # debug for parsing .dep file
|
| 10 | my $InterMode = 0; # turn ON/OFF interaction mode
|
| 11 |
|
| 12 | my $time = 0;
|
| 13 | $time = time if($DEBUG);
|
| 14 |
|
| 15 | chomp($CWD = cwd());
|
| 16 | $CWD =~ s/\\$// if ($CWD =~ /\\$/);
|
| 17 | print "[CWD]: ",$CWD,"\n" if ($DEBUG);
|
| 18 |
|
| 19 | my ($CODEBASE_PATH,$PROJECT_NAME,$FLAVOR,$MODEM_TYPE,@CHANGE_SET) = @ARGV;
|
| 20 | my @DEP_MODS = ();
|
| 21 |
|
| 22 | $CODEBASE_PATH = (dirname($CODEBASE_PATH) =~ /:/)? $CODEBASE_PATH : "$CWD/$CODEBASE_PATH";
|
| 23 | die "$CODEBASE_PATH does NOT exist, PLEASE check it!!!\n" if (!-d $CODEBASE_PATH);
|
| 24 |
|
| 25 | if ((@CHANGE_SET == 1) && $CHANGE_SET[0] =~ /^\s*@(.*)/)
|
| 26 | {
|
| 27 | @CHANGE_SET = ();
|
| 28 | open (FH, "<$1") or die "can NOT open $1!!!\n";
|
| 29 | while(<FH>)
|
| 30 | {
|
| 31 | chomp;
|
| 32 | push (@CHANGE_SET, $_);
|
| 33 | }
|
| 34 | close (FH);
|
| 35 | &Usage() if (!@CHANGE_SET);
|
| 36 | }
|
| 37 |
|
| 38 | print "[CHANGE_SET]: @CHANGE_SET\n" if ($DEBUG);
|
| 39 |
|
| 40 | chdir($CODEBASE_PATH);
|
| 41 | foreach my $f (@CHANGE_SET)
|
| 42 | {
|
| 43 | die "$f does NOT exist, PLEASE check it!!!\n" if (!-e $f);
|
| 44 | }
|
| 45 |
|
| 46 | open (MF,"<make/pcore/${PROJECT_NAME}_${MODEM_TYPE}(${FLAVOR}).mak") or die "can NOT open make/pcore/${PROJECT_NAME}_${MODEM_TYPE}(${FLAVOR}).mak!!!\n";
|
| 47 | while(<MF>)
|
| 48 | {
|
| 49 | if (/^\s*(\w+)\s*=\s*(\w+)/)
|
| 50 | {
|
| 51 | my $keyname = uc($1);
|
| 52 | $${keyname} = uc($2);
|
| 53 | }
|
| 54 | }
|
| 55 | close (MF);
|
| 56 | my @tmp = &NOTExistDEPMods("build/${PROJECT_NAME}_${MODEM_TYPE}/$FLAVOR/bin/dep",
|
| 57 | &GetSRCMods("build/${PROJECT_NAME}_${MODEM_TYPE}/$FLAVOR/bin/log/infomake.log"));
|
| 58 |
|
| 59 | print "[NOTExistDEPMods]: @tmp\n" if ($DEBUG && @tmp);
|
| 60 |
|
| 61 | if (@tmp)
|
| 62 | {
|
| 63 | print "\n===========================================================\n";
|
| 64 | print "@tmp";
|
| 65 | print "\n===========================================================\n";
|
| 66 | my $msg = "The above " . ((@tmp == 1)? "module's" : "modules'") . " .dep file NOT exists";
|
| 67 |
|
| 68 | if ($InterMode)
|
| 69 | {
|
| 70 | my $flag = 1;
|
| 71 | while(1)
|
| 72 | {
|
| 73 | if ($flag)
|
| 74 | {
|
| 75 | print "$msg!!!\n".
|
| 76 | "WARNING: *** Execute the action \"check_dep/remake_dep/update_dep\" may get the wrong result!!!\n";
|
| 77 | $flag = 0;
|
| 78 | }
|
| 79 | print "Do you really want to go ahead? (Y/N): ";
|
| 80 | my $choice = <STDIN>;
|
| 81 | last if ($choice =~ /^\s*(Y|YES)\s*$/i);
|
| 82 | exit 1 if ($choice =~ /^\s*(N|NO)\s*$/i);
|
| 83 | }
|
| 84 | }
|
| 85 | else
|
| 86 | {
|
| 87 | print "$msg!!!\n".
|
| 88 | "Execute the action \"check_dep/remake_dep/update_dep\" may get the wrong result!!!\n".
|
| 89 | "PLEASE use action \"scan\" to generate" . ((@tmp == 1)? " its dependency file" : " their dependency files") . "!!!\n";
|
| 90 | exit 1;
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 | print "Scanning dependency modules...\n";
|
| 95 | @DEP_MODS = &GetDEPMods("build/${PROJECT_NAME}_${MODEM_TYPE}/$FLAVOR/bin/dep", \@CHANGE_SET);
|
| 96 | if (@DEP_MODS)
|
| 97 | {
|
| 98 | print "===================DEPENDENCY MODULE(S)===================\n";
|
| 99 | print "@DEP_MODS\n";
|
| 100 | }
|
| 101 | else
|
| 102 | {
|
| 103 | print "NOT found dependency modules!!!\n";
|
| 104 | }
|
| 105 |
|
| 106 | $time = time - $time if ($DEBUG);
|
| 107 | print "Time Comsumption: $time\n" if ($DEBUG);
|
| 108 |
|
| 109 |
|
| 110 | sub GetDEPMods
|
| 111 | {
|
| 112 | my ($deppath, $change_set_ref) = @_;
|
| 113 | my @result = ();
|
| 114 | while(<$deppath/*.dep>)
|
| 115 | {
|
| 116 | my $depfile = $_;
|
| 117 | print $depfile,"\n" if ($DEBUG1);
|
| 118 | my $module = basename($_, '.dep');
|
| 119 | next if ($module eq "codegen" || $module eq "resgen" || $module eq "nvram_auto_gen");
|
| 120 | my $tar = '';
|
| 121 | open(FH, "<$depfile") or die "can NOT open $depfile!!!\n";
|
| 122 | while(<FH>)
|
| 123 | {
|
| 124 | chomp;
|
| 125 | next if (/^\s*#/);
|
| 126 | next if ($_ eq '');
|
| 127 | print $_,"\n" if ($DEBUG1);
|
| 128 | $_ =~ s/\//\\/g;
|
| 129 | # if (/^\s*((\w+)\.obj:)?\s+(\w+(\\\w+)*\\\w+\.\w+)(\s+\\)?$/)
|
| 130 | # if (/^\s*((.+)\.obj:)?\s+(.+(\\.+)*\\.+\.\w+)(\s+\\)?$/)
|
| 131 |
|
| 132 | if (/^\s*((\S+)\.(?:obj|o|db):)?\s+(\S+(\\\S+)*\\\S+\.\w+)(\s+\\)?$/)
|
| 133 | {
|
| 134 | # ------------------------------------------------------
|
| 135 | # $2: target, $3: dependency
|
| 136 | # sourcename.obj: dir1\dir2\...\dirN\headername.(h|hpp)
|
| 137 | # ------------------------------------------------------
|
| 138 | # $3: dependency
|
| 139 | # dir1\dir2\...\dirN\headername.(h|hpp)
|
| 140 | # ------------------------------------------------------
|
| 141 | my $dep = $3;
|
| 142 | $dep =~ s/\//\\/g;
|
| 143 | $dep =~ s/\\/\\\\/g;
|
| 144 | my $dep_head = (/^\s*(\S+)\.(?:obj|o|db):/)? 1:0;
|
| 145 | $tar = $1 if ($dep_head);
|
| 146 | print "[target: dependency] \$tar: $tar\n" if ($DEBUG1 && $dep_head);
|
| 147 | print "[dependency] \$tar: $tar\n" if ($DEBUG1 && !$dep_head);
|
| 148 |
|
| 149 | foreach my $i (@$change_set_ref)
|
| 150 | {
|
| 151 | $i =~s/\//\\/g;
|
| 152 | if ($i =~ /$dep/i)
|
| 153 | {
|
| 154 | push (@result, $module) if (!grep(/^$module$/i, @result));
|
| 155 | }
|
| 156 | elsif (basename($i) =~ /^$tar\.(c|cpp|s|arm)\b$/i)
|
| 157 | {
|
| 158 | push (@result, $module) if (!grep(/^$module$/i, @result));
|
| 159 | }
|
| 160 | else
|
| 161 | {
|
| 162 | next;
|
| 163 | }
|
| 164 | }
|
| 165 | }
|
| 166 | elsif ($tar eq '')
|
| 167 | {
|
| 168 | die "Incorrect content in dependency file \"$depfile\"!!!\n";
|
| 169 | }
|
| 170 | else
|
| 171 | {
|
| 172 | print "Match Failed Line: *** ",$_,"\n" if ($DEBUG1);
|
| 173 | next;
|
| 174 | }
|
| 175 | }
|
| 176 | close(FH);
|
| 177 | }
|
| 178 | return @result;
|
| 179 | }
|
| 180 |
|
| 181 | sub GetSRCMods
|
| 182 | {
|
| 183 | my $infomakelog = shift;
|
| 184 | my @allSRCMods = ();
|
| 185 | open (INFOMAKELOG, "<$infomakelog") or die "can NOT open $infomakelog!!!\n";
|
| 186 | while(<INFOMAKELOG>)
|
| 187 | {
|
| 188 | chomp;
|
| 189 | if (/^\s*COMPLIST\s*=\s*(.*)\s*/)
|
| 190 | {
|
| 191 | my $COMPLIST = $1;
|
| 192 | @allSRCMods = split(/\s+/,$COMPLIST);
|
| 193 | last;
|
| 194 | }
|
| 195 | }
|
| 196 | close (INFOMAKELOG);
|
| 197 | return \@allSRCMods;
|
| 198 | }
|
| 199 |
|
| 200 | sub NOTExistDEPMods
|
| 201 | {
|
| 202 | my ($deppath, $arr_ref) = @_;
|
| 203 | my @DEPMods = ();
|
| 204 | foreach my $d (@$arr_ref)
|
| 205 | {
|
| 206 | push (@DEPMods, $d) if (!-e "$deppath/$d.dep");
|
| 207 | }
|
| 208 | return @DEPMods;
|
| 209 | }
|
| 210 |
|
| 211 | sub Usage
|
| 212 | {
|
| 213 | my $script = basename($0);
|
| 214 | print <<"__EOFUSAGE";
|
| 215 |
|
| 216 | Usage: $script CODEBASE PROJECT_NAME MODEM_TYPE <file1[ file2[ ...]] | \@files>
|
| 217 |
|
| 218 | CODEBASE Specify the code path
|
| 219 | PROJECT_NAME Specify project name, such as TIANYU28_DEMO etc...
|
| 220 | MODEM_TYPE Specify modem type, such as l1s, basic, gsm, gprs, umts etc...
|
| 221 | file1 Specify the changed source/header
|
| 222 | \@files Specify more changed sources/headers via a file (change list)
|
| 223 | __EOFUSAGE
|
| 224 | exit 1;
|
| 225 | } |