Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
6.2 KiB

  1. #!perl
  2. use strict;
  3. BEGIN {use File::Basename; push @INC, dirname($0); }
  4. require "valve_perl_helpers.pl";
  5. sub PrintCleanPerforceOutput
  6. {
  7. my $line;
  8. while( $line = shift )
  9. {
  10. if( $line =~ m/currently opened/i )
  11. {
  12. next;
  13. }
  14. if( $line =~ m/already opened for edit/i )
  15. {
  16. next;
  17. }
  18. if( $line =~ m/also opened/i )
  19. {
  20. next;
  21. }
  22. if( $line =~ m/add of existing file/i )
  23. {
  24. next;
  25. }
  26. print $line;
  27. }
  28. }
  29. # HACK!!!! Need to pass something in to do this rather than hard coding.
  30. sub NormalizePerforceFilename
  31. {
  32. my $line = shift;
  33. # remove newlines.
  34. $line =~ s/\n//;
  35. # downcase.
  36. $line =~ tr/[A-Z]/[a-z]/;
  37. # backslash to forwardslash
  38. $line =~ s,\\,/,g;
  39. # for inc files HACK!
  40. $line =~ s/^.*(fxctmp9.*)/$1/i;
  41. $line =~ s/^.*(vshtmp9.*)/$1/i;
  42. # for vcs files. HACK!
  43. $line =~ s,^.*game/platform/shaders/,,i;
  44. return $line;
  45. }
  46. # COMMAND-LINE ARGUMENTS
  47. my $x360 = 0;
  48. my $ps3 = 0;
  49. my $filename = shift;
  50. if( $filename =~ m/-x360/i )
  51. {
  52. $x360 = 1;
  53. $filename = shift;
  54. }
  55. elsif( $filename =~ m/-ps3/i )
  56. {
  57. $ps3 = 1;
  58. $filename = shift;
  59. }
  60. my $changelistname = shift;
  61. my $perforcebasepath = shift;
  62. my $diffpath = join " ", @ARGV;
  63. #print STDERR "\$filename: $filename\n";
  64. #print STDERR "\$changelistname: $changelistname\n";
  65. #print STDERR "\$perforcebasepath: $perforcebasepath\n";
  66. #print STDERR "\$diffpath: $diffpath\n";
  67. # Read the input file list before changing to the perforce directory.
  68. open FILELIST, "<$filename";
  69. my @inclist = <FILELIST>;
  70. close FILELIST;
  71. # change from the perforce directory so that our client will be correct from here out.
  72. #print STDERR "chdir $perforcebasepath\n";
  73. chdir $perforcebasepath || die "can't cd to $perforcebasepath";
  74. #print "inclist before @inclist\n";
  75. # get rid of newlines and fix slashes
  76. @inclist =
  77. map
  78. {
  79. $_ =~ s,_tmp,,g; # remove _tmp so that we check out in the proper directory
  80. $_ =~ s,\\,/,g; # backslash to forwardslash
  81. $_ =~ s/\n//g; # remove newlines
  82. $_ =~ tr/[A-Z]/[a-z]/; # downcase
  83. # $_ =~ s,.*platform/shaders/,,i;
  84. # $_ =~ s,$perforcebasepath/,,i;
  85. $_ =~ s,../../../game/platform/shaders/,,i; # hack. . .really want something here that works generically.
  86. $_
  87. } @inclist;
  88. #print "inclist after @inclist\n";
  89. my $prevline;
  90. my @outlist;
  91. foreach $_ ( sort( @inclist ) )
  92. {
  93. next if( defined( $prevline ) && $_ eq $prevline );
  94. $prevline = $_;
  95. push @outlist, $_;
  96. }
  97. @inclist = @outlist;
  98. #print "\@inclist: @inclist\n";
  99. # Get list of files on the client
  100. # -sl Every unopened file, along with the status of
  101. # 'same, 'diff', or 'missing' as compared to its
  102. # revision in the depot.
  103. my @unopenedlist = &RunCommand( "p4 diff -sl $diffpath" );
  104. #print "\@unopenedlist: @unopenedlist\n";
  105. my %sameunopened;
  106. my %diffunopened;
  107. my %missingunopened;
  108. my $line;
  109. foreach $line ( @unopenedlist )
  110. {
  111. my $same = 0;
  112. my $diff = 0;
  113. my $missing = 0;
  114. if( $line =~ s/^same //i )
  115. {
  116. $same = 1;
  117. }
  118. elsif( $line =~ s/^diff //i )
  119. {
  120. $diff = 1;
  121. }
  122. elsif( $line =~ s/^missing //i )
  123. {
  124. $missing = 1;
  125. }
  126. else
  127. {
  128. die "checkoutincfiles.pl don't understand p4 diff -sl results: $line\n";
  129. }
  130. # clean up the filename
  131. # print "before: $line\n" if $line =~ m/aftershock_vs20/i;
  132. $line = NormalizePerforceFilename( $line );
  133. # print "after: \"$line\"\n" if $line =~ m/aftershock_vs20/i;
  134. # if( $line =~ m/aftershock/i )
  135. # {
  136. # print "unopenedlist: $line same: $same diff: $diff missing: $missing\n";
  137. # }
  138. # Save off the results for each line so that we can query them later.
  139. if( $same )
  140. {
  141. $sameunopened{$line} = 1;
  142. }
  143. elsif( $diff )
  144. {
  145. $diffunopened{$line} = 1;
  146. }
  147. elsif( $missing )
  148. {
  149. $missingunopened{$line} = 1;
  150. }
  151. else
  152. {
  153. die;
  154. }
  155. }
  156. # -sr Opened files that are the same as the revision in the
  157. # depot.
  158. my @openedbutsame = &RunCommand( "p4 diff -sr $diffpath" );
  159. my %sameopened;
  160. foreach $line ( @openedbutsame )
  161. {
  162. if( $line =~ m/not opened on this client/i )
  163. {
  164. next;
  165. }
  166. # clean up the filename
  167. # print "before: $line\n" if $line =~ m/aftershock_vs20/i;
  168. $line = NormalizePerforceFilename( $line );
  169. # print "after: $line\n" if $line =~ m/aftershock_vs20/i;
  170. # if( $line =~ m/aftershock/i )
  171. # {
  172. # print STDERR "sameopened: $line\n";
  173. # }
  174. $sameopened{$line} = 1;
  175. }
  176. my @sameunopened;
  177. my @revert;
  178. my @edit;
  179. my @add;
  180. foreach $line ( @inclist )
  181. {
  182. if( defined( $sameunopened{$line} ) )
  183. {
  184. push @sameunopened, $line;
  185. }
  186. elsif( defined( $sameopened{$line} ) )
  187. {
  188. push @revert, $line;
  189. }
  190. elsif( defined( $diffunopened{$line} ) )
  191. {
  192. push @edit, $line;
  193. }
  194. elsif( defined( $missingunopened{$line} ) )
  195. {
  196. printf STDERR "p4autocheckout.pl: $line missing\n";
  197. }
  198. else
  199. {
  200. push @add, $line;
  201. }
  202. }
  203. #print "\@sameunopened = @sameunopened\n";
  204. #print "\@revert = @revert\n";
  205. #print "\@edit = @edit\n";
  206. #print "\@add = @add\n";
  207. # Get the changelist number for the named changelist if we are actually going to edit or add anything.
  208. # We don't need it for deleting.
  209. my $changelistarg = "";
  210. # Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist.
  211. my $changelistnumber = `valve_p4_create_changelist.cmd . \"$changelistname\"`;
  212. # Get rid of the newline
  213. $changelistnumber =~ s/\n//g;
  214. #print STDERR "changelistnumber: $changelistnumber\n";
  215. if( $changelistnumber != 0 )
  216. {
  217. $changelistarg = "-c $changelistnumber"
  218. }
  219. #my %sameunopened;
  220. #my %diffunopened;
  221. #my %missingunopened;
  222. #my %sameopened;
  223. if( scalar @edit )
  224. {
  225. while( scalar @edit )
  226. {
  227. # Grab 10 files at a time so that we don't blow cmd.exe line limits.
  228. my @files = splice @edit, 0, 10;
  229. my $cmd = "p4 edit $changelistarg @files";
  230. # print STDERR $cmd . "\n";
  231. my @results = &RunCommand( $cmd );
  232. # print STDERR @results;
  233. &PrintCleanPerforceOutput( @results );
  234. }
  235. }
  236. if( scalar @revert )
  237. {
  238. while( scalar @revert )
  239. {
  240. # Grab 10 files at a time so that we don't blow cmd.exe line limits.
  241. my @files = splice @revert, 0, 10;
  242. my $cmd = "p4 revert @files";
  243. # print STDERR $cmd . "\n";
  244. my @results = &RunCommand( $cmd );
  245. &PrintCleanPerforceOutput( @results );
  246. }
  247. }
  248. if( scalar @add )
  249. {
  250. while( scalar @add )
  251. {
  252. # Grab 10 files at a time so that we don't blow cmd.exe line limits.
  253. my @files = splice @add, 0, 10;
  254. my $cmd = "p4 add $changelistarg @files";
  255. # print STDERR $cmd . "\n";
  256. my @results = &RunCommand( $cmd );
  257. # print STDERR "@results\n";
  258. &PrintCleanPerforceOutput( @results );
  259. }
  260. }