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.

309 lines
6.0 KiB

  1. #!perl
  2. #
  3. # Runs swig to compute dependencies and update a .dep file
  4. #
  5. # Expects to be in $SRCDIR/vpc_scripts/swig_auto_dme.pl
  6. #
  7. # As paths are computed relative to the script location
  8. #
  9. use strict;
  10. use File::Basename;
  11. use File::Spec;
  12. use File::Copy;
  13. use File::Path;
  14. use Cwd;
  15. use Getopt::Std;
  16. use File::Path;
  17. our $sScriptPath = File::Spec->rel2abs( File::Spec->canonpath( $0 ) );
  18. our ( $sScript, $sVpcDir ) = fileparse( ${sScriptPath} );
  19. our $sPre = "[" . $sScript . "]";
  20. our $srcDir = File::Spec->catdir( $sVpcDir, '..' );
  21. our $opt_c = 0;
  22. our $opt_h = 0;
  23. our $opt_f = 0;
  24. our $opt_q = 0;
  25. our $opt_v = 0;
  26. getopts( 'cfhqv' );
  27. our $swigOutDir = shift( @ARGV );
  28. main();
  29. #
  30. #
  31. #
  32. sub main
  33. {
  34. if ( $opt_h )
  35. {
  36. print <<"EOF";
  37. ${sScript}(1)
  38. NAME
  39. ${sScript} - Updates swig auto_<elementlib>.i files
  40. auto_<elementlib>.i files are files generated from datamodel
  41. elementlib.cpp files. The macro USING_ELEMENT_FACTORY is
  42. used to define various swig bindings for all of the elements
  43. in the src/public/<elementlib>/<elementlib>.cpp file
  44. SYNOPSYS
  45. ${srcDir}/devtools/runperl ${sScriptPath} [ -h ] | [ -c ] | < [ -f ] [ -q ] [ -v ] out_sub_dir swigfile >
  46. OPTIONS
  47. -h Print this message
  48. -c Clean SWIG files from projects
  49. -f Force update of projects
  50. -q Produce no output (unless -v is also specified)
  51. -v Produce more output (overrides -q)
  52. swigfile
  53. EOF
  54. exit 0;
  55. }
  56. if ( $#ARGV < 0 )
  57. {
  58. die( "No swigfile specified\n" );
  59. }
  60. my $swigFile = shift( @ARGV );
  61. if ( ! -d $srcDir )
  62. {
  63. die( "Can't Find src directory: ${srcDir}\n" );
  64. }
  65. if ( $opt_v )
  66. {
  67. print "${sPre} * Script: " . $sScriptPath . "\n";
  68. print "${sPre} * vpc_scripts: " . $sVpcDir . "\n";
  69. print "${sPre} * SRC: " . $srcDir . "\n";
  70. print "${sPre} * out: " . $swigOutDir . "\n";
  71. print "${sPre} * swigfile: " . $swigFile . "\n";
  72. }
  73. if ( $opt_c )
  74. {
  75. Clean( $swigOutDir );
  76. }
  77. else
  78. {
  79. ComputeAutoDme( $swigOutDir, $swigFile );
  80. }
  81. }
  82. #
  83. # Cleans up
  84. #
  85. sub Clean
  86. {
  87. my $dir = shift( @_ );
  88. if ( -d $dir )
  89. {
  90. if ( !$opt_q || $opt_v )
  91. {
  92. print( "${sPre} rmtree " . $dir . "\n" );
  93. }
  94. rmtree( $dir );
  95. }
  96. }
  97. #
  98. # Creates the output directory if necessary
  99. #
  100. sub CreateOutDir
  101. {
  102. my $dir = shift( @_ );
  103. if ( ! -d $dir )
  104. {
  105. print( "${sPre} mkdir ${dir}\n" );
  106. mkpath( $dir );
  107. }
  108. if ( ! -d $dir )
  109. {
  110. die( "${sPre} ERROR - Couldn't Create ${dir}\n" );
  111. }
  112. if ( ! -w $dir )
  113. {
  114. die( "${sPre} ERROR - ${dir} Isn't Writable\n" );
  115. }
  116. return $dir;
  117. }
  118. #
  119. # Compute auto DME list
  120. #
  121. sub ComputeAutoDme
  122. {
  123. my $outSubDir = shift( @_ );
  124. my $swigFile = shift( @_ );
  125. #
  126. # Only create auto_*.i files for these element libraries
  127. #
  128. my %autos = ( "movieobjects", 1, "mdlobjects", 1, "materialobjects", 1, "sfmobjects", 1, "worldobjects", 1 );
  129. if ( !$autos{ $swigFile } )
  130. {
  131. return;
  132. }
  133. my $hFile = File::Spec->rel2abs( File::Spec->catdir( ${srcDir}, "public", ${swigFile}, ${swigFile} . ".h" ) );
  134. my @dependencies = (
  135. $sScriptPath,
  136. $hFile
  137. );
  138. my $bUpdate = $opt_f;
  139. my $maxTime = 0;
  140. my $dependency;
  141. foreach $dependency ( @dependencies )
  142. {
  143. if ( -r $dependency )
  144. {
  145. my ( $dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks ) = stat( $dependency );
  146. if ( $mtime >= $maxTime )
  147. {
  148. $maxTime = $mtime;
  149. }
  150. }
  151. else
  152. {
  153. $bUpdate = 1;
  154. }
  155. }
  156. my $autoFile = File::Spec->catdir( CreateOutDir( $outSubDir ), "auto_${swigFile}.i" );
  157. if ( -r $autoFile )
  158. {
  159. my ( $dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks ) = stat( $autoFile );
  160. if ( $mtime < $maxTime )
  161. {
  162. $bUpdate = 1;
  163. }
  164. else
  165. {
  166. # If this script is run but gets here, it means that the build system wanted to run this because some other dependency changed
  167. # but the actual auto file is ok because this script itself nor the header it parses has changed, so just update the last access
  168. # time of auto_*.i
  169. my $tCurrent = time;
  170. utime $tCurrent, $tCurrent, $autoFile;
  171. my ( $dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks ) = stat( $autoFile );
  172. if ( $opt_v )
  173. {
  174. print "${sPre} - Touch " . localtime( $mtime ) . " : " . ${autoFile} . "\n";
  175. }
  176. else
  177. {
  178. print "${sPre} Touch " . localtime( $mtime ) . " : " . ${autoFile} . "\n";
  179. }
  180. }
  181. }
  182. else
  183. {
  184. $bUpdate = 1;
  185. }
  186. if ( $bUpdate )
  187. {
  188. open OUT, ">${autoFile}" || die( "${sPre} ERROR: Can't Open ${autoFile} For Writing" );
  189. print OUT <<"EOF";
  190. //
  191. // This file is a processed version of:
  192. // ${hFile}
  193. //
  194. // It is created automatically by:
  195. // ${sScriptPath}
  196. //
  197. // During the Post-Build step of: ${swigFile}
  198. //
  199. %{
  200. #include "datamodel/dmattribute.h"
  201. #include "${swigFile}/${swigFile}.h"
  202. PyObject *NewSwigDmElement( CDmElement *pDmElement );
  203. %}
  204. %import( package="vs", module="datamodel" ) "datamodel/idatamodel.h"
  205. %import( package="vs", module="datamodel" ) "datamodel/dmelement.h"
  206. %import( package="vs", module="datamodel" ) "datamodel/dmattribute.h"
  207. EOF
  208. if ( ${swigFile} =~ /mdlobjects/i )
  209. {
  210. print OUT <<"EOF";
  211. %import( package="vs", module="movieobjects" ) "movieobjects/dmeshape.h"
  212. %import( package="vs", module="movieobjects" ) "movieobjects/dmedag.h"
  213. %import( package="vs", module="movieobjects" ) "movieobjects/dmejoint.h"
  214. EOF
  215. }
  216. print OUT "\n";
  217. print OUT <<"EOF";
  218. %include "../swig_common/swig_dmelement_wrap.i"
  219. %include "${swigFile}/${swigFile}.cpp"
  220. EOF
  221. if ( ${swigFile} =~ /movieobjects/ )
  222. {
  223. print OUT <<"EOF";
  224. %include "${swigFile}/${swigFile}_compiletools.cpp"
  225. EOF
  226. }
  227. print OUT "\n";
  228. open IN, "${hFile}" || die( "${sPre} ERROR: Can't Open ${hFile} For Reading" );
  229. while ( <IN> )
  230. {
  231. chomp;
  232. if ( /^\s*#include\s("[^"]+")/ )
  233. {
  234. print OUT "%include $1\n"
  235. }
  236. }
  237. close IN;
  238. close OUT;
  239. if ( !$opt_q || $opt_v )
  240. {
  241. my ( $dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks ) = stat( $autoFile );
  242. if ( $opt_v )
  243. {
  244. print "${sPre} - Update " . localtime( $mtime ) . " : " . ${autoFile} . "\n";
  245. }
  246. else
  247. {
  248. print "${sPre} Update " . localtime( $mtime ) . " : " . ${autoFile} . "\n";
  249. }
  250. }
  251. }
  252. }