rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.64k stars 306 forks source link

Calling `bear -- emmake make` from makefile has different output than without the makefile #560

Closed lesleyrs closed 3 months ago

lesleyrs commented 5 months ago

Describe the bug I'm using emscripten to build. While using bear -- emmake make -B works correctly, trying to call it from a makefile target doesn't work the same way. Using bear directly only shows clang with args, from a makefile it shows emcc + clang. Which stops the lsp from working correctly, until you remove the emcc args.

To Reproduce make a target in a makefile that calls bear:

db:
    bear -- emmake make -B

Expected behavior I expected the compile_commands.json to be the same regardless of where u call it from.

Environment:

Before you send...

It's not that important so feel free to close, just wanted to point this out.

rizsotto commented 5 months ago

Hey @lesleyrs , thanks for the report.

In order to help, could you give more context? I am not familiar with the emmake and emcc tools. Could you send a link to a getting started page? Or just highlight how they works? And what you want to achieve? Maybe give an example of a Makefile and what output you would like to see?

lesleyrs commented 5 months ago

Sure, I did some more digging and actually found a hack that works! But I still don't fully understand the problem. I have a conditional in my makefile that checks which compiler is being used and ignores the path besides the name because emmake (which is a make wrapper that sets up the variables) sets the full path to emcc. If I set CC=emcc instead of using bear with the "full path/emcc" it works!

I made a simplified example of my makefile that has the same behavior: https://github.com/lesleyrs/emscripten-issue

Compiling with bear -- emmake make emmake make db CC=emcc make db CC=emcc all work, but emmake make db doesn't which was my intention. You can tell it doesn't work because it has 2 argument arrays, one for emcc and one for clang. The emcc one stops clangd lsp from activating for emscripten related stuff, in a succesful db it only shows clang.

You can uncomment the line in makefile to make emmake make db work as intended, but of course that stops it from using the full path. I don't know why changing the path directly to emcc makes it work though...

emscripten + raylib resources here for building to wasm: https://emscripten.org/docs/getting_started/downloads.html https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5)

lesleyrs commented 3 months ago

Closing this as it's not really an issue anymore with the workaround.