Skip to content
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

boards/native: fix overriden INCLUDES leading to build failure #11572

Merged
merged 1 commit into from
Aug 6, 2019

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented May 24, 2019

Contribution description

This PR fixes an issue when one loads the log_printfnoformat submodule into an application and builds for native. This use case works for all other boards.

I'm not sure this is the best fix and I'm also wondering why using INCLUDES = $(NATIVEINCLUDES) in Makefile.include is needed.

Testing procedure

Build an application with log_printfnoformat on native:

USEMODULE=log_printfnoformat make -C examples/hello-world/ clean all

With this PR it works, on master, you get the following error:

make: Entering directory '/home/aabadie/softs/src/riot/RIOT/examples/hello-world'
Building application "hello-world" for "native" with MCU "native".

"make" -C /home/aabadie/softs/src/riot/RIOT/boards/native
In file included from /home/aabadie/softs/src/riot/RIOT/boards/native/board.c:21:
/home/aabadie/softs/src/riot/RIOT/core/include/log.h:98:10: fatal error: log_module.h: No such file or directory
 #include "log_module.h"
          ^~~~~~~~~~~~~~
compilation terminated.

Issues/PRs references

Required by #11573, fixes #11603

@aabadie aabadie added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Platform: native Platform: This PR/issue effects the native platform 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 labels May 24, 2019
@aabadie aabadie requested a review from kaspar030 May 24, 2019 11:38
@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 24, 2019
@aabadie aabadie requested a review from cladmi May 27, 2019 11:33
Copy link
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

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

NATIVEINCLUDES is currently necessary here. At least, changing it is not trivial. And += should not be used at all.

The goal to use NATIVEINCLUDES is to not use the modules include directories and currently use the system posix headers for example.

It make sense for module giving a RIOT interface around system functionalities.

If boards needs both RIOT and system headers it means the system specific part may need to be split out.

@cladmi cladmi requested a review from miri64 May 27, 2019 12:00
@cladmi
Copy link
Contributor

cladmi commented May 27, 2019

I checked in board.c and the issue is only for native_motor, so I think it should be moved outside.

@cladmi cladmi requested a review from jcarrano May 27, 2019 12:07
@cladmi
Copy link
Contributor

cladmi commented May 27, 2019

The main question for native, is what should be using the system headers instead of the RIOT ones. Restricting this to the lowest layer modules as possible would be good.
Another solution is to make our headers use the reference posix ones if available.

@jcarrano
Copy link
Contributor

@cladmi So you say that the real solution is to move ´native_motor´ outside?

@aabadie
Copy link
Contributor Author

aabadie commented May 27, 2019

I checked in board.c and the issue is only for native_motor, so I think it should be moved outside.

I don't understand the relation with the problem that this PR is trying to solve. Moving native_motor "outside" doesn't solve the build issue you get with USEMODULE=log_printfnoformat make -C examples/hello-world.

I checked info-build target to compare the list of directories included (in INCLUDES), using USEMODULE=log_printfnoformat make -C examples/hello-world info-build:

  • this PR:
INCLUDES: 
	-I/home/aabadie/softs/src/riot/RIOT/core/include  
	-I/home/aabadie/softs/src/riot/RIOT/drivers/include  
	-I/home/aabadie/softs/src/riot/RIOT/sys/include  
	-I/home/aabadie/softs/src/riot/RIOT/boards/native/include  
	-DNATIVE_INCLUDES  
	-I/home/aabadie/softs/src/riot/RIOT/boards/native/include/  
	-I/home/aabadie/softs/src/riot/RIOT/core/include/  
	-I/home/aabadie/softs/src/riot/RIOT/drivers/include/  
	-I/home/aabadie/softs/src/riot/RIOT/cpu/native/include  
	-I/home/aabadie/softs/src/riot/RIOT/sys/include  
	-I/home/aabadie/softs/src/riot/RIOT/cpu/native/include  
	-I/home/aabadie/softs/src/riot/RIOT/sys/log/log_printfnoformat
  • master:
INCLUDES: 
	-I/home/aabadie/softs/src/riot/RIOT/core/include  
	-I/home/aabadie/softs/src/riot/RIOT/drivers/include  
	-I/home/aabadie/softs/src/riot/RIOT/sys/include  
	-I/home/aabadie/softs/src/riot/RIOT/boards/native/include  
	-DNATIVE_INCLUDES  
	-I/home/aabadie/softs/src/riot/RIOT/boards/native/include/  
	-I/home/aabadie/softs/src/riot/RIOT/core/include/  
	-I/home/aabadie/softs/src/riot/RIOT/drivers/include/  
	-I/home/aabadie/softs/src/riot/RIOT/cpu/native/include  
	-I/home/aabadie/softs/src/riot/RIOT/sys/include  
	-I/home/aabadie/softs/src/riot/RIOT/cpu/native/include  
	-I/home/aabadie/softs/src/riot/RIOT/sys/log/log_printfnoformat

They are exactly the same but the latter doesn't work. So for me the use of INCLUDES = $(NATIVEINCLUDES) in the board Makefile is somehow breaking the list of includes.

Now if I use the verbose build, one can see that the log_printfnoformat is not in the list of -I arguments of gcc, which is in contradiction with what info-build returns:

  • on master (and it fails right after of course):
gcc \
	-DRIOT_FILE_RELATIVE=\"boards/native/board_init.c\" \
	-DRIOT_FILE_NOPATH=\"board_init.c\" \
	-Werror -Wall -Wextra -pedantic -std=gnu99 -m32 -fstack-protector-all -ffunction-sections -fdata-sections -fno-delete-null-pointer-checks -fdiagnostics-color -Wstrict-prototypes -Wold-style-definition -fno-common -Wall -Wextra -Wformat=2 -Wformat-overflow -Wformat-truncation -Wmissing-include-dirs -include '/home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/riotbuild/riotbuild.h'  -DNATIVE_INCLUDES -I/home/aabadie/softs/src/riot/RIOT/boards/native/include/ -I/home/aabadie/softs/src/riot/RIOT/core/include/ -I/home/aabadie/softs/src/riot/RIOT/drivers/include/ -I/home/aabadie/softs/src/riot/RIOT/cpu/native/include -I/home/aabadie/softs/src/riot/RIOT/sys/include -MD -MP -c -o /home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/board/board_init.o /home/aabadie/softs/src/riot/RIOT/boards/native/board_init.c
gcc \
	-DRIOT_FILE_RELATIVE=\"boards/native/board.c\" \
	-DRIOT_FILE_NOPATH=\"board.c\" \
	-Werror -Wall -Wextra -pedantic -std=gnu99 -m32 -fstack-protector-all -ffunction-sections -fdata-sections -fno-delete-null-pointer-checks -fdiagnostics-color -Wstrict-prototypes -Wold-style-definition -fno-common -Wall -Wextra -Wformat=2 -Wformat-overflow -Wformat-truncation -Wmissing-include-dirs -include '/home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/riotbuild/riotbuild.h'  -DNATIVE_INCLUDES -I/home/aabadie/softs/src/riot/RIOT/boards/native/include/ -I/home/aabadie/softs/src/riot/RIOT/core/include/ -I/home/aabadie/softs/src/riot/RIOT/drivers/include/ -I/home/aabadie/softs/src/riot/RIOT/cpu/native/include -I/home/aabadie/softs/src/riot/RIOT/sys/include -MD -MP -c -o /home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/board/board.o /home/aabadie/softs/src/riot/RIOT/boards/native/board.c
In file included from /home/aabadie/softs/src/riot/RIOT/boards/native/board.c:21:
/home/aabadie/softs/src/riot/RIOT/core/include/log.h:98:10: fatal error: log_module.h: No such file or directory
 #include "log_module.h"
  • with this PR:
gcc \
	-DRIOT_FILE_RELATIVE=\"examples/hello-world/main.c\" \
	-DRIOT_FILE_NOPATH=\"main.c\" \
	-Werror -Wall -Wextra -pedantic -std=gnu99 -m32 -fstack-protector-all -ffunction-sections -fdata-sections -fno-delete-null-pointer-checks -fdiagnostics-color -Wstrict-prototypes -Wold-style-definition -fno-common -Wall -Wextra -Wformat=2 -Wformat-overflow -Wformat-truncation -Wmissing-include-dirs -include '/home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/riotbuild/riotbuild.h'  -I/home/aabadie/softs/src/riot/RIOT/core/include -I/home/aabadie/softs/src/riot/RIOT/drivers/include -I/home/aabadie/softs/src/riot/RIOT/sys/include -I/home/aabadie/softs/src/riot/RIOT/boards/native/include -DNATIVE_INCLUDES -I/home/aabadie/softs/src/riot/RIOT/boards/native/include/ -I/home/aabadie/softs/src/riot/RIOT/core/include/ -I/home/aabadie/softs/src/riot/RIOT/drivers/include/ -I/home/aabadie/softs/src/riot/RIOT/cpu/native/include -I/home/aabadie/softs/src/riot/RIOT/sys/include -I/home/aabadie/softs/src/riot/RIOT/cpu/native/include -I/home/aabadie/softs/src/riot/RIOT/sys/log/log_printfnoformat -MD -MP -c -o /home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/application_hello-world/main.o /home/aabadie/softs/src/riot/RIOT/examples/hello-world/main.c
"make" -C /home/aabadie/softs/src/riot/RIOT/boards/native
make[2]: Entering directory '/home/aabadie/softs/src/riot/RIOT/boards/native'
mkdir -p /home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/board/
gcc \
	-DRIOT_FILE_RELATIVE=\"boards/native/board_init.c\" \
	-DRIOT_FILE_NOPATH=\"board_init.c\" \
	-Werror -Wall -Wextra -pedantic -std=gnu99 -m32 -fstack-protector-all -ffunction-sections -fdata-sections -fno-delete-null-pointer-checks -fdiagnostics-color -Wstrict-prototypes -Wold-style-definition -fno-common -Wall -Wextra -Wformat=2 -Wformat-overflow -Wformat-truncation -Wmissing-include-dirs -include '/home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/riotbuild/riotbuild.h'  -I/home/aabadie/softs/src/riot/RIOT/core/include -I/home/aabadie/softs/src/riot/RIOT/drivers/include -I/home/aabadie/softs/src/riot/RIOT/sys/include -I/home/aabadie/softs/src/riot/RIOT/boards/native/include -DNATIVE_INCLUDES -I/home/aabadie/softs/src/riot/RIOT/boards/native/include/ -I/home/aabadie/softs/src/riot/RIOT/core/include/ -I/home/aabadie/softs/src/riot/RIOT/drivers/include/ -I/home/aabadie/softs/src/riot/RIOT/cpu/native/include -I/home/aabadie/softs/src/riot/RIOT/sys/include -I/home/aabadie/softs/src/riot/RIOT/cpu/native/include -I/home/aabadie/softs/src/riot/RIOT/sys/log/log_printfnoformat -DNATIVE_INCLUDES -I/home/aabadie/softs/src/riot/RIOT/boards/native/include/ -I/home/aabadie/softs/src/riot/RIOT/core/include/ -I/home/aabadie/softs/src/riot/RIOT/drivers/include/ -I/home/aabadie/softs/src/riot/RIOT/cpu/native/include -I/home/aabadie/softs/src/riot/RIOT/sys/include -MD -MP -c -o /home/aabadie/softs/src/riot/RIOT/examples/hello-world/bin/native/board/board_init.o /home/aabadie/softs/src/riot/RIOT/boards/native/board_init.c

@cladmi
Copy link
Contributor

cladmi commented May 27, 2019

