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