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