NATIVEINCLUDES is not as simple as this. It is there for a good reason.

#8940

And indeed, the modules using NATIVEINCLUDES cannot use any riot modules includes. It is on purpose.

@cladmi
Copy link
Contributor

cladmi commented May 28, 2019

@jcarrano currently it is using APIs that are not available for boards/native/board.c as it uses restrictive includes, so the placement is wrong.
As native/boards is not using any system posix headers it should be possible to use the normal INCLUDES there. Doing a rationalization of the NATIVEINCLUDES handling in general could be a good thing.

However, in practice, why is there even a native_motor_driver_qdec_simulation in boards/native/board.c?
If there is a need for a fake test device, why not put it in its own module ?
It is always compiled even if motor_driver features is not used.

@aabadie
Copy link
Contributor Author

aabadie commented May 28, 2019

And indeed, the modules using NATIVEINCLUDES cannot use any riot modules includes. It is on purpose.

Can you explain this a bit more ?

@cladmi
Copy link
Contributor

cladmi commented May 28, 2019

And indeed, the modules using NATIVEINCLUDES cannot use any riot modules includes. It is on purpose.

Can you explain this a bit more ?

From #8940.

The goal of NATIVEINCLUDES, as I understood it, is to handle conflicts between RIOT headers and the system headers which may contain different values.
(I know about POSIX for example)
POSIX is only an API and not an ABI, so "names" are the same but not the values for the enums/defines and even differ between linux/mac.

For native our POSIX headers do not match with the ones from the system.
Using INCLUDES directories can make the system use RIOT posix values, which are not the one for the host system. So not working when communication with the system.

Every modules that need to communicate with the Linux/mac underlying system, must use the system headers, not the ones we provide if they can be different.

Currently who should use NATIVEINCLUDES is not that clear and maybe too general as here board for native does not interact directly with Host system.

@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

@cladmi, see #11603 where there is an alternative to the change proposed here: extend NATIVEINCLUDES from the log submodule.
I have no idea what would be better. Do you have an even better suggestion ?

@cladmi
Copy link
Contributor

cladmi commented Jun 3, 2019

