2019-11-11 03:39:42 +00:00
|
|
|
# Sphinx extension to integrate IDF build system information
|
|
|
|
# into the Sphinx Build
|
|
|
|
#
|
|
|
|
# Runs early in the Sphinx process, runs CMake to generate the dummy IDF project
|
|
|
|
# in this directory - including resolving paths, etc.
|
|
|
|
#
|
|
|
|
# Then emits the new 'idf-info' event which has information read from IDF
|
|
|
|
# build system, that other extensions can use to generate relevant data.
|
|
|
|
import os.path
|
2020-02-07 04:36:14 +00:00
|
|
|
import shutil
|
2019-11-11 03:39:42 +00:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
|
|
|
|
# this directory also contains the dummy IDF project
|
|
|
|
project_path = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
2019-11-28 21:56:53 +00:00
|
|
|
|
2019-11-11 03:39:42 +00:00
|
|
|
def setup(app):
|
2019-11-28 21:56:53 +00:00
|
|
|
# Setup some common paths
|
|
|
|
|
|
|
|
try:
|
|
|
|
build_dir = os.environ["BUILDDIR"] # TODO see if we can remove this
|
|
|
|
except KeyError:
|
|
|
|
build_dir = os.path.dirname(app.doctreedir.rstrip(os.sep))
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(build_dir)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(os.path.join(build_dir, 'inc'))
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Fill in a default IDF_PATH if it's missing (ie when Read The Docs is building the docs)
|
|
|
|
try:
|
|
|
|
idf_path = os.environ['IDF_PATH']
|
|
|
|
except KeyError:
|
|
|
|
idf_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
|
|
|
|
app.add_config_value('docs_root', os.path.join(idf_path, "docs"), 'env')
|
|
|
|
app.add_config_value('idf_path', idf_path, 'env')
|
|
|
|
app.add_config_value('build_dir', build_dir, 'env') # not actually an IDF thing
|
2019-11-11 03:39:42 +00:00
|
|
|
app.add_event('idf-info')
|
|
|
|
|
|
|
|
# we want this to run early in the docs build but unclear exactly when
|
2019-12-06 09:22:55 +00:00
|
|
|
app.connect('config-inited', generate_idf_info)
|
2019-11-11 03:39:42 +00:00
|
|
|
|
2019-11-28 21:56:53 +00:00
|
|
|
return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.1'}
|
|
|
|
|
2019-11-28 05:00:24 +00:00
|
|
|
|
2019-12-06 09:22:55 +00:00
|
|
|
def generate_idf_info(app, config):
|
2019-11-11 03:39:42 +00:00
|
|
|
print("Running CMake on dummy project to get build info...")
|
2019-11-12 10:42:03 +00:00
|
|
|
build_dir = os.path.dirname(app.doctreedir.rstrip(os.sep))
|
|
|
|
cmake_build_dir = os.path.join(build_dir, "build_dummy_project")
|
2019-11-11 03:39:42 +00:00
|
|
|
idf_py_path = os.path.join(app.config.idf_path, "tools", "idf.py")
|
|
|
|
print("Running idf.py...")
|
2019-11-12 10:42:03 +00:00
|
|
|
idf_py = [sys.executable,
|
|
|
|
idf_py_path,
|
|
|
|
"-B",
|
|
|
|
cmake_build_dir,
|
|
|
|
"-C",
|
2020-02-07 04:36:14 +00:00
|
|
|
project_path,
|
|
|
|
"-D",
|
|
|
|
"SDKCONFIG={}".format(os.path.join(build_dir, "dummy_project_sdkconfig"))
|
|
|
|
]
|
2019-11-13 03:46:16 +00:00
|
|
|
|
2020-02-07 04:36:14 +00:00
|
|
|
# force a clean idf.py build w/ new sdkconfig each time
|
|
|
|
# (not much slower than 'reconfigure', avoids any potential config & build versioning problems
|
|
|
|
shutil.rmtree(cmake_build_dir, ignore_errors=True)
|
|
|
|
print("Starting new dummy IDF project... ")
|
|
|
|
subprocess.check_call(idf_py + ["set-target", app.config.idf_target])
|
|
|
|
print("Running CMake on dummy project...")
|
2019-11-28 21:56:53 +00:00
|
|
|
subprocess.check_call(idf_py + ["reconfigure"])
|
2020-02-07 04:36:14 +00:00
|
|
|
|
2019-11-12 10:42:03 +00:00
|
|
|
with open(os.path.join(cmake_build_dir, "project_description.json")) as f:
|
2019-11-11 03:39:42 +00:00
|
|
|
project_description = json.load(f)
|
2019-11-13 03:46:16 +00:00
|
|
|
if project_description["target"] != app.config.idf_target:
|
|
|
|
# this shouldn't really happen unless someone has been moving around directories inside _build, as
|
|
|
|
# the cmake_build_dir path should be target-specific
|
2019-11-28 21:56:53 +00:00
|
|
|
raise RuntimeError(("Error configuring the dummy IDF project for {}. " +
|
|
|
|
"Target in project description is {}. " +
|
|
|
|
"Is build directory contents corrupt?")
|
|
|
|
.format(app.config.idf_target, project_description["target"]))
|
2019-11-11 03:39:42 +00:00
|
|
|
app.emit('idf-info', project_description)
|
|
|
|
|
|
|
|
return []
|