Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.

145 lines
4.3 KiB

  1. <?php
  2. /**
  3. * When I installed docblox, I had the experience that it does not generate any output at all.
  4. * This script may be used to find that kind of problems with the documentation build process.
  5. * If docblox generates output, use another approach for debugging.
  6. *
  7. * Basically, docblox takes a list of files to build documentation from. This script assumes there is a file or set of files
  8. * breaking the build when it is included in that list. It tries to calculate the smallest list containing these files.
  9. * Unfortunatly, the original problem is NP-complete, so what the script does is a best guess only.
  10. *
  11. * So it starts with a list of all files in the project.
  12. * If that list can't be build, it cuts it in two parts and tries both parts independently. If only one of them breaks,
  13. * it takes that one and tries the same independently. If both break, it assumes this is the smallest set. This assumption
  14. * is not necessarily true. Maybe the smallest set consists of two files and both of them were in different parts when
  15. * the list was divided, but by now it is my best guess. To make this assumption better, the list is shuffled after every step.
  16. *
  17. * After that, the script tries to remove a file from the list. It tests if the list breaks and if so, it
  18. * assumes that the file it removed belongs to the set of errorneous files.
  19. * This is done for all files, so, in the end removing one file leads to a working doc build.
  20. *
  21. * @package util
  22. * @author Alexander Kampmann
  23. */
  24. /**
  25. * This function generates a comma seperated list of file names.
  26. *
  27. * @package util
  28. *
  29. * @param array $fileset Set of file names
  30. *
  31. * @return string comma-seperated list of the file names
  32. */
  33. function namesList($fileset) {
  34. $fsparam="";
  35. foreach($fileset as $file) {
  36. $fsparam=$fsparam.",".$file;
  37. }
  38. return $fsparam;
  39. };
  40. /**
  41. * This functions runs phpdoc on the provided list of files
  42. * @package util
  43. *
  44. * @param array $fileset Set of filenames
  45. *
  46. * @return bool true, if that set can be built
  47. */
  48. function runs($fileset) {
  49. $fsParam=namesList($fileset);
  50. exec('docblox -t phpdoc_out -f '.$fsParam);
  51. if(file_exists("phpdoc_out/index.html")) {
  52. echo "\n Subset ".$fsParam." is okay. \n";
  53. exec('rm -r phpdoc_out');
  54. return true;
  55. } else {
  56. echo "\n Subset ".$fsParam." failed. \n";
  57. return false;
  58. }
  59. };
  60. /**
  61. * This functions cuts down a fileset by removing files until it finally works.
  62. * it was meant to be recursive, but php's maximum stack size is to small. So it just simulates recursion.
  63. *
  64. * In that version, it does not necessarily generate the smallest set, because it may not alter the elements order enough.
  65. *
  66. * @package util
  67. *
  68. * @param array $fileset set of filenames
  69. * @param int $ps number of files in subsets
  70. *
  71. * @return array a part of $fileset, that crashes
  72. */
  73. function reduce($fileset, $ps) {
  74. //split array...
  75. $parts=array_chunk($fileset, $ps);
  76. //filter working subsets...
  77. $parts=array_filter($parts, "runs");
  78. //melt remaining parts together
  79. if(is_array($parts)) {
  80. return array_reduce($parts, "array_merge", array());
  81. }
  82. return array();
  83. };
  84. //return from util folder to frindica base dir
  85. $dir='..';
  86. //stack for dirs to search
  87. $dirstack=array();
  88. //list of source files
  89. $filelist=array();
  90. //loop over all files in $dir
  91. while($dh=opendir($dir)) {
  92. while($file=readdir($dh)) {
  93. if(is_dir($dir."/".$file)) {
  94. //add to directory stack
  95. if($file!=".." && $file!=".") {
  96. array_push($dirstack, $dir."/".$file);
  97. echo "dir ".$dir."/".$file."\n";
  98. }
  99. } else {
  100. //test if it is a source file and add to filelist
  101. if(substr($file, strlen($file)-4)==".php") {
  102. array_push($filelist, $dir."/".$file);
  103. echo $dir."/".$file."\n";
  104. }
  105. }
  106. }
  107. //look at the next dir
  108. $dir=array_pop($dirstack);
  109. }
  110. //check the entire set
  111. if(runs($filelist)) {
  112. echo "I can not detect a problem. \n";
  113. exit;
  114. }
  115. //check half of the set and discard if that half is okay
  116. $res=$filelist;
  117. $i=0;
  118. do {
  119. $i=count($res);
  120. echo $i."/".count($fileset)." elements remaining. \n";
  121. $res=reduce($res, count($res)/2);
  122. shuffle($res);
  123. } while(count($res)<$i);
  124. //check one file after another
  125. $needed=array();
  126. while(count($res)!=0) {
  127. $file=array_pop($res);
  128. if(runs(array_merge($res, $needed))) {
  129. echo "needs: ".$file." and file count ".count($needed);
  130. array_push($needed, $file);
  131. }
  132. }
  133. echo "\nSmallest Set is: ".namesList($needed)." with ".count($needed)." files. ";