docgen.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env php
  2. <?php
  3. $shortoptions = '';
  4. $longoptions = array('plugin=');
  5. $helptext = <<<ENDOFHELP
  6. Build HTML documentation from doc comments in source.
  7. Usage: docgen.php [options] output-directory
  8. Options:
  9. --plugin=... build docs for given plugin instead of core
  10. ENDOFHELP;
  11. define('INSTALLDIR', dirname(__DIR__));
  12. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  13. set_include_path(INSTALLDIR . DIRECTORY_SEPARATOR . 'extlib' . PATH_SEPARATOR . get_include_path());
  14. $pattern = "*.php *.inc";
  15. $exclude = 'config.php */extlib/* */local/* */plugins/* */scripts/*';
  16. $plugin = false;
  17. require_once INSTALLDIR . '/vendor/autoload.php';
  18. $parser = new Console_Getopt();
  19. $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
  20. if (PEAR::isError($result)) {
  21. print $result->getMessage() . "\n";
  22. exit(1);
  23. }
  24. list($options, $args) = $result;
  25. foreach ($options as $option) {
  26. $arg = $option[0];
  27. if ($arg == '--plugin') {
  28. $plugin = $options[1];
  29. } else if ($arg == 'h' || $arg == '--help') {
  30. print $helptext;
  31. exit(0);
  32. }
  33. }
  34. if (isset($args[0])) {
  35. $outdir = $args[0];
  36. if (!is_dir($outdir)) {
  37. echo "Output directory $outdir is not a directory.\n";
  38. exit(1);
  39. }
  40. } else {
  41. print $helptext;
  42. exit(1);
  43. }
  44. if ($plugin) {
  45. $exclude = "*/extlib/*";
  46. $indir = INSTALLDIR . "/plugins/" . $plugin;
  47. if (!is_dir($indir)) {
  48. $indir = INSTALLDIR . "/plugins";
  49. $filename = "{$plugin}Plugin.php";
  50. if (!file_exists("$indir/$filename")) {
  51. echo "Can't find plugin $plugin.\n";
  52. exit(1);
  53. } else {
  54. $pattern = $filename;
  55. }
  56. }
  57. } else {
  58. $indir = INSTALLDIR;
  59. }
  60. function getVersion()
  61. {
  62. // define('GNUSOCIAL_VERSION', '0.9.1');
  63. $source = file_get_contents(INSTALLDIR . '/lib/common.php');
  64. if (preg_match('/^\s*define\s*\(\s*[\'"]GNUSOCIAL_VERSION[\'"]\s*,\s*[\'"](.*)[\'"]\s*\)\s*;/m', $source, $matches)) {
  65. return $matches[1];
  66. }
  67. return 'unknown';
  68. }
  69. $replacements = array(
  70. '%%version%%' => getVersion(),
  71. '%%indir%%' => $indir,
  72. '%%pattern%%' => $pattern,
  73. '%%outdir%%' => $outdir,
  74. '%%htmlout%%' => $outdir,
  75. '%%exclude%%' => $exclude,
  76. );
  77. var_dump($replacements);
  78. $template = file_get_contents(dirname(__FILE__) . '/doxygen.tmpl');
  79. $template = strtr($template, $replacements);
  80. $templateFile = tempnam(sys_get_temp_dir(), 'statusnet-doxygen');
  81. file_put_contents($templateFile, $template);
  82. $cmd = "doxygen " . escapeshellarg($templateFile);
  83. $retval = 0;
  84. passthru($cmd, $retval);
  85. if ($retval == 0) {
  86. echo "Done!\n";
  87. unlink($templateFile);
  88. exit(0);
  89. } else {
  90. echo "Failed! Doxygen config left in $templateFile\n";
  91. exit($retval);
  92. }