Skip to content

Comments

Support different format stratagies for compiler executable path#671

Open
MabaKalox wants to merge 2 commits intorizsotto:masterfrom
MabaKalox:feature/executable_path_format_rebase
Open

Support different format stratagies for compiler executable path#671
MabaKalox wants to merge 2 commits intorizsotto:masterfrom
MabaKalox:feature/executable_path_format_rebase

Conversation

@MabaKalox
Copy link

I have cross compiled project, with custom toolchain which is not on PATH and Bear is hard-coded to set executable path to executable name.
That becomes problem, because clangd fails to resolve toolchain headers from such compiles_commands.json.
Example: bear -- /opt/custom_toolchain/bin/arm-linux-gnueabihf-gcc -o main main.c
Produces:

[
  {
    "file": "main.c",
    "arguments": [
      "arm-linux-gnueabihf-gcc",
      "-o",
      "main",
      "main.c"
    ],
    "directory": "/tmp/smth",
    "output": "main"
  }
]

This pull request adds setting executale: PathResolver, which behaves in same manner as file: PathResolver. e.g:

schema: "4.0"
format:
  paths:
    executable: absolute
    file: absolute
    directory: absolute

Would generate:

[
  {
    "file": "/tmp/smth/main.c",
    "arguments": [
      "/opt/custom_toolchain/bin/arm-linux-gnueabihf-gcc",
      "-o",
      "main",
      "/tmp/smth/main.c"
    ],
    "directory": "/tmp/smth",
    "output": "/tmp/smth/main"
  }
]

Please Note:

  • That changes original behavior. Is that a problem?:
    1. original - file name, e.g. gcc
    2. new - default is what was intercepted AS-IS by bear/src/interpreters
  • this is draft. Need to modify exciting tests and add new one.

@rizsotto
Copy link
Owner

Interesting problem!

My first reaction is... I am not 100% sure if the reported executable always comes with full path. I can imagine when preload is used, some of the exec methods are not providing the full path.

The other thing which come to my mind... if the same configuration values would make sense for the executable? Should it be absolute or filename-only? And does it make sense to validate against the working directory value?

I am traveling at the moment, can't write code, but can read comments. :)

@MabaKalox
Copy link
Author

MabaKalox commented Feb 17, 2026

Hi! I agree that default format options seems pointless. Also I have done some testing, and executable path captured by libexec.so is different, e.g.:
With PATH set:

% env PATH=$PATH:/opt/custom/bin bear -- arm-linux-gnueabihf-gcc -o main main.c

/tmp/smth
% cat compile_commands.json
[
  {
    "file": "main.c",
    "arguments": [
      "arm-linux-gnueabihf-gcc",
      "-o",
      "main",
      "main.c"
    ],
    "directory": "/tmp/smth",
    "output": "main"
  }
]

Without PATH set:

bear -- /opt/custom/bin/arm-linux-gnueabihf-gcc -o main main.c

/tmp/smth
% cat compile_commands.json
[
  {
    "file": "main.c",
    "arguments": [
      "/opt/custom/bin/arm-linux-gnueabihf-gcc",
      "-o",
      "main",
      "main.c"
    ],
    "directory": "/tmp/smth",
    "output": "main"
  }
]

Maybe options could be: AsIs and FileName only, so without Absolute option? I am not sure if there is reliable method to get executable absolute path in libexec.so, since it would require different behavior of resolving absolute path of executable for different types of exec* calls.

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.

2 participants