← index #14352PR #16021
Related · high · value 5.699
QUERY · ISSUE

ESP32 micropython port build with relative path to external user C-modules was failed

openby aso-copened 2024-04-22updated 2025-03-03
bugport-esp32

Checks

  • I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.

  • I've searched for existing issues matching this bug, and didn't find any.

Port, board and/or hardware

esp32 port, ESP32-boards of any kind, I guess

MicroPython version

MicroPython v1.22.2-dirty on 2024-04-18; Generic ESP32 module with ESP32

Reproduction

make USER_C_MODULES=../../examples/usercmodule/micropython.cmake

Expected behaviour

Make process failed with error message like a:
modules not found in the path <specified_path>

Observed behaviour

During the build, make changed current directory and relative path to micropython.cmake file turns out to be incorrect

Additional Information

Need expand relative path of USER_C_MODULES variable, to absolute path before passed it to the ./py/usermod.cmake as described below:
In the file ./ports/esp32/Makefile , line 41:

ifdef USER_C_MODULES
       CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
endif

change it to a:

ifdef USER_C_MODULES
        CMAKE_ARGS += -DUSER_C_MODULES=$(abspath ${USER_C_MODULES})
endif

Thnx!

CANDIDATE · PULL REQUEST

py/py.mk: Add check that any specified USER_C_MODULES folder exists.

mergedby andrewleechopened 2024-10-16updated 2024-12-18
py-core

Summary

When compiling with USER_C_MODULES set on the command line it's easy to get the path slightly wrong, particularly as it's usually given as a relative path to the port / build root directory.

Currently, if the provided path is incorrect the build proceeds as usual simply without including any of the user c modules which causes confusion for the developer.

This PR adds a basic check in the make rules to ensure that the provided path does indeed exist.

After also getting confused by the different way this is specifed for make vs cmake I updated cmake script to also accept the folder (same as make) and simply append the micropython.cmake file to that if needed. This still works as it did previously if the full path to that file is given.

Testing

With invalid paths:

anl@STEP:~/micropython$ make -C ports/unix/ USER_C_MODULES=../../../examples/usercmodule
make: Entering directory '/home/anl/micropython/ports/unix'
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
../../py/py.mk:36: *** USER_C_MODULES doesn't exist: /home/anl/examples/usercmodule.  Stop.
make: Leaving directory '/home/anl/micropython/ports/unix'```
anl@STEP:~/micropython$ make -C ports/rp2/ USER_C_MODULES=../../../examples/usercmodule/micropython.cmake 
make: Entering directory '/home/anl/micropython/ports/rp2'
[ -e build-RPI_PICO/Makefile ] || cmake -S . -B build-RPI_PICO -DPICO_BUILD_DOCS=0 -DMICROPY_BOARD=RPI_PICO -DMICROPY_BOARD_DIR="/home/anl/micropython/ports/rp2/boards/RPI_PICO" -DUSER_C_MODULES=../../../examples/usercmodule/micropython.cmake
PICO_SDK_PATH is /home/anl/micropython/lib/pico-sdk<snip>
<snip>
CMake Error at /home/anl/micropython/py/usermod.cmake:47 (message):
  USER_C_MODULES doesn't exist:
  /home/anl/examples/usercmodule/micropython.cmake
Call Stack (most recent call first):
  CMakeLists.txt:92 (include)

-- Configuring incomplete, errors occurred!

With corrected path:

anl@STEP:~/micropython$ make -C ports/unix/ USER_C_MODULES=../../examples/usercmodule
make: Entering directory '/home/anl/micropython/ports/unix'
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Including User C Module from ../../examples/usercmodule/cexample
Including User C Module from ../../examples/usercmodule/cppexample
Including User C Module from ../../examples/usercmodule/subpackage
GEN build-standard/genhdr/mpversion.h
mkdir -p build-standard/cexample/
mkdir -p build-standard/cppexample/
mkdir -p build-standard/subpackage/
CC ../../examples/usercmodule/cexample/examplemodule.c
...
anl@STEP:~/micropython$ make -C ports/rp2/ USER_C_MODULES=../../examples/usercmodule/micropython.cmake 
make: Entering directory '/home/anl/micropython/ports/rp2'
[ -e build-RPI_PICO/Makefile ] || cmake -S . -B build-RPI_PICO -DPICO_BUILD_DOCS=0 -DMICROPY_BOARD=RPI_PICO -DMICROPY_BOARD_DIR="/home/anl/micropython/ports/rp2/boards/RPI_PICO" -DUSER_C_MODULES=../../examples/usercmodule/micropython.cmake
PICO_SDK_PATH is /home/anl/micropython/lib/pico-sdk
<snip>
Including User C Module(s) from ../../examples/usercmodule/micropython.cmake
Found User C Module(s): usermod_cexample, usermod_cppexample
...

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied