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