TestMakefile.hx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. class TestMakefile {
  2. static public function main() {
  3. Sys.setCwd("../");
  4. var mlFiles = [];
  5. FileSystemTools.mapFiles("./src", function(s) {
  6. mlFiles.push(s);
  7. }, ~/\.ml$/);
  8. var failure = false;
  9. var times = [];
  10. function makeWithTimer(name) {
  11. var start = haxe.Timer.stamp();
  12. var code = make();
  13. var time = haxe.Timer.stamp() - start;
  14. times.push({name: name, time: time});
  15. return code;
  16. }
  17. Sys.command("make", ["clean_haxe"]);
  18. makeWithTimer("initial");
  19. for (mlFile in mlFiles) {
  20. Sys.command("touch", [mlFile]);
  21. Sys.println('[START] $mlFile');
  22. var code = makeWithTimer(mlFile);
  23. if (code == 0) {
  24. Sys.println('[DONE] $mlFile');
  25. } else {
  26. Sys.println('[ERROR] $mlFile');
  27. failure = true;
  28. break;
  29. }
  30. }
  31. times.sort(function(t1, t2) return t1.time < t2.time ? -1 : 1);
  32. var total = 0.;
  33. for (time in times) {
  34. Sys.println('${time.name}: ${ghettoFormatTime(time.time)}');
  35. total += time.time;
  36. }
  37. Sys.println('Total: ${ghettoFormatTime(total)}');
  38. Sys.exit(failure ? 1 : 0);
  39. }
  40. static function make() {
  41. return Sys.command("make", ["LFLAGS=-c", "haxe"]);
  42. }
  43. static function ghettoFormatTime(f:Float) {
  44. var s = Std.string(f);
  45. return s.substr(0, s.indexOf(".") + 3);
  46. }
  47. }
  48. class FileSystemTools {
  49. static public function mapFiles(directory:String, f:String -> Void, ?match:EReg) {
  50. var workList = [directory];
  51. while (workList.length > 0) {
  52. var current = workList.shift();
  53. if (sys.FileSystem.isDirectory(current)) {
  54. var files = sys.FileSystem.readDirectory(current);
  55. for (file in files) {
  56. switch (file) {
  57. case "." | "..":
  58. case _: workList.push(haxe.io.Path.join([current, file]));
  59. }
  60. }
  61. } else {
  62. if (match.match == null || match.match(current)) {
  63. f(current);
  64. }
  65. }
  66. }
  67. }
  68. }