zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.37k stars 6.35k forks source link

scripts: checkpatch.pl: refinements required to reduce false positives #67283

Closed cfriedt closed 5 months ago

cfriedt commented 7 months ago

Describe the bug There are 2 main issues covered here with how scripts/checkpatch.pl enforces rules A.4 and A.5 of the coding guidelines.

Rule A.4

Rule A.4 restricts the Zephyr kernel from being built with ISO C functions (and some POSIX functions) other than those listed.

However, scripts/checkpatch.pl looks at the entire Zephyr codebase when enforcing those restrictions rather than enforcing it for (only) kernel/ and (probably) include/zephyr/kernel*.

With that, scripts/checkpatch.pl currently generates false positives in CI for valid code changes that are not in violation of Rule A.4.

Note: The rationale for Rule A.4 is to support building the Zephyr kernel with the minimal libc.

Rule A.5

Rule A.5 is there to restrict use of "C standard library functions and macros" in the Zephyr codebase to that of C11, mainly because e.g. Newlib and Picolibc also provide implementations of non-ISO-C library routines bundled with their versions of the C library.

However, Zephyr's POSIX API, network subsystem, as well as conformant applications and libraries do require being able to declare e.g. _POSIX_C_SOURCE or _XOPEN_SOURCE (possibly gated via some Kconfig option) in order to signal to the implementation that POSIX prototypes and structures should be made available (See IEEE 1003.1-2017, section 2.2, "Application Conformance").

We generally do want to support applications (libraries, etc) that are built according to standards.

Please also mention any information which could help others to understand the problem you're facing:

To Reproduce Steps to reproduce the behavior:

  1. modify samples/hello_world to use gethostname() as in #67282
  2. submit PR
  3. See CI produce coding guideline errors

Expected behavior Applications and libraries (outside of the kernel) should be able to depend on and select POSIX options and option groups without CI generating errors.

Impact A bit of a showstopper, since whenever reviewers see compliance failures, they assume that something is wrong with the code, but in many applications (particularly those in networking, fs, posix, etc), that is not the case.

Logs and console output

Run if [[ ! -s "compliance.xml" ]]; then
Error: See https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style for more details.

 API_DEFINE: do not specify a non-Zephyr API for libc
File:samples/hello_world/src/main.c
Line:10
Error: Process completed with exit code 1.

Environment (please complete the following information):

Additional context

Screenshot 2024-01-07 at 2 16 26 PM
github-actions[bot] commented 5 months ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.