Source code of Windows XP (NT5)
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.

382 lines
12 KiB

  1. /*
  2. Dazzle.js:
  3. Usage:
  4. Dazzle.js [-e env_templ.xml] [-man buildmanager Identity] [-m macros_file]
  5. Get a list of machines
  6. For each machine
  7. create an alias for each depot on the machine, except root.
  8. BC1 jporkka1\bldcon1 _x86 _fre _x86fre _postbuild _root _inetsrv
  9. BC2 jporkka1\bldcon2 _x86 _fre _x86fre _ds _sdktools
  10. BC3 jporkka1\bldcon3 _x86 _fre _x86fre _termsrv
  11. */
  12. var DEFAULT_IDENTITY_BM = "BuildManager";
  13. var DEFAULT_IDENTITY_BUILDER = "Build";
  14. Error.prototype.toString = Error_ToString;
  15. var g_FSObj = new ActiveXObject("Scripting.FileSystemObject"); // Parse input Parameter List
  16. var g_aBuildManagers = new Array();
  17. var g_aServersFiles = new Array();
  18. var g_aMacrosFiles = new Array();
  19. var g_hMacrosWritten = new Object();
  20. ParseArguments(WScript.Arguments);
  21. main();
  22. WScript.Quit(0);
  23. function main()
  24. {
  25. var PrivateData;
  26. var objFile;
  27. var objMacroFile;
  28. var i;
  29. var strMacroFileName;
  30. var strFileName;
  31. var strCmdLine;
  32. for(i = 0; i < g_aBuildManagers.length; ++i)
  33. {
  34. WScript.Echo("Build manager: " + g_aBuildManagers[i].strMachine + "\\" + g_aBuildManagers[i].strMachineIdentity);
  35. PrivateData = GetEnvironment(g_aBuildManagers[i].strMachine, g_aBuildManagers[i].strMachineIdentity);
  36. if (PrivateData)
  37. {
  38. strFileName = CreateConfigFileName("Servers", g_aBuildManagers[i].strMachine, g_aBuildManagers[i].strMachineIdentity);
  39. g_aServersFiles[g_aServersFiles.length] = strFileName;
  40. objFile = g_FSObj.CreateTextFile(strFileName, true);
  41. objFile.WriteLine("######################################################");
  42. objFile.WriteLine("# Servers for build manager: " + g_aBuildManagers[i].strMachine + "\\" + g_aBuildManagers[i].strMachineIdentity);
  43. if (!strMacroFileName)
  44. {
  45. strMacroFileName = CreateConfigFileName("Macros", g_aBuildManagers[i].strMachine, g_aBuildManagers[i].strMachineIdentity);
  46. objMacroFile = g_FSObj.CreateTextFile(strMacroFileName, true);
  47. WriteMacro(objMacroFile, 'root', null);
  48. WriteMacro(objMacroFile, 'postbuild', null);
  49. }
  50. WriteServerInfo(objFile, objMacroFile, PrivateData);
  51. objFile.Close();
  52. }
  53. }
  54. strCmdLine = "BCDazzle.exe ";
  55. if (objMacroFile)
  56. {
  57. objMacroFile.Close();
  58. strCmdLine += " -m " + strMacroFileName;
  59. }
  60. if (g_aServersFiles.length)
  61. strCmdLine += " -s " + g_aServersFiles.join(" -s ");
  62. if (g_aMacrosFiles.length)
  63. strCmdLine += " -m " + g_aMacrosFiles.join(" -m ");
  64. var objShell;
  65. objShell = WScript.CreateObject( "WScript.Shell" )
  66. WScript.Echo("Running " + strCmdLine);
  67. objShell.Run(strCmdLine, 1);
  68. }
  69. // macro com ( _com ) "CD /d %sdxroot%\\com\n"
  70. function WriteMacro(objMacroFile, strDepotName, strDepotPath)
  71. {
  72. if (!g_hMacrosWritten[strDepotName])
  73. {
  74. g_hMacrosWritten[strDepotName] = true;
  75. objMacroFile.WriteLine('macro '
  76. + strDepotName
  77. + ' ( _' + strDepotName
  78. + ' ) "cd /d %sdxroot%'
  79. + (strDepotPath ? '\\\\' + strDepotPath : '')
  80. + '\\n"');
  81. }
  82. }
  83. function CreateConfigFileName(strName, strMachine, strMachineIdentity)
  84. {
  85. var strResult =
  86. g_FSObj.GetSpecialFolder(2)
  87. + "\\"
  88. + strName
  89. + "_"
  90. + strMachine
  91. + "_"
  92. + strMachineIdentity
  93. + ".txt";
  94. return strResult;
  95. }
  96. function ParseArguments(Arguments)
  97. {
  98. var strArg;
  99. var chArg0;
  100. var chArg1;
  101. var argn;
  102. var objBM;
  103. for(argn = 0; argn < Arguments.length; argn++)
  104. {
  105. strArg = Arguments(argn);
  106. chArg0 = strArg.charAt(0);
  107. chArg1 = strArg.toLowerCase().slice(1);
  108. if (chArg0 != '-' && chArg0 != '/')
  109. Usage(1);
  110. else
  111. {
  112. switch(chArg1)
  113. {
  114. case 'e':
  115. if (argn + 1 < Arguments.length)
  116. objBM = LoadEnvironmentTemplate(Arguments(argn + 1));
  117. else
  118. Usage(2);
  119. if (!objBM)
  120. Usage(3);
  121. g_aBuildManagers[g_aBuildManagers.length] = objBM;
  122. argn++;
  123. break;
  124. case 'man':
  125. objBM = new Object;
  126. if (argn + 2 < Arguments.length)
  127. {
  128. objBM.strMachine = Arguments(argn + 1);
  129. objBM.strMachineIdentity = Arguments(argn + 2);
  130. }
  131. else
  132. Usage(4);
  133. g_aBuildManagers[g_aBuildManagers.length] = objBM;
  134. argn += 2;
  135. break;
  136. case 'm':
  137. if (argn + 1 < Arguments.length)
  138. g_aMacrosFiles[g_aMacrosFiles.length] = Arguments(argn + 1);
  139. else
  140. Usage(5);
  141. argn++;
  142. break;
  143. default:
  144. Usage(4);
  145. break;
  146. }
  147. }
  148. }
  149. }
  150. // MyEval(expr)
  151. // evaluating uneval'ed objects creates a bunch of junk local variables.
  152. // by putting the eval call in a little subroutine, we avoid keeping those
  153. // locals around.
  154. function MyEval(expr)
  155. {
  156. try
  157. {
  158. return eval(expr);
  159. }
  160. catch(ex)
  161. {
  162. throw ex;
  163. }
  164. }
  165. function Error_ToString()
  166. {
  167. var i;
  168. var str = 'Exception(';
  169. /*
  170. Only some error messages get filled in for "ex".
  171. Specifically the text for disk full never seems
  172. to get set by functions such as CreateTextFile().
  173. */
  174. if (this.number != null && this.description == "")
  175. {
  176. switch(this.number)
  177. {
  178. case -2147024784:
  179. this.description = "There is not enough space on the disk.";
  180. break;
  181. case -2147024894:
  182. this.description = "The system cannot find the file specified.";
  183. break;
  184. case -2147023585:
  185. this.description = "There are currently no logon servers available to service the logon request.";
  186. break;
  187. case -2147023170:
  188. this.description = "The remote procedure call failed.";
  189. break;
  190. case -2147024837:
  191. this.description = "An unexpected network error occurred";
  192. break;
  193. case -2147024890:
  194. this.description = "The handle is invalid.";
  195. break;
  196. default:
  197. this.description = "Error text not set for (" + this.number + ")";
  198. break;
  199. }
  200. }
  201. for(i in this)
  202. {
  203. str += i + ": " + this[i] + " ";
  204. }
  205. return str + ")";
  206. }
  207. function WriteServerInfo(objFile, objMacroFile, PrivateData)
  208. {
  209. var i;
  210. var j;
  211. var strLine;
  212. var aMachines = PrivateData.objEnviron.Machine;
  213. var strDepotName;
  214. for(i = 0; i < aMachines.length; ++i)
  215. {
  216. strLine = aMachines[i].Name
  217. + " "
  218. + aMachines[i].Name + "\\BldCon_" + aMachines[i].Identity
  219. + " _" + PrivateData.objConfig.Options.BuildType
  220. + " _" + PrivateData.objConfig.Options.Platform;
  221. if (PrivateData.objConfig.Options.Aliases)
  222. strLine += " " + PrivateData.objConfig.Options.Aliases;
  223. if (aMachines[i].Aliases)
  224. strLine += " " + aMachines[i].Aliases;
  225. if (aMachines[i].Name == PrivateData.objEnviron.BuildManager.PostBuildMachine)
  226. strLine += " _root _postbuild";
  227. for(j = 0; j < aMachines[i].Depot.length; ++j)
  228. {
  229. strDepotName = aMachines[i].Depot[j].toLowerCase();
  230. if (strDepotName != 'root')
  231. {
  232. strLine += " _" + strDepotName;
  233. WriteMacro(objMacroFile, strDepotName, strDepotName);
  234. }
  235. }
  236. objFile.WriteLine(strLine);
  237. }
  238. }
  239. function GetEnvironment(strMachineName, strIdentity)
  240. {
  241. var strMode;
  242. var obj;
  243. var PrivateData = new Object();
  244. try
  245. {
  246. WScript.Echo("Attempting connection to " + strMachineName + "\\" + strIdentity);
  247. obj = new ActiveXObject('MTScript.Proxy');
  248. obj.ConnectToMTScript(strMachineName, strIdentity, false);
  249. strMode = obj.Exec('getpublic', 'PublicData.strMode');
  250. strMode = MyEval(strMode);
  251. if (strMode == 'idle')
  252. {
  253. WScript.Echo(strMachineName + "\\" + strIdentity + " is currently idle");
  254. return null;
  255. }
  256. PrivateData.objConfig = obj.Exec('getpublic', 'PrivateData.objConfig');
  257. PrivateData.objConfig = MyEval(PrivateData.objConfig);
  258. PrivateData.objEnviron = obj.Exec('getpublic', 'PrivateData.objEnviron');
  259. PrivateData.objEnviron = MyEval(PrivateData.objEnviron);
  260. var result;
  261. WScript.Echo("Starting Remote Razzle Windows...");
  262. result = obj.Exec('remote','');
  263. WScript.Echo("Remote result is " + result);
  264. return PrivateData;
  265. }
  266. catch(ex)
  267. {
  268. WScript.Echo("CaptureLogsManager '" + strMachineName + "\\" + strIdentity + "' failed, ex=" + ex);
  269. }
  270. return null;
  271. }
  272. function LoadEnvironmentTemplate(strEnviroURL)
  273. {
  274. var xml = new ActiveXObject('Microsoft.XMLDOM');
  275. var err = new Error();
  276. var node;
  277. var objBM = new Object();
  278. fStandaloneMode = false;
  279. xml.async = false;
  280. // It's unlikely they have the schema file available for this template,
  281. // so we turn off schema validation right now. The script engine will
  282. // validate it when we start the build.
  283. xml.validateOnParse = false;
  284. xml.resolveExternals = false;
  285. if (!xml.load(strEnviroURL) || !xml.documentElement)
  286. {
  287. err.description = 'Error loading the environment template ' + strEnviroURL;
  288. err.details = xml.parseError.reason;
  289. throw(err);
  290. }
  291. node = xml.documentElement.selectSingleNode('BuildManager');
  292. if (!node)
  293. {
  294. err.description = 'Invalid environment template file (BuildManager tag missing): ' + strEnviroURL;
  295. throw(err);
  296. }
  297. objBM.strMachine = node.getAttribute("Name");
  298. objBM.strMachineIdentity = node.getAttribute("Identity");
  299. if (!objBM.strMachine)
  300. {
  301. err.description = 'Invalid environment template file (BuildManager tag badly formatted): ' + strEnviroURL;
  302. throw(err);
  303. }
  304. if (!objBM.strMachineIdentity)
  305. objBM.strMachineIdentity = DEFAULT_IDENTITY_BM;
  306. if (objBM.strMachine.toLowerCase() == '%localmachine%' ||
  307. objBM.strMachine.toLowerCase() == '%remotemachine%')
  308. {
  309. err.description = 'Sorry, cannot use the local machine or remote machine templates from this script';
  310. throw(err);
  311. }
  312. return objBM;
  313. }
  314. function Usage(x)
  315. {
  316. WScript.Echo('');
  317. WScript.Echo('Usage: dazzle [-e env_template.xml] [-man bldmgr identity] [-m macros]');
  318. WScript.Echo('');
  319. WScript.Echo(' -e env_template.xml : Use the specific environment template to find the build machines');
  320. WScript.Echo(' -man bldmgr identity : Query "bldmgr" with "identity" for list of');
  321. WScript.Echo(' build machines instead of template files.');
  322. WScript.Echo(' -m macros.txt : Load the macros file.');
  323. WScript.Echo('');
  324. WScript.Echo(' You may specify multiple -e, -man and -m options.');
  325. WScript.Echo('');
  326. WScript.Quit(1);
  327. }