Skip to content

Makefile.include: perform checks for all relevant targets #21199

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

Merged
merged 2 commits into from
Feb 10, 2025

Conversation

crasbe
Copy link
Contributor

@crasbe crasbe commented Feb 7, 2025

Contribution description

This is mostly documented in #21198.

tl;dr: When building an application that specifies some restrictions such as BOARD_WHITELIST, BOARD_BLACKLIST, etc, the check in Makefile.include is only performed for the all and flash targets, not for any other target that builds the code base.

Therefore trying to build an application such as examples/openthread with an unsupported board such as nrf52dk will not be blocked, instead make will try to build it and fail on an unrelated error.

I don't expect any bad sideeffects from this.

Testing procedure

Execute BOARD=nrf52dk make -C examples/openthread. Make will quite with an error message that the board is not supported (as it should):

$ BOARD=nrf52dk make -C examples/openthread
make: Entering directory '/home/cbuec/riot-dev/RIOT/examples/openthread'
The selected BOARD=nrf52dk is not whitelisted: samr21-xpro iotlab-m3 iotlab-a8-m3 frdm-kw41z openlabs-kw41z-mini-256kib openlabs-kw41z-mini phynode-kw41z usb-kw41z cc2538dk remote-reva remote-revb omote openmote-cc2538 nrf52840dk nrf52840-mdk reel 
/home/cbuec/riot-dev/RIOT/examples/openthread/../../Makefile.include:1007: *** You can let the build continue on expected errors by setting CONTINUE_ON_EXPECTED_ERRORS=1 to the command line.  Stop.
make: Leaving directory '/home/cbuec/riot-dev/RIOT/examples/openthread

On master: Execute BOARD=nrf52dk make -C examples/openthread hexfile. Make will attempt to build the application but will fail due to an undefined constant.

Log:
$ BOARD=nrf52dk make -C examples/openthread hexfile
make: Entering directory '/home/cbuec/riot-dev/RIOT/examples/openthread'
"make" -C /home/cbuec/riot-dev/RIOT/pkg/cmsis/ 
"make" -C /home/cbuec/riot-dev/RIOT/pkg/openthread/ 
cmake -Wno-dev -B/home/cbuec/riot-dev/RIOT/examples/openthread/bin/nrf52dk/pkg-build/openthread -H/home/cbuec/riot-dev/RIOT/build/pkg/openthread \
 -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
 -DCMAKE_C_COMPILER="arm-none-eabi-gcc" \
 -DCMAKE_C_COMPILER_AR="ar" \
 -DCMAKE_C_COMPILER_RANLIB="arm-none-eabi-ranlib" \
 -DCMAKE_C_FLAGS="-mcpu=cortex-m4 -mlittle-endian -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fdata-sections -ffunction-sections -Os -ffunction-sections -fshort-enums -Wno-implicit-fallthrough -Wno-unused-parameter" \
 -DCMAKE_CXX_COMPILER="arm-none-eabi-g++" \
 -DCMAKE_CXX_FLAGS="-mcpu=cortex-m4 -mlittle-endian -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fdata-sections -ffunction-sections -Os -ffunction-sections -fshort-enums -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-class-memaccess -DOPENTHREAD_TARGET_RIOT -fno-exceptions -fno-rtti" \
 -DCMAKE_NM="arm-none-eabi-nm" \
 -DCMAKE_STRIP="" \
 -DOT_PLATFORM=NO \
 -DOT_CONFIG="/home/cbuec/riot-dev/RIOT/pkg/openthread/include/platform_config.h" \
 -DOT_APP_CLI=ON \
 -DOT_JOINER=OFF \
 -DOT_COAP=ON
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/arm-none-eabi-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/arm-none-eabi-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
third_party/nlbuild-autotools/repo/scripts/mkversion: line 132: arm-none-eabi-/dev/null: No such file or directory
third_party/nlbuild-autotools/repo/scripts/mkversion: line 203: arm-none-eabi-/usr/bin/printf: No such file or directory
third_party/nlbuild-autotools/repo/scripts/mkversion: line 245: arm-none-eabi-/usr/bin/printf: No such file or directory
-- Version: 
-- Project core config: "/home/cbuec/riot-dev/RIOT/pkg/openthread/include/platform_config.h"
-- Found PythonInterp: /usr/bin/python3.10 (found version "3.10.12") 
-- Found Perl: /usr/bin/perl (found version "5.34.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cbuec/riot-dev/RIOT/examples/openthread/bin/nrf52dk/pkg-build/openthread
"make" -C /home/cbuec/riot-dev/RIOT/examples/openthread/bin/nrf52dk/pkg-build/openthread mbedcrypto mbedtls openthread-ftd openthread-cli-ftd
[  0%] Building C object third_party/mbedtls/repo/library/CMakeFiles/mbedcrypto.dir/aes.c.o
[  0%] Building C object third_party/mbedtls/repo/library/CMakeFiles/mbedcrypto.dir/aesni.c.o
...
[ 98%] Building CXX object src/cli/CMakeFiles/openthread-cli-ftd.dir/cli_udp.cpp.o
[100%] Linking CXX static library libopenthread-cli-ftd.a
[100%] Built target openthread-cli-ftd
"make" -C /home/cbuec/riot-dev/RIOT/boards/common/init
"make" -C /home/cbuec/riot-dev/RIOT/boards/nrf52dk
"make" -C /home/cbuec/riot-dev/RIOT/boards/common/nrf52xxxdk
"make" -C /home/cbuec/riot-dev/RIOT/core
"make" -C /home/cbuec/riot-dev/RIOT/core/lib
"make" -C /home/cbuec/riot-dev/RIOT/cpu/nrf52
"make" -C /home/cbuec/riot-dev/RIOT/cpu/cortexm_common
"make" -C /home/cbuec/riot-dev/RIOT/cpu/cortexm_common/periph
"make" -C /home/cbuec/riot-dev/RIOT/cpu/nrf52/periph
"make" -C /home/cbuec/riot-dev/RIOT/cpu/nrf52/vectors
"make" -C /home/cbuec/riot-dev/RIOT/cpu/nrf5x_common
"make" -C /home/cbuec/riot-dev/RIOT/cpu/nrf5x_common/periph
"make" -C /home/cbuec/riot-dev/RIOT/drivers
"make" -C /home/cbuec/riot-dev/RIOT/drivers/netdev
"make" -C /home/cbuec/riot-dev/RIOT/drivers/periph_common
"make" -C /home/cbuec/riot-dev/RIOT/pkg/openthread/contrib
/home/cbuec/riot-dev/RIOT/pkg/openthread/contrib/openthread.c: In function 'openthread_bootstrap':
/home/cbuec/riot-dev/RIOT/pkg/openthread/contrib/openthread.c:103:27: error: 'netdev' undeclared (first use in this function)
  103 |     openthread_radio_init(netdev, tx_buf, rx_buf);
      |                           ^~~~~~
/home/cbuec/riot-dev/RIOT/pkg/openthread/contrib/openthread.c:103:27: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [/home/cbuec/riot-dev/RIOT/Makefile.base:149: /home/cbuec/riot-dev/RIOT/examples/openthread/bin/nrf52dk/openthread_contrib/openthread.o] Error 1
make[1]: *** [/home/cbuec/riot-dev/RIOT/Makefile.base:31: ALL--/home/cbuec/riot-dev/RIOT/pkg/openthread/contrib] Error 2
make: *** [/home/cbuec/riot-dev/RIOT/examples/openthread/../../Makefile.include:747: application_openthread.module] Error 2
make: Leaving directory '/home/cbuec/riot-dev/RIOT/examples/openthread'

With this PR: Execute BOARD=nrf52dk make -C examples/openthread hexfile. Make will

$ BOARD=nrf52dk make -C examples/openthread hexfile
make: Entering directory '/home/cbuec/riot-dev/RIOT/examples/openthread'
The selected BOARD=nrf52dk is not whitelisted: samr21-xpro iotlab-m3 iotlab-a8-m3 frdm-kw41z openlabs-kw41z-mini-256kib openlabs-kw41z-mini phynode-kw41z usb-kw41z cc2538dk remote-reva remote-revb omote openmote-cc2538 nrf52840dk nrf52840-mdk reel 
/home/cbuec/riot-dev/RIOT/examples/openthread/../../Makefile.include:1007: *** You can let the build continue on expected errors by setting CONTINUE_ON_EXPECTED_ERRORS=1 to the command line.  Stop.
make: Leaving directory '/home/cbuec/riot-dev/RIOT/examples/openthread'

Issues/PRs references

Fixes #21198.

@github-actions github-actions bot added the Area: build system Area: Build system label Feb 7, 2025
Copy link
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the issue and fix!

Quite brittle to have this explicit list of user-selected targets, instead of somehow checking for the recursive targets. A quick search online didn't suggest me a simple way of obtaining that with Make, though.

@crasbe
Copy link
Contributor Author

crasbe commented Feb 10, 2025

I wonder if it makes sense to have the target check at all or to exclude targets where the check should not be executed.
That latter makes sure that when a new target it added where the checks should not be ran, the author will stumble upon that.

But both have a higher risk of breaking something if we miss something I guess?

@mguetschow
Copy link
Contributor

I think I like the approach of excluding targets where the test is skipped. I can only think of help and generate-Makefile.ci which are BOARD-independant and should not need the check. While, e.g., flash-only or info-buildsize do not trigger a build themselves, they expect a prior successful build which should have failed anyhow.

@crasbe
Copy link
Contributor Author

crasbe commented Feb 10, 2025

So essentially we could do something like this:

# Warn if the selected board and drivers don't provide all needed features:
ifeq (, $(filter help generate-Makefile.ci, $(if $(MAKECMDGOALS), $(MAKECMDGOALS), all)))
...
endif

What's odd though: $(MAKECMDGOALS) sometimes seems to be undefined for the 'help' target. I added $(warning MAKECMDGOALS is '$(MAKECMDGOALS)') before the ifeq block and got this:

RIOT/examples/openthread$ BOARD=nrf52dk make help
/home/cbuec/riot-dev/RIOT/examples/openthread/../../Makefile.include:936: MAKECMDGOALS is 'help'
/home/cbuec/riot-dev/RIOT/Makefile.include:936: MAKECMDGOALS is ''
The selected BOARD=nrf52dk is not whitelisted: samr21-xpro iotlab-m3 iotlab-a8-m3 frdm-kw41z openlabs-kw41z-mini-256kib openlabs-kw41z-mini phynode-kw41z usb-kw41z cc2538dk remote-reva remote-revb omote openmote-cc2538 nrf52840dk nrf52840-mdk reel 
/home/cbuec/riot-dev/RIOT/Makefile.include:1010: *** You can let the build continue on expected errors by setting CONTINUE_ON_EXPECTED_ERRORS=1 to the command line.  Stop.
all
all-ubsan
bindist
....

The reason is a bit stupid and I don't really know how to fix it. This is the help target and it calls... make. But without a target

help:
  # filter all targets starting with lowercase and containing lowercase letters, hyphens, or underscores; explicitly include generate-Makefile.ci
	@$(MAKE) -qp | sed -ne 's/\(^[a-z][a-z_-]*\|generate-Makefile.ci\):.*/\1/p' | sort -u

I played around with this, and of course, Stack Overflow came to the rescure. Apparently, make>4.1.1 includes a --print-targets option, but it's gonna be more than 10 years until Ubuntu and other distributions include that... Until then, this is probably the best solution: https://stackoverflow.com/a/26339924
Unfortunately, this prints too many things, so the filtering does not work well for RIOT yet:

Log: ``` RIOT/examples/openthread$ BOARD=nrf52dk make help /home/cbuec/riot-dev/RIOT/examples/openthread/../../Makefile.include:936: MAKECMDGOALS is 'help' all application_openthread.module auto_init.module bindist binfile board.module board_common_init.module boards_common_nrf52xxxdk.module check-toolchain-supported check_bindist clang-tidy clean clean-intermediates clean-pkg compile-commands core.module core_lib.module cortexm_common.module cortexm_common_periph.module cosy cpp11-compat.module cpp_new_delete.module cpu.module cpu_common.module debug debug-client debug-server dependency-debug dependency-debug-features-provided-kconfig distclean div.module doc eclipsesym eclipsesym.xml elffile eui_provider.module event.module flash flash-only flashfile fmt.module frac.module fuzz hexfile info-boards info-build info-build-json info-buildsize info-concurrency info-cpu info-emulated-boards info-features-missing info-features-provided info-features-required info-features-used info-kconfig-variables info-modules info-objsize info-packages info-programmers-supported info-rust info-toolchains-supported l2util.module libc.module link list-ttys lstfile luid.module malloc_thread_safe.module mosquitto_rsmb netdev.module newlib_syscalls_default.module nrf52_vectors.module nrf5x_common_periph.module objdump openthread-cli-ftd.module openthread-ftd.module openthread_contrib.module openthread_contrib_netdev.module periph.module periph_common.module pkg-build pkg-prepare preflash prepare_check_bindist preprocessor.module print-size ps.module random.module reset scan-build-analyze stdio.module stdio_uart.module sys.module term termdeps test-as-root/available test-input-hash test-input-hash-changed test-with-config/check-config test/available timex.module usb_id_check ztimer64.module ztimer_core.module ```

So we mix and match with the command we already had:

help:
  # filter all targets starting with lowercase and containing lowercase letters, hyphens, or underscores; explicitly include generate-Makefile.ci
+  # inspired by: https://stackoverflow.com/a/26339924
- 	@$(MAKE) -qp | sed -ne 's/\(^[a-z][a-z_-]*\|generate-Makefile.ci\):.*/\1/p' | sort -u
+	@LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | sed -ne 's/\(^[a-z][a-z_-]*\|generate-Makefile.ci\):.*/\1/p' | sort -u
+  # IMPORTANT: The line above must be indented by (at least one) actual TAB character - spaces do *not* work.

This yields what we previously had:

Log:
RIOT/examples/openthread$ BOARD=nrf52dk make help
/home/cbuec/riot-dev/RIOT/examples/openthread/../../Makefile.include:936: MAKECMDGOALS is 'help'
all
all-ubsan
bindist
binfile
check-toolchain-supported
check_bindist
clang-tidy
clean
clean-intermediates
clean-pkg
cleanterm
compile-commands
cosy
debug
debug-client
debug-server
dependency-debug
dependency-debug-features-provided-kconfig
distclean
doc
eclipsesym
elffile
flash
flash-only
flashfile
fuzz
generate-Makefile.ci
help
hexfile
info-boards
info-boards-supported
info-build
info-build-json
info-buildsize
info-buildsizes
info-concurrency
info-cpu
info-emulated-boards
info-features-missing
info-features-provided
info-features-required
info-features-used
info-files
info-kconfig-variables
info-modules
info-objsize
info-packages
info-programmers-supported
info-rust
info-toolchains-supported
link
list-ttys
lstfile
mosquitto_rsmb
objdump
pkg-build
pkg-prepare
preflash
prepare_check_bindist
print-size
reset
scan-build
scan-build-analyze
term
term-rtt
termdeps
test
test-as-root
test-input-hash
test-input-hash-changed
test-with-config
usb_id_check

The comment about the tab is probably optional, because the tab was necessary previously as well. I don't really understand why, but the make gods probably have their reasons 🤣

@crasbe
Copy link
Contributor Author

crasbe commented Feb 10, 2025

I'm not sure if it's worth separating this into two commits, but it is somewhat related and somewhat unrelated.
Just let me know before squashing, I'm fine with both :)

Copy link
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'd leave it in two commits. Let's see if CI complains about something...

@mguetschow mguetschow added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 10, 2025
@riot-ci
Copy link

riot-ci commented Feb 10, 2025

Murdock results

✔️ PASSED

91dae97 Makefile.include: Update help command to avoid checks

Success Failures Total Runtime
10271 0 10271 09m:16s

Artifacts

@mguetschow
Copy link
Contributor

Please squash then :)

@crasbe
Copy link
Contributor Author

crasbe commented Feb 10, 2025

Something broke during squashing.

@mguetschow mguetschow disabled auto-merge February 10, 2025 13:46
@mguetschow
Copy link
Contributor

@crasbe
Copy link
Contributor Author

crasbe commented Feb 10, 2025

Yes, I think I squashed it in the wrong order and then something else got inbetween as well.

I thought about adding clean to the list as well, but since you can't compile for the wrong board, you shouldn't be able to clean for the wrong board? I guess?

@mguetschow
Copy link
Contributor

I thought about adding clean to the list as well, but since you can't compile for the wrong board, you shouldn't be able to clean for the wrong board? I guess?

Yeah, I'd second that reasoning. In particular, clean will depend on the given BOARD, unlike help and generate-Makefile.ci which are board-independent.

crasbe and others added 2 commits February 10, 2025 15:10
Co-authored-by: mguetschow <mikolai.guetschow@tu-dresden.de>
Co-authored-by: mguetschow <mikolai.guetschow@tu-dresden.de>
@mguetschow mguetschow added this pull request to the merge queue Feb 10, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2025
@mguetschow mguetschow added this pull request to the merge queue Feb 10, 2025
Merged via the queue into RIOT-OS:master with commit d630a15 Feb 10, 2025
25 checks passed
@crasbe
Copy link
Contributor Author

crasbe commented Feb 10, 2025

Thank you @mguetschow :)
Such a simple fix, but it wasn't so easy getting to it.

@crasbe crasbe deleted the pr/fix_makechecks branch February 10, 2025 19:57
@mguetschow mguetschow added this to the Release 2025.04 milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build System: make hexfile ignores BOARD_WHITELIST
3 participants