build_doc.pl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/perl
  2. # Documentation Builder
  3. # Builds documentation using doxygen and updates version number.
  4. use strict;
  5. use File::Basename;
  6. use Getopt::Long;
  7. #prgm option
  8. my $sHelp = 0;
  9. my $sDocFile = "doxyconf";
  10. my $outputdir = "doc/doxygen";
  11. my $sForceBuild = 0;
  12. my $sIgnChk = "None";
  13. my $sValidTarget = "None|All|Doxygen|Git";
  14. my $sNoUpd = 0;
  15. GetArgs();
  16. Main();
  17. sub GetArgs {
  18. GetOptions(
  19. 'doxyconf=s' => \$sDocFile, #specify the doxygen configuration file
  20. 'outdir=s' => \$outputdir, #specify in which folder to build the documentation
  21. 'ignorechk=s' => \$sIgnChk, #Target (which setup to run)
  22. 'forcebuild=i' => \$sForceBuild, #should we chk if all doc are linked to a src ?
  23. 'noupd=i' => \$sNoUpd, #prevent altering doxygen conf
  24. 'help!' => \$sHelp,
  25. ) or $sHelp=1; #display help if invalid option
  26. if( $sHelp ) {
  27. print "Incorect option specified, available option are:\n"
  28. ."\t --doxyconf filename => specify which doxygen configuration to use\n"
  29. ."\t --outdir path => specify in which path to build doxygen documentation\n"
  30. ."\t --forcebuild=0|1 => should we force building of documentation even if same git detected ?\n"
  31. ."\t --noupd=0|1 => should we skip producing a new doxyconf for version ?\n"
  32. ."\t --ignorechk => target (specify which check to ignore [$sValidTarget])\n";
  33. exit;
  34. }
  35. if($sIgnChk && !($sIgnChk =~ /$sValidTarget/i)){
  36. print "Incorect ignorechk target specified. Available targets:\n"
  37. ."\t --ignorechk => target (specify which check to ignore [(default)$sValidTarget])\n";
  38. exit;
  39. }
  40. }
  41. sub Main {
  42. my $repoversion;
  43. my $sSkipBuild=0;
  44. my($filename, $dir, $suffix) = fileparse($0);
  45. chdir $dir; #put ourself like was called in main
  46. chdir "..";
  47. DoxygenChk() unless($sIgnChk =~ /Doxygen|All/i);
  48. GitChk() unless($sIgnChk =~ /Git|All/i);
  49. $repoversion = GetRepoVersion();
  50. unless(-r "$outputdir"){
  51. mkdir "$outputdir" or die "Can't create output directory for documentation (outdir=$outputdir)\n";
  52. }
  53. $sSkipBuild = UpdDoxyConf($repoversion);
  54. if($sForceBuild || $sSkipBuild==0){
  55. print "Building doc\n";
  56. system("doxygen doxyconf");
  57. }
  58. }
  59. sub DoxygenChk {
  60. my $doxyversion;
  61. my @line = ();
  62. #checking for doxygen
  63. open PIPE,"doxygen --version |" or die $!;
  64. @line = grep { /\d.\d.\d/ } <PIPE>;
  65. $doxyversion = $line[0];
  66. chomp($doxyversion); #remove newline
  67. print "doxyversion = [ $doxyversion ]\n";
  68. if($doxyversion eq ""){
  69. die "Please install doxygen to proceed.";
  70. }
  71. close PIPE;
  72. return $doxyversion;
  73. }
  74. sub GitChk {
  75. my $gitversion;
  76. my @line = ();
  77. #cheking for git cli
  78. open PIPE,"git --version |" or die $!;
  79. @line = grep { /\d.\d.\d/ } <PIPE>;
  80. $gitversion = $line[0];
  81. $gitversion =~ s/[^\d.\d.\d]//g;
  82. chomp($gitversion);
  83. print "git = [ $gitversion ]\n";
  84. if($gitversion eq ""){
  85. die "Please install git to proceed.";
  86. }
  87. close PIPE;
  88. return $gitversion;
  89. }
  90. sub GetRepoVersion {
  91. my $repoversion;
  92. my @line = ();
  93. open PIPE,"git rev-parse --short HEAD |" or die $!;
  94. @line = grep { /\w/ } <PIPE>;
  95. $repoversion = $line[0];
  96. chomp($repoversion);
  97. print "Git hash is : $repoversion\n";
  98. close PIPE;
  99. return $repoversion;
  100. }
  101. sub UpdDoxyConf { my ($repoversion) = @_;
  102. my $sSkipBuild=0;
  103. my @line = ();
  104. my $chked=0;
  105. die "$sDocFile doesn't seem to exist or coudldn't be read" unless(-r "$sDocFile");
  106. open FHIN,"$sDocFile" || die "couldn't openfile/create $sDocFile \n";
  107. open FHOUT,">doxyconf.tmp" || die "couldn't openfile/create doxyconf.tmp \n";
  108. while(<FHIN>){
  109. if(($chked&1)==0 && $_ =~ /^PROJECT_NUMBER/) {
  110. chomp($_);
  111. @line = split('=',$_);
  112. @line = split('/',$line[1]);
  113. my $old_version = $line[scalar(@line)-1];
  114. print "old_version found=$old_version, current version=$repoversion \n";
  115. if($old_version == $repoversion) { $sSkipBuild=1; }
  116. elsif($sNoUpd==0) { print "Updated project number\n"; }
  117. print FHOUT "PROJECT_NUMBER = http://github.com/rathena/rathena/commit/$repoversion\n";
  118. $chked &=1;
  119. }
  120. elsif(($chked&2)==0 && $_ =~ /^OUTPUT_DIRECTORY/){
  121. print FHOUT "OUTPUT_DIRECTORY = $outputdir\n";
  122. print "Updated output dir\n" if($sNoUpd==0);
  123. $chked &=2;
  124. }
  125. else { print FHOUT $_; }
  126. }
  127. close FHIN;
  128. close FHOUT;
  129. if($sNoUpd==0){
  130. unlink $sDocFile;
  131. rename "doxyconf.tmp", $sDocFile;
  132. print "Updating doxygen file version (doxyconf=$sDocFile)\n";
  133. }
  134. else { unlink "doxyconf.tmp"; }
  135. return $sSkipBuild;
  136. }