build(cmake): remove python package dependencies for gcc/clang (#10400)
Code Generation / Code Generation (push) Failing after 5s
Static Checks / Static Checks (push) Failing after 3s
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify GDB constants are up-to-date / verify-gdb-consts (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled

This commit is contained in:
André Costa authored and GitHub committed 2026-07-30 15:19:11 +00:00
1 parent 516b581620
commit 066d8db0b5
13 files changed
+7577 -229

No files matched your search

-2
View File
@@ -34,8 +34,6 @@ jobs:
python3 \
pkg-config \
python3-kconfiglib \
python3-venv \
python3-pcpp \
libwebp-dev \
libevdev-dev \
libdrm-dev \
+1 -1
View File
@@ -207,7 +207,7 @@ Below is a list of the available options/variables
| LV_BUILD_DEFCONFIG_PATH | PATH | Specify to use a .defconfig file instead of the current .config in a Kconfig setup. |
| LV_BUILD_LVGL_H_SYSTEM_INCLUDE | BOOLEAN | Enable if LVGL will be installed to the system or your build system uses a sysroot. Turning this option on implies that the resources generated by the image generation script will include `lvgl.h` as a system include. i.e: `#include <lvgl.h>`. This option is disabled by default. |
| LV_BUILD_LVGL_H_SIMPLE_INCLUDE | BOOLEAN | When enabled the resources will include `lvgl.h` as a simple include, this option is enabled by default. |
| LV_BUILD_SET_CONFIG_OPTS | BOOLEAN | When enabled, this option runs a script that processes the `lv_conf.h`/Kconfig configuration using `pcpp` to generate corresponding `CONFIG_LV_*` and `CONFIG_LV_BUILD_*` CMake variables based on the contents of `lv_conf_internal.h`. This requires python3 with `venv` and `pip` or access to a working `pcpp`. If KConfig is used, this is enabled automatically. |
| LV_BUILD_SET_CONFIG_OPTS | BOOLEAN | When enabled, this option runs a script that processes the `lv_conf.h`/Kconfig configuration to generate corresponding `CONFIG_LV_*` and `CONFIG_LV_BUILD_*` CMake variables. This requires python3 and a C compiler able to expand the configuration with `-E -dD`, which GCC and Clang are. [pcpp](https://pypi.org/project/pcpp/) can be used as an alternative. If KConfig is used, this is enabled automatically. |
| LV_USE_FIND_PACKAGE | BOOLEAN | Allow resolving dependencies via `find_package`. Enabled by default. |
| LV_USE_PKG_CONFIG | BOOLEAN | Allow resolving dependencies via `pkg-config`. Enabled by default. Requires pkg-config to be installed. |
| LV_FETCH_DEPENDENCIES | BOOLEAN | Fetch dependencies from source if not found on the system. Enabled by default. |
+1 -1
View File
@@ -43,7 +43,7 @@ endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E env LVGL_DIR=${LVGL_ROOT_DIR}
${Python_EXECUTABLE}
${LVGL_ROOT_DIR}/scripts/kconfig.py
${LVGL_ROOT_DIR}/scripts/build-tools/kconfig.py
${LVGL_ROOT_DIR}/Kconfig
${OUTPUT_DOTCONFIG}
${AUTOCONF_H}
+8 -7
View File
@@ -51,14 +51,14 @@ if (LV_BUILD_CONF_PATH AND LV_BUILD_CONF_DIR)
endif()
if (LV_BUILD_USE_KCONFIG)
# If Kconfig is used then enable PCPP
# If Kconfig is used then the configuration has to be expanded
set(LV_BUILD_SET_CONFIG_OPTS ON)
endif()
if (LV_BUILD_SET_CONFIG_OPTS)
# Python is required when LV_BUILD_SET_CONFIG_OPTS is enabled
# PCPP is used to pre-process lv_conf_internal.h and it avoids setting
# CONFIG_LV_USE or CONFIG_LV_BUILD options manually
# lv_conf_internal.h is pre-processed to avoid setting CONFIG_LV_USE
# or CONFIG_LV_BUILD options manually
find_package(Python REQUIRED)
endif()
@@ -185,20 +185,21 @@ endif()
if (LV_BUILD_SET_CONFIG_OPTS)
# Use the portable pcpp to preprocess lv_conf_internal.h
# Use the C compiler of the build to preprocess lv_conf_internal.h
# Use the definitions active during the build (recorded by
# lvgl_build_definitions). We can't use get_target_property(...
# COMPILE_DEFINITIONS) here because it returns raw generator-expression
# syntax (e.g. "$<BUILD_INTERFACE:LV_CONF_SKIP>") that pcpp can't parse.
# syntax (e.g. "$<BUILD_INTERFACE:LV_CONF_SKIP>") that the preprocessor
# can't parse.
get_property(CONF_DEFINES GLOBAL PROPERTY LVGL_BUILD_DEFINES)
execute_process(
COMMAND ${Python_EXECUTABLE} ${LVGL_ROOT_DIR}/scripts/preprocess_lv_conf_internal.py
COMMAND ${Python_EXECUTABLE} ${LVGL_ROOT_DIR}/scripts/build-tools/preprocess_lv_conf_internal.py
--input ${LVGL_INCLUDE_DIR}/lvgl/config/lv_conf_internal.h
--tmp_file ${CMAKE_CURRENT_BINARY_DIR}/tmp.h
--output ${CMAKE_CURRENT_BINARY_DIR}/lv_conf_expanded.h
--workfolder ${CMAKE_CURRENT_BINARY_DIR}
--cc ${CMAKE_C_COMPILER}
--defs ${CONF_DEFINES}
--include ${LVGL_ROOT_DIR} ${CMAKE_SOURCE_DIR} ${LVGL_ROOT_DIR}/src ${CONF_INC_DIR}
RESULT_VARIABLE ret
-2
View File
@@ -9,8 +9,6 @@ Build-Depends:
python3,
pkg-config,
python3-kconfiglib,
python3-venv,
python3-pcpp,
libwebp-dev,
libjpeg-dev,
libpng-dev,
-4
View File
@@ -17,10 +17,7 @@ CONFIG_ARRAY = declare -A PKGS=( \
dh $@ --buildsystem=cmake+ninja
override_dh_auto_configure:
mkdir -p $(CURDIR)/debian/pcpp
ln -sf /usr/bin/pcpp-python $(CURDIR)/debian/pcpp/pcpp
$(CONFIG_ARRAY); \
export PATH=$(CURDIR)/debian/pcpp:$$PATH; \
for config in "$${!PKGS[@]}"; do \
cmake -B build-$$config \
-DCMAKE_INSTALL_PREFIX=/usr \
@@ -49,7 +46,6 @@ override_dh_auto_clean:
for config in "$${!PKGS[@]}"; do \
rm -rf build-$$config ; \
done
rm -rf $(CURDIR)/debian/pcpp
override_dh_auto_test:
# no tests
@@ -21,16 +21,20 @@ import textwrap
# Lvgl doesn't use tristate symbols. They're supported here just to make the
# script a bit more generic.
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
KCONFIGLIB_PATH = os.path.join(SCRIPT_DIR, "third_party", "kconfiglib")
sys.path.insert(0, KCONFIGLIB_PATH)
from kconfiglib import (
Kconfig,
split_expr,
expr_value,
expr_str,
BOOL,
TRISTATE,
TRI_TO_STR,
AND,
BOOL,
OR,
TRI_TO_STR,
TRISTATE,
Kconfig,
expr_str,
expr_value,
split_expr,
)
@@ -134,13 +138,10 @@ def check_no_promptless_assign(kconf):
for sym in kconf.unique_defined_syms:
if sym.user_value is not None and promptless(sym):
err(
f"""\
err(f"""\
{sym.name_and_loc} is assigned in a configuration file, but is not directly
user-configurable (has no prompt). It gets its value indirectly from other
symbols. """
+ SYM_INFO_HINT.format(sym)
)
symbols. """ + SYM_INFO_HINT.format(sym))
def check_assigned_sym_values(kconf):
@@ -230,13 +231,10 @@ def check_assigned_choice_values(kconf):
for choice in kconf.unique_choices:
if choice.user_selection and choice.user_selection is not choice.selection:
warn(
f"""\
warn(f"""\
The choice symbol {choice.user_selection.name_and_loc} was selected (set =y),
but {choice.selection.name_and_loc if choice.selection else "no symbol"} ended
up as the choice selection. """
+ SYM_INFO_HINT.format(choice.user_selection)
)
up as the choice selection. """ + SYM_INFO_HINT.format(choice.user_selection))
# Hint on where to find symbol information. Used like
@@ -343,4 +341,4 @@ def err(msg):
if __name__ == "__main__":
main()
main()
+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
# Turns the output of a preprocessor backend into the expanded configuration
# header, which generate_cmake_variables.py consumes
#
# Both backends emit the #define/#undef directives of the taken branches, so
# the same output is produced no matter which one ran
import re
# Only the configuration directives are of interest, everything else a backend
# may emit (its predefined macros, #pragma message, stray declarations left by
# the expansion of a macro) is dropped. The prefixes cover LV_*, LVGL_* and
# their CONFIG_* counterparts
DIRECTIVE_RE = re.compile(r"^#\s*(?:define|undef)\s+(?:CONFIG_)?LV")
DEFINE_NAME_RE = re.compile(r"^#\s*define\s+([A-Za-z_][A-Za-z0-9_]*)")
# lv_conf_internal.h aligns the values of its definitions, a compiler collapses
# that padding while pcpp keeps it. Normalizing it - the padding between the
# name and the value only, never the value itself - makes both backends emit
# the very same header
PADDING_RE = re.compile(r"^(#define\s+[A-Za-z_][A-Za-z0-9_]*(?:\([^)]*\))?)\s+")
def extract_directives(lines, defs):
"""
Keeps the configuration directives only, left aligned and with a single
space after the #
"""
# A backend may echo back the definitions it was given on the command line,
# they come from the build system and are not part of the configuration
cmdline_defs = {definition.split("=", 1)[0] for definition in defs}
directives = []
for line in lines:
stripped = re.sub(r"^#\s+", "#", line.strip())
if not DIRECTIVE_RE.match(stripped):
continue
name = DEFINE_NAME_RE.match(stripped)
if name and name.group(1) in cmdline_defs:
continue
directives.append(PADDING_RE.sub(r"\1 ", stripped) + "\n")
return directives
def add_include_guards(lines):
"""
This is required - to avoid include errors when Kconfig is used and LVGL is
installed on the system - i.e when lvgl.h is used as a system include
"""
lines.insert(0, "#define LV_CONF_H\n\n")
lines.insert(0, "#ifndef LV_CONF_H\n")
lines.append("#endif /* END LV_CONF_H */\n")
return lines
def generate(preprocessed_file, output_file, defs):
with open(preprocessed_file, "r") as f:
lines = f.readlines()
lines = add_include_guards(extract_directives(lines, defs))
with open(output_file, "w") as f:
f.writelines(lines)
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# Expands the configuration with the C compiler used for the build
#
# The -dD option emits the #define/#undef directives of the taken branches, in
# source order, which is what the expanded configuration header is made of
import os
import re
import subprocess
import tempfile
NAME = "the C compiler"
def build_command(cc, input_file, output_file, include_dirs, defs):
"""
-dD emit the #define/#undef directives along with the preprocessed output
-P omit the linemarkers
-nostdinc
the system include directories must not be searched, otherwise an
lv_conf.h of an LVGL installed on the system is picked up by the
__has_include() check of lv_conf_internal.h
"""
command = [cc, "-E", "-dD", "-P", "-nostdinc", "-x", "c", "-o", output_file]
for include_path in include_dirs:
command.append(f"-I{include_path}")
for definition in defs:
command.append(f"-D{definition}")
command.append(input_file)
return command
def is_available(cc):
"""
Checks that the compiler keeps the #define directives in its output. MSVC
has no equivalent of -dD, it can't be used to expand the configuration
"""
if not cc:
return False
with tempfile.TemporaryDirectory() as tmp_dir:
probe_input = os.path.join(tmp_dir, "probe.h")
probe_output = os.path.join(tmp_dir, "probe.i")
with open(probe_input, "w") as f:
f.write("#define LV_PROBE 1\n")
try:
subprocess.run(
build_command(cc, probe_input, probe_output, [], []),
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
with open(probe_output, "r") as f:
return any(
re.match(r"^\s*#\s*define\s+LV_PROBE\s+1", line) for line in f
)
except (subprocess.CalledProcessError, OSError):
return False
def preprocess(cc, input_file, output_file, include_dirs, defs):
subprocess.run(
build_command(cc, input_file, output_file, include_dirs, defs), check=True
)
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
# Expands the configuration with pcpp, a C preprocessor written in Python
# Needed for the compilers that can't emit their #define directives like MSVC
import shutil
import subprocess
NAME = "pcpp"
def build_args(input_file, output_file, include_dirs, defs):
"""
--passthru-defines
keep the #define directives in the output instead of consuming them
--line-directive=
omit the linemarkers
"""
args = ["-o", output_file, "--passthru-defines", "--line-directive="]
for include_path in include_dirs:
args.append(f"-I{include_path}")
for definition in defs:
args.append(f"-D{definition}")
args.append(input_file)
return args
def import_pcpp():
try:
import pcpp
return pcpp
except ImportError:
return None
def is_available():
return import_pcpp() is not None or shutil.which("pcpp") is not None
def preprocess(input_file, output_file, include_dirs, defs):
args = build_args(input_file, output_file, include_dirs, defs)
module = import_pcpp()
if module is not None:
# argv[0] is the program name, pcpp expects it to be present
preprocessor = module.CmdPreprocessor(["pcpp"] + args)
if preprocessor.return_code:
raise RuntimeError(
f"pcpp failed with return code: {preprocessor.return_code}"
)
return
executable = shutil.which("pcpp")
if executable is None:
raise RuntimeError("pcpp is not installed")
subprocess.run([executable] + args, check=True)
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env python3
# Preprocess the lv_conf_internal.h to generate a header file containing the
# evaluated definitions. This output will be used to generate the cmake
# variables
#
# The C compiler of the build does the preprocessing. When it can't emit its
# #define directives - which is the case of MSVC - pcpp is used instead, if it
# is available
import argparse
import os
import subprocess
import lv_conf_header
import lv_conf_preprocess_cc as cc_backend
import lv_conf_preprocess_pcpp as pcpp_backend
def fatal(msg):
print()
print("ERROR! " + msg)
exit(1)
def get_args():
parser = argparse.ArgumentParser(
description="Expand the configuration of a C header file."
)
parser.add_argument(
"--input", help="Path to the input C header file", required=True
)
parser.add_argument(
"--tmp_file", help="Path to save the preprocessed output", required=True
)
parser.add_argument(
"--output", help="Path to save the expanded configuration header", required=True
)
parser.add_argument(
"--cc", help="C compiler used to preprocess the input", default=None
)
parser.add_argument(
"--defs",
nargs="+",
default=[],
help="Definitions to be passed to the preprocessor (flag -D)",
)
parser.add_argument(
"--include",
nargs="+",
default=[],
help="Paths to include directories for the preprocessor (flag -I)",
)
return parser.parse_args()
def select_backend(cc):
"""
Returns the name of the backend to use and a callable running it
"""
if cc_backend.is_available(cc):
return cc_backend.NAME, lambda *args: cc_backend.preprocess(cc, *args)
if pcpp_backend.is_available():
return pcpp_backend.NAME, pcpp_backend.preprocess
fatal(
f"'{cc}' can not expand the configuration.\n"
"Install pcpp to expand the configuration without the compiler, or set\n"
"the CONFIG_LV_* variables manually by disabling LV_BUILD_SET_CONFIG_OPTS"
)
def main():
args = get_args()
name, preprocess = select_backend(args.cc)
print(f"Expanding the configuration with {name}")
try:
preprocess(args.input, args.tmp_file, args.include, args.defs)
except (subprocess.CalledProcessError, RuntimeError, OSError) as e:
fatal(f"Preprocessing of {args.input} failed: {e}")
try:
lv_conf_header.generate(args.tmp_file, args.output, args.defs)
except OSError as e:
fatal(f"Writing {args.output} failed: {e}")
print(f"Expanded configuration header saved to {args.output}")
os.remove(args.tmp_file)
if __name__ == "__main__":
main()
File diff suppressed because it is too large. Load diff
-194
View File
@@ -1,194 +0,0 @@
#!/usr/bin/env python3
#
# Preprocess the lv_conf_internal.h to generate a header file
# containing the evaluated definitions. This output will be used to
# generate the cmake variables
#
# Author: David TRUAN (david.truan@edgemtech.ch)
# Author: Erik Tagirov (erik.tagirov@edgemtech.ch)
#
import sys
import subprocess
import os
import argparse
import re
import shutil
import importlib.util
def get_args():
parser = argparse.ArgumentParser(description="Preprocess a C header file and remove indentation.")
parser.add_argument("--input", help="Path to the input C header file", required=True)
parser.add_argument("--tmp_file", help="Path to save the preprocessed output", required=True)
parser.add_argument("--output", help="Path to save the cleaned output with removed indentation", required=True)
parser.add_argument("--workfolder", help="Path used to create a python environment", required=True)
parser.add_argument(
"--defs",
nargs='+',
default=[],
help="Definitions to be added to pcpp (flag -D)"
)
parser.add_argument(
"--include",
nargs='+',
default=[],
help="Paths to include directories for the preprocessor (flag -I)"
)
return parser.parse_args()
def preprocess_file(pcpp_exe, input_file, tmp_file, output_file, include_dirs, defs):
try:
pcpp_command = [pcpp_exe, "-o", tmp_file, "--passthru-defines", "--line-directive=", input_file]
for include_path in include_dirs:
pcpp_command.append(f"-I{include_path}")
for definition in defs:
pcpp_command.append(f"-D{definition}")
subprocess.run(pcpp_command, check=True)
print(f"Preprocessing completed. Output saved to {tmp_file}")
except subprocess.CalledProcessError as e:
print(f"Error during preprocessing: {e}")
exit(1)
# Read the temporary files and return an array of lines
def read_lines(tmp_file):
try:
with open(tmp_file, "r") as f:
lines = f.readlines()
except Exception as e:
print(f"Failed to pre-process file: {e}")
exit(1)
return lines
def remove_indentation(lines):
clean_lines = []
try:
for line in lines:
stripped = line.lstrip()
# Remove extra spaces after #
if stripped.startswith("#"):
stripped = re.sub(r"^#\s+", "#", stripped)
clean_lines.append(stripped)
except Exception as e:
print(f"Error during indentation removal: {e}")
exit(1)
return clean_lines
# This is required - to avoid include errors when Kconfig is used and
# LVGL is installed on the system - i.e when lvgl.h is used as a system include
def add_include_guards(lines):
lines.insert(0, "#define LV_CONF_H\n\n")
lines.insert(0, "#ifndef LV_CONF_H\n")
lines.append("#endif /* END LV_CONF_H */\n")
return lines
def init_venv(venv_path):
"""
Creates a virtual env named .venv in the `workfolder` directory
It is usually set to the path of the build directory.
If the .venv already exists it enters the venv
Returns the path to the venv
"""
try:
if os.path.exists(venv_path) == False:
# Create venv
subprocess.check_call([sys.executable, "-m", "venv", venv_path])
# Enter venv
venv_path = os.path.join(venv_path, ".venv")
subprocess.check_call([sys.executable, "-m", "venv", venv_path])
except subprocess.CalledProcessError as e:
print(f"Error during the setup of python venv: {e}")
exit(1)
return venv_path
def install_pcpp_in_venv(venv_path):
"""
Install pcpp a python implementation of the C pre-processor
On success - Returns the path to pcpp, None on failure
"""
if sys.platform == "win32":
venv_pip = os.path.join(venv_path, "Scripts", "pip.exe")
venv_pcpp = os.path.join(venv_path, "Scripts", "pcpp.exe")
else:
venv_pip = os.path.join(venv_path, "bin", "pip")
venv_pcpp = os.path.join(venv_path, "bin", "pcpp")
if os.path.exists(venv_pcpp) == False:
# Install pcpp
try:
subprocess.check_call([venv_pip, "install", "pcpp"])
except subprocess.CalledProcessError as e:
print(f"Failed to install PCPP: {e}")
return None
else:
print("PCPP is already installed in venv")
return venv_pcpp
def main():
args = get_args()
# Check if PCPP is already present on the system
# if it's not - create a python venv inside the workfolder directory
# and install it there
pcpp_path = shutil.which("pcpp")
if pcpp_path:
pcpp_exe = pcpp_path
print(f"Found PCPP: {pcpp_exe}")
else:
print("Failed to locate pcpp - installing it")
venv_path = init_venv(args.workfolder)
pcpp_exe = install_pcpp_in_venv(venv_path)
if pcpp_exe is None:
exit(1)
preprocess_file(pcpp_exe, args.input, args.tmp_file, args.output, args.include, args.defs)
lines = read_lines(args.tmp_file)
lines = remove_indentation(lines)
lines = add_include_guards(lines)
# Write the resulting output header file with include guards and no indentation
try:
with open(args.output, "w") as f:
f.writelines(lines)
except Exception as e:
print(f"Writing resulting file failed: {e}")
exit(1)
print(f"Expanded configuration header saved to {args.output}")
os.remove(args.tmp_file)
print(f"Temporary preprocessed file {args.tmp_file} removed.")
if __name__ == "__main__":
main()