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.

ISEWrap.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //
  2. // Vivado(TM)
  3. // ISEWrap.js: Vivado Runs Script for WSH 5.1/5.6
  4. // Copyright 1986-1999, 2001-2013,2015 Xilinx, Inc. All Rights Reserved.
  5. //
  6. // GLOBAL VARIABLES
  7. var ISEShell = new ActiveXObject( "WScript.Shell" );
  8. var ISEFileSys = new ActiveXObject( "Scripting.FileSystemObject" );
  9. var ISERunDir = "";
  10. var ISELogFile = "runme.log";
  11. var ISELogFileStr = null;
  12. var ISELogEcho = true;
  13. var ISEOldVersionWSH = false;
  14. // BOOTSTRAP
  15. ISEInit();
  16. //
  17. // ISE FUNCTIONS
  18. //
  19. function ISEInit() {
  20. // 1. RUN DIR setup
  21. var ISEScrFP = WScript.ScriptFullName;
  22. var ISEScrN = WScript.ScriptName;
  23. ISERunDir =
  24. ISEScrFP.substr( 0, ISEScrFP.length - ISEScrN.length - 1 );
  25. // 2. LOG file setup
  26. ISELogFileStr = ISEOpenFile( ISELogFile );
  27. // 3. LOG echo?
  28. var ISEScriptArgs = WScript.Arguments;
  29. for ( var loopi=0; loopi<ISEScriptArgs.length; loopi++ ) {
  30. if ( ISEScriptArgs(loopi) == "-quiet" ) {
  31. ISELogEcho = false;
  32. break;
  33. }
  34. }
  35. // 4. WSH version check
  36. var ISEOptimalVersionWSH = 5.6;
  37. var ISECurrentVersionWSH = WScript.Version;
  38. if ( ISECurrentVersionWSH < ISEOptimalVersionWSH ) {
  39. ISEStdErr( "" );
  40. ISEStdErr( "Warning: ExploreAhead works best with Microsoft WSH " +
  41. ISEOptimalVersionWSH + " or higher. Downloads" );
  42. ISEStdErr( " for upgrading your Windows Scripting Host can be found here: " );
  43. ISEStdErr( " http://msdn.microsoft.com/downloads/list/webdev.asp" );
  44. ISEStdErr( "" );
  45. ISEOldVersionWSH = true;
  46. }
  47. }
  48. function ISEStep( ISEProg, ISEArgs ) {
  49. // CHECK for a STOP FILE
  50. if ( ISEFileSys.FileExists(ISERunDir + "/.stop.rst") ) {
  51. ISEStdErr( "" );
  52. ISEStdErr( "*** Halting run - EA reset detected ***" );
  53. ISEStdErr( "" );
  54. WScript.Quit( 1 );
  55. }
  56. // WRITE STEP HEADER to LOG
  57. ISEStdOut( "" );
  58. ISEStdOut( "*** Running " + ISEProg );
  59. ISEStdOut( " with args " + ISEArgs );
  60. ISEStdOut( "" );
  61. // LAUNCH!
  62. var ISEExitCode = ISEExec( ISEProg, ISEArgs );
  63. if ( ISEExitCode != 0 ) {
  64. WScript.Quit( ISEExitCode );
  65. }
  66. }
  67. function ISEExec( ISEProg, ISEArgs ) {
  68. var ISEStep = ISEProg;
  69. if (ISEProg == "realTimeFpga" || ISEProg == "planAhead" || ISEProg == "vivado") {
  70. ISEProg += ".bat";
  71. }
  72. var ISECmdLine = ISEProg + " " + ISEArgs;
  73. var ISEExitCode = 1;
  74. if ( ISEOldVersionWSH ) { // WSH 5.1
  75. // BEGIN file creation
  76. ISETouchFile( ISEStep, "begin" );
  77. // LAUNCH!
  78. ISELogFileStr.Close();
  79. ISECmdLine =
  80. "%comspec% /c " + ISECmdLine + " >> " + ISELogFile + " 2>&1";
  81. ISEExitCode = ISEShell.Run( ISECmdLine, 0, true );
  82. ISELogFileStr = ISEOpenFile( ISELogFile );
  83. } else { // WSH 5.6
  84. // LAUNCH!
  85. ISEShell.CurrentDirectory = ISERunDir;
  86. // Redirect STDERR to STDOUT
  87. ISECmdLine = "%comspec% /c " + ISECmdLine + " 2>&1";
  88. var ISEProcess = ISEShell.Exec( ISECmdLine );
  89. // BEGIN file creation
  90. var wbemFlagReturnImmediately = 0x10;
  91. var wbemFlagForwardOnly = 0x20;
  92. var objWMIService = GetObject ("winmgmts:{impersonationLevel=impersonate, (Systemtime)}!//./root/cimv2");
  93. var processor = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);
  94. var computerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
  95. var NOC = 0;
  96. var NOLP = 0;
  97. var TPM = 0;
  98. var cpuInfos = new Enumerator(processor);
  99. for(;!cpuInfos.atEnd(); cpuInfos.moveNext()) {
  100. var cpuInfo = cpuInfos.item();
  101. NOC += cpuInfo.NumberOfCores;
  102. NOLP += cpuInfo.NumberOfLogicalProcessors;
  103. }
  104. var csInfos = new Enumerator(computerSystem);
  105. for(;!csInfos.atEnd(); csInfos.moveNext()) {
  106. var csInfo = csInfos.item();
  107. TPM += csInfo.TotalPhysicalMemory;
  108. }
  109. var ISEHOSTCORE = NOLP
  110. var ISEMEMTOTAL = TPM
  111. var ISENetwork = WScript.CreateObject( "WScript.Network" );
  112. var ISEHost = ISENetwork.ComputerName;
  113. var ISEUser = ISENetwork.UserName;
  114. var ISEPid = ISEProcess.ProcessID;
  115. var ISEBeginFile = ISEOpenFile( "." + ISEStep + ".begin.rst" );
  116. ISEBeginFile.WriteLine( "<?xml version=\"1.0\"?>" );
  117. ISEBeginFile.WriteLine( "<ProcessHandle Version=\"1\" Minor=\"0\">" );
  118. ISEBeginFile.WriteLine( " <Process Command=\"" + ISEProg +
  119. "\" Owner=\"" + ISEUser +
  120. "\" Host=\"" + ISEHost +
  121. "\" Pid=\"" + ISEPid +
  122. "\" HostCore=\"" + ISEHOSTCORE +
  123. "\" HostMemory=\"" + ISEMEMTOTAL +
  124. "\">" );
  125. ISEBeginFile.WriteLine( " </Process>" );
  126. ISEBeginFile.WriteLine( "</ProcessHandle>" );
  127. ISEBeginFile.Close();
  128. var ISEOutStr = ISEProcess.StdOut;
  129. var ISEErrStr = ISEProcess.StdErr;
  130. // WAIT for ISEStep to finish
  131. while ( ISEProcess.Status == 0 ) {
  132. // dump stdout then stderr - feels a little arbitrary
  133. while ( !ISEOutStr.AtEndOfStream ) {
  134. ISEStdOut( ISEOutStr.ReadLine() );
  135. }
  136. WScript.Sleep( 100 );
  137. }
  138. ISEExitCode = ISEProcess.ExitCode;
  139. }
  140. ISELogFileStr.Close();
  141. // END/ERROR file creation
  142. if ( ISEExitCode != 0 ) {
  143. ISETouchFile( ISEStep, "error" );
  144. } else {
  145. ISETouchFile( ISEStep, "end" );
  146. }
  147. return ISEExitCode;
  148. }
  149. //
  150. // UTILITIES
  151. //
  152. function ISEStdOut( ISELine ) {
  153. ISELogFileStr.WriteLine( ISELine );
  154. if ( ISELogEcho ) {
  155. WScript.StdOut.WriteLine( ISELine );
  156. }
  157. }
  158. function ISEStdErr( ISELine ) {
  159. ISELogFileStr.WriteLine( ISELine );
  160. if ( ISELogEcho ) {
  161. WScript.StdErr.WriteLine( ISELine );
  162. }
  163. }
  164. function ISETouchFile( ISERoot, ISEStatus ) {
  165. var ISETFile =
  166. ISEOpenFile( "." + ISERoot + "." + ISEStatus + ".rst" );
  167. ISETFile.Close();
  168. }
  169. function ISEOpenFile( ISEFilename ) {
  170. // This function has been updated to deal with a problem seen in CR #870871.
  171. // In that case the user runs a script that runs impl_1, and then turns around
  172. // and runs impl_1 -to_step write_bitstream. That second run takes place in
  173. // the same directory, which means we may hit some of the same files, and in
  174. // particular, we will open the runme.log file. Even though this script closes
  175. // the file (now), we see cases where a subsequent attempt to open the file
  176. // fails. Perhaps the OS is slow to release the lock, or the disk comes into
  177. // play? In any case, we try to work around this by first waiting if the file
  178. // is already there for an arbitrary 5 seconds. Then we use a try-catch block
  179. // and try to open the file 10 times with a one second delay after each attempt.
  180. // Again, 10 is arbitrary. But these seem to stop the hang in CR #870871.
  181. // If there is an unrecognized exception when trying to open the file, we output
  182. // an error message and write details to an exception.log file.
  183. var ISEFullPath = ISERunDir + "/" + ISEFilename;
  184. if (ISEFileSys.FileExists(ISEFullPath)) {
  185. // File is already there. This could be a problem. Wait in case it is still in use.
  186. WScript.Sleep(5000);
  187. }
  188. var i;
  189. for (i = 0; i < 10; ++i) {
  190. try {
  191. return ISEFileSys.OpenTextFile(ISEFullPath, 8, true);
  192. } catch (exception) {
  193. var error_code = exception.number & 0xFFFF; // The other bits are a facility code.
  194. if (error_code == 52) { // 52 is bad file name or number.
  195. // Wait a second and try again.
  196. WScript.Sleep(1000);
  197. continue;
  198. } else {
  199. WScript.StdErr.WriteLine("ERROR: Exception caught trying to open file " + ISEFullPath);
  200. var exceptionFilePath = ISERunDir + "/exception.log";
  201. if (!ISEFileSys.FileExists(exceptionFilePath)) {
  202. WScript.StdErr.WriteLine("See file " + exceptionFilePath + " for details.");
  203. var exceptionFile = ISEFileSys.OpenTextFile(exceptionFilePath, 8, true);
  204. exceptionFile.WriteLine("ERROR: Exception caught trying to open file " + ISEFullPath);
  205. exceptionFile.WriteLine("\tException name: " + exception.name);
  206. exceptionFile.WriteLine("\tException error code: " + error_code);
  207. exceptionFile.WriteLine("\tException message: " + exception.message);
  208. exceptionFile.Close();
  209. }
  210. throw exception;
  211. }
  212. }
  213. }
  214. // If we reached this point, we failed to open the file after 10 attempts.
  215. // We need to error out.
  216. WScript.StdErr.WriteLine("ERROR: Failed to open file " + ISEFullPath);
  217. WScript.Quit(1);
  218. }