Team Fortress 2 Source Code as on 22/4/2020
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.

172 lines
3.5 KiB

  1. BEGIN {use File::Basename; push @INC, dirname($0); }
  2. require "valve_perl_helpers.pl";
  3. use Cwd;
  4. use String::CRC32;
  5. sub ReadInputFileWithIncludes
  6. {
  7. local( $filename ) = shift;
  8. local( *INPUT );
  9. local( $output );
  10. open INPUT, "<$filename" || die;
  11. local( $line );
  12. local( $linenum ) = 1;
  13. while( $line = <INPUT> )
  14. {
  15. if( $line =~ m/\#include\s+\"(.*)\"/i )
  16. {
  17. $output.= ReadInputFileWithIncludes( $1 );
  18. }
  19. else
  20. {
  21. $output .= $line;
  22. }
  23. }
  24. close INPUT;
  25. return $output;
  26. }
  27. sub PatchCRC
  28. {
  29. my $filename = shift;
  30. my $crc = shift;
  31. # print STDERR "PatchCRC( $filename, $crc )\n";
  32. local( *FP );
  33. open FP, "+<$filename" || die;
  34. binmode( FP );
  35. seek FP, 6 * 4, 0;
  36. my $uInt = "I";
  37. if( $filename =~ m/360/ )
  38. {
  39. $uInt = "N";
  40. }
  41. print FP pack $uInt, $crc;
  42. close FP;
  43. }
  44. my $txtfilename = shift;
  45. my $arg = shift;
  46. my $is360 = 0;
  47. my $platformextension = "";
  48. if( $arg =~ m/-x360/i )
  49. {
  50. $is360 = 1;
  51. $platformextension = ".360";
  52. }
  53. # Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist.
  54. my $changelistnumber = `valve_p4_create_changelist.cmd ..\\..\\..\\game\\hl2\\shaders \"Shader Auto Checkout VCS\"`;
  55. # Get rid of the newline
  56. $changelistnumber =~ s/\n//g;
  57. my $changelistarg = "";
  58. if( $changelistnumber != 0 )
  59. {
  60. $changelistarg = "-c $changelistnumber"
  61. }
  62. open TXTFILE, "<$txtfilename";
  63. my $src;
  64. my $dst;
  65. while( $src = <TXTFILE> )
  66. {
  67. # get rid of comments
  68. $src =~ s,//.*,,g;
  69. # skip blank lines
  70. if( $src =~ m/^\s*$/ )
  71. {
  72. next;
  73. }
  74. # Get rid of newlines.
  75. $src =~ s/\n//g;
  76. # Save off the shader source filename.
  77. my $shadersrcfilename = $src;
  78. $shadersrcfilename =~ s/-----.*$//;
  79. # use only target basename.
  80. $src =~ s/^.*-----//;
  81. # where the binary vcs file is
  82. my $spath = "";
  83. if ( $shadersrcfilename =~ m@\.fxc@i )
  84. {
  85. $spath = "shaders\\fxc\\";
  86. }
  87. if ( $shadersrcfilename =~ m@\.vsh@i )
  88. {
  89. $spath = "shaders\\vsh\\";
  90. }
  91. if ( $shadersrcfilename =~ m@\.psh@i )
  92. {
  93. $spath = "shaders\\psh\\";
  94. }
  95. # make the source have path and extension
  96. $src = $spath . $src . $platformextension . ".vcs";
  97. # build the dest filename.
  98. $dst = $src;
  99. $dst =~ s/shaders\\/..\\..\\..\\game\\hl2\\shaders\\/i;
  100. # Does the dst exist?
  101. my $dstexists = -e $dst;
  102. my $srcexists = -e $src;
  103. # What are the time stamps for the src and dst?
  104. my $srcmodtime = ( stat $src )[9];
  105. my $dstmodtime = ( stat $dst )[9];
  106. # Write $dst to a file so that we can do perforce stuff to it later.
  107. local( *VCSLIST );
  108. open VCSLIST, ">>vcslist.txt" || die;
  109. print VCSLIST $dst . "\n";
  110. close VCSLIST;
  111. # Open for edit or add if different than what is in perforce already.
  112. if( !$dstexists || ( $srcmodtime != $dstmodtime ) )
  113. {
  114. if ( $srcexists && $shadersrcfilename =~ m@\.fxc@i )
  115. {
  116. # Get the CRC for the source file.
  117. my $srccode = ReadInputFileWithIncludes( $shadersrcfilename );
  118. my $crc = crc32( $srccode );
  119. # Patch the source VCS file with the CRC32 of the source code used to build that file.
  120. PatchCRC( $src, $crc );
  121. }
  122. # Make the target vcs writable if it exists
  123. if( $dstexists )
  124. {
  125. MakeFileWritable( $dst );
  126. }
  127. my $dir = $dst;
  128. $dir =~ s,([^/\\]*$),,; # rip the filename off the end
  129. my $filename = $1;
  130. # create the target directory if it doesn't exist
  131. if( !$dstexists )
  132. {
  133. &MakeDirHier( $dir, 0777 );
  134. }
  135. # copy the file to its targets. . . we want to see STDERR here if there is an error.
  136. my $cmd = "copy $src $dst > nul";
  137. # print STDERR "$cmd\n";
  138. system $cmd;
  139. MakeFileReadOnly( $dst );
  140. }
  141. }
  142. close TXTFILE;