blob: dfc622f66615dfab3ec30b61b7b3e128187f237c [file] [log] [blame]
Zachary Ware3f8f16d2017-06-10 23:04:36 -05001@echo off
2setlocal
3
4pushd %~dp0
5
6set this=%~n0
7
Stefan Grönkef1502d02017-09-25 18:58:10 +02008call ..\PCbuild\find_python.bat %PYTHON%
Steve Dowere5f41d22018-05-16 17:50:29 -04009
10if not defined PYTHON set PYTHON=py
11
12if not defined SPHINXBUILD (
Steve Dowerd5cd21d2017-09-04 14:26:27 -070013 %PYTHON% -c "import sphinx" > nul 2> nul
14 if errorlevel 1 (
Steve Dower68d663c2017-07-17 11:15:48 +020015 echo Installing sphinx with %PYTHON%
Andrés Delfino3d3e66c2018-05-28 20:20:34 -030016 %PYTHON% -m pip install sphinx
17 if errorlevel 1 exit /B
18 )
Steve Dowerafe17a72018-12-19 18:20:06 -080019 set SPHINXBUILD=%PYTHON% -c "import sphinx.cmd.build, sys; sys.exit(sphinx.cmd.build.main())"
Steve Dower68d663c2017-07-17 11:15:48 +020020)
21
Andrés Delfino05f1c892018-05-30 13:08:25 -030022%PYTHON% -c "import python_docs_theme" > nul 2> nul
23if 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 Dowere5f41d22018-05-16 17:50:29 -040029if not defined BLURB (
Steve Dower5fcd5e62017-09-06 10:01:38 -070030 %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 Ware3f8f16d2017-06-10 23:04:36 -050039if "%1" NEQ "htmlhelp" goto :skiphhcsearch
40if exist "%HTMLHELP%" goto :skiphhcsearch
41
42rem Search for HHC in likely places
43set HTMLHELP=
chrullriche61cc482019-01-08 03:57:29 +010044where hhc /q && set "HTMLHELP=hhc" && goto :skiphhcsearch
Zachary Ware3f8f16d2017-06-10 23:04:36 -050045where /R ..\externals hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
46if not exist "%HTMLHELP%" where /R "%ProgramFiles(x86)%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
47if not exist "%HTMLHELP%" where /R "%ProgramFiles%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
48if 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
57if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v
58
59if "%BUILDDIR%" EQU "" set BUILDDIR=build
60
61rem Targets that don't require sphinx-build
62if "%1" EQU "" goto help
63if "%1" EQU "help" goto help
64if "%1" EQU "check" goto check
65if "%1" EQU "serve" goto serve
66if "%1" == "clean" (
Steve Dowera4bb58f2017-09-19 12:31:28 -070067 rmdir /q /s "%BUILDDIR%"
Zachary Ware3f8f16d2017-06-10 23:04:36 -050068 goto end
69)
70
71%SPHINXBUILD% >nul 2> nul
72if 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
85rem Targets that do require sphinx-build and have their own label
86if "%1" EQU "htmlview" goto htmlview
87
88rem Everything else
89goto build
90
91:help
92echo.usage: %this% BUILDER [filename ...]
93echo.
94echo.Call %this% with the desired Sphinx builder as the first argument, e.g.
95echo.``%this% html`` or ``%this% doctest``. Interesting targets that are
96echo.always available include:
97echo.
98echo. Provided by Sphinx:
99echo. html, htmlhelp, latex, text
100echo. suspicious, linkcheck, changes, doctest
101echo. Provided by this script:
102echo. clean, check, serve, htmlview
103echo.
104echo.All arguments past the first one are passed through to sphinx-build as
105echo.filenames to build or are ignored. See README.rst in this directory or
106echo.the documentation for your version of Sphinx for more exhaustive lists
107echo.of available targets and descriptions of each.
108echo.
109echo.This script assumes that the SPHINXBUILD environment variable contains
110echo.a legitimate command for calling sphinx-build, or that sphinx-build is
111echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can
112echo.be passed by setting the SPHINXOPTS environment variable.
113goto end
114
115:build
Steve Dowera4bb58f2017-09-19 12:31:28 -0700116if not exist "%BUILDDIR%" mkdir "%BUILDDIR%"
117
Steve Dowerafe17a72018-12-19 18:20:06 -0800118rem PY_MISC_NEWS_DIR is also used by our Sphinx extension in tools/extensions/pyspecific.py
119if not defined PY_MISC_NEWS_DIR set PY_MISC_NEWS_DIR=%BUILDDIR%\%1
Steve Dowerf78e66c2019-06-14 14:20:16 -0700120if not exist "%PY_MISC_NEWS_DIR%" mkdir "%PY_MISC_NEWS_DIR%"
Steve Dower5fcd5e62017-09-06 10:01:38 -0700121if exist ..\Misc\NEWS (
Steve Dowerafe17a72018-12-19 18:20:06 -0800122 echo.Copying Misc\NEWS to %PY_MISC_NEWS_DIR%\NEWS
123 copy ..\Misc\NEWS "%PY_MISC_NEWS_DIR%\NEWS" > nul
Steve Dower5fcd5e62017-09-06 10:01:38 -0700124) else if exist ..\Misc\NEWS.D (
125 if defined BLURB (
126 echo.Merging Misc/NEWS with %BLURB%
Steve Dowerafe17a72018-12-19 18:20:06 -0800127 %BLURB% merge -f "%PY_MISC_NEWS_DIR%\NEWS"
Steve Dower5fcd5e62017-09-06 10:01:38 -0700128 ) else (
129 echo.No Misc/NEWS file and Blurb is not available.
130 exit /B 1
131 )
132)
133
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500134if NOT "%PAPER%" == "" (
135 set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
136)
Zachary Wared824ca72018-07-02 15:31:42 -0500137if "%1" EQU "htmlhelp" (
138 set SPHINXOPTS=-D html_theme_options.body_max_width=none %SPHINXOPTS%
139)
Steve Dowera4bb58f2017-09-19 12:31:28 -0700140cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500141
142if "%1" EQU "htmlhelp" (
Steve Dowera4bb58f2017-09-19 12:31:28 -0700143 "%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500144 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
148echo.
149if 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)
155goto end
156
157:htmlview
158if NOT "%2" EQU "" (
159 echo.Can't specify filenames to build with htmlview target, ignoring.
160)
161cmd /C %this% html
162
Steve Dowera4bb58f2017-09-19 12:31:28 -0700163if EXIST "%BUILDDIR%\html\index.html" (
164 echo.Opening "%BUILDDIR%\html\index.html" in the default web browser...
Andrés Delfino0e5f9012018-06-11 13:58:18 -0300165 start "" "%BUILDDIR%\html\index.html"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500166)
167
168goto end
169
170:check
Steve Dowera4bb58f2017-09-19 12:31:28 -0700171cmd /S /C "%PYTHON% tools\rstlint.py -i tools"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500172goto end
173
174:serve
Steve Dowera4bb58f2017-09-19 12:31:28 -0700175cmd /S /C "%PYTHON% ..\Tools\scripts\serve.py "%BUILDDIR%\html""
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500176goto end
177
178:end
179popd