microsoft / vscode-makefile-tools

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

Shell expansion is not supported in compile_commands.json #670

Open Lassebq opened 1 week ago

Lassebq commented 1 week ago

As per https://clang.llvm.org/docs/JSONCompilationDatabase.html neither "command" nor "arguments" key support shell expansion but makefile tools extension generates backticked shell commands regardless.

Example input makefile:

SRC = \
    src/main.c \
    build/main_ui.c

# OBJ = ${SRC:.c=.o}

BINNAME = bootroot

LIBS = \
    -lefivar

LIBS += `pkg-config --libs gtk4` -ladwaita-1

CFLAGS += `pkg-config --cflags gtk4`

all:
    mkdir -p build
    glib-compile-resources --sourcedir src/ui --generate-source --target build/main_ui.c src/ui/app_resources_ui.gresource.xml
    ${CC} ${CFLAGS} -g -o ${BINNAME} ${SRC} ${LIBS}

Output compile database:

[
    {
        "command": "cc `pkg-config --cflags gtk4` -g -o bootroot src/main.c build/main_ui.c -lefivar `pkg-config --libs gtk4` -ladwaita-1",
        "directory": "/media/Stuff/git/bootroot",
        "file": "/media/Stuff/git/bootroot/src/main.c"
    },
    {
        "command": "cc `pkg-config --cflags gtk4` -g -o bootroot src/main.c build/main_ui.c -lefivar `pkg-config --libs gtk4` -ladwaita-1",
        "directory": "/media/Stuff/git/bootroot",
        "file": "/media/Stuff/git/bootroot/build/main_ui.c"
    }
]
Yingzi1234 commented 1 week ago

@Lassebq We can't reproduce your question Based on the information you provided, can you answer the following question? It would be very helpful for us to investigate this question. Thank you very much!

  1. Could you provide how you generated compile_commands.json? Was it through bear or some other tool? What are the commands used?
  2. Could you provide the actual output of your pkg-config --cflags gtk4 and pkg-config --libs gtk4? This will help us understand the specific compiler flags and library paths!
  3. Which operating system (e.g. Ubuntu, macOS, etc.) and version are you using? This helps to know if it's related to a specific environment or toolchain
  4. Could you please provide your reproduction project?
gcampbell-msft commented 1 week ago

@Lassebq Is this essentially a feature request for us to recognize the command within your Makefile, execute it, and then replace the content when we drop it in your compile_commands.json?

Is the current functionality not working for you? (i.e. Intellisense isn't working)

Lassebq commented 1 week ago

@Yingzi1234

  1. It's generated by the extension with "makefile.compileCommandsPath" json key set to "compile_commands.json"
  2. $ pkg-config --cflags --libs gtk4
    -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/graphene-1.0 -I/usr/lib/graphene-1.0/include -mfpmath=sse -msse -msse2 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/sysprof-6 -pthread -I/usr/include/libpng16 -I/usr/include/pixman-1 -lgtk-4 -lharfbuzz -lpangocairo-1.0 -lpango-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lvulkan -lgraphene-1.0 -lgio-2.0 -lglib-2.0 -lgobject-2.0
  3. Alpine Linux, Arch Linux
  4. I've provided an example makefile in the issue. Content of source files doesn't matter.
Lassebq commented 1 week ago

@gcampbell-msft This is not a feature request. The extension already makes compile_commands.json if you specify it's path via "makefile.compileCommandsPath". However, it's not valid. It doesn't follow the specification linked above and therefore clangd does not work properly. Shell expansion must be evaluated before being stored to the json. Intellisense does not work.