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

Move _GNU_SOURCE from CCFLAGS to CPPDEFINES #8579

Merged
merged 2 commits into from
May 28, 2022

Conversation

maxgerhardt
Copy link
Contributor

@maxgerhardt maxgerhardt commented May 22, 2022

For more than 2 years people were complaining that in VSCode, certain functions were not recognized as existing, but compiled just fine. For example, tzset(), setenv or strlcpy.

The cause of building fine but not intellisense visible in regards to these functions is because they're GNU / BSD functions whose declaration is only enabled in headers if e.g. __BSD_VISBLE is defined, which gets activated through one possible chain through _GNU_SOURCE. PlatlformIO gives the -D_GNU_SOURCE flag via CCFLAGS (like Arduino platform.txt does), which causes that flag to be given in compilation correctly, but not showing up in Intellisense (.vscode/c_cpp_properties), which only shows CPPDEFINES. The usage of -D... in CCFLAGS or the macro itself in CPPDEFINES is equivalent.

This PR fixes that _GNU_SOURCE is given via CPPDEFINES instead and is thus visible in intellisense and fixes all these "Intellisense can't find function but it still compiles" errors. Compilation is logically unaffected. Tested fine on my local machine.

Makes _GNU_SOURCE visible in VSCode Intellisense and other IDEs.
@mcspr
Copy link
Collaborator

mcspr commented May 22, 2022

Doesn't it also mean -U__STRICT_ANSI__ is not being processed? See 7e6ee37 for the reasoning
Just curious, is there a standalone way to generate c_cpp_properties from our sources, or it is something internal to vscode, it's cpptools or platformio extension?

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented May 22, 2022

PlatformIO generates the c_cpp_properties.json by executing the template logic here and here.

Indeed, the -U__STRICT_ANSI__ does not appear in this file (see e.g. here for after PR state). And looking at the microsoft docs, they have defines, but not undefines, so not sure how to inform Intellisense about that all.

But of course PlatformIO still gives that -U flag into the compilation process. It's just the VSCode Intellisense that knows nothing about it -- and it doesn't seem to be causing display issues with missing functions.

To be clear again, the c_cpp_properties.json just controls VSCode's Intellisense, i.e. how it displays the code and what include folders and activated macros it knows about. Actual firmware compilation is doen by the PlatformIO core where -D_GNU_SOURCE and -U__STRICT_ANSI__ is given as normal (since its in CCFLAGS, or CPPDEFINES for the first one after this PR). The compiled binary has no problems, just VSCode Intellisense display stuff.

@maxgerhardt
Copy link
Contributor Author

The function referenced in the STRICT ANSI comment displays nicely with my PR.

grafik

What I am noticing though is that maybe a more general fix in the PlatformIO could would be better, so that if CCFLAGS contains -D flags for defines, it correctly transfers them to the defines in the IDE intellisense files.

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented May 22, 2022

Let's wait a bit so that we might resolve this issue in the core ^.

@ivankravets ivankravets merged commit c1144c5 into esp8266:master May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants