Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 1 | @echo off |
| 2 | setlocal |
| 3 | |
| 4 | pushd %~dp0 |
| 5 | |
| 6 | set this=%~n0 |
| 7 | |
Stefan Grönke | f1502d0 | 2017-09-25 18:58:10 +0200 | [diff] [blame] | 8 | call ..\PCbuild\find_python.bat %PYTHON% |
Steve Dower | e5f41d2 | 2018-05-16 17:50:29 -0400 | [diff] [blame] | 9 | |
| 10 | if not defined PYTHON set PYTHON=py |
| 11 | |
| 12 | if not defined SPHINXBUILD ( |
Steve Dower | d5cd21d | 2017-09-04 14:26:27 -0700 | [diff] [blame] | 13 | %PYTHON% -c "import sphinx" > nul 2> nul |
| 14 | if errorlevel 1 ( |
Steve Dower | 68d663c | 2017-07-17 11:15:48 +0200 | [diff] [blame] | 15 | echo Installing sphinx with %PYTHON% |
Andrés Delfino | 3d3e66c | 2018-05-28 20:20:34 -0300 | [diff] [blame^] | 16 | %PYTHON% -m pip install sphinx |
| 17 | if errorlevel 1 exit /B |
| 18 | ) |
| 19 | %PYTHON% -c "import python_docs_theme" > nul 2> nul |
| 20 | if errorlevel 1 ( |
| 21 | echo Installing python-docs-theme with %PYTHON% |
| 22 | %PYTHON% -m pip install python-docs-theme |
Steve Dower | 68d663c | 2017-07-17 11:15:48 +0200 | [diff] [blame] | 23 | if errorlevel 1 exit /B |
| 24 | ) |
Steve Dower | d5cd21d | 2017-09-04 14:26:27 -0700 | [diff] [blame] | 25 | set SPHINXBUILD=%PYTHON% -c "import sphinx, sys; sys.argv[0] = 'sphinx-build'; sphinx.main()" |
Steve Dower | 68d663c | 2017-07-17 11:15:48 +0200 | [diff] [blame] | 26 | ) |
| 27 | |
Steve Dower | e5f41d2 | 2018-05-16 17:50:29 -0400 | [diff] [blame] | 28 | if not defined BLURB ( |
Steve Dower | 5fcd5e6 | 2017-09-06 10:01:38 -0700 | [diff] [blame] | 29 | %PYTHON% -c "import blurb" > nul 2> nul |
| 30 | if errorlevel 1 ( |
| 31 | echo Installing blurb with %PYTHON% |
| 32 | %PYTHON% -m pip install blurb |
| 33 | if errorlevel 1 exit /B |
| 34 | ) |
| 35 | set BLURB=%PYTHON% -m blurb |
| 36 | ) |
| 37 | |
Steve Dower | d5cd21d | 2017-09-04 14:26:27 -0700 | [diff] [blame] | 38 | if not defined SPHINXBUILD set SPHINXBUILD=sphinx-build |
Steve Dower | 5fcd5e6 | 2017-09-06 10:01:38 -0700 | [diff] [blame] | 39 | if not defined BLURB set BLURB=blurb |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 40 | |
| 41 | if "%1" NEQ "htmlhelp" goto :skiphhcsearch |
| 42 | if exist "%HTMLHELP%" goto :skiphhcsearch |
| 43 | |
| 44 | rem Search for HHC in likely places |
| 45 | set HTMLHELP= |
| 46 | where hhc /q && set HTMLHELP=hhc && goto :skiphhcsearch |
| 47 | where /R ..\externals hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" |
| 48 | if not exist "%HTMLHELP%" where /R "%ProgramFiles(x86)%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" |
| 49 | if not exist "%HTMLHELP%" where /R "%ProgramFiles%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" |
| 50 | if not exist "%HTMLHELP%" ( |
| 51 | echo. |
| 52 | echo.The HTML Help Workshop was not found. Set the HTMLHELP variable |
| 53 | echo.to the path to hhc.exe or download and install it from |
| 54 | echo.http://msdn.microsoft.com/en-us/library/ms669985 |
| 55 | exit /B 1 |
| 56 | ) |
| 57 | :skiphhcsearch |
| 58 | |
| 59 | if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v |
| 60 | |
| 61 | if "%BUILDDIR%" EQU "" set BUILDDIR=build |
| 62 | |
| 63 | rem Targets that don't require sphinx-build |
| 64 | if "%1" EQU "" goto help |
| 65 | if "%1" EQU "help" goto help |
| 66 | if "%1" EQU "check" goto check |
| 67 | if "%1" EQU "serve" goto serve |
| 68 | if "%1" == "clean" ( |
Steve Dower | a4bb58f | 2017-09-19 12:31:28 -0700 | [diff] [blame] | 69 | rmdir /q /s "%BUILDDIR%" |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 70 | goto end |
| 71 | ) |
| 72 | |
| 73 | %SPHINXBUILD% >nul 2> nul |
| 74 | if errorlevel 9009 ( |
| 75 | echo. |
| 76 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx |
| 77 | echo.installed, then set the SPHINXBUILD environment variable to point |
| 78 | echo.to the full path of the 'sphinx-build' executable. Alternatively you |
| 79 | echo.may add the Sphinx directory to PATH. |
| 80 | echo. |
| 81 | echo.If you don't have Sphinx installed, grab it from |
| 82 | echo.http://sphinx-doc.org/ |
| 83 | popd |
| 84 | exit /B 1 |
| 85 | ) |
| 86 | |
| 87 | rem Targets that do require sphinx-build and have their own label |
| 88 | if "%1" EQU "htmlview" goto htmlview |
| 89 | |
| 90 | rem Everything else |
| 91 | goto build |
| 92 | |
| 93 | :help |
| 94 | echo.usage: %this% BUILDER [filename ...] |
| 95 | echo. |
| 96 | echo.Call %this% with the desired Sphinx builder as the first argument, e.g. |
| 97 | echo.``%this% html`` or ``%this% doctest``. Interesting targets that are |
| 98 | echo.always available include: |
| 99 | echo. |
| 100 | echo. Provided by Sphinx: |
| 101 | echo. html, htmlhelp, latex, text |
| 102 | echo. suspicious, linkcheck, changes, doctest |
| 103 | echo. Provided by this script: |
| 104 | echo. clean, check, serve, htmlview |
| 105 | echo. |
| 106 | echo.All arguments past the first one are passed through to sphinx-build as |
| 107 | echo.filenames to build or are ignored. See README.rst in this directory or |
| 108 | echo.the documentation for your version of Sphinx for more exhaustive lists |
| 109 | echo.of available targets and descriptions of each. |
| 110 | echo. |
| 111 | echo.This script assumes that the SPHINXBUILD environment variable contains |
| 112 | echo.a legitimate command for calling sphinx-build, or that sphinx-build is |
| 113 | echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can |
| 114 | echo.be passed by setting the SPHINXOPTS environment variable. |
| 115 | goto end |
| 116 | |
| 117 | :build |
Steve Dower | a4bb58f | 2017-09-19 12:31:28 -0700 | [diff] [blame] | 118 | if not exist "%BUILDDIR%" mkdir "%BUILDDIR%" |
| 119 | |
Steve Dower | 5fcd5e6 | 2017-09-06 10:01:38 -0700 | [diff] [blame] | 120 | if exist ..\Misc\NEWS ( |
| 121 | echo.Copying Misc\NEWS to build\NEWS |
| 122 | copy ..\Misc\NEWS build\NEWS > nul |
| 123 | ) else if exist ..\Misc\NEWS.D ( |
| 124 | if defined BLURB ( |
| 125 | echo.Merging Misc/NEWS with %BLURB% |
| 126 | %BLURB% merge -f build\NEWS |
| 127 | ) else ( |
| 128 | echo.No Misc/NEWS file and Blurb is not available. |
| 129 | exit /B 1 |
| 130 | ) |
| 131 | ) |
| 132 | |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 133 | if NOT "%PAPER%" == "" ( |
| 134 | set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS% |
| 135 | ) |
Steve Dower | a4bb58f | 2017-09-19 12:31:28 -0700 | [diff] [blame] | 136 | cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9" |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 137 | |
| 138 | if "%1" EQU "htmlhelp" ( |
Steve Dower | a4bb58f | 2017-09-19 12:31:28 -0700 | [diff] [blame] | 139 | "%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp" |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 140 | rem hhc.exe seems to always exit with code 1, reset to 0 for less than 2 |
| 141 | if not errorlevel 2 cmd /C exit /b 0 |
| 142 | ) |
| 143 | |
| 144 | echo. |
| 145 | if errorlevel 1 ( |
| 146 | echo.Build failed (exit code %ERRORLEVEL%^), check for error messages |
| 147 | echo.above. Any output will be found in %BUILDDIR%\%1 |
| 148 | ) else ( |
| 149 | echo.Build succeeded. All output should be in %BUILDDIR%\%1 |
| 150 | ) |
| 151 | goto end |
| 152 | |
| 153 | :htmlview |
| 154 | if NOT "%2" EQU "" ( |
| 155 | echo.Can't specify filenames to build with htmlview target, ignoring. |
| 156 | ) |
| 157 | cmd /C %this% html |
| 158 | |
Steve Dower | a4bb58f | 2017-09-19 12:31:28 -0700 | [diff] [blame] | 159 | if EXIST "%BUILDDIR%\html\index.html" ( |
| 160 | echo.Opening "%BUILDDIR%\html\index.html" in the default web browser... |
| 161 | start "%BUILDDIR%\html\index.html" |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 162 | ) |
| 163 | |
| 164 | goto end |
| 165 | |
| 166 | :check |
Steve Dower | a4bb58f | 2017-09-19 12:31:28 -0700 | [diff] [blame] | 167 | cmd /S /C "%PYTHON% tools\rstlint.py -i tools" |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 168 | goto end |
| 169 | |
| 170 | :serve |
Steve Dower | a4bb58f | 2017-09-19 12:31:28 -0700 | [diff] [blame] | 171 | cmd /S /C "%PYTHON% ..\Tools\scripts\serve.py "%BUILDDIR%\html"" |
Zachary Ware | 3f8f16d | 2017-06-10 23:04:36 -0500 | [diff] [blame] | 172 | goto end |
| 173 | |
| 174 | :end |
| 175 | popd |