@aabadie I think we can change that NATIVEINCLUDES is not used at all boards/native/* as neither board nor native-drivers implement direct interaction with the system. If another periph using system interaction must be implemented it should be put in its own directory .
So the definition of NATIVEINCLUDES could be moved to cpu/native too.

@aabadie
Copy link
Contributor Author

aabadie commented Jun 3, 2019

@cladmi, I remove INCLUDES = $(NATIVEINCLUDES) from boards/native and cpu/native and it seems to work. I'm not sure if that was what you proposed.

I'll removed the previous commits if it's ok for you, just keeping the commit with the new test application.

@aabadie aabadie added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Jun 3, 2019
@cladmi
Copy link
Contributor

cladmi commented Jun 3, 2019

I was thinking about boards/native and boards/native/drivers.

cpu/native should keep it, async_read.c uses posix headers, and we have a custom fcntl.h. It may be ok but would not want to try.

When removing it needs to be reviewed that the included header did not change unexpectedly.
This can be checked by comparing the .d files output after compilation for all affected files like bin/native/board/board.d. So this needs its specific pull request.

@aabadie
Copy link
Contributor Author

aabadie commented Jun 4, 2019

@cladmi, I updated this PR following your suggestion: cpu/native/Makefile change is reverted and only boards/native/Makefile/boards/native/drivers/Makefile are modified.

When removing it needs to be reviewed that the included header did not change unexpectedly.

After building examples/hello-world, I also checked the content of bin/native/board/board.d, it doesn't seem to have changed: same number of files included (using a combination of cat and grep with regexp).

So this needs its specific pull request.

I'm not sure to understand. Do you mean the included files verification ? e.g. a new static test or something ?

@aabadie
Copy link
Contributor Author

aabadie commented Jun 26, 2019

ping @cladmi

@cladmi
Copy link
Contributor

cladmi commented Jun 26, 2019

So this needs its specific pull request.

I'm not sure to understand. Do you mean the included files verification ? e.g. a new static test or something ?

I mean tests/log_printfnoformat: add test application & script should not stay in the pr removing NATIVE_INCLUDES from boards/native and boards/native/drivers.

I will test the update now.

@cladmi
Copy link
Contributor

cladmi commented Jun 26, 2019

Comparing with your reference PR, it indeed did not change the .d files for board and native-led according to diff RIOT_CI_BUILD=1 make -C examples/hello-world/

diff -u bin_master/native/native-drivers/native-led.d bin_pr/native/native-drivers/native-led.d
diff -u bin_master/native/board/board.d bin_pr/native/board/board.d

And to be even more precise, the whole binary directories are the same

diff -r -a bin_master/ bin_pr/

And both the log_printfnoformat and the USEMODULE=log_printfnoformat make -C examples/hello-world/ clean all test case work.

Can you please rebase and only keep the commit removing NATIVEINCLUDES from native, and update the PR description.

As a justification somehow if you want inspiration

Both `board` and `native-drivers` do not interact with the host operating system so does not need to use system headers. So using restricted `NATIVEINCLUDES` is not needed.

It also fixes the issue that they use RIOT headers for, for example logging, which were not available in `NATIVEINCLUDES`.

@aabadie
Copy link
Contributor Author

aabadie commented Jun 26, 2019

I mean tests/log_printfnoformat: add test application & script should not stay in the pr removing NATIVE_INCLUDES from boards/native and boards/native/drivers.

I'm sorry but I read 3 times your initial comment about "So this needs its specific pull request" and this cannot the reason. It seems at least that the test application had nothing to with "So this needs its specific pull request".
Can you explain this again better ?

Also I think it's fine to keep the test application in this PR event if it doesn't seem related: it gives a way to verify that log_printfnoformat can be build for native (which was the initial goal of this PR).

@aabadie aabadie removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Jun 27, 2019
@aabadie
Copy link
Contributor Author

aabadie commented Aug 6, 2019

I cut out the test application from this PR and opened #11968

@miri64
Copy link
Member

miri64 commented Aug 6, 2019

So where do NATIVEINCLUDES go now? IIRC native needs some different defines, otherwise their is a collision with our POSIX headers, and the host system's POSIX headers.

@aabadie
Copy link
Contributor Author

aabadie commented Aug 6, 2019

So where do NATIVEINCLUDES go now?

They are not needed in boards/native

IIRC native needs some different defines, otherwise their is a collision with our POSIX headers, and the host system's POSIX headers.

See #11572 (comment)

@miri64
Copy link
Member

miri64 commented Aug 6, 2019

So where do NATIVEINCLUDES go now?

They are not needed in boards/native

IIRC native needs some different defines, otherwise their is a collision with our POSIX headers, and the host system's POSIX headers.

See #11572 (comment)

I see. I did not read the whole discussion.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

ACK. The argumentation in this PR makes sense and I locally-tested locally with some apps I know had problems with POSIX headers in the past:

  • examples/posix_sockets
  • tests/gnrc_sock_dns
  • tests/posix_*
  • tests/pthreads_*

I also tested #11968 with and without this PR merged and it indeed fixes it fixes compiling for the test introduced there for native.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 6, 2019
@miri64
Copy link
Member

miri64 commented Aug 6, 2019

Triggered rebuild, since last build was a few days back.

@aabadie
Copy link
Contributor Author

aabadie commented Aug 6, 2019

All green, let's merge. Thanks @miri64 !

@aabadie aabadie merged commit b388a5b into RIOT-OS:master Aug 6, 2019
@aabadie aabadie deleted the pr/boards/native_fix_log branch August 6, 2019 10:05
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 16, 2019
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 Platform: native Platform: This PR/issue effects the native platform Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NATIVEINCLUDES Does not include USEMODULE_INCLUDES from log_printfnoformat
5 participants