Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8de3293f0b84c2e529390510f05dd17a6bd46422
[simgrid.git] / buildtools / Cmake / tesh.pl
1 #! /usr/bin/perl -w
2
3 use strict;
4
5 if($#ARGV<0){die "Usage: tesh.pl <options> <teshfile.tesh>\n";}
6 my($line1);
7 my($line2);
8 my($execline);
9 my($ok)=0;
10 my($ok1)=0;
11 my($sort)=0;
12 my($nb_arg)=0;
13 my($result);
14 my(@list1)=();
15 my(@list2)=();
16 my(@list3)=();
17 my(@buffer)=();
18
19 #options
20 do{
21         if($ARGV[$nb_arg] =~ /^--cd$/)
22         {
23                 $nb_arg++;
24                 if(!$ARGV[$nb_arg] or $ARGV[$nb_arg] =~ /^--/){die "Usage: tesh.pl --cd <directory>\n";}
25                 my($directory)=$ARGV[$nb_arg];
26                 if( -e $directory) 
27                 {
28                         chdir("$directory");
29                         print "-- Tesh options   : Change directory to \"$directory\"\n";
30                 }
31                 else
32                 {
33                         die "Directory not found : \"$directory\"\n";
34                 }
35                 $nb_arg++;      
36         }
37         elsif($ARGV[$nb_arg] =~ /^--setenv$/)
38         {
39                 $nb_arg++;
40                 if(!$ARGV[$nb_arg] or $ARGV[$nb_arg] =~ /^--/){die "Usage: tesh.pl --setenv environment_variable\n";}
41                 if(!$ARGV[$nb_arg+1] or $ARGV[$nb_arg+1] =~ /^--/){die "Usage: tesh.pl --setenv environment_variable\n";}
42                 $ENV{$ARGV[$nb_arg]} = "$ENV{$ARGV[$nb_arg]}:$ARGV[$nb_arg+1]";
43                 print "-- Tesh options   : export $ARGV[$nb_arg]=\"$ENV{$ARGV[$nb_arg]}\"\n";
44                 $nb_arg++;
45                 $nb_arg++;
46         }
47         else
48         {
49                 print "-- Tesh options   : Unrecognized option : $ARGV[$nb_arg]\n";
50                 $nb_arg++;
51         }
52 }while(($nb_arg) < $#ARGV);
53
54 #Add current directory to path
55 $ENV{PATH} = "$ENV{PATH}:.";
56
57 #tesh file
58 if(!$ARGV[$nb_arg]){die "tesh.pl <options> <teshfile.tesh>\n";}
59 print "-- Tesh load file : $ARGV[$nb_arg]\n";
60 my($file)=$ARGV[$nb_arg];
61 open SH_LIGNE, $file or die "Unable to open $file. $!\n";
62
63 while(defined($line1=<SH_LIGNE>))
64 {
65                 if($line1 =~ /^\$ mkfile/){     #command line
66                         $line1 =~ s/\$ //g;
67                         chomp $line1;
68                         print "-- Tesh exec_line : $line1\n";
69                         $line1 =~ s/mkfile//g;
70                         `rm -f $line1`;
71                         foreach(@buffer)
72                         {
73                                 `echo $_ >> $line1`;
74                         }
75                         $execline = $line1;
76                         @buffer = ();           
77                 }
78                 elsif($line1 =~ /^\$/){         #command line
79                         $ok = 1;
80                         $line1 =~ s/\$\{srcdir\:\=\.\}/./g;
81                         $line1 =~ s/\$SG_TEST_EXENV//g;
82                         $line1 =~ s/\$SG_EXENV_TEST//g;
83                         $line1 =~ s/\$EXEEXT//g;
84                         $line1 =~ s/\${EXEEXT:=}//g;
85                         $line1 =~ s/^\$\ *//g;
86                         $line1 =~ s/^.\/lua/lua/g;
87                         $line1 =~ s/^.\/ruby/ruby/g;
88                         $line1 =~ s/^.\///g;
89                         $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
90                         chomp $line1;
91                         $execline = $line1;
92                         print "-- Tesh exec_line : $execline\n";
93                         $result=`$execline 2>&1`;
94                         @list1 = split(/\n/,$result);
95                         
96                 }               
97                 elsif($line1 =~ /^\>/){ #expected result line
98                         if($ok == 0){die "No command line$!";}
99                         $ok1 = 1;
100                         $line1 =~ s/^\> //g;
101                         $line1 =~ s/\r//g;
102                         chomp $line1;
103                         push @list2, $line1;
104                 }
105                 elsif($line1 =~ /^\</){ #need to buffer
106                         $line1 =~ s/^\< //g;
107                         $line1 =~ s/\r//g;
108                         chomp $line1;
109                         push @buffer, $line1;
110                 }
111                 elsif($line1 =~ /^p/){  #comment
112                         $line1 =~ s/^p //g;
113                         $line1 =~ s/\r//g;
114                         chomp $line1;
115                         print "-- Tesh comment_line :$line1\n";
116                 }
117                 elsif($line1 =~ /^! output sort/){      #output sort
118                         $sort=1;
119                 }
120                 elsif($line1 =~ /^! include/){  #output sort
121                         die "-- Tesh need include\n";
122                 }
123                 elsif($ok == 1 and $ok1 == 1)
124                 {
125                         if($sort == 1)
126                         {
127                                 @list3 = sort @list1;
128                                 @list1=();
129                                 @list1=@list3;
130                                 @list3=();
131                                 
132                                 @list3 = sort @list2;
133                                 @list2=();
134                                 @list2=@list3;
135                                 @list3=();
136                                 
137                                 $sort=0;
138                         }
139                         while(@list1 or @list2)
140                         {
141                                 $line1 = shift (@list1);
142                                 $line2 = shift (@list2);
143                                 if($line1 eq $line2){}
144                                 else
145                                 {       print "- $line2\n";
146                                         print "+ $line1\n";
147                                         die;}
148                         }
149                         $ok = 0;
150                         $ok1= 0;
151                         @list1=();
152                         @list2=();
153                 }
154 }
155
156 if($ok == 1 and $ok1 == 1)
157 {
158         while(@list1 or @list2)
159         {
160                 $line1 = shift (@list1);
161                 $line2 = shift (@list2);
162                 if($line1 eq $line2){}
163                 else
164                 {       print "- $line1\n";
165                         print "+ $line2\n";
166                         die;}
167         }
168         $ok = 0;
169         $ok1= 0;
170         @list1=();
171         @list2=();
172 }