3 // ISEWrap.js: Vivado Runs Script for WSH 5.1/5.6
4 // Copyright 1986-1999, 2001-2013,2015 Xilinx, Inc. All Rights Reserved.
8 var ISEShell
= new ActiveXObject( "WScript.Shell" );
9 var ISEFileSys
= new ActiveXObject( "Scripting.FileSystemObject" );
11 var ISELogFile
= "runme.log";
12 var ISELogFileStr
= null;
13 var ISELogEcho
= true;
14 var ISEOldVersionWSH
= false;
29 var ISEScrFP
= WScript
.ScriptFullName
;
30 var ISEScrN
= WScript
.ScriptName
;
32 ISEScrFP
.substr( 0, ISEScrFP
.length
- ISEScrN
.length
- 1 );
35 ISELogFileStr
= ISEOpenFile( ISELogFile
);
38 var ISEScriptArgs
= WScript
.Arguments
;
39 for ( var loopi
=0; loopi
<ISEScriptArgs
.length
; loopi
++ ) {
40 if ( ISEScriptArgs(loopi
) == "-quiet" ) {
46 // 4. WSH version check
47 var ISEOptimalVersionWSH
= 5.6;
48 var ISECurrentVersionWSH
= WScript
.Version
;
49 if ( ISECurrentVersionWSH
< ISEOptimalVersionWSH
) {
52 ISEStdErr( "Warning: ExploreAhead works best with Microsoft WSH " +
53 ISEOptimalVersionWSH
+ " or higher. Downloads" );
54 ISEStdErr( " for upgrading your Windows Scripting Host can be found here: " );
55 ISEStdErr( " http://msdn.microsoft.com/downloads/list/webdev.asp" );
58 ISEOldVersionWSH
= true;
63 function ISEStep( ISEProg
, ISEArgs
) {
65 // CHECK for a STOP FILE
66 if ( ISEFileSys
.FileExists(ISERunDir
+ "/.stop.rst") ) {
68 ISEStdErr( "*** Halting run - EA reset detected ***" );
73 // WRITE STEP HEADER to LOG
75 ISEStdOut( "*** Running " + ISEProg
);
76 ISEStdOut( " with args " + ISEArgs
);
80 var ISEExitCode
= ISEExec( ISEProg
, ISEArgs
);
81 if ( ISEExitCode
!= 0 ) {
82 WScript
.Quit( ISEExitCode
);
87 function ISEExec( ISEProg
, ISEArgs
) {
89 var ISEStep
= ISEProg
;
90 if (ISEProg
== "realTimeFpga" || ISEProg
== "planAhead" || ISEProg
== "vivado") {
94 var ISECmdLine
= ISEProg
+ " " + ISEArgs
;
97 if ( ISEOldVersionWSH
) { // WSH 5.1
99 // BEGIN file creation
100 ISETouchFile( ISEStep
, "begin" );
103 ISELogFileStr
.Close();
105 "%comspec% /c " + ISECmdLine
+ " >> " + ISELogFile
+ " 2>&1";
106 ISEExitCode
= ISEShell
.Run( ISECmdLine
, 0, true );
107 ISELogFileStr
= ISEOpenFile( ISELogFile
);
112 ISEShell
.CurrentDirectory
= ISERunDir
;
114 // Redirect STDERR to STDOUT
115 ISECmdLine
= "%comspec% /c " + ISECmdLine
+ " 2>&1";
116 var ISEProcess
= ISEShell
.Exec( ISECmdLine
);
118 // BEGIN file creation
119 var wbemFlagReturnImmediately
= 0x10;
120 var wbemFlagForwardOnly
= 0x20;
121 var objWMIService
= GetObject ("winmgmts:{impersonationLevel=impersonate, (Systemtime)}!//./root/cimv2");
122 var processor
= objWMIService
.ExecQuery("SELECT * FROM Win32_Processor", "WQL",wbemFlagReturnImmediately
| wbemFlagForwardOnly
);
123 var computerSystem
= objWMIService
.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately
| wbemFlagForwardOnly
);
128 var cpuInfos
= new Enumerator(processor
);
129 for(;!cpuInfos
.atEnd(); cpuInfos
.moveNext()) {
130 var cpuInfo
= cpuInfos
.item();
131 NOC
+= cpuInfo
.NumberOfCores
;
132 NOLP
+= cpuInfo
.NumberOfLogicalProcessors
;
134 var csInfos
= new Enumerator(computerSystem
);
135 for(;!csInfos
.atEnd(); csInfos
.moveNext()) {
136 var csInfo
= csInfos
.item();
137 TPM
+= csInfo
.TotalPhysicalMemory
;
140 var ISEHOSTCORE
= NOLP
141 var ISEMEMTOTAL
= TPM
143 var ISENetwork
= WScript
.CreateObject( "WScript.Network" );
144 var ISEHost
= ISENetwork
.ComputerName
;
145 var ISEUser
= ISENetwork
.UserName
;
146 var ISEPid
= ISEProcess
.ProcessID
;
147 var ISEBeginFile
= ISEOpenFile( "." + ISEStep
+ ".begin.rst" );
148 ISEBeginFile
.WriteLine( "<?xml version=\"1.0\"?>" );
149 ISEBeginFile
.WriteLine( "<ProcessHandle Version=\"1\" Minor=\"0\">" );
150 ISEBeginFile
.WriteLine( " <Process Command=\"" + ISEProg
+
151 "\" Owner=\"" + ISEUser
+
152 "\" Host=\"" + ISEHost
+
153 "\" Pid=\"" + ISEPid
+
154 "\" HostCore=\"" + ISEHOSTCORE
+
155 "\" HostMemory=\"" + ISEMEMTOTAL
+
157 ISEBeginFile
.WriteLine( " </Process>" );
158 ISEBeginFile
.WriteLine( "</ProcessHandle>" );
159 ISEBeginFile
.Close();
161 var ISEOutStr
= ISEProcess
.StdOut
;
162 var ISEErrStr
= ISEProcess
.StdErr
;
164 // WAIT for ISEStep to finish
165 while ( ISEProcess
.Status
== 0 ) {
167 // dump stdout then stderr - feels a little arbitrary
168 while ( !ISEOutStr
.AtEndOfStream
) {
169 ISEStdOut( ISEOutStr
.ReadLine() );
172 WScript
.Sleep( 100 );
175 ISEExitCode
= ISEProcess
.ExitCode
;
178 ISELogFileStr
.Close();
180 // END/ERROR file creation
181 if ( ISEExitCode
!= 0 ) {
182 ISETouchFile( ISEStep
, "error" );
185 ISETouchFile( ISEStep
, "end" );
195 function ISEStdOut( ISELine
) {
197 ISELogFileStr
.WriteLine( ISELine
);
200 WScript
.StdOut
.WriteLine( ISELine
);
204 function ISEStdErr( ISELine
) {
206 ISELogFileStr
.WriteLine( ISELine
);
209 WScript
.StdErr
.WriteLine( ISELine
);
213 function ISETouchFile( ISERoot
, ISEStatus
) {
216 ISEOpenFile( "." + ISERoot
+ "." + ISEStatus
+ ".rst" );
220 function ISEOpenFile( ISEFilename
) {
222 // This function has been updated to deal with a problem seen in CR #870871.
223 // In that case the user runs a script that runs impl_1, and then turns around
224 // and runs impl_1 -to_step write_bitstream. That second run takes place in
225 // the same directory, which means we may hit some of the same files, and in
226 // particular, we will open the runme.log file. Even though this script closes
227 // the file (now), we see cases where a subsequent attempt to open the file
228 // fails. Perhaps the OS is slow to release the lock, or the disk comes into
229 // play? In any case, we try to work around this by first waiting if the file
230 // is already there for an arbitrary 5 seconds. Then we use a try-catch block
231 // and try to open the file 10 times with a one second delay after each attempt.
232 // Again, 10 is arbitrary. But these seem to stop the hang in CR #870871.
233 // If there is an unrecognized exception when trying to open the file, we output
234 // an error message and write details to an exception.log file.
235 var ISEFullPath
= ISERunDir
+ "/" + ISEFilename
;
236 if (ISEFileSys
.FileExists(ISEFullPath
)) {
237 // File is already there. This could be a problem. Wait in case it is still in use.
241 for (i
= 0; i
< 10; ++i
) {
243 return ISEFileSys
.OpenTextFile(ISEFullPath
, 8, true);
244 } catch (exception
) {
245 var error_code
= exception
.number
& 0xFFFF; // The other bits are a facility code.
246 if (error_code
== 52) { // 52 is bad file name or number.
247 // Wait a second and try again.
251 WScript
.StdErr
.WriteLine("ERROR: Exception caught trying to open file " + ISEFullPath
);
252 var exceptionFilePath
= ISERunDir
+ "/exception.log";
253 if (!ISEFileSys
.FileExists(exceptionFilePath
)) {
254 WScript
.StdErr
.WriteLine("See file " + exceptionFilePath
+ " for details.");
255 var exceptionFile
= ISEFileSys
.OpenTextFile(exceptionFilePath
, 8, true);
256 exceptionFile
.WriteLine("ERROR: Exception caught trying to open file " + ISEFullPath
);
257 exceptionFile
.WriteLine("\tException name: " + exception
.name
);
258 exceptionFile
.WriteLine("\tException error code: " + error_code
);
259 exceptionFile
.WriteLine("\tException message: " + exception
.message
);
260 exceptionFile
.Close();
266 // If we reached this point, we failed to open the file after 10 attempts.
267 // We need to error out.
268 WScript
.StdErr
.WriteLine("ERROR: Failed to open file " + ISEFullPath
);