Boot Linux faster!

Check our new training course

Boot Linux faster!

Check our new training course
and Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

# Copyright (c) 2019 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# based on

from __future__ import print_function
from __future__ import unicode_literals
import re
from docutils import nodes
from local_util import run_cmd_get_output
    from west.manifest import Manifest as WestManifest
except ImportError:
    WestManifest = None

def get_github_rev():
    tag = run_cmd_get_output('git describe --exact-match')
    if tag:
        return tag.decode("utf-8")
        return 'master'

def setup(app):
    rev = get_github_rev()

    # try to get url from West; this adds compatibility with repos
    # located elsewhere
    if WestManifest is not None:
        baseurl = WestManifest.from_file().get_projects(['zephyr'])[0].url
        baseurl = None

    # or fallback to default
    if baseurl is None:
        baseurl = ''

    app.add_role('zephyr_file', autolink('{}/blob/{}/%s'.format(baseurl, rev)))
    app.add_role('zephyr_raw', autolink('{}/raw/{}/%s'.format(baseurl, rev)))

    # The role just creates new nodes based on information in the
    # arguments; its behavior doesn't depend on any other documents.
    return {
        'parallel_read_safe': True,
        'parallel_write_safe': True,

def autolink(pattern):
    def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
        m ='(.*)\s*<(.*)>', text)
        if m:
            link_text =
            link =
            link_text = text
            link = text
        url = pattern % (link,)
        node = nodes.reference(rawtext, link_text, refuri=url, **options)
        return [node], []
    return role