00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "VASTi.H"
00022 #include "Err.H"
00023 #include "Files.H"
00024 #include "Val.H"
00025 #include "PrimRunTool.H"
00026 #include <CacheIndex.H>
00027 #include <CacheConfig.H>
00028 #include <CacheC.H>
00029 #include <ParCacheC.H>
00030 #include <VestaConfig.H>
00031
00032 using std::cout;
00033 using std::cerr;
00034 using std::endl;
00035
00036
00037 bool recordTrace;
00038 bool recordCallStack;
00039
00040 CacheC *theCache = NULL;
00041 time_t leaseDuration;
00042
00043 VestaSource *rRoot, *mRoot, *topModelRoot;
00044 VestaSource *rootForDeriveds;
00045 ShortId topModelSid;
00046
00047 bool printVersion;
00048 bool printResult;
00049 bool printCacheStats;
00050 bool printSidNum;
00051
00052
00053 Text toolDirServerIntfName;
00054
00055
00056 extern const char *Version;
00057
00058
00059 bool parseOnly, noAddEntry, fsDeps, evalCalls, stopOnError,
00060 psStat, shipBySymLink, shipClean, forceClean, diagnose,
00061 hushedShipping, pauseBeforeTool, pauseAfterTool,
00062 pauseAfterToolSignal, pauseAfterToolError, autoRepl, dotLogFiles;
00063
00064 int toolCallCounter, toolHitCounter, appCallCounter, appHitCounter,
00065 sModelCallCounter, sModelHitCounter, nModelCallCounter, nModelHitCounter,
00066 cacheOption, maxThreads;
00067
00068 IntegerVC *fpContent;
00069
00070 Text shipToPath, shipFromPath;
00071
00072 int main(int argc, char* argv[]) {
00073 bool success = false;
00074 CacheIntf::DebugLevel cdebug = CacheIntf::None;
00075
00076 leaseDuration = Config_LeaseTimeoutSecs;
00077
00078 parseOnly = noAddEntry = fsDeps = evalCalls = psStat = false;
00079 shipBySymLink = shipClean = forceClean = hushedShipping = false;
00080 pauseBeforeTool = pauseAfterTool =
00081 pauseAfterToolSignal = pauseAfterToolError = false;
00082 cacheOption = 3;
00083 stopOnError = true;
00084 diagnose = false;
00085 recordTrace = false;
00086 recordCallStack = false;
00087 printVersion = false;
00088 printResult = false;
00089 printSidNum = false;
00090 printCacheStats = false;
00091 autoRepl = true;
00092 dotLogFiles = true;
00093
00094 maxThreads = -1;
00095
00096 toolCallCounter = toolHitCounter = appCallCounter = appHitCounter = 0;
00097 sModelCallCounter = sModelHitCounter = nModelCallCounter = nModelHitCounter = 0;
00098
00099 int evalArgc = 0;
00100 char *evalArgs[32];
00101
00102
00103 Text defaultmain(".main.ves");
00104 (void) VestaConfig::get("Evaluator", "DefaultMain", defaultmain);
00105 Text filename;
00106
00107
00108 if(VestaConfig::is_set("Evaluator", "print_numeric_sid")) {
00109 printSidNum = VestaConfig::get_bool("Evaluator", "print_numeric_sid");
00110 }
00111
00112
00113
00114 try {
00115 Text switches;
00116 if (VestaConfig::get("Evaluator", "Switches", switches)) {
00117 int i = 0, len = switches.Length();
00118 while (i < len) {
00119
00120 char c = switches[i];
00121 while (i < len && (c == ' ' || c == '\t' || c == '\f' || c == '\n'))
00122 c = switches[++i];
00123
00124 int j = i;
00125 while (j < len && c != ' ' && c != '\t' && c != '\f' && c != '\n')
00126 c = switches[++j];
00127
00128 evalArgs[evalArgc++] = switches.Sub(i, j - i).chars();
00129
00130 i = j;
00131 }
00132 }
00133 } catch (VestaConfig::failure f) {
00134 Error(Text("Vesta configuration failure: ") + f.msg + ".\n");
00135 return true;
00136 }
00137
00138 int i;
00139 for (i = 1; i < argc; i++) {
00140 evalArgs[evalArgc++] = argv[i];
00141 }
00142
00143 i = 0;
00144 while (i < evalArgc) {
00145 if (evalArgs[i][0] == '-') {
00146 if (strcmp(evalArgs[i], "-cache") == 0) {
00147 if (evalArgc <= ++i) {
00148 cerr << "Error: expecting a caching level: none, runtool, model, or pfga.\n";
00149 return true;
00150 }
00151 if (strcmp(evalArgs[i], "none") == 0) {
00152 cacheOption = 0;
00153
00154 }
00155 else if (strcmp(evalArgs[i], "runtool") == 0) {
00156 cacheOption = 1;
00157
00158 }
00159 else if (strcmp(evalArgs[i], "model") == 0) {
00160 cacheOption = 2;
00161
00162 }
00163 else if (strcmp(evalArgs[i], "all") == 0) {
00164
00165 }
00166 else {
00167 cerr << "Error: unrecognized caching-level '" << evalArgs[i] << "'\n";
00168 return true;
00169 }
00170 i++;
00171 }
00172 else if (strcmp(evalArgs[i], "-trace") == 0) {
00173 recordTrace = true;
00174
00175 i++;
00176 }
00177 else if (strcmp(evalArgs[i], "-no-trace") == 0) {
00178 recordTrace = false;
00179
00180 i++;
00181 }
00182 else if (strcmp(evalArgs[i], "-stack") == 0) {
00183 recordCallStack = true;
00184 i++;
00185 }
00186 else if (strcmp(evalArgs[i], "-no-stack") == 0) {
00187 recordCallStack = false;
00188 i++;
00189 }
00190 else if (strcmp(evalArgs[i], "-s") == 0) {
00191 shipBySymLink = true;
00192 i++;
00193 }
00194 else if (strcmp(evalArgs[i], "-no-s") == 0) {
00195 shipBySymLink = false;
00196 i++;
00197 }
00198 else if (strcmp(evalArgs[i], "-result") == 0) {
00199 printResult = true;
00200 i++;
00201 }
00202 else if (strcmp(evalArgs[i], "-no-result") == 0) {
00203 printResult = false;
00204 i++;
00205 }
00206 else if (strcmp(evalArgs[i], "-cstats") == 0) {
00207 printCacheStats = true;
00208 i++;
00209 }
00210 else if (strcmp(evalArgs[i], "-no-cstats") == 0) {
00211 printCacheStats = false;
00212 i++;
00213 }
00214 else if (strcmp(evalArgs[i], "-version") == 0) {
00215 printVersion = true;
00216 i++;
00217 }
00218 else if (strcmp(evalArgs[i], "-no-version") == 0) {
00219 printVersion = false;
00220 i++;
00221 }
00222 else if (strcmp(evalArgs[i], "-clean") == 0) {
00223 shipClean = true;
00224 i++;
00225 }
00226 else if (strcmp(evalArgs[i], "-no-clean") == 0) {
00227 shipClean = false;
00228 i++;
00229 }
00230 else if (strcmp(evalArgs[i], "-CLEAN") == 0) {
00231 forceClean = true;
00232 i++;
00233 }
00234 else if (strcmp(evalArgs[i], "-no-CLEAN") == 0) {
00235 forceClean = false;
00236 i++;
00237 }
00238 else if (strcmp(evalArgs[i], "-shipto") == 0) {
00239 if (evalArgc <= ++i) {
00240 cerr << "Error: expecting a pathname to which to ship the result.\n";
00241 return true;
00242 }
00243 shipToPath = evalArgs[i++];
00244 }
00245 else if (strcmp(evalArgs[i], "-shipfrom") == 0) {
00246 if (evalArgc <= ++i) {
00247 cerr << "Error: expecting a pathname from which to get the result.\n";
00248 return true;
00249 }
00250 shipFromPath = evalArgs[i++];
00251 }
00252 else if (strcmp(evalArgs[i], "-cdebug") == 0) {
00253 if (evalArgc <= ++i) {
00254 cerr << "Error: expecting cache server debugging level.\n";
00255 return true;
00256 }
00257 if (sscanf(evalArgs[i], "%d", &cdebug) != 1) {
00258 int j;
00259 for (j = 0; j <= CacheIntf::All; j++) {
00260 if (strcmp(evalArgs[i], CacheIntf::DebugName(j)) == 0) break;
00261 }
00262 cdebug = (CacheIntf::DebugLevel)j;
00263 }
00264 if (cdebug < CacheIntf::None || cdebug > CacheIntf::All) {
00265 cerr << "Error: unrecognized debug-level '" << evalArgs[i] << "'\n";
00266 return true;
00267 }
00268 i++;
00269 }
00270 else if (strcmp(evalArgs[i], "-k") == 0) {
00271 stopOnError = false;
00272 i++;
00273 }
00274 else if (strcmp(evalArgs[i], "-no-k") == 0) {
00275 stopOnError = true;
00276 i++;
00277 }
00278 else if (strcmp(evalArgs[i], "-diagnose") == 0) {
00279 diagnose = true;
00280 i++;
00281 }
00282 else if (strcmp(evalArgs[i], "-no-diagnose") == 0) {
00283 diagnose = false;
00284 i++;
00285 }
00286 else if (strcmp(evalArgs[i], "-noaddentry") == 0) {
00287 noAddEntry = true;
00288
00289 i++;
00290 }
00291 else if (strcmp(evalArgs[i], "-no-noaddentry") == 0) {
00292 noAddEntry = false;
00293
00294 i++;
00295 }
00296 else if (strcmp(evalArgs[i], "-addentry") == 0) {
00297 noAddEntry = false;
00298
00299 i++;
00300 }
00301 else if (strcmp(evalArgs[i], "-stop-before-tool") == 0 ) {
00302 pauseBeforeTool = true;
00303 i++;
00304 }
00305 else if (strcmp(evalArgs[i], "-stop-after-tool") == 0 ) {
00306 pauseAfterTool = true;
00307 i++;
00308 }
00309 else if (strcmp(evalArgs[i], "-stop-after-tool-signal") == 0 ) {
00310 pauseAfterToolSignal = true;
00311 i++;
00312 }
00313 else if (strcmp(evalArgs[i], "-stop-after-tool-error") == 0 ) {
00314 pauseAfterToolError = true;
00315 i++;
00316 }
00317 else if (strcmp(evalArgs[i], "-fsdeps") == 0) {
00318 fsDeps = true;
00319
00320 i++;
00321 }
00322 else if (strcmp(evalArgs[i], "-no-fsdeps") == 0) {
00323 fsDeps = false;
00324
00325 i++;
00326 }
00327 else if (strcmp(evalArgs[i], "-evalcalls") == 0) {
00328 evalCalls = true;
00329
00330 i++;
00331 }
00332 else if (strcmp(evalArgs[i], "-no-evalcalls") == 0) {
00333 evalCalls = false;
00334
00335 i++;
00336 }
00337 else if (strcmp(evalArgs[i], "-ps") == 0) {
00338 psStat = true;
00339 i++;
00340 }
00341 else if (strcmp(evalArgs[i], "-no-ps") == 0) {
00342 psStat = false;
00343 i++;
00344 }
00345 else if (strcmp(evalArgs[i], "-maxthreads") == 0) {
00346 if (evalArgc <= ++i) {
00347 cerr << "Error: expecting an integer for maxthreads.\n";
00348 return true;
00349 }
00350 maxThreads = atoi(evalArgs[i++]);
00351 }
00352 else if (strcmp(evalArgs[i], "-parse") == 0) {
00353 parseOnly = true;
00354
00355 i++;
00356 }
00357 else if (strcmp(evalArgs[i], "-no-parse") == 0) {
00358 parseOnly = false;
00359
00360 i++;
00361 }
00362 else if (strcmp(evalArgs[i], "-hushship") == 0) {
00363 hushedShipping = true;
00364 i++;
00365 }
00366 else if (strcmp(evalArgs[i], "-no-hushship") == 0) {
00367 hushedShipping = false;
00368 i++;
00369 }
00370 else if (strcmp(evalArgs[i], "-autorepl") == 0) {
00371 autoRepl = true;
00372 i++;
00373 }
00374 else if (strcmp(evalArgs[i], "-no-autorepl") == 0) {
00375 autoRepl = false;
00376 i++;
00377 }
00378 else if (strcmp(evalArgs[i], "-no-log") == 0) {
00379 dotLogFiles = false;
00380 i++;
00381 }
00382 else if (strcmp(evalArgs[i], "-log") == 0) {
00383 dotLogFiles = true;
00384 i++;
00385 }
00386 else {
00387 cerr << "\n++++ unrecognized flag: " << evalArgs[i] << ".\n\n";
00388 return true;
00389 }
00390 }
00391 else {
00392 if (i != evalArgc-1) {
00393 cerr << "\n++++ unrecognized flag: " << evalArgs[i] << ".\n\n";
00394 return true;
00395 }
00396 filename = evalArgs[i++];
00397 }
00398 }
00399
00400 if (printVersion) {
00401 cout << "Vesta evaluator, version " << Version << "\n" << endl;
00402 }
00403
00404 try {
00405 if (maxThreads == -1) {
00406 maxThreads = VestaConfig::get_int("Evaluator", "MaxThreads");
00407 }
00408 fpContent = NEW_CONSTR(IntegerVC,
00409 (VestaConfig::get_int("Evaluator", "FpContent")));
00410
00411 if (cacheOption != 0) {
00412 Text host;
00413 if (VestaConfig::get("CacheServer", "Host", host) && host.Length() > 0)
00414 ParCacheC::SetServerHost(host.chars());
00415 theCache = NEW_CONSTR(CacheC, (cdebug));
00416 }
00417
00418 rRoot = VestaSource::repositoryRoot();
00419 CreateRootForDeriveds();
00420
00421 filename = MainModel(filename, defaultmain);
00422
00423 success = StartEval(filename);
00424 DeleteRootForDeriveds();
00425 } catch (VestaConfig::failure f) {
00426 Error(Text("Vesta configuration failure: ") + f.msg + ".\n");
00427 success = false;
00428 } catch (SRPC::failure f) {
00429 Error(Text("SRPC failure: ") + f.msg + ". ");
00430 if (theCache == NULL) {
00431 cerr << "The cache server is possibly down.";
00432 }
00433 else {
00434 cerr << "The repository server is possibly down.";
00435 }
00436 success = false;
00437 } catch (Evaluator::failure f) {
00438 Error(Text("Vesta evaluation failure: ") + f.msg + ".\n");
00439 success = false;
00440 }
00441
00442
00443 ErrorSummary(&cerr);
00444 if (!success) {
00445 cerr << "Vesta evaluation failed.\n";
00446 }
00447
00448 return !success;
00449 }