Commit 862a2c0b authored by eliben@chromium.org's avatar eliben@chromium.org

[NaCl docs] Initial commit of the new docs infrastructure into Chromium.

This reflects the current state of master in
https://github.com/eliben/nacl-docs-rst

BUG=None
R=binji@chromium.org

Review URL: https://codereview.chromium.org/23835002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220672 0039d316-1c4b-4281-b951-d872f2087c98
parent bac709aa
...@@ -21,6 +21,7 @@ def CommonChecks(input_api, output_api): ...@@ -21,6 +21,7 @@ def CommonChecks(input_api, output_api):
black_list = [ black_list = [
r'src[\\\/]build_tools[\\\/]tests[\\\/].*', r'src[\\\/]build_tools[\\\/]tests[\\\/].*',
r'src[\\\/]build_tools[\\\/]sdk_tools[\\\/]third_party[\\\/].*', r'src[\\\/]build_tools[\\\/]sdk_tools[\\\/]third_party[\\\/].*',
r'src[\\\/]doc[\\\/]*',
] ]
canned = input_api.canned_checks canned = input_api.canned_checks
output.extend(canned.RunPylint(input_api, output_api, black_list=black_list, output.extend(canned.RunPylint(input_api, output_api, black_list=black_list,
......
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " devsite build docs for developer.google.com"
@echo " serve start python web server on port server 8009"
clean:
rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/NativeClient.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/NativeClient.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/NativeClient"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/NativeClient"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
devsite:
$(SPHINXBUILD) -b devsite $(ALLSPHINXOPTS) $(BUILDDIR)/devsite
serve:
cd _build/devsite && python -m SimpleHTTPServer 8009
nacl-docs-rst
=============
Directory structure
-------------------
This is a tree of .rst files that represent the source of the NaCl
documentation. Some of the files and directories here are special:
* conf.py: Sphinx configuration file
* images/: Images are stored here. Note that this isn't necessary - Sphinx
doesn't mind about interspersing images in .rst directories.
* _sphinxext/: Code of the Sphinx extension we use to generate HTML from .rst
* _static/: Static files, like CSS, for the documentation. This should be seen
as part of the infrastructure - the real CSS comes from the real doc
publishing server.
* _build/: Build artifacts (not checked into source control).
* Makefile & README
How to build
------------
To build the docs you will needs sphinx installed (and sphinx-build in your
path), and simply run:
make devsite
To rebuild all the pages always, add 'SPHINXOPTS=-a', e.g.:
make SPHINXOPTS=-a devsite
To emit local-testing mode, instead of production mode, add:
SPHINXOPTS='-D devsite_production_mode=0'
e.g.:
make SPHINXOPTS='-D devsite_production_mode=0' devsite
Production mode contains devsite-specific templating and non-HTML constructs.
The builder prints out the value of this setting - make sure it's what you
expect it to be. For example:
$ make devsite
sphinx-build -b devsite -d _build/doctrees . _build/devsite
Running Sphinx v1.2b1
loading pickled environment... done
----> Devsite builder with production mode = 1
Local HTTP server to view the docs
----------------------------------
To view the HTML locally, build the docs with production mode turned off, and
run:
make serve
This will start a webserver on the local machine, and allows the pages
to be viewed by in a browser by navigating to:
http://localhost:8009/
Serving through a server and not just file:/// because this way the <link>
relative paths to CSS actually work.
# Copyright (c) 2013 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This is a Sphinx extension.
#
import codecs
import os
import string
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from sphinx.util.osutil import ensuredir
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.writers.html import HTMLWriter
from sphinx.writers.html import SmartyPantsHTMLTranslator as HTMLTranslator
# TODO(eliben): it may be interesting to use an actual Sphinx template here at
# some point.
PAGE_TEMPLATE = string.Template(r'''
${devsite_prefix}
<html devsite>
<head>
<title>${doc_title}</title>
<meta name="project_path" value="/native-client/_project.yaml" />
<meta name="book_path" value="/native-client/_book.yaml" />
<link href="/native-client/css/local_extensions.css" rel="stylesheet" type="text/css"/>
${nonprod_css}
<style type="text/css">
.nested-def {list-style-type: none; margin-bottom: 0.3em;}
.maxheight {height: 200px;}
</style>
</head>
<body>
${devsite_butterbar}
${doc_body}
</body>
</html>
'''.lstrip())
DEVSITE_PREFIX = r'''
{% setvar pepperversion %}pepper28{% endsetvar %}
{% include "native-client/_local_variables.html" %}
'''.lstrip()
DEVSITE_BUTTERBAR = '{{butterbar}}'
# We want the non-production-mode HTML to resemble the real one, so this points
# to a copied version of the devsite CSS that we'll keep locally. It's for
# testing purposes only.
NONPROD_CSS = '<link href="/_static/css/local_extensions.css"'\
'rel="stylesheet" type="text/css"/>'
class DevsiteHTMLTranslator(HTMLTranslator):
""" Custom HTML translator for devsite output.
Hooked into the HTML builder by setting the html_translator_class
option in conf.py
"""
def __init__(self, builder, *args, **kwds):
# HTMLTranslator is an old-style Python class, so 'super' doesn't work: use
# direct parent invocation.
HTMLTranslator.__init__(self, builder, *args, **kwds)
self.within_ignored_h1 = False
self.within_toc = False
def visit_bullet_list(self, node):
if self.within_toc:
# Within a TOC, devsite wants <ol>
self.body.append(self.starttag(node, 'ol'))
else:
# Use our own class attribute for <ul>. Don't care about compacted lists.
self.body.append(self.starttag(node, 'ul', **{'class': 'small-gap'}))
def depart_bullet_list(self, node):
if self.within_toc:
self.body.append('</ol>\n')
else:
# Override to not pop anything from context
self.body.append('</ul>\n')
def visit_literal_block(self, node):
# We don't use Sphinx's buildin pygments integration for code highlighting,
# because the devsite requires special <pre> tags for that and handles the
# highlighting on its own.
attrs = {'class': 'prettyprint'} if node.get('prettyprint', 1) else {}
self.body.append(self.starttag(node, 'pre', **attrs))
def depart_literal_block(self, node):
self.body.append('\n</pre>\n')
def visit_paragraph(self, node):
# Don't generate <p>s within the table of contents
if not self.within_toc:
HTMLTranslator.visit_paragraph(self, node)
def depart_paragraph(self, node):
if not self.within_toc:
HTMLTranslator.depart_paragraph(self, node)
def visit_section(self, node):
# devsite needs <section> instead of <div class='section'>
self.section_level += 1
self.body.append(self.starttag(node, 'section'))
def depart_section(self, node):
self.section_level -= 1
self.body.append('</section>')
def visit_image(self, node):
# Paths to images in .rst sources should be absolute. This visitor does the
# required transformation for the path to be correct in the final HTML.
if self.builder.devsite_production_mode:
node['uri'] = '/native-client/' + node['uri']
HTMLTranslator.visit_image(self, node)
def visit_title(self, node):
# Why this?
#
# Sphinx insists on inserting a <h1>Page Title</h1> into the page, but this
# is not how the devsite wants it. The devsite inserts the page title on
# its own, the the extra h1 is duplication.
#
# Killing the doctree title node in a custom transform doesn't work, because
# Sphinx explicitly looks for it when writing a document. So instead we rig
# the HTML produced.
#
# When a title node is visited, and this is the h1-to-be, we ignore it and
# also set a flag that tells visit_Text not to print the actual text of the
# header.
# The h1 node is in the section whose parent is the document itself. Other
# sections have this top-section as their parent.
if (node.parent and node.parent.parent and
isinstance(node.parent.parent, nodes.document)):
# Internal flag. Also, nothing is pushed to the context. Our depart_title
# doesn't pop anything when this flag is set.
self.within_ignored_h1 = True
else:
HTMLTranslator.visit_title(self, node)
def depart_title(self, node):
if not self.within_ignored_h1:
HTMLTranslator.depart_title(self, node)
self.within_ignored_h1 = False
def visit_Text(self, node):
if not self.within_ignored_h1:
HTMLTranslator.visit_Text(self, node)
def visit_topic(self, node):
if 'contents' in node['classes']:
# Detect a TOC: this requires special treatment for devsite.
self.within_toc = True
# Emit <nav> manually and not through starttage because we don't want
# additional class components to be added
self.body.append('\n<nav class="inline-toc">')
def depart_topic(self, node):
if self.within_toc:
self.within_toc = False
self.body.append('</nav>\n')
def write_colspecs(self):
# Override this method from docutils to do nothing. We don't need those
# pesky <col width=NN /> tags in our markup.
pass
def visit_admonition(self, node, name=''):
self.body.append(self.starttag(node, 'aside', CLASS=node.get('class', '')))
def depart_admonition(self, node=''):
self.body.append('\n</aside>\n')
def unknown_visit(self, node):
raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
class DevsiteBuilder(StandaloneHTMLBuilder):
""" Builder for the NaCl devsite HTML output.
Loosely based on the code of Sphinx's standard SerializingHTMLBuilder.
"""
name = 'devsite'
out_suffix = '.html'
link_suffix = '.html'
# Disable the addition of "pi"-permalinks to each section header
add_permalinks = False
def init(self):
self.devsite_production_mode = int(self.config.devsite_production_mode) == 1
print "----> Devsite builder with production mode = %d" % (
self.devsite_production_mode,)
self.config_hash = ''
self.tags_hash = ''
self.theme = None # no theme necessary
self.templates = None # no template bridge necessary
self.init_translator_class()
self.init_highlighter()
def get_target_uri(self, docname, typ=None):
if self.devsite_production_mode:
# TODO(eliben): testrst here will have to be replaced with
# {{pepperversion}}
return '/native-client/testrst/%s' % docname
else:
return docname + self.link_suffix
def handle_page(self, pagename, ctx, templatename='page.html',
outfilename=None, event_arg=None):
ctx['current_page_name'] = pagename
if not outfilename:
outfilename = os.path.join(self.outdir,
pagename + self.out_suffix)
# Emit an event to Sphinx
self.app.emit('html-page-context', pagename, templatename,
ctx, event_arg)
ensuredir(os.path.dirname(outfilename))
self._dump_context(ctx, outfilename)
def _dump_context(self, context, filename):
""" Do the actual dumping of the page to the file. context is a dict. Some
important fields:
body - document contents
title
current_page_name
Some special pages (genindex, etc.) may not have some of the fields, so
fetch them conservatively.
"""
if not 'body' in context:
return
# codecs.open is the fast Python 2.x way of emulating the encoding= argument
# in Python 3's builtin open.
with codecs.open(filename, 'w', encoding='utf-8') as f:
f.write(PAGE_TEMPLATE.substitute(
doc_title=context.get('title', ''),
doc_body=context.get('body'),
nonprod_css=self._conditional_nonprod(NONPROD_CSS),
devsite_prefix=self._conditional_devsite(DEVSITE_PREFIX),
devsite_butterbar=self._conditional_devsite(DEVSITE_BUTTERBAR)))
def _conditional_devsite(self, s):
return s if self.devsite_production_mode else ''
def _conditional_nonprod(self, s):
return s if not self.devsite_production_mode else ''
class NaclCodeDirective(Directive):
""" Custom "naclcode" directive for code snippets. To keep it under our
control.
"""
has_content = True
required_arguments = 0
optional_arguments = 1
option_spec = {
'prettyprint': int,
}
def run(self):
code = u'\n'.join(self.content)
literal = nodes.literal_block(code, code)
literal['prettyprint'] = self.options.get('prettyprint', 1)
return [literal]
def setup(app):
""" Extension registration hook.
"""
app.add_directive('naclcode', NaclCodeDirective)
app.add_builder(DevsiteBuilder)
# "Production mode" for local testing vs. on-server documentation.
app.add_config_value('devsite_production_mode', default='1', rebuild='html')
This source diff could not be displayed because it is too large. You can view the blob instead.
# -*- coding: utf-8 -*-
#
# Native Client documentation build configuration file, created by
# sphinx-quickstart on Thu Aug 15 11:31:06 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# Where we keep our extensions...
sys.path.insert(0, os.path.abspath('_sphinxext'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['devsite_builder']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Native Client'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '31'
# The full version, including alpha/beta/rc tags.
release = '31'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_translator_class = 'devsite_builder.DevsiteHTMLTranslator'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static', 'images']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'NativeClientdoc'
.. _devcycle-application-structure:
#####################
Application Structure
#####################
foo
.. _devcycle-building:
########
Building
########
foo
This diff is collapsed.
.. _devguide-index:
#################
Developer's Guide
#################
This is the index of the ``devguide`` directory.
.. _tutorial:
########################
Getting Started Tutorial
########################
This is the tutorial.
Welcome to Native Client's documentation!
=========================================
Contents:
.. toctree::
:maxdepth: 2
rest-devsite-examples.rst
overview.rst
quick-start.rst
sdk/download.rst
sdk/examples.rst
sdk/release-notes.rst
devguide/index.rst
devguide/tutorial.rst
devguide/devcycle/building.rst
devguide/coding/application-structure.rst
devguide/distributing.rst
This diff is collapsed.
.. _quick-start:
###########
Quick-start
###########
To get started with Native Client:
1. Read the :doc:`Technical Overview <overview>` to understand how a Native
Client application is structured and to get a feel for what you need to do
to port existing code.
2. Play with some of the applications in the `Application Gallery
<https://developers.google.com/native-client/community/application-gallery>`_
to see what others have done so far.
3. Download the :doc:`Native Client SDK <sdk/download>`.
4. Go through the `Getting Started Tutorial
<https://developers.google.com/native-client/devguide/tutorial>`_. The
tutorial walks you through how to get Native Client set up for the first
time and check for browser version compatibility.
5. Take a look through some of the applications in the ``pepper_28/examples/``
directory in the SDK. You can learn how to build and run the applications
on the `Running the SDK Examples page
<https://developers.google.com/native-client/sdk/sdk-examples>`_.
6. Browse through the `Developer's Guide
<https://developers.google.com/native-client/devguide>`_ and the `Pepper
API <https://developers.google.com/native-client/peppercpp/>`_ reference
documentation.
.. _getting_started:
####################################################
Examples of ReST markup for devsite (Document title)
####################################################
This is an auto-generated table of contents for this document. ``:local:`` and
``:backlinks: none`` are required to make the devsite look consistent;
``:depth:`` level can be controlled.
.. contents::
:local:
:backlinks: none
:depth: 2
Document structure
==================
A document starts with a Sphinx target which serves as the document name
throughout the tree. It can serve as a link target in other documents that want
to link to this one (see the Links section below).
It follows with the document title (which doesn't get generated to the HTML body
in production mode, but is picked up by the devsite from ``<head><title>``.
Basic markup
============
In general, follow the rules from http://sphinx-doc.org/rest.html
Some **bold text** and *italic text* and ``fixed-font text``.
For pleasant collaborative editing, please use the accepted coding guidelines:
wrap at 80 columns, no tabs, etc.
Quotes (``<blockquote>``) are created by indenting the paragraph:
Most good programmers do programming not because they expect to get paid or
get adulation by the public, but because it is fun to program.
-- Linus Torvalds
Images
======
Please use absolute paths (starting with ``/``) for images:
.. image:: /images/NaclBlock.png
Links
=====
To other documents within the tree
----------------------------------
Internal links to other documents are created :doc:`like this <overview>`. The
document name within the angle brackets is relative to the root dir of the
devsite doc tree and does not have an extension.
Here's a link to a document in a subdirectory: :doc:`the tutorial
<devguide/tutorial>`. And a link to a subdirectory index page :doc:`devguide index <devguide/index>`.
To sections inside documents
----------------------------
To internal locations within documents, labels are used. For example, this link
goes to the label explicitly placed in this document -
:ref:`link_for_section_heading`. This works across documents as well. Label
names must be unique in the tree, and can refer to anything (like images).
It's also possible to give such cross-references custom names: :ref:`Same
Section Heading<link_for_section_heading>`.
To external locations
---------------------
Plain links can be placed like this: http://google.com and also `like this
<http://google.com>`_.
Notes and Admonitions
=====================
The devsite supports special "notes" that are indented and have a background
color. We'll generate them with the ``Note`` directive, providing the class
explicitly. The class is one of ``note``, ``caution``, ``warning``,
``special``.
.. Note::
:class: note
This is a note.
Foo bar.
Also:
.. Note::
:class: caution
Caution -- you have been warned.
Source code
===========
Here's source code that will be pretty-printed on the devsite. Outside
production mode, it's just a plain ``<pre>`` that presents pre-formatted code
without coloring:
.. naclcode::
#include <iostream>
int main() {
std::cout << "Hello world\n";
return 0;
}
For some code (like shell samples), we want to disable pretty-printing:
.. naclcode::
:prettyprint: 0
$ ls | wc
$ echo "hello world"
By default ``:prettyprint:`` is ``1``.
.. _link_for_section_heading:
Section heading
===============
Here's a demonstration of heading nesting levels. This is a top-level section in
the document. The document title is the first header and it's delimited by hash
signes (``#``) from above and below.
Subsection heading
------------------
Subsection.
Sub-subsection heading
^^^^^^^^^^^^^^^^^^^^^^
That's pretty deep...
Sub-sub-subsection heading
""""""""""""""""""""""""""
It's probably not the best idea to go this far (renders to ``<h5>``).
Lists
=====
Auto-numbered ordered lists:
#. One
#. Two
#. Three
Manually numbered ordered lists:
1. One
2. Two
3. Three
Unordered (bullet) lists:
* One
* Two
* Three
Lists can be nested and mixed too:
* Toplevel
1. One
2. Two
* Back to top level
Tables
======
The full scoop on tables is http://sphinx-doc.org/rest.html#tables and the
Docutils pages linked from it.
"Simple tables" require less markup but are limited:
===== ===== =======
A B A and B
===== ===== =======
False False False
True False False
False True False
True True True
===== ===== =======
"Grid tables" are versatile but require more markup:
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
| (header rows optional) | | | |
+========================+============+==========+==========+
| body row 1, column 1 | column 2 | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2 | ... | ... | |
+------------------------+------------+----------+----------+
.. _download:
Download the Native Client SDK
==============================
Follow the steps below to download and install the SDK:
1. Prerequisites:
* Make sure you have Python 2.6 or 2.7 installed, and that the Python
executable is in your path.
* On Mac/Linux, Python is probably preinstalled. Run the command ``"python
-V``" in a terminal window, and make sure that the version of Python you
have is 2.6.x or 2.7.x (if it's not, upgrade to one of those versions).
* On Windows, you may need to install Python. Go to
`http://www.python.org/download/ <http://www.python.org/download/>`_ and
select the latest 2.x version. In addition, be sure to add the Python
directory (for example, ``C:\python27``) to the PATH `environment
variable <http://en.wikipedia.org/wiki/Environment_variable>`_. After
you've installed Python, run the command ``"python -V``" in a Command
Prompt window and verify that the version of Python you have is 2.6.x or
2.7.x.
* Note that Python 3.x is not yet supported.
* On the Mac, you need to install the ``make`` command on your system before
you can build and run the examples. One easy way to get ``make``, along
with several other useful tools, is to install `Xcode Developer Tools
<https://developer.apple.com/technologies/tools/>`_. After installing
Xcode, go to the Preferences menu, select Downloads and Components, and
verify that Command Line Tools are installed. If you'd rather not install
Xcode, you can download and build an `open source version
<http://mac.softpedia.com/dyn-postdownload.php?p=44632&t=4&i=1>`_ of
``make``. In order to build the command you may also need to download and
install a copy of `gcc
<https://github.com/kennethreitz/osx-gcc-installer>`_.
2. Download the SDK update utility: `nacl_sdk.zip
<http://storage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk/nacl_sdk.zip>`_.
3. Unzip the SDK update utility:
* On Mac/Linux, run the command "``unzip nacl_sdk.zip``" in a Terminal window.
* On Windows, right-click on the .zip file and select "Extract All...". A
dialog box will open; enter a location and click "Extract".
Unzipping the SDK update utility creates a directory called ``nacl_sdk`` with
the following files and directories:
* ``naclsdk`` (and ``naclsdk.bat`` for Windows) --- the front end of the update
utility, i.e., the command you run to download the latest bundles
* ``sdk_cache`` --- a directory with a manifest file that lists the bundles you
have already downloaded
* ``sdk_tools`` --- the back end of the update utility, also known as the
"sdk_tools" bundle
4. Go to the ``nacl_sdk`` directory and run ``naclsdk`` with the "list"
command to see a list of available bundles. The SDK includes a separate
bundle for each version of Chrome/Pepper (see versioning information).
On Mac/Linux::
$ cd nacl_sdk
$ ./naclsdk list
On Windows::
> cd nacl_sdk
> naclsdk list
You should see output similar to this::
Bundles:
I: installed
*: update available
I sdk_tools (stable)
vs_addin (dev)
pepper_25 (post_stable)
pepper_26 (post_stable)
pepper_27 (post_stable)
pepper_28 (stable)
pepper_29 (beta)
pepper_30 (dev)
pepper_canary (canary)
This sample output shows many bundles available for download, and that you
have already installed the latest revision of the sdk_tools bundle (it was
included in the zip file you downloaded). Note that the bundles are labelled
"post-stable", "stable", "beta", "dev" and "canary". These labels correspond
to the current versions of Chrome. In this example, Chrome 28 is stable,
Chrome 29 is beta, etc. Therefore ``pepper_28`` is the recommended bundle to
download, because if you released an application that used it today, it
could be used by all current Chrome users. Note that Native Client is
designed to be backward compatible---users of Chrome 29 can use the features
of ``pepper_28`` and earlier.
5. Run ``naclsdk`` with the "update" command to download particular bundles that
are available.
On Mac/Linux::
$ ./naclsdk update
On Windows::
> naclsdk update
By default, ``naclsdk`` only downloads bundles that are recommended. In
general, only the "stable" bundles are recommended. Continuing with the
earlier example, the "update" command would only download the ``pepper_28``
bundles, since the bundles ``pepper_29`` and greater are not yet recommended.
If you want the ``pepper_29`` bundle, you must ask for it explicitly::
$ ./naclsdk update pepper_29
Note that you never need update the ``sdk_tools`` bundle, it is
updated automatically as necessary whenever ``naclsdk`` is run.
6. Run ``naclsdk`` with the "list" command again; this will show you the list of
available bundles and verify which bundles are installed.
On Mac/Linux::
$ ./naclsdk list
On Windows::
> naclsdk list
Continuing with the earlier example, if you previously downloaded the
``pepper_28`` bundle, you should see output similar to this::
Bundles:
I: installed
*: update available
I sdk_tools (stable)
vs_addin (dev)
pepper_25 (post_stable)
pepper_26 (post_stable)
pepper_27 (post_stable)
I pepper_28 (stable)
pepper_29 (beta)
pepper_30 (dev)
pepper_canary (canary)
7. Running ``naclsdk`` with the "update" command again will verify that your
bundles are up-to-date, or warn if you there are new versions of previously
installed bundles.
On Mac/Linux::
$ ./naclsdk update
On Windows::
> naclsdk update
Continuing with the earlier example, you should see output similar to this::
pepper_28 is already up-to-date.
To check if there is a new version of a previously installed bundle, you can
run the "list" command again::
Bundles:
I: installed
*: update available
I sdk_tools (stable)
vs_addin (dev)
pepper_25 (post_stable)
pepper_26 (post_stable)
pepper_27 (post_stable)
I* pepper_28 (stable)
pepper_29 (beta)
pepper_30 (dev)
pepper_canary (canary)
The asterisk next to the bundle name indicates that there is an update
available. If you run the "update" command now, ``naclsdk`` will warn you
with a message similar to this::
WARNING: pepper_28 already exists, but has an update available.
Run update with the --force option to overwrite the existing directory.
Warning: This will overwrite any modifications you have made within this directory.
To dowload the new version of a bundle and overwrite the existing directory
for that bundle, run ``naclsdk`` with the ``--force`` option.
On Mac/Linux::
$ ./naclsdk update --force
On Windows::
> naclsdk update --force
8. For more information about the ``naclsdk`` utility, run:
On Mac/Linux::
$ ./naclsdk help
On Windows::
> naclsdk help
Next steps:
* Browse through the `Release Notes
<https://developers.google.com/native-client/sdk/release-notes>`_ for
important information about the SDK and new bundles.
* If you're just getting started with Native Client, we recommend reading
the :doc:`Technical Overview <../overview>` and walking through the
`Getting Started Tutorial
<https://developers.google.com/native-client/devguide/tutorial>`_.
* If you'd rather dive into information about the toolchains, see `Building
Native Client Modules
<https://developers.google.com/native-client/devguide/devcycle/building>`_.
.. _sdk-examples-2:
Running the SDK Examples
========================
Every Native Client SDK bundle comes with a folder of example applications.
Each example demonstrates one or two key Native Client programming concepts.
After you've :doc:`downloaded the SDK <download>`, follow the instructions
on this page to build and run the examples.
Configure the Google Chrome Browser
-----------------------------------
1. Your version of Chrome must be equal to or greater than the version of
your SDK bundle. For example, if you're developing with the ``pepper_28``
bundle, you must use Google Chrome version 28 or greater. To find out what
version of Chrome you're using, type ``about:chrome`` or ``about:version``
in the Chrome address bar.
2. Enable the Native Client flag. Native Client is enabled by default only
for applications distributed through the Chrome Web Store. To run Native
Client applications that are not distributed through the Chrome Web Store,
like the SDK examples, you must specifically enable the Native Client flag
in Chrome:
* Type ``about:flags`` in the Chrome address bar and scroll down to
"Native Client".
* If the link below "Native Client" says "Disable", then Native Client is
already enabled and you don't need to do anything else.
* If the link below "Native Client" says "Enable", click the "Enable"
link, scroll down to the bottom of the page, and click the "Relaunch
Now" button. All browser windows will restart when you relaunch Chrome.
3. Disable the Chrome cache. Chrome caches resources aggressively; when you
are building a Native Client application you should disable the cache to
make sure that Chrome loads the latest version:
* Open Chrome's developer tools by clicking the menu icon |menu-icon| and
choosing Tools > Developer tools.
* Click the gear icon |gear-icon| in the bottom right corner of the
Chrome window.
* Under the "General" settings, check the box next to "Disable cache".
Build the SDK examples
----------------------
Starting with the ``pepper_24`` bundle, the Makefile scripts for the SDK
examples build multiple versions of the examples using all three SDK
toolchains (newlib, glibc, and PNaCl) and in both release and debug
configurations. (Note that some examples build only with the particular
toolchains).
To build all the examples, go to the examples directory in a specific SDK
bundle and run ``make``::
$ cd pepper_28/examples
$ make
make -C api all
make[1]: Entering directory `pepper_28/examples/api'
make -C audio all
make[2]: Entering directory `pepper_28/examples/api/audio'
CXX newlib/Debug/audio_x86_32.o
LINK newlib/Debug/audio_x86_32.nexe
CXX newlib/Debug/audio_x86_64.o
LINK newlib/Debug/audio_x86_64.nexe
CXX newlib/Debug/audio_arm.o
LINK newlib/Debug/audio_arm.nexe
CREATE_NMF newlib/Debug/audio.nmf
make[2]: Leaving directory `pepper_28/examples/api/audio'
make -C url_loader all
make[2]: Entering directory `pepper_28/examples/api/url_loader'
CXX newlib/Debug/url_loader_x86_32.o
...
Calling ``make`` from inside a particular example's directory will build only
that example::
$ cd pepper_28/examples/api/core
$ make
CXX newlib/Debug/core_x86_32.o
LINK newlib/Debug/core_x86_32.nexe
CXX newlib/Debug/core_x86_64.o
LINK newlib/Debug/core_x86_64.nexe
CXX newlib/Debug/core_arm.o
LINK newlib/Debug/core_arm.nexe
CREATE_NMF newlib/Debug/core.nmf
You can call ``make`` with the ``TOOLCHAIN`` and ``CONFIG`` parameters to
override the defaults::
$ make TOOLCHAIN=pnacl CONFIG=Release
CXX pnacl/Release/core_pnacl.o
LINK pnacl/Release/core.bc
FINALIZE pnacl/Release/core.pexe
CREATE_NMF pnacl/Release/core.nmf
You can also set ``TOOLCHAIN`` to "all" to build one or more examples with
all available toolchains::
$ make TOOLCHAIN=all
make TOOLCHAIN=newlib
make[1]: Entering directory `pepper_31/examples/api/core'
CXX newlib/Debug/core_x86_32.o
LINK newlib/Debug/core_x86_32.nexe
CXX newlib/Debug/core_x86_64.o
LINK newlib/Debug/core_x86_64.nexe
CXX newlib/Debug/core_arm.o
LINK newlib/Debug/core_arm.nexe
CREATE_NMF newlib/Debug/core.nmf
make[1]: Leaving directory `pepper_31/examples/api/core'
make TOOLCHAIN=glibc
make[1]: Entering directory `pepper_31/examples/api/core'
CXX glibc/Debug/core_x86_32.o
LINK glibc/Debug/core_x86_32.nexe
CXX glibc/Debug/core_x86_64.o
LINK glibc/Debug/core_x86_64.nexe
CREATE_NMF glibc/Debug/core.nmf
make[1]: Leaving directory `pepper_31/examples/api/core'
make TOOLCHAIN=pnacl
make[1]: Entering directory `pepper_31/examples/api/core'
CXX pnacl/Debug/core_pnacl.o
LINK pnacl/Debug/core.bc
FINALIZE pnacl/Debug/core.pexe
TRANSLATE pnacl/Debug/core_x86_32.nexe
TRANSLATE pnacl/Debug/core_x86_64.nexe
TRANSLATE pnacl/Debug/core_arm.nexe
CREATE_NMF pnacl/Debug/core.nmf
make[1]: Leaving directory `pepper_31/examples/api/core'
make TOOLCHAIN=linux
make[1]: Entering directory `pepper_31/examples/api/core'
CXX linux/Debug/core.o
LINK linux/Debug/core.so
make[1]: Leaving directory `pepper_31/examples/api/core'
After running ``make``, each example directory will contain one or more of
the following subdirectories:
* a ``newlib`` directory with subdirectories ``Debug`` and ``Release``;
* a ``glibc`` directory with subdirectories ``Debug`` and ``Release``;
* a ``pnacl`` directory with subdirectories ``Debug`` and ``Release``;
For the newlib and glibc toolchains the Debug and Release subdirectories
contain .nexe files for all target architectures. For the PNaCl toolchain
they contain a single .pexe file. PNaCl debug also produces pre-translated
.nexe files, for ease of debugging. All Debug and Release directories contain
a manifest (.nmf) file that references the associated .nexe or .pexe files.
For information about Native Client manifest files, see the :doc:`Technical
Overview <../overview>`.
For details on how to use ``make``, see the `GNU 'make' Manual
<http://www.gnu.org/software/make/manual/make.html>`_. For details on how to
use the SDK toolchain itself, see :doc:`Building Native Client Modules
<devcycle/building>`.
Run the SDK examples
--------------------
To run the SDK examples, you can use the ``make run`` command::
$ cd pepper_28/examples/api/core
$ make run
This will launch a local HTTP server which will serve the data for the
example. It then launches Chrome with the address of this server, usually
http://localhost:5103. After you close Chrome, the local HTTP server is
automatically shutdown.
This command will try to find an executable named ``google-chrome`` in your
``PATH`` environment variable. If it can't, you'll get an error message like
this::
pepper_31/tools/common.mk:415: No valid Chrome found at CHROME_PATH=
pepper_31/tools/common.mk:415: *** Set CHROME_PATH via an environment variable, or command-line.. Stop.
Set the CHROME_PATH environment variable to the location of your Chrome
executable **TODO(binji):** use default Chrome paths here, especially
important for Mac:
On Windows::
> set CHROME_PATH=<Path to chrome.exe>
On Linux::
$ export CHROME_PATH=<Path to google-chrome>
On Mac::
$ export CHROME_PATH=<Path to chrome>
You can run via a different toolchain or configuration by using the
``TOOLCHAIN`` and ``CONFIG`` parameters to make::
$ make run TOOLCHAIN=pnacl CONFIG=Debug
Run the SDK examples as packaged apps
-------------------------------------
Each example can also be launched as a packaged app. For more information about
using Native Client for packaged apps, see :ref:`Packaged appliction
<packaged>`. For general information about packaged apps, see the
`Chrome apps documentation
<http://developer.chrome.com/apps/about_apps.html>`_.
Some Pepper features, such as TCP/UDP socket access, are only allowed in
packaged apps. The examples that use these features must be run as packaged
apps, by using the ``make run_package`` command::
$ make run_package
You can use ``TOOLCHAIN`` and ``CONFIG`` parameters as above to run with a
different toolchain or configuration.
Debugging the SDK examples
--------------------------
The NaCl SDK uses `GDB <https://www.gnu.org/software/gdb/>`_ to debug Native
Client code. The SDK includes a prebuilt version of GDB that is compatible with
NaCl code. To use it, run the ``make debug`` command from an example directory::
$ make debug
This will launch Chrome with the ``--enable-nacl-debug`` flag set. This flag
will cause Chrome to pause when a NaCl module is first loaded, waiting for a
connection from gdb. The ``make debug`` command also simultaneously launches
GDB and loads the symbols for that NEXE. To connect GDB to Chrome, in the GDB
console, type::
(gdb) target remote :4014
This tells GDB to connect to a TCP port on localhost:4014--the port that
Chrome is listening on. GDB will respond::
Remote debugging using :4014
0x000000000fa00080 in ?? ()
At this point, you can use the standard GDB commands to debug your NaCl module.
The most common commands you will use to debug are ``continue``, ``step``,
``next``, ``break`` and ``backtrace``. See :doc:`Debugging
<devcycle/debugging>` for more information about debugging a Native Client
application.
.. |menu-icon| image:: /images/menu-icon.png
.. |gear-icon| image:: /images/gear-icon.png
.. _sdk-release-notes:
#################
SDK Release Notes
#################
foo
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment