2021-04-24 05:45:34 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-04-27 20:42:02 +08:00
|
|
|
# ****************************************************************************
|
|
|
|
# IMPOTRANT: If you are getting a lexer error for an example you need to check
|
2023-08-14 22:49:30 +08:00
|
|
|
# for extra lines at the end of the file. Only a single empty line
|
2023-04-27 20:42:02 +08:00
|
|
|
# is allowed!!! Ask me how long it took me to figure this out
|
|
|
|
# ****************************************************************************
|
|
|
|
|
2021-04-24 05:45:34 +08:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import re
|
2021-06-15 05:13:22 +08:00
|
|
|
import example_list as ex
|
2023-04-27 20:42:02 +08:00
|
|
|
import doc_builder
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
2023-05-29 16:46:42 +08:00
|
|
|
import config_builder
|
2024-03-14 06:22:27 +08:00
|
|
|
import add_translation
|
2023-04-27 20:42:02 +08:00
|
|
|
|
|
|
|
# due to the modifications that take place to the documentation files
|
|
|
|
# when the documentaation builds it is better to copy the source files to a
|
|
|
|
# temporary folder and modify the copies. Not setting it up this way makes it
|
2023-08-14 22:49:30 +08:00
|
|
|
# a real headache when making alterations that need to be committed as the
|
2023-04-27 20:42:02 +08:00
|
|
|
# alterations trigger the files as changed.
|
|
|
|
|
|
|
|
# If there is debugging that needs to be done you can provide a command line
|
|
|
|
# switch of "develop" and it will leave the temporary directory in tact and
|
|
|
|
# that directory will be output at the end of the build.
|
|
|
|
|
|
|
|
# the html and PDF output locations are going to remain the same as they were.
|
|
|
|
# it's just the source documentation files that are going to be copied.
|
|
|
|
|
|
|
|
temp_directory = tempfile.mkdtemp(suffix='.lvgl_docs')
|
2021-04-24 05:45:34 +08:00
|
|
|
|
|
|
|
langs = ['en']
|
|
|
|
|
|
|
|
# Change to script directory for consistency
|
2023-04-27 20:42:02 +08:00
|
|
|
|
|
|
|
base_path = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
project_path = os.path.abspath(os.path.join(base_path, '..'))
|
|
|
|
examples_path = os.path.join(project_path, 'examples')
|
|
|
|
|
|
|
|
lvgl_src_path = os.path.join(project_path, 'src')
|
|
|
|
latex_output_path = os.path.join(temp_directory, 'out_latex')
|
|
|
|
|
|
|
|
pdf_src_file = os.path.join(latex_output_path, 'LVGL.pdf')
|
|
|
|
pdf_dst_file = os.path.join(temp_directory, 'LVGL.pdf')
|
|
|
|
html_src_path = temp_directory
|
|
|
|
html_dst_path = os.path.join(project_path, 'out_html')
|
|
|
|
|
|
|
|
os.chdir(base_path)
|
|
|
|
|
|
|
|
|
|
|
|
clean = 0
|
|
|
|
trans = 0
|
|
|
|
skip_latex = False
|
|
|
|
develop = False
|
|
|
|
args = sys.argv[1:]
|
|
|
|
|
|
|
|
if len(args) >= 1:
|
|
|
|
if "clean" in args:
|
|
|
|
clean = 1
|
|
|
|
if "skip_latex" in args:
|
|
|
|
skip_latex = True
|
|
|
|
if 'develop' in args:
|
|
|
|
develop = True
|
|
|
|
|
2021-04-24 05:45:34 +08:00
|
|
|
|
|
|
|
def cmd(s):
|
2023-04-27 20:42:02 +08:00
|
|
|
print("")
|
|
|
|
print(s)
|
|
|
|
print("-------------------------------------")
|
2024-06-21 04:02:25 +08:00
|
|
|
|
|
|
|
result = os.system(s)
|
|
|
|
if result != 0:
|
2023-04-27 20:42:02 +08:00
|
|
|
print("Exit build due to previous error")
|
2024-06-21 04:02:25 +08:00
|
|
|
sys.exit(result)
|
2023-04-27 20:42:02 +08:00
|
|
|
|
2021-04-24 05:45:34 +08:00
|
|
|
|
|
|
|
# Get the current branch name
|
2024-03-14 06:22:27 +08:00
|
|
|
status, br = subprocess.getstatusoutput("git branch --show-current")
|
2021-05-26 23:58:46 +08:00
|
|
|
_, gitcommit = subprocess.getstatusoutput("git rev-parse HEAD")
|
2021-04-24 05:45:34 +08:00
|
|
|
br = re.sub('\* ', '', br)
|
2021-06-15 05:13:22 +08:00
|
|
|
|
|
|
|
|
2021-04-24 05:45:34 +08:00
|
|
|
urlpath = re.sub('release/', '', br)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2022-05-10 01:28:06 +08:00
|
|
|
os.environ['LVGL_URLPATH'] = urlpath
|
|
|
|
os.environ['LVGL_GITCOMMIT'] = gitcommit
|
2021-04-24 05:45:34 +08:00
|
|
|
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-04-24 05:45:34 +08:00
|
|
|
lang = "en"
|
|
|
|
print("")
|
|
|
|
print("****************")
|
|
|
|
print("Building")
|
|
|
|
print("****************")
|
2023-04-27 20:42:02 +08:00
|
|
|
|
2021-04-24 05:45:34 +08:00
|
|
|
if clean:
|
2023-04-27 20:42:02 +08:00
|
|
|
print('cleaning...')
|
|
|
|
# api_path = os.path.join(dname, 'API')
|
|
|
|
# xml_path = os.path.join(dname, 'xml')
|
|
|
|
# doxy_path = os.path.join(dname, 'doxygen_html')
|
|
|
|
|
|
|
|
# if os.path.exists(api_path):
|
|
|
|
# shutil.rmtree(api_path)
|
|
|
|
|
|
|
|
# if os.path.exists(lang):
|
|
|
|
# shutil.rmtree(lang)
|
|
|
|
|
|
|
|
if os.path.exists(html_dst_path):
|
|
|
|
shutil.rmtree(html_dst_path)
|
|
|
|
|
|
|
|
# if os.path.exists(xml_path):
|
|
|
|
# shutil.rmtree(xml_path)
|
|
|
|
#
|
|
|
|
# if os.path.exists(doxy_path):
|
|
|
|
# shutil.rmtree(doxy_path)
|
|
|
|
|
|
|
|
# os.mkdir(api_path)
|
|
|
|
# os.mkdir(lang)
|
2021-04-24 05:45:34 +08:00
|
|
|
|
2023-05-29 16:46:42 +08:00
|
|
|
config_builder.run()
|
|
|
|
|
2023-04-27 20:42:02 +08:00
|
|
|
shutil.copytree('.', temp_directory, dirs_exist_ok=True)
|
|
|
|
shutil.copytree(examples_path, os.path.join(temp_directory, 'examples'))
|
|
|
|
|
|
|
|
with open(os.path.join(temp_directory, 'Doxyfile'), 'rb') as f:
|
|
|
|
data = f.read().decode('utf-8')
|
|
|
|
|
2023-05-01 17:27:28 +08:00
|
|
|
data = data.replace('#*#*LV_CONF_PATH*#*#', os.path.join(base_path, 'lv_conf.h'))
|
2023-04-27 20:42:02 +08:00
|
|
|
data = data.replace('*#*#SRC#*#*', '"{0}"'.format(lvgl_src_path))
|
|
|
|
|
|
|
|
with open(os.path.join(temp_directory, 'Doxyfile'), 'wb') as f:
|
|
|
|
f.write(data.encode('utf-8'))
|
|
|
|
|
|
|
|
|
|
|
|
print("Generate the list of examples")
|
|
|
|
ex.exec(temp_directory)
|
2021-04-24 05:45:34 +08:00
|
|
|
|
2024-03-14 06:22:27 +08:00
|
|
|
print("Add translation")
|
|
|
|
add_translation.exec(temp_directory)
|
|
|
|
|
2021-04-24 05:45:34 +08:00
|
|
|
print("Running doxygen")
|
2024-06-21 04:02:25 +08:00
|
|
|
cmd('cd "{temp_directory}" && doxygen Doxyfile'.format(temp_directory=temp_directory))
|
2023-04-27 20:42:02 +08:00
|
|
|
|
|
|
|
print('Reading Doxygen output')
|
|
|
|
|
|
|
|
doc_builder.run(
|
|
|
|
project_path,
|
|
|
|
temp_directory,
|
|
|
|
os.path.join(temp_directory, 'layouts'),
|
|
|
|
os.path.join(temp_directory, 'libs'),
|
|
|
|
os.path.join(temp_directory, 'others'),
|
|
|
|
os.path.join(temp_directory, 'overview'),
|
|
|
|
os.path.join(temp_directory, 'overview', 'renderers'),
|
|
|
|
os.path.join(temp_directory, 'porting'),
|
|
|
|
os.path.join(temp_directory, 'widgets')
|
|
|
|
)
|
2021-04-24 05:45:34 +08:00
|
|
|
|
2023-04-27 20:42:02 +08:00
|
|
|
# we make sure to remove the link to the PDF before the PDF get generated
|
|
|
|
# doesn't make any sense to have a link to the PDF in the PDF. The link gets
|
|
|
|
# added if there is a PDF build so the HTML build will have the link.
|
|
|
|
index_path = os.path.join(temp_directory, 'index.rst')
|
2021-04-24 05:45:34 +08:00
|
|
|
|
2023-04-27 20:42:02 +08:00
|
|
|
with open(index_path, 'rb') as f:
|
|
|
|
index_data = f.read().decode('utf-8')
|
|
|
|
|
|
|
|
if 'PDF version: :download:`LVGL.pdf <LVGL.pdf>`' in index_data:
|
|
|
|
index_data = index_data.replace(
|
|
|
|
'PDF version: :download:`LVGL.pdf <LVGL.pdf>`\n',
|
|
|
|
''
|
|
|
|
)
|
|
|
|
with open(index_path, 'wb') as f:
|
|
|
|
f.write(index_data.encode('utf-8'))
|
|
|
|
|
|
|
|
# BUILD PDF
|
|
|
|
if skip_latex:
|
|
|
|
print("skipping latex build as requested")
|
2021-05-15 08:15:25 +08:00
|
|
|
else:
|
2023-04-27 20:42:02 +08:00
|
|
|
|
|
|
|
# Silly workaround to include the more or less correct
|
|
|
|
# PDF download link in the PDF
|
|
|
|
# cmd("cp -f " + lang +"/latex/LVGL.pdf LVGL.pdf | true")
|
|
|
|
cmd('sphinx-build -b latex "{src}" "{dst}" -j {cpu}'.format(
|
|
|
|
src=temp_directory,
|
|
|
|
dst=latex_output_path,
|
|
|
|
cpu=os.cpu_count()
|
|
|
|
))
|
|
|
|
|
|
|
|
# Generate PDF
|
|
|
|
cmd('cd "{out_latex}" && latexmk -pdf "LVGL.tex"'.format(
|
|
|
|
out_latex=latex_output_path
|
|
|
|
))
|
|
|
|
|
|
|
|
# Copy the result PDF to the main directory to make
|
|
|
|
# it available for the HTML build
|
|
|
|
|
|
|
|
shutil.copyfile(pdf_src_file, pdf_dst_file)
|
|
|
|
# cmd("cd out_latex && cp -f LVGL.pdf ../LVGL.pdf")
|
|
|
|
|
|
|
|
# add the PDF link so the HTML build will have it.
|
|
|
|
index_data = 'PDF version: :download:`LVGL.pdf <LVGL.pdf>`\n' + index_data
|
|
|
|
|
|
|
|
with open(index_path, 'wb') as f:
|
|
|
|
f.write(index_data.encode('utf-8'))
|
2021-04-24 05:45:34 +08:00
|
|
|
|
2021-11-23 17:50:18 +08:00
|
|
|
# BUILD HTML
|
2021-04-24 05:45:34 +08:00
|
|
|
|
2023-04-27 20:42:02 +08:00
|
|
|
|
|
|
|
def get_version():
|
2024-04-25 16:39:59 +08:00
|
|
|
_, ver = subprocess.getstatusoutput("../scripts/find_version.sh")
|
2023-04-27 20:42:02 +08:00
|
|
|
return ver
|
|
|
|
|
|
|
|
cmd('sphinx-build -b html "{src}" "{dst}" -D version="{version}" -E -j {cpu}'.format(
|
|
|
|
src=html_src_path,
|
|
|
|
dst=html_dst_path,
|
|
|
|
version=get_version(),
|
|
|
|
cpu=os.cpu_count()
|
|
|
|
))
|
|
|
|
|
|
|
|
if develop:
|
|
|
|
print('temp directory:', temp_directory)
|
|
|
|
else:
|
|
|
|
def iter_temp(p):
|
|
|
|
folders = []
|
|
|
|
remove_folder = True
|
|
|
|
for temp_file in os.listdir(p):
|
|
|
|
temp_file = os.path.join(p, temp_file)
|
|
|
|
if os.path.isdir(temp_file):
|
|
|
|
folders.append(temp_file)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
os.remove(temp_file)
|
|
|
|
except OSError:
|
|
|
|
remove_folder = False
|
|
|
|
|
|
|
|
for folder in folders:
|
|
|
|
if not iter_temp(folder):
|
|
|
|
remove_folder = False
|
|
|
|
|
|
|
|
if remove_folder:
|
|
|
|
try:
|
|
|
|
os.rmdir(p)
|
|
|
|
except OSError:
|
|
|
|
remove_folder = False
|
|
|
|
|
|
|
|
return remove_folder
|
|
|
|
|
|
|
|
iter_temp(temp_directory)
|
|
|
|
|
2023-05-29 16:46:42 +08:00
|
|
|
config_builder.cleanup()
|
|
|
|
|
2023-04-27 20:42:02 +08:00
|
|
|
print('output path:', html_dst_path)
|
|
|
|
print('\nFINISHED!!')
|