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

Compile option "--include <path>" generates incorrect database entry #562

Closed
HclX opened this issue Mar 8, 2024 · 2 comments
Closed

Compile option "--include <path>" generates incorrect database entry #562

HclX opened this issue Mar 8, 2024 · 2 comments
Labels

Comments

@HclX
Copy link

HclX commented Mar 8, 2024

Describe the bug
A clear and concise description of what the bug is.
Both clang and gcc support "--include " to include a header file when compiling a C files. It seems the right format should be either "--include=" or "--include" according to man page, but separated by space also works in practice. However, when separated by space, bear doesn't generate correct result database.

To Reproduce
Steps to reproduce the behavior:

Here are the test files:

~/Source/test$ cat foo.c
#ifdef BAR_AVAILABLE
int bar(int x) { return x + 5; }
#endif

int foo(int x) {
    return bar(x) * 5;
}
:~/Source/test$ cat bar.h
#define BAR_AVAILABLE

Running command bear -- clang --includebar.h -c foo.c -o foo.o or bear -- clang --include=bar.h -c foo.c -o foo.o will generate expected database.

[
  {
    "arguments": [
      "/usr/bin/clang",
      "--include=bar.h",
      "-c",
      "-o",
      "foo.o",
      "foo.c"
    ],
    "directory": "/usr/home/test/Source/test",
    "file": "/usr/home/test/Source/test/foo.c",
    "output": "/usr/home/test/Source/test/foo.o"
  }
]

However, bear -- clang --include bar.h -c foo.c -o foo.o will not:

[
  {
    "arguments": [
      "/usr/bin/gcc",
      "--include",
      "-c",
      "-o",
      "foo.o",
      "bar.h"
    ],
    "directory": "/usr/home/test/Source/test",
    "file": "/usr/home/test/Source/test/bar.h",
    "output": "/usr/home/test/Source/test/foo.o"
  },
  {
    "arguments": [
      "/usr/bin/gcc",
      "--include",
      "-c",
      "-o",
      "foo.o",
      "foo.c"
    ],
    "directory": "/usr/home/test/Source/test",
    "file": "/usr/home/test/Source/test/foo.c",
    "output": "/usr/home/test/Source/test/foo.o"
  }
]

All three commands build fine when not using bear.

Expected behavior
I'd expect bear generates same, correct json file when using "--include " just like the other two ways.

Environment:

  • OS name: Linux
  • OS version: Debian
  • OS architecture: x86_64
  • Bear version: 3.1.3
  • Bear install method: apt install

Additional context

I'm using both clang and gcc and the behavior is same. Here are the clang/gcc versions I'm using:

~/Source/test$ clang --version
Debian clang version 16.0.6 (19)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

~/Source/test$ gcc --version
gcc (Debian 13.2.0-10) 13.2.0

@rizsotto rizsotto added the bug label Mar 11, 2024
@rizsotto
Copy link
Owner

Thanks @HclX for this report. Looks like the compiler flag parsing logic needs to be fixed.

@rizsotto
Copy link
Owner

#572 PR is suppose to fix this issue. (Although it is -include and not --include what we handle. But double checked the GCC manual, and it mentions the include with a single dash prefix.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants