blob: d28dae78e86d4f84937de2052eeea65edfa7a22e [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 )
Andrés Delfino8c1ad0c2018-05-28 20:28:22 -030019 set SPHINXBUILD=%PYTHON% -c "import sphinx, sys; sys.argv[0] = 'sphinx-build'; sys.exit(sphinx.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=
44where hhc /q && set HTMLHELP=hhc && goto :skiphhcsearch
45where /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 Dower5fcd5e62017-09-06 10:01:38 -0700118if exist ..\Misc\NEWS (
119 echo.Copying Misc\NEWS to build\NEWS
120 copy ..\Misc\NEWS build\NEWS > nul
121) else if exist ..\Misc\NEWS.D (
122 if defined BLURB (
123 echo.Merging Misc/NEWS with %BLURB%
124 %BLURB% merge -f build\NEWS
125 ) else (
126 echo.No Misc/NEWS file and Blurb is not available.
127 exit /B 1
128 )
129)
130
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500131if NOT "%PAPER%" == "" (
132 set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
133)
Zachary Wared824ca72018-07-02 15:31:42 -0500134if "%1" EQU "htmlhelp" (
135 set SPHINXOPTS=-D html_theme_options.body_max_width=none %SPHINXOPTS%
136)
Steve Dowera4bb58f2017-09-19 12:31:28 -0700137cmd /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 -0500138
139if "%1" EQU "htmlhelp" (
Steve Dowera4bb58f2017-09-19 12:31:28 -0700140 "%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500141 rem hhc.exe seems to always exit with code 1, reset to 0 for less than 2
142 if not errorlevel 2 cmd /C exit /b 0
143)
144
145echo.
146if errorlevel 1 (
147 echo.Build failed (exit code %ERRORLEVEL%^), check for error messages
148 echo.above. Any output will be found in %BUILDDIR%\%1
149) else (
150 echo.Build succeeded. All output should be in %BUILDDIR%\%1
151)
152goto end
153
154:htmlview
155if NOT "%2" EQU "" (
156 echo.Can't specify filenames to build with htmlview target, ignoring.
157)
158cmd /C %this% html
159
Steve Dowera4bb58f2017-09-19 12:31:28 -0700160if EXIST "%BUILDDIR%\html\index.html" (
161 echo.Opening "%BUILDDIR%\html\index.html" in the default web browser...
Andrés Delfino0e5f9012018-06-11 13:58:18 -0300162 start "" "%BUILDDIR%\html\index.html"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500163)
164
165goto end
166
167:check
Steve Dowera4bb58f2017-09-19 12:31:28 -0700168cmd /S /C "%PYTHON% tools\rstlint.py -i tools"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500169goto end
170
171:serve
Steve Dowera4bb58f2017-09-19 12:31:28 -0700172cmd /S /C "%PYTHON% ..\Tools\scripts\serve.py "%BUILDDIR%\html""
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500173goto end
174
175:end
176popd