Skip to content

Commit

Permalink
doc: move context back to doc/, fix broken links
Browse files Browse the repository at this point in the history
Running documentation scripts on the top directory shifted all links one
level dowwn and is breaking all incoming links.

Use a script to copy all RST files into the doc/ directory before
running sphinx and keep structure intact.

Jira: ZEP-1579
Change-Id: Iccff068430e2ddb29e172cd8ae920475815d199e
Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
nashif committed Jan 16, 2017
1 parent 9811d2b commit 06382b8
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ scripts/kconfig/zconf.tab.c
doc/_build
doc/xml
doc/html
doc/boards
doc/samples
doc/latex
sanity-out/
scripts/grub
Expand Down
10 changes: 8 additions & 2 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Makefile for Sphinx documentation
#

CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)
# You can set these variables from the command line.
SPHINXOPTS ?= -q
SPHINXBUILD = sphinx-build
Expand All @@ -16,7 +19,7 @@ endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -c $(ZEPHYR_BASE)/doc -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(ZEPHYR_BASE)
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

Expand Down Expand Up @@ -63,10 +66,13 @@ clean:

htmldocs: doxy html

content: scripts/extract_content.py
$(Q)$<

kconfig: scripts/genrest/genrest.py
srctree=../ SRCARCH=x86 python $< ../Kconfig reference/kconfig/

html: kconfig
html: content kconfig
$(SPHINXBUILD) -t $(DOC_TAG) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html

dirhtml:
Expand Down
24 changes: 12 additions & 12 deletions index.rst → doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ Sections
.. toctree::
:maxdepth: 1

doc/introduction/introducing_zephyr.rst
doc/getting_started/getting_started.rst
introduction/introducing_zephyr.rst
getting_started/getting_started.rst
boards/boards.rst
doc/kernel/kernel.rst
doc/application/application.rst
doc/porting/porting.rst
doc/drivers/drivers.rst
doc/subsystems/subsystems.rst
doc/api/api.rst
kernel/kernel.rst
application/application.rst
porting/porting.rst
drivers/drivers.rst
subsystems/subsystems.rst
api/api.rst
samples/samples.rst
doc/reference/kconfig/index.rst
doc/contribute/code.rst
doc/release-notes.rst
doc/LICENSING.rst
reference/kconfig/index.rst
contribute/code.rst
release-notes.rst
LICENSING.rst

You can find further information on the `Zephyr Project Wiki`_.

Expand Down
74 changes: 74 additions & 0 deletions doc/scripts/extract_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3
#
# Copyright (c) 2017, Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Very quick script to move docs from different places into the doc directory
# to fix the website and external links

import os
import shutil
import re
import sys
import fnmatch


# direcories to search for .rst files
CONTENT_DIRS = ["samples", "boards"]

# directives to parse for included files
DIRECTIVES = ["figure","include","image","literalinclude"]

if "ZEPHYR_BASE" not in os.environ:
sys.stderr.write("$ZEPHYR_BASE environment variable undefined.\n")
exit(1)
ZEPHYR_BASE = os.environ["ZEPHYR_BASE"]

def get_rst_files(dir):
matches = []
for root, dirnames, filenames in os.walk('%s/%s' %(ZEPHYR_BASE, dir)):
for filename in fnmatch.filter(filenames, '*.rst'):
matches.append(os.path.join(root, filename))
for file in matches:
frel = file.replace(ZEPHYR_BASE,"").strip("/")
dir=os.path.dirname(frel)
if not os.path.exists(os.path.join(ZEPHYR_BASE, "doc", dir)):
os.makedirs(os.path.join(ZEPHYR_BASE, "doc", dir))

shutil.copyfile(file, os.path.join(ZEPHYR_BASE, "doc", frel))

with open(file) as f:
content = f.readlines()
content = [x.strip() for x in content]
directives = "|".join(DIRECTIVES)
pattern = re.compile("\s*\.\.\s+(%s)::\s+(.*)" %directives)
for l in content:
m = pattern.match(l)
if m:
inf = m.group(2)
ind = os.path.dirname(inf)
if not os.path.exists(os.path.join(ZEPHYR_BASE, "doc", dir, ind)):
os.makedirs(os.path.join(ZEPHYR_BASE, "doc", dir, ind))

shutil.copyfile(os.path.join(ZEPHYR_BASE, dir, inf),
os.path.join(ZEPHYR_BASE, "doc", dir, inf))

f.close()

def main():
for d in CONTENT_DIRS:
get_rst_files(d)

if __name__ == "__main__":
main()

0 comments on commit 06382b8

Please sign in to comment.