microsoft / vscode-makefile-tools

MAKE integration in Visual Studio Code
Other
196 stars 60 forks source link

Header includes specified as preprocessor macros are not resolved #196

Closed cdwilson closed 11 months ago

cdwilson commented 3 years ago

The micropython Makefile specifies some of the header includes as preprocessor macros. For example, STM32_HAL_H is defined in ports/stm32/Makefile as:

CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>'

This shows up as an include in the source files like this:

// ports/stm32/mphalport.h
#include STM32_HAL_H

Makefile Tools doesn't seem to be able to resolve headers defined this way. If I replace the preprocessor macro with the actual header file, the red squiggles go a way and IntelliSense starts working:

-#include STM32_HAL_H
+#include <stm32f4xx_hal.h>
andreeis commented 3 years ago

@cdwilson, thank you for describing this scenario. We weren't aware of it. It's very interesting and we will address this case.

andreeis commented 3 years ago

Also, can you share your .vscode/dryrun.log for this project when you don't change the header definition? And define "makefile.extensionLog": ".vscode/extension.log" and "makefile.loggingLevel": "Debug" and share .vscode/extension.log.

cdwilson commented 3 years ago

@andreeis please see attached

settings.json

{
    "C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools",
    "makefile.extensionOutputFolder": "./.vscode",
    "makefile.configurations": [
        {
            "name": "PYBv1.1",
            "makeArgs": [
                "BOARD=PYBV11",
                "V=1"
            ]
        }
    ],
    "makefile.phonyOnlyTargets": true,
    "makefile.loggingLevel": "Debug",
    "makefile.extensionLog": ".vscode/extension.log",
    "makefile.makeDirectory": "./ports/stm32/"
}

dryrun.log extension.log

image

TomIowaSoft commented 3 years ago

In my case Intellisense never learns of any of the macros defined via the compiler -D argument, when building with gcc.

andreeis commented 3 years ago

@TomIowaSoft, when we will get to work on a fix for this problem we will let you know and give you a private vsix to install and confirm if you are unblocked for your specific scenario. If your -D switch is not of the type described above at the beginning (like CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>') then let's create a new issue.

TomIowaSoft commented 3 years ago

My -D switches are specified in APP_DEFINES rather than added to CFLAGS.

andreeis commented 3 years ago

Oh ok, if that is the only difference then your scenario should be the same and we will address it with the same fix.

andreeis commented 2 years ago

@cdwilson, @TomIowaSoft, can you cut the quotes and define like this? CFLAGS += -DSTM32_HAL_H=<stm32$(MCU_SERIES)xx_hal.h>

I tried this pattern and without quotes I get a valid include. Also, make sure you have Makefile Tools 0.3.0 which we released last week. Maybe with the previous 0.2.2 you were not able to use this define without quotes because of some other bugs.

cdwilson commented 2 years ago

can you cut the quotes and define like this?

@andreeis The example I gave above was from the open source micropython project. I don't have any control over how they quote the includes in that project.

BTW, I'm trying to get a working environment so I can test out the new 0.3.0 changes (I got a new laptop and I'm running into a couple issues like https://github.com/microsoft/vscode-makefile-tools/issues/249 setting things up). Once I can get things sorted out, I'll get you some feedback on the new release.

andreeis commented 2 years ago

@cdwilson, thank you for testing the new release and we are looking forward for your feedback. Regarding the quotes, thanks for explaining where those come from. I will revisit my investigation then.

TomIowaSoft commented 2 years ago

I am unable to build anything with current makefile tools. I get this. It appears to not like the extra set of ' ' around all the arguments to make. If I copy the command line and remove the extra ' ' around the paths then it works when I enter it in the terminal.

Executing task: 'c:\program files\git\usr\bin\make.exe' 'all' 'mcu=1' 'build=debug' '-f' '"d:\OneDrop\sano-potentiostats-firmware\wpstat\mcu\makefile"' '-C' '"d:\OneDrop\sano-potentiostats-firmware\wpstat\mcu"' <

make: *** "d:\OneDrop\sano-potentiostats-firmware\wpstat\mcu": No such file or directory. Stop. The terminal process "C:\Program Files\Git\bin\bash.exe '--login', '-c', ''c:\program files\git\usr\bin\make.exe' 'all' 'mcu=1' 'build=debug' '-f' '"d:\OneDrop\sano-potentiostats-firmware\wpstat\mcu\makefile"' '-C' '"d:\OneDrop\sano-potentiostats-firmware\wpstat\mcu"''" terminated with exit code: 2.

TomIowaSoft commented 2 years ago

Also, my makefile does not appear to have any ' ' or " " in any of the /D for mcu=1. It uses " " for /I

For mcu=2 I tried changing this: '-DUSB_MANUFACTURER="Sano $(TARGET)"' to this: -DUSB_MANUFACTURER=<Sano $(TARGET)> And the compile command line ends up with: -DUSB_MANUFACTURER= Which it does not like. There is a $lt;Sano mcu2$gt; following the = in the line above that this editor strips off .

TomIowaSoft commented 2 years ago

This command works if I enter it in the terminal. "C:\Program Files\Git\bin\bash.exe" '--login' '-c' '"c:\program files\git\usr\bin\make.exe" 'all' 'mcu=2' 'build=debug' '-f' "d:/OneDrop/sano-potentiostats-firmware/wpstat/mcu/makefile" '-C ' "d:/OneDrop/sano-potentiostats-firmware/wpstat/mcu"'

andreeis commented 2 years ago

@TomIowaSoft, thank you for the comments so far, this is very valuable. I am investigating all of these scenarios and will be back with an update.

TomIowaSoft commented 2 years ago

The configurationCache.log appears to be parsing the quoted values correctly. ie: "USB_MANUFACTURER='\"Sano mcu2\"' although Intellisense does not realize it.

In the code it needs to have the double quotes in the value of USB_MANUFACTURER.

andreeis commented 2 years ago

@cdwilson and @TomIowaSoft, if you manually install the vsix from this link until we release 0.3.1, you can be unblocked with the quoting build problem. Continuing to work on the other issues, quotes for -D define switches, etc... and anything else was reported. Let me know how the new vsix works for you.

andreeis commented 2 years ago

@TomIowaSoft, I went through all your other comments.

Regarding the USB_MANUFACTURER define: don't change that " into <. I suggested such change only for defines that in the end are used for #include paths in c/c++ files. Like the first pattern in this bug report. Your second define scenario is different and should work in its original form. How is '-DUSB_MANUFACTURER="Sano $(TARGET)"' working for you now?

Regarding the first pattern, I may have a fix for that, even if I said that I recommended the define to be changed. Since it's from a third party, maybe it's a valid scenario we should support. I'll be back with update on this.

Regarding mcu 1 and 2: can I see your settings.json? I am curious of "makefile.configurations" and which one you chose in the left Makefile Tools UI panel ("configuration" item)? We construct that command line from 2 sources: the "makefile.configurations" entry corresponding to the "configuration" item in the Makefile Tools left side panel + "makefile.additionalDryRunSwitches" array (did you happen to leave by mistake -e mcu=1 in there maybe?).

TomIowaSoft commented 2 years ago

It looks like things maybe working correctly now. Thank you. Best support I have ever had!

andreeis commented 2 years ago

@TomIowaSoft, very glad to hear this. If you would like, you can also leave us a review on Microsoft Market Place.

gcampbell-msft commented 11 months ago

Closing this based on https://github.com/microsoft/vscode-makefile-tools/issues/196#issuecomment-990347488.

Thanks!