2018-07-25 00:30:15 -04:00
|
|
|
|
#!/usr/bin/env python
|
2018-07-31 00:34:10 -04:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2018-07-25 00:30:15 -04:00
|
|
|
|
#
|
2019-11-28 16:56:53 -05:00
|
|
|
|
# Sphinx extension to generate ReSTructured Text .inc snippets
|
2018-07-25 00:30:15 -04:00
|
|
|
|
# with version-based content for this IDF version
|
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
|
2018-07-25 00:30:15 -04:00
|
|
|
|
import os
|
|
|
|
|
import re
|
2021-01-25 21:49:01 -05:00
|
|
|
|
import subprocess
|
|
|
|
|
from io import open
|
|
|
|
|
|
|
|
|
|
from .util import copy_if_modified
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
|
|
|
|
TEMPLATES = {
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'en': {
|
|
|
|
|
'git-clone-bash': """
|
2018-12-18 01:22:40 -05:00
|
|
|
|
.. code-block:: bash
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
2020-08-11 02:08:45 -04:00
|
|
|
|
mkdir -p ~/esp
|
2018-07-25 00:30:15 -04:00
|
|
|
|
cd ~/esp
|
|
|
|
|
git clone %(clone_args)s--recursive https://github.com/espressif/esp-idf.git
|
2018-12-18 01:22:40 -05:00
|
|
|
|
""",
|
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'git-clone-windows': """
|
2018-12-18 01:22:40 -05:00
|
|
|
|
.. code-block:: batch
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
2018-12-18 01:22:40 -05:00
|
|
|
|
mkdir %%userprofile%%\\esp
|
|
|
|
|
cd %%userprofile%%\\esp
|
|
|
|
|
git clone %(clone_args)s--recursive https://github.com/espressif/esp-idf.git
|
|
|
|
|
""",
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'git-clone-notes': {
|
|
|
|
|
'template': """
|
2018-07-25 00:30:15 -04:00
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
%(extra_note)s
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
%(zipfile_note)s
|
2018-12-01 03:25:08 -05:00
|
|
|
|
""",
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'master': 'This command will clone the master branch, which has the latest development ("bleeding edge") '
|
2018-12-18 01:22:40 -05:00
|
|
|
|
'version of ESP-IDF. It is fully functional and updated on weekly basis with the most recent features and bugfixes.',
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'branch': 'The ``git clone`` option ``-b %(clone_arg)s`` tells git to clone the %(ver_type)s in the ESP-IDF repository ``git clone`` '
|
2018-12-18 01:22:40 -05:00
|
|
|
|
'corresponding to this version of the documentation.',
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'zipfile': {
|
|
|
|
|
'stable': 'As a fallback, it is also possible to download a zip file of this stable release from the `Releases page`_. '
|
2018-12-01 03:25:08 -05:00
|
|
|
|
'Do not download the "Source code" zip file(s) generated automatically by GitHub, they do not work with ESP-IDF.',
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'unstable': 'GitHub\'s "Download zip file" feature does not work with ESP-IDF, a ``git clone`` is required. As a fallback, '
|
2018-12-01 03:25:08 -05:00
|
|
|
|
'`Stable version`_ can be installed without Git.'
|
|
|
|
|
}, # zipfile
|
2018-12-18 01:22:40 -05:00
|
|
|
|
}, # git-clone-notes
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'version-note': {
|
|
|
|
|
'master': """
|
2018-07-25 00:30:15 -04:00
|
|
|
|
.. note::
|
2018-12-01 03:25:08 -05:00
|
|
|
|
This is documentation for the master branch (latest version) of ESP-IDF. This version is under continual development.
|
|
|
|
|
`Stable version`_ documentation is available, as well as other :doc:`/versions`.
|
|
|
|
|
""",
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'stable': """
|
2018-07-25 00:30:15 -04:00
|
|
|
|
.. note::
|
|
|
|
|
This is documentation for stable version %s of ESP-IDF. Other :doc:`/versions` are also available.
|
2018-12-01 03:25:08 -05:00
|
|
|
|
""",
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'branch': """
|
2018-07-25 00:30:15 -04:00
|
|
|
|
.. note::
|
|
|
|
|
This is documentation for %s ``%s`` of ESP-IDF. Other :doc:`/versions` are also available.
|
|
|
|
|
"""
|
2018-12-01 03:25:08 -05:00
|
|
|
|
}, # version-note
|
|
|
|
|
}, # en
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'zh_CN': {
|
|
|
|
|
'git-clone-bash': """
|
2018-12-18 01:22:40 -05:00
|
|
|
|
.. code-block:: bash
|
2018-07-31 00:34:10 -04:00
|
|
|
|
|
2020-08-11 02:08:45 -04:00
|
|
|
|
mkdir -p ~/esp
|
2018-07-31 00:34:10 -04:00
|
|
|
|
cd ~/esp
|
|
|
|
|
git clone %(clone_args)s--recursive https://github.com/espressif/esp-idf.git
|
2018-12-18 01:22:40 -05:00
|
|
|
|
""",
|
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'git-clone-windows': """
|
2018-12-18 01:22:40 -05:00
|
|
|
|
.. code-block:: batch
|
2018-07-31 00:34:10 -04:00
|
|
|
|
|
2018-12-18 01:22:40 -05:00
|
|
|
|
mkdir %%userprofile%%\\esp
|
|
|
|
|
cd %%userprofile%%\\esp
|
|
|
|
|
git clone %(clone_args)s--recursive https://github.com/espressif/esp-idf.git
|
|
|
|
|
""",
|
2018-07-31 00:34:10 -04:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'git-clone-notes': {
|
|
|
|
|
'template': """
|
2018-07-31 00:34:10 -04:00
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
%(extra_note)s
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
%(zipfile_note)s
|
2018-12-01 03:25:08 -05:00
|
|
|
|
""",
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'master': '此命令将克隆 master 分支,该分支保存着 ESP-IDF 的最新版本,它功能齐全,每周都会更新一些新功能并修正一些错误。',
|
|
|
|
|
'branch': '``git clone`` 命令的 ``-b %(clone_arg)s`` 选项告诉 git 从 ESP-IDF 仓库中克隆与此版本的文档对应的分支。',
|
|
|
|
|
'zipfile': {
|
|
|
|
|
'stable': '作为备份,还可以从 `Releases page`_ 下载此稳定版本的 zip 文件。不要下载由 GitHub 自动生成的"源代码"的 zip 文件,它们不适用于 ESP-IDF。',
|
|
|
|
|
'unstable': 'GitHub 中"下载 zip 文档"的功能不适用于 ESP-IDF,所以需要使用 ``git clone`` 命令。作为备份,可以在没有安装 Git 的环境中下载 '
|
2018-12-01 03:25:08 -05:00
|
|
|
|
'`Stable version`_ 的 zip 归档文件。'
|
|
|
|
|
}, # zipfile
|
|
|
|
|
}, # git-clone
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'version-note': {
|
|
|
|
|
'master': """
|
2018-07-31 00:34:10 -04:00
|
|
|
|
.. note::
|
|
|
|
|
这是ESP-IDF master 分支(最新版本)的文档,该版本在持续开发中。还有 `Stable version`_ 的文档,以及其他版本的文档 :doc:`/versions` 供参考。
|
2018-12-01 03:25:08 -05:00
|
|
|
|
""",
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'stable': """
|
2018-07-31 00:34:10 -04:00
|
|
|
|
.. note::
|
|
|
|
|
这是ESP-IDF 稳定版本 %s 的文档,还有其他版本的文档 :doc:`/versions` 供参考。
|
2018-12-01 03:25:08 -05:00
|
|
|
|
""",
|
2021-01-25 21:49:01 -05:00
|
|
|
|
'branch': """
|
2018-07-31 00:34:10 -04:00
|
|
|
|
.. note::
|
|
|
|
|
这是ESP-IDF %s ``%s`` 版本的文档,还有其他版本的文档 :doc:`/versions` 供参考。
|
|
|
|
|
"""
|
2018-12-01 03:25:08 -05:00
|
|
|
|
}, # version-note
|
|
|
|
|
} # zh_CN
|
2018-07-25 00:30:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-28 16:56:53 -05:00
|
|
|
|
def setup(app):
|
|
|
|
|
# doesn't need to be this event specifically, but this is roughly the right time
|
|
|
|
|
app.connect('idf-info', generate_version_specific_includes)
|
|
|
|
|
return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.1'}
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
2019-11-28 16:56:53 -05:00
|
|
|
|
|
|
|
|
|
def generate_version_specific_includes(app, project_description):
|
|
|
|
|
language = app.config.language
|
2021-01-25 21:49:01 -05:00
|
|
|
|
tmp_out_dir = os.path.join(app.config.build_dir, 'version_inc')
|
2019-11-28 16:56:53 -05:00
|
|
|
|
if not os.path.exists(tmp_out_dir):
|
2021-01-25 21:49:01 -05:00
|
|
|
|
print('Creating directory %s' % tmp_out_dir)
|
2019-11-28 16:56:53 -05:00
|
|
|
|
os.mkdir(tmp_out_dir)
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
|
|
|
|
template = TEMPLATES[language]
|
|
|
|
|
|
|
|
|
|
version, ver_type, is_stable = get_version()
|
|
|
|
|
|
2019-11-28 16:56:53 -05:00
|
|
|
|
write_git_clone_inc_files(template, tmp_out_dir, version, ver_type, is_stable)
|
2021-01-25 21:49:01 -05:00
|
|
|
|
write_version_note(template['version-note'], tmp_out_dir, version, ver_type, is_stable)
|
|
|
|
|
copy_if_modified(tmp_out_dir, os.path.join(app.config.build_dir, 'inc'))
|
|
|
|
|
print('Done')
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
|
|
|
|
|
2018-12-18 01:22:40 -05:00
|
|
|
|
def write_git_clone_inc_files(templates, out_dir, version, ver_type, is_stable):
|
|
|
|
|
def out_file(basename):
|
2021-01-25 21:49:01 -05:00
|
|
|
|
p = os.path.join(out_dir, '%s.inc' % basename)
|
|
|
|
|
print('Writing %s...' % p)
|
2018-12-18 01:22:40 -05:00
|
|
|
|
return p
|
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
if version == 'master':
|
|
|
|
|
clone_args = ''
|
2018-07-25 00:30:15 -04:00
|
|
|
|
else:
|
2021-01-25 21:49:01 -05:00
|
|
|
|
clone_args = '-b %s ' % version
|
2018-12-18 01:22:40 -05:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
with open(out_file('git-clone-bash'), 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(templates['git-clone-bash'] % locals())
|
2018-12-18 01:22:40 -05:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
with open(out_file('git-clone-windows'), 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(templates['git-clone-windows'] % locals())
|
2018-12-18 01:22:40 -05:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
with open(out_file('git-clone-notes'), 'w', encoding='utf-8') as f:
|
|
|
|
|
template = templates['git-clone-notes']
|
2018-12-18 01:22:40 -05:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
zipfile = template['zipfile']
|
2018-12-18 01:22:40 -05:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
if version == 'master':
|
|
|
|
|
extra_note = template['master']
|
|
|
|
|
zipfile_note = zipfile['unstable']
|
2018-12-18 01:22:40 -05:00
|
|
|
|
else:
|
2021-01-25 21:49:01 -05:00
|
|
|
|
extra_note = template['branch'] % {'clone_arg': version, 'ver_type': ver_type}
|
|
|
|
|
zipfile_note = zipfile['stable'] if is_stable else zipfile['unstable']
|
2018-12-18 01:22:40 -05:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
f.write(template['template'] % locals())
|
2018-12-18 01:22:40 -05:00
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
|
print('Wrote git-clone-xxx.inc files')
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_version_note(template, out_dir, version, ver_type, is_stable):
|
2021-01-25 21:49:01 -05:00
|
|
|
|
if version == 'master':
|
|
|
|
|
content = template['master']
|
|
|
|
|
elif ver_type == 'tag' and is_stable:
|
|
|
|
|
content = template['stable'] % version
|
2018-07-25 00:30:15 -04:00
|
|
|
|
else:
|
2021-01-25 21:49:01 -05:00
|
|
|
|
content = template['branch'] % (ver_type, version)
|
|
|
|
|
out_file = os.path.join(out_dir, 'version-note.inc')
|
|
|
|
|
with open(out_file, 'w', encoding='utf-8') as f:
|
2018-07-25 00:30:15 -04:00
|
|
|
|
f.write(content)
|
2021-01-25 21:49:01 -05:00
|
|
|
|
print('%s written' % out_file)
|
2018-07-25 00:30:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_version():
|
|
|
|
|
"""
|
2020-07-27 05:30:40 -04:00
|
|
|
|
Returns a tuple of (name of branch/tag/commit-id, type branch/tag/commit, is_stable)
|
2018-07-25 00:30:15 -04:00
|
|
|
|
"""
|
2020-07-27 05:30:40 -04:00
|
|
|
|
# Use git to look for a tag
|
2018-07-25 00:30:15 -04:00
|
|
|
|
try:
|
2021-01-25 21:49:01 -05:00
|
|
|
|
tag = subprocess.check_output(['git', 'describe', '--exact-match']).strip().decode('utf-8')
|
|
|
|
|
is_stable = re.match(r'v[0-9\.]+$', tag) is not None
|
|
|
|
|
return (tag, 'tag', is_stable)
|
2018-07-25 00:30:15 -04:00
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
|
pass
|
|
|
|
|
|
2020-07-27 05:30:40 -04:00
|
|
|
|
# No tag, look at branch name from CI, this will give the correct branch name even if the ref for the branch we
|
|
|
|
|
# merge into has moved forward before the pipeline runs
|
2021-01-25 21:49:01 -05:00
|
|
|
|
branch = os.environ.get('CI_COMMIT_REF_NAME', None)
|
2020-07-27 05:30:40 -04:00
|
|
|
|
if branch is not None:
|
2021-01-25 21:49:01 -05:00
|
|
|
|
return (branch, 'branch', False)
|
2020-07-27 05:30:40 -04:00
|
|
|
|
|
|
|
|
|
# Try to find the branch name even if docs are built locally
|
2021-01-25 21:49:01 -05:00
|
|
|
|
branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode('utf-8')
|
|
|
|
|
if branch != 'HEAD':
|
|
|
|
|
return (branch, 'branch', False)
|
2020-07-27 05:30:40 -04:00
|
|
|
|
|
|
|
|
|
# As a last resort we return commit SHA-1, should never happen in CI/docs that should be published
|
2021-01-25 21:49:01 -05:00
|
|
|
|
return (subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8'), 'commit', False)
|