-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests/subsys/settings/functional: make common code a zephyr_library() #19531
tests/subsys/settings/functional: make common code a zephyr_library() #19531
Conversation
All checks are passing now. Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
5445725
to
ca97635
Compare
This fixes only I have a bigger, WIP series in my workspace that fixes everything in tests/subsys/settings/ with the same approach. However the (CMake) structure of tests/subsys/settings/ is a maze that takes me at least 1/2h to wrap my head around every time. To avoid losing reviewers too in this maze (and duplication) let's focus on this much smaller, self-contained subset first. Will replicate the same approach elsewhere if/when this is merged. For a complete record, this issue was also mentioned briefly in PR #18891 |
|
||
zephyr_library_named( settings_func_test) | ||
zephyr_library_sources(settings_basic_test.c) | ||
add_dependencies( settings_func_test offsets_h) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this dependency required?
I see this in the top level zephyr/CMakeLists.txt:
foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
# TODO: Could this become an INTERFACE property of zephyr_interface?
add_dependencies(${zephyr_lib} ${OFFSETS_H_TARGET})
endforeach()
So it looks like zephyr_library_named() should be taking care of this:
macro(zephyr_library_named name)
[...]
set(ZEPHYR_CURRENT_LIBRARY ${name})
add_library(${name} STATIC "")
zephyr_append_cmake_library(${name})
[...]
endmacro()
[...]
function(zephyr_append_cmake_library library)
set_property(GLOBAL APPEND PROPERTY ZEPHYR_LIBS ${library})
endfunction()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this explicit dependency is needed. It was suggested by @SebastianBoe . See below how make -C build [settings_func_test]
always fails without it.
Note: make -j
sometimes succeeds in building even without this dependency thanks to a race condition. make -k; make
obviously succeeds too.
make: Entering directory 'zephyr/tests/subsys/settings/functional/nvs/build'
/usr/bin/cmake -Szephyr/tests/subsys/settings/functional/nvs -Bzephyr/tests/subsys/settings/functional/nvs/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start zephyr/tests/subsys/settings/functional/nvs/build/CMakeFiles zephyr/tests/subsys/settings/functional/nvs/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory 'zephyr/tests/subsys/settings/functional/nvs/build'
make -f func_test_bindir/CMakeFiles/settings_func_test.dir/build.make func_test_bindir/CMakeFiles/settings_func_test.dir/depend
make[2]: Entering directory 'zephyr/tests/subsys/settings/functional/nvs/build'
cd zephyr/tests/subsys/settings/functional/nvs/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" zephyr/tests/subsys/settings/functional/nvs zephyr/tests/subsys/settings/functional/src zephyr/tests/subsys/settings/functional/nvs/build zephyr/tests/subsys/settings/functional/nvs/build/func_test_bindir zephyr/tests/subsys/settings/functional/nvs/build/func_test_bindir/CMakeFiles/settings_func_test.dir/DependInfo.cmake --color=
make[2]: Leaving directory 'zephyr/tests/subsys/settings/functional/nvs/build'
make -f func_test_bindir/CMakeFiles/settings_func_test.dir/build.make func_test_bindir/CMakeFiles/settings_func_test.dir/build
make[2]: Entering directory 'zephyr/tests/subsys/settings/functional/nvs/build'
[ 0%] Building C object func_test_bindir/CMakeFiles/settings_func_test.dir/settings_basic_test.c.obj
In file included from zephyr/lib/libc/minimal/include/errno.h:20,
from zephyr/include/kernel.h:18,
from zephyr/include/zephyr.h:18,
from zephyr/tests/subsys/settings/functional/src/settings_basic_test.c:12:
zephyr/include/sys/errno_private.h:34:10: fatal error: syscalls/errno_private.h: No such file or directory
#include <syscalls/errno_private.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [func_test_bindir/CMakeFiles/settings_func_test.dir/build.make:63: func_test_bindir/CMakeFiles/settings_func_test.dir/settings_basic_test.c.obj] Error 1
make[2]: Leaving directory 'zephyr/tests/subsys/settings/functional/nvs/build'
make[1]: *** [CMakeFiles/Makefile2:2972: func_test_bindir/CMakeFiles/settings_func_test.dir/all] Error 2
make[1]: Leaving directory 'zephyr/tests/subsys/settings/functional/nvs/build'
make: *** [Makefile:84: all] Error 2
make: Leaving directory 'zephyr/tests/subsys/settings/functional/nvs/build'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be papering over a bug in the cmake extensions somehow, then. @SebastianBoe any comment?
I guess as a band-aid that makes sense then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ninja -j1
doesn't fail, it seems "lucky" enough to build in some order that avoids the missing dependency issue.
However ninja settings_func_test
fails with the same error than make settings_func_test
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbolivar It seems to be that at the time the foreach loop is executed the library settings_func_test has not been added to the list yet. I think the TODO statement in the foreach loop would fix that issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But for now this is best-practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a black-magic it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any sufficiently obscure code is indistinguishable from magic ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining @SebastianBoe @joerchan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add license and copyright to empty files in order to satisfy CI, also include comment which explains why the empty file is needed.
Stops leaking very long source paths in build directories; makes them deterministic. Besides satisfying a CMake requirement, the new empty_file.c provide a clue that the actual test code is not in the directory of the test case. See zephyrproject-rtos/hal_nordic#6 and https://gitlab.kitware.com/cmake/cmake/issues/19475 for more details. - Test with a simple: sanitycheck -T $ZEPHYR_BASE/tests/subsys/settings/functional/ - Before: CMakeFiles ├── app.dir │ ├── HOME │ │ └── JOHN │ │ └── zephyrproject │ │ └── zephyr │ │ └── tests │ │ └── subsys │ │ └── settings │ │ └── functional │ │ └── src │ │ └── settings_basic_test.c.obj - After: func_test_bindir/ ├── CMakeFiles │ └── settings_func_test.dir │ └── settings_basic_test.c.obj │ ├── libsettings_func_test.a Signed-off-by: Marc Herbert <marc.herbert@intel.com>
ca97635
to
df3b926
Compare
Stops leaking very long source paths in build directories; makes them deterministic. This is identical to what was already merged in zephyrproject-rtos/hal_nordic#6 or zephyrproject-rtos/zephyr#19531 see previous code reviews there. See also CMake issue https://gitlab.kitware.com/cmake/cmake/issues/19475 for more details. This is basically a search/replace of "zephyr_sources" with "zephyr_library_sources" For instance, when running sanitycheck -p stm3210c_eval, this changes the build directories from: sample.helloworld/ └── zephyr ├── CMakeFiles │ │ ├── HOME │ │ │ └── JOHN │ │ │ └── ZEPHYRPROJECT │ │ │ └── modules │ │ │ └── hal │ │ │ └── stm32 │ │ │ └── stm32cube │ │ │ └── stm32f1xx │ │ │ ├── drivers │ │ │ │ └── src │ │ │ │ ├── stm32f1xx_hal.c.obj │ │ │ │ ├── stm32f1xx_hal_rcc.c.obj │ │ │ │ └── stm32f1xx_ll_utils.c.obj │ │ │ └── soc │ │ │ └── system_stm32f1xx.c.obj ... to: sample.helloworld/ ├── modules │ ├── stm32 │ │ ├── CMakeFiles │ │ └── stm32cube │ │ ├── CMakeFiles │ │ │ └── ..__modules__hal__stm32__stm32cube.dir │ │ │ └── stm32f1xx │ │ │ ├── drivers │ │ │ │ └── src │ │ │ │ ├── stm32f1xx_hal.c.obj │ │ │ │ ├── stm32f1xx_hal_rcc.c.obj │ │ │ │ └── stm32f1xx_ll_utils.c.obj │ │ │ └── soc │ │ │ └── system_stm32f1xx.c.obj │ │ ├── │ │ ├── lib..__modules__hal__stm32__stm32cube.a Signed-off-by: Marc Herbert <marc.herbert@intel.com>
Completed in PR #19671 |
Stops leaking very long source paths in build directories; makes them deterministic. This is identical to what was already merged in zephyrproject-rtos/hal_nordic#6 or zephyrproject-rtos/zephyr#19531 see previous code reviews there. See also CMake issue https://gitlab.kitware.com/cmake/cmake/issues/19475 for more details. This is basically a search/replace of "zephyr_sources" with "zephyr_library_sources" For instance, when running sanitycheck -p stm3210c_eval, this changes the build directories from: sample.helloworld/ └── zephyr ├── CMakeFiles │ │ ├── HOME │ │ │ └── JOHN │ │ │ └── ZEPHYRPROJECT │ │ │ └── modules │ │ │ └── hal │ │ │ └── stm32 │ │ │ └── stm32cube │ │ │ └── stm32f1xx │ │ │ ├── drivers │ │ │ │ └── src │ │ │ │ ├── stm32f1xx_hal.c.obj │ │ │ │ ├── stm32f1xx_hal_rcc.c.obj │ │ │ │ └── stm32f1xx_ll_utils.c.obj │ │ │ └── soc │ │ │ └── system_stm32f1xx.c.obj ... to: sample.helloworld/ ├── modules │ ├── stm32 │ │ ├── CMakeFiles │ │ └── stm32cube │ │ ├── CMakeFiles │ │ │ └── ..__modules__hal__stm32__stm32cube.dir │ │ │ └── stm32f1xx │ │ │ ├── drivers │ │ │ │ └── src │ │ │ │ ├── stm32f1xx_hal.c.obj │ │ │ │ ├── stm32f1xx_hal_rcc.c.obj │ │ │ │ └── stm32f1xx_ll_utils.c.obj │ │ │ └── soc │ │ │ └── system_stm32f1xx.c.obj │ │ ├── │ │ ├── lib..__modules__hal__stm32__stm32cube.a Signed-off-by: Marc Herbert <marc.herbert@intel.com>
Stops leaking very long source paths in build directories; makes them
deterministic.
Besides satisfying a CMake requirement, the new empty_file.c provide a
clue that the actual test code is not in the directory of the test case.
See zephyrproject-rtos/hal_nordic#6 and
https://gitlab.kitware.com/cmake/cmake/issues/19475 for more details.
sanitycheck -T $ZEPHYR_BASE/tests/subsys/settings/functional/
Signed-off-by: Marc Herbert marc.herbert@intel.com