Skip to content

Commit 8f7fadf

Browse files
authored
Improve support for building docs on Windows (mattermost#6156)
* Improve support for building the docs on Windows by adding more targets to make.bat and adding Windows support to the Makefile; Update README.md with more instruction for Windows platforms * Remove redundant reference to Windows in build instructions
1 parent edd876a commit 8f7fadf

File tree

3 files changed

+77
-19
lines changed

3 files changed

+77
-19
lines changed

Makefile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ SPHINXAUTOBUILD ?= pipenv run sphinx-autobuild
1313

1414
# Put it first so that "make" without argument is like "make help".
1515
help:
16+
ifeq ($(OS),Windows_NT)
17+
@CMD /C $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
18+
else
1619
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
endif
1721

1822
# Install necessary dependencies for the CI build pipeline.
1923
# NOTE: if the version of Python used to build the docs changes, update the `pipenv` command below accordingly.
@@ -26,25 +30,46 @@ test:
2630

2731
# Run `make livehtml` to start sphinx-autobuild.
2832
livehtml:
33+
ifeq ($(OS),Windows_NT)
34+
@CMD /C IF NOT EXIST $(BUILDDIR) MD $(BUILDDIR)
35+
@CMD /C $(SPHINXAUTOBUILD) "$(SOURCEDIR)" "$(BUILDDIR)/html" -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) $(O)
36+
else
2937
@mkdir -p "$(BUILDDIR)"
3038
@$(SPHINXAUTOBUILD) "$(SOURCEDIR)" "$(BUILDDIR)/html" -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) $(O)
39+
endif
3140

