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