hcttodo.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // hcttodo.js //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. //
  10. // Verifies that all TODO comments have some explanation.
  11. //
  12. eval(new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings("%HLSL_SRC_DIR%\\utils\\hct\\hctjs.js"), 1).ReadAll());
  13. // It would be nice to tag with issue numbers.
  14. // var goodToDoLine = /TODO: HLSL #[0-9]+ - [0-9a-zA-Z]+/;
  15. var goodToDoLine = /TODO: HLSL #[0-9]+ - [0-9a-zA-Z]+/;
  16. var fileExts = [
  17. ".c", ".cpp", ".h", ".td", ".cs", ".hlsl", ".fx"
  18. ];
  19. function CountBadTodoLines(files) {
  20. var badTodoCount = 0;
  21. for (var i = 0; i < files.length; i++) {
  22. var path = files[i];
  23. var extension = PathGetExtension(path).toLowerCase();
  24. if (ArrayIndexOf(fileExts, extension) >= 0) {
  25. var content = ReadAllTextFile(path);
  26. var lines = StringSplit(content, "\n");
  27. for (var j = 0; j < lines.length; j++) {
  28. var line = lines[j];
  29. var todoIndex = line.indexOf("TODO");
  30. if (todoIndex !== -1) {
  31. // if (!goodToDoLine.exec(line)) {
  32. WScript.Echo(path + "(" + (j+1) + ":" + (todoIndex+1) + "): " + lines[j]);
  33. // badTodoCount += 1;
  34. // }
  35. }
  36. }
  37. }
  38. }
  39. return badTodoCount;
  40. }
  41. function ExpandPath(path) {
  42. return new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings(path);
  43. }
  44. var ignorePaths = [
  45. "%HLSL_SRC_DIR%\\lib\\target\\hexagon",
  46. "%HLSL_SRC_DIR%\\lib\\executionengine",
  47. "%HLSL_SRC_DIR%\\lib\\target\\arm",
  48. "%HLSL_SRC_DIR%\\lib\\target\\mips",
  49. "%HLSL_SRC_DIR%\\lib\\target\\nvptx",
  50. "%HLSL_SRC_DIR%\\lib\\target\\r600",
  51. "%HLSL_SRC_DIR%\\lib\\target\\powerpc",
  52. "%HLSL_SRC_DIR%\\lib\\target\\x86",
  53. "%HLSL_SRC_DIR%\\lib\\target\\xcore"
  54. ];
  55. ignorePaths = ArraySelect(ignorePaths, function(path) { return StringToLower(ExpandPath(path)); });
  56. var files = GetFilesRecursive(ExpandPath("%HLSL_SRC_DIR%"));
  57. files = ArraySelectMany(files, function (path) {
  58. path = StringToLower(path);
  59. if (ArrayAny(ignorePaths, function (ignore) { return path.indexOf(ignore) === 0; })) {
  60. return [];
  61. } else {
  62. return [path];
  63. }
  64. });
  65. var counts = CountBadTodoLines(files);
  66. // Fail on any bad TODO lines.
  67. if (counts !== 0) {
  68. WScript.Echo("Badly formatted TODO comments found in " + files.length + " files: " + counts);
  69. WScript.Echo("\nFormat should be something like this, with the right number and description (spaces and symbols enforced for consistency).");
  70. WScript.Echo(" // TODO: HLSL #123 - description");
  71. WScript.Quit(1);
  72. } else {
  73. WScript.Echo("No badly formatted TODO comments found in " + files.length + " files.");
  74. WScript.Quit(0);
  75. }