3241
# Run `make linkcheck` to check external links
3342
# Overriding `exclude_patterns` configuration to exclude
3443
# directories or files not included in the documentation
3544
linkcheck:
45+
ifeq ($(OS),Windows_NT)
46+
@CMD /C IF NOT EXIST $(BUILDDIR) MD $(BUILDDIR)
47+
@CMD /C $(SPHINXBUILD) -M $@ -D exclude_patterns=archive/*,process/* "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -w "$(WARNINGSFILE)" 2>NUL
48+
else
3649
@mkdir -p "$(BUILDDIR)"
3750
@$(SPHINXBUILD) -M $@ -D exclude_patterns=archive/*,process/* "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 2>>"$(WARNINGSFILE)"
51+
endif
52+
3853

3954
# Download the latest Compass Icon assets.
4055
compass-icons:
41-
mkdir -p source/_static/css
42-
mkdir -p source/_static/font
56+
ifeq ($(OS),Windows_NT)
57+
@CMD /C IF NOT EXIST source/_static/css MD source/_static/css
58+
@CMD /C IF NOT EXIST source/_static/font MD source/_static/font
59+
else
60+
@mkdir -p source/_static/css
61+
@mkdir -p source/_static/font
62+
endif
4363
curl --no-progress-meter -o source/_static/css/compass-icons.css https://mattermost.github.io/compass-icons/css/compass-icons.css
4464
curl --no-progress-meter -o "source/_static/font/compass-icons.#1" "https://mattermost.github.io/compass-icons/font/compass-icons.{eot,woff2,woff,ttf,svg}"
4565

4666
# Catch-all target: route all unknown targets to Sphinx using the new
4767
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
4868
%: Makefile
69+
ifeq ($(OS),Windows_NT)
70+
@CMD /C IF NOT EXIST $(BUILDDIR) MD $(BUILDDIR)
71+
@CMD /C $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -w "$(WARNINGSFILE)" 2>NUL
72+
else
4973
@mkdir -p "$(BUILDDIR)"
5074
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 2>>"$(WARNINGSFILE)"
75+
endif

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,39 @@ Once the review process is complete, and depending on the type of issue it is (e
5757

5858
## Build locally
5959

60-
If you've downloaded the `mattermost/docs` repository and are editing Mattermost documentation on your local machine, you can generate the HTML files from markdown in the `/source` directory. You can review your changes before you commit them or create pull requests.
60+
If you've downloaded the `mattermost/docs` repository and are editing Mattermost documentation on your local machine, you can generate the HTML files from markdown in the `source` directory. You can review your changes before you commit them or create pull requests.
6161

62-
**Note:** Terminal commands can be executed on Linux, Mac, and Windows (using Powershell).
62+
**Note:** Terminal commands can be executed on Linux, Mac, and Windows (using PowerShell).
63+
64+
### Build prerequisites
65+
66+
The following software is required to build the documentation:
67+
68+
- Git [[download]](https://git-scm.com/downloads)
69+
- Python 3.9 or later [[download]](https://www.python.org/downloads/)
70+
71+
### Build instructions
6372

6473
1. Open a terminal window, then clone a forked copy of the documentation repository:
65-
```sh
74+
```shell
6675
git clone https://github.com/mattermost/docs.git
6776
```
6877

6978
2. In the terminal window, navigate into the cloned repository:
70-
```sh
79+
```shell
7180
cd docs
7281
```
7382

7483
3. Install [pipenv](https://docs.pipenv.org/) by using one of the following commands based on your operating system:
7584

7685
For Mac users where Homebrew is installed:
7786
```shell
78-
brew install pipenv
87+
brew install pipenv
7988
```
8089

8190
For other operating systems:
8291
```shell
83-
pip install --user pipenv
92+
pip install --user pipenv
8493
```
8594

8695
4. Install required Python packages:
@@ -94,10 +103,15 @@ If you've downloaded the `mattermost/docs` repository and are editing Mattermost
94103
- Use `make clean html` to delete all static HTML output in the `/build` directory and re-build all files. This command is particularly useful when you're making changes to the LHS navigation pane and want to ensure you're not reviewing cached results.
95104
- Use `make livehtml` to review a live preview published to `http://127.0.0.1:8000` that automatically updates as new changes are saved in your local IDE.
96105
97-
6. When working with static build results, navigate to the `/build` directory:
106+
Windows users will require [GNU Make](https://gnuwin32.sourceforge.net/packages/make.htm) installed for the above commands to work correctly. If GNU Make is not installed, please substitute `CMD /C make.bat` for `make` in the above commands to use the Windows command interpreter. For example `make html` will become `CMD /C make.bat html`.
107+
108+
Note: When using the `CMD /C make.bat` substitution, only a single target may be specified. Instead of running `CMD /C make.bat clean html`, each target must be run seperately. For example, `CMD /C make.bat clean` followed by `CMD /C make.bat html`.
109+
110+
6. When working with static build results, navigate to the `build` directory:
98111
```sh
99-
cd /build
112+
cd build
100113
```
101-
7. Then, preview your changes by opening the `/source/html/index.html` file.
114+
115+
7. Then, preview your changes by opening the `source/html/index.html` file.
102116
103-
Build errors are written to the `/build/warning.log`.
117+
Build errors are written to the `build/warnings.log` file.

make.bat

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ if "%SPHINXAUTOBUILD%" == "" (
1313
set SOURCEDIR=source
1414
set BUILDDIR=build
1515
set WARNINGSFILE=%BUILDDIR%/warnings.log
16-
set ERRORSFILE=%BUILDDIR%/errors.log
17-
if not "%SPHINXOPTS%" == "" (
18-
set SPHINXOPTS=-j auto -w %WARNINGSFILE%
16+
if "%SPHINXOPTS%" == "" (
17+
set SPHINXOPTS=-j auto
1918
)
2019

2120
if "%1" == "" goto help
21+
if "%1" == "livehtml" goto livehtml
22+
if "%1" == "linkcheck" goto linkcheck
23+
if "%1" == "test" goto test
24+
if "%1" == "compass-icons" goto compassicons
2225

2326
%SPHINXBUILD% >NUL 2>NUL
2427
if errorlevel 9009 (
@@ -33,13 +36,29 @@ if errorlevel 9009 (
3336
exit /b 1
3437
)
3538

36-
md %BUILDDIR%
37-
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 2>%ERRORSFILE%
39+
if not exist %BUILDDIR% md %BUILDDIR%
40+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -w "%WARNINGSFILE% 2>NUL
3841
goto end
3942

4043
:livehtml
41-
md %BUILDDIR%
42-
%SPHINXAUTOBUILD% %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
44+
if not exist %BUILDDIR% md %BUILDDIR%
45+
%SPHINXAUTOBUILD% %SOURCEDIR% %BUILDDIR%/html -d %BUILDDIR%/doctrees %SPHINXOPTS% %O%
46+
goto end
47+
48+
:linkcheck
49+
if not exist %BUILDDIR% md %BUILDDIR%
50+
%SPHINXBUILD% -M linkcheck -D exclude_patterns=archive/*,process/* %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
51+
goto end
52+
53+
:test
54+
pipenv run pytest
55+
goto end
56+
57+
:compassicons
58+
IF NOT EXIST source/_static/css MD source/_static/css
59+
IF NOT EXIST source/_static/font MD source/_static/font
60+
curl --no-progress-meter -o source/_static/css/compass-icons.css https://mattermost.github.io/compass-icons/css/compass-icons.css
61+
curl --no-progress-meter -o "source/_static/font/compass-icons.#1" "https://mattermost.github.io/compass-icons/font/compass-icons.{eot,woff2,woff,ttf,svg}"
4362
goto end
4463

4564
:help

0 commit comments

Comments
 (0)