sphinx_doc_gen.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/sh
  2. # run from the blender source dir
  3. # bash doc/python_api/sphinx_doc_gen.sh
  4. # ssh upload means you need an account on the server
  5. # ----------------------------------------------------------------------------
  6. # Upload vars
  7. # disable for testing
  8. DO_UPLOAD=true
  9. DO_EXE_BLENDER=true
  10. DO_OUT_HTML=true
  11. DO_OUT_HTML_ZIP=true
  12. DO_OUT_PDF=false
  13. if [ -z $BLENDER_BIN ] ; then
  14. BLENDER_BIN="./blender.bin"
  15. fi
  16. if [ "$1" == "" ] ; then
  17. echo "Expected a single argument for the username on blender.org, skipping upload step!"
  18. DO_UPLOAD=false
  19. else
  20. SSH_USER=$1
  21. SSH_HOST=$SSH_USER"@blender.org"
  22. SSH_UPLOAD="/data/www/vhosts/www.blender.org/api" # blender_python_api_VERSION, added after
  23. fi
  24. # ----------------------------------------------------------------------------
  25. # Blender Version & Info
  26. # 'Blender 2.53 (sub 1) Build' --> '2_53_1' as a shell script.
  27. # "_".join(str(v) for v in bpy.app.version)
  28. # custom blender vars
  29. blender_srcdir=$(dirname -- $0)/../..
  30. blender_version_header="$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h"
  31. blender_version=$(grep "BLENDER_VERSION\s" "$blender_version_header" | awk '{print $3}')
  32. blender_version_char=$(grep "BLENDER_VERSION_CHAR\s" "$blender_version_header" | awk '{print $3}')
  33. blender_version_cycle=$(grep "BLENDER_VERSION_CYCLE\s" "$blender_version_header" | awk '{print $3}')
  34. blender_subversion=$(grep "BLENDER_SUBVERSION\s" "$blender_version_header" | awk '{print $3}')
  35. unset blender_version_header
  36. if [ "$blender_version_cycle" = "release" ] ; then
  37. BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)$blender_version_char"_release"
  38. else
  39. BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)_$blender_subversion
  40. fi
  41. SSH_UPLOAD_FULL=$SSH_UPLOAD/"blender_python_api_"$BLENDER_VERSION
  42. SPHINXBASE=doc/python_api
  43. SPHINX_WORKDIR="$(mktemp --directory --suffix=.sphinx)"
  44. # ----------------------------------------------------------------------------
  45. # Generate reStructuredText (blender/python only)
  46. if $DO_EXE_BLENDER ; then
  47. # Don't delete existing docs, now partial updates are used for quick builds.
  48. #
  49. # Disable ASAN error halt since it results in nonzero exit code on any minor issue.
  50. ASAN_OPTIONS=halt_on_error=0 \
  51. $BLENDER_BIN \
  52. --background \
  53. -noaudio \
  54. --factory-startup \
  55. --python-exit-code 1 \
  56. --python $SPHINXBASE/sphinx_doc_gen.py \
  57. -- \
  58. --output=$SPHINX_WORKDIR
  59. if (($? != 0)) ; then
  60. echo "Generating documentation failed, aborting"
  61. exit 1
  62. fi
  63. fi
  64. # ----------------------------------------------------------------------------
  65. # Generate HTML (sphinx)
  66. if $DO_OUT_HTML ; then
  67. # sphinx-build -n -b html $SPHINX_WORKDIR/sphinx-in $SPHINX_WORKDIR/sphinx-out
  68. # annoying bug in sphinx makes it very slow unless we do this. should report.
  69. cd $SPHINX_WORKDIR
  70. sphinx-build -b html sphinx-in sphinx-out
  71. # XXX, saves space on upload and zip, should move HTML outside
  72. # and zip up there, for now this is OK
  73. rm -rf sphinx-out/.doctrees
  74. # in case we have a zip already
  75. rm -f blender_python_reference_$BLENDER_VERSION.zip
  76. # ------------------------------------------------------------------------
  77. # ZIP the HTML dir for upload
  78. if $DO_OUT_HTML_ZIP ; then
  79. # lame, temp rename dir
  80. mv sphinx-out blender_python_reference_$BLENDER_VERSION
  81. zip -r -9 blender_python_reference_$BLENDER_VERSION.zip blender_python_reference_$BLENDER_VERSION
  82. mv blender_python_reference_$BLENDER_VERSION sphinx-out
  83. fi
  84. cd -
  85. fi
  86. # ----------------------------------------------------------------------------
  87. # Generate PDF (sphinx/laytex)
  88. if $DO_OUT_PDF ; then
  89. cd $SPHINX_WORKDIR
  90. sphinx-build -n -b latex $SPHINX_WORKDIR/sphinx-in $SPHINX_WORKDIR/sphinx-out
  91. make -C $SPHINX_WORKDIR/sphinx-out
  92. mv $SPHINX_WORKDIR/sphinx-out/contents.pdf \
  93. $SPHINX_WORKDIR/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf
  94. fi
  95. # ----------------------------------------------------------------------------
  96. # Upload to blender servers, comment this section for testing
  97. if $DO_UPLOAD ; then
  98. ssh $SSH_USER@blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
  99. rsync --progress -ave "ssh -p 22" $SPHINX_WORKDIR/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
  100. ## symlink the dir to a static URL
  101. #ssh $SSH_USER@blender.org 'rm '$SSH_UPLOAD'/250PythonDoc && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/250PythonDoc'
  102. if [ "$blender_version_cycle" = "release" ] ; then
  103. ssh $SSH_USER@blender.org 'rm '$SSH_UPLOAD'/blender_python_api_current && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/blender_python_api_current'
  104. fi
  105. # better redirect
  106. ssh $SSH_USER@blender.org 'echo "<html><head><title>Redirecting...</title><meta http-equiv=\"REFRESH\" content=\"0;url=../blender_python_api_'$BLENDER_VERSION'/\"></head><body>Redirecting...</body></html>" > '$SSH_UPLOAD'/250PythonDoc/index.html'
  107. # redirect for release only so wiki can point here
  108. if [ "$blender_version_cycle" = "release" ] ; then
  109. ssh $SSH_USER@blender.org 'echo "<html><head><title>Redirecting...</title><meta http-equiv=\"REFRESH\" content=\"0;url=../blender_python_api_'$BLENDER_VERSION'/\"></head><body>Redirecting...</body></html>" > '$SSH_UPLOAD'/blender_python_api/index.html'
  110. fi
  111. if $DO_OUT_PDF ; then
  112. # rename so local PDF has matching name.
  113. rsync --progress -ave "ssh -p 22" \
  114. $SPHINX_WORKDIR/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf \
  115. $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.pdf
  116. fi
  117. if $DO_OUT_HTML_ZIP ; then
  118. rsync --progress -ave "ssh -p 22" \
  119. $SPHINX_WORKDIR/blender_python_reference_$BLENDER_VERSION.zip \
  120. $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.zip
  121. fi
  122. fi
  123. # ----------------------------------------------------------------------------
  124. # Print some useful text
  125. echo ""
  126. echo "Finished! view the docs from: "
  127. if $DO_OUT_HTML ; then echo " html:" $SPHINX_WORKDIR/sphinx-out/index.html ; fi
  128. if $DO_OUT_PDF ; then echo " pdf:" $SPHINX_WORKDIR/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf ; fi