Skip to content

Support compiler querying (fo scripts) that depend on a particular current working directory #10842

Open
@tcm0116

Description

@tcm0116

Environment

  • OS and Version: Ubuntu 18.04
  • VS Code Version: 1.77.3
  • C/C++ Extension Version: v1.14.5
  • If using SSH remote, specify OS of remote machine: N/A

Bug Summary and Steps to Reproduce

Bug Summary:

Our project utilizes Bazel and uses a tool to generate a compile_commands.json file that is intended to be used by the C/C++ IntelliSense engine. In our case, the compiler provided in the compile_commands.json is actually a script that sets some environment variables and eventually executes the actual compiler. However, we're running into an issue when IntelliSense is generating the database where the following error is generated:

Querying compiler for default C++ language standard using command line: /home/thomas/workspace/external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/wrappers/x86_64-linux-gnu-gcc-9 -x c++ -E -dM /dev/null
Querying compiler for default C++ language standard using command line: /home/thomas/workspace/external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/wrappers/x86_64-linux-gnu-gcc-9 -x c++ -E -dM /dev/null
Detected language standard version: c++98
Querying compiler's default target using command line: "/home/thomas/workspace/external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/wrappers/x86_64-linux-gnu-gcc-9" -dumpmachine
Failed to query compiler. Falling back to 32-bit intelliSenseMode.
Failed to query compiler. Falling back to no bitness.
/home/thomas/workspace/external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/wrappers/x86_64-linux-gnu-gcc-9: line 9: /home/thomas/.cache/bazel/_bazel_thomas/6492692a2eb6be5f61b303fedafae60b/external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/wrappers/external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/toolchain/usr/bin/x86_64-linux-gnu-gcc-9: No such file or directory

As stated above, the /home/thomas/workspace/external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/wrappers/x86_64-linux-gnu-gcc-9 file is actually a script which contains the following line to execute the physical compiler:

exec "external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/toolchain/usr/bin/${NAME}" "$@"

As this is used in a Bazel workspace, an assumption has been made that this script will always be run from the root of the workspace, which is true for typical building activities. However, as can be seen by the path provided for the No such file or directory error, it appears that the C/C++ extension is attempting to query the compiler while the pwd is set to the folder containing the compiler, resulting in the script attempting to execute the compiler at a path relative to its location rather than relative to the root of the workspace.

A simplified version of the compile_commands.json file being used show below and it can be seen that the directory field for each entry is set at the root of the workspace. As such a possible solution for this issue would be to ensure that the pwd is set to the directory when querying the compiler.

[
  {
    "file": "<path_to_cpp_file>",
    "arguments": [
      "external/cc_toolchain_linux-linux-gcc9-x86_64-linux_ubuntu_focal-x86_64/wrappers/x86_64-linux-gnu-gcc-9",
      <additional_compiler_arguments>
    ],
    "directory": "/home/thomas/workspace"
  }
}

Configuration and Logs

A c_cpp_properties.json file is not used, but the following setting is used in the workspace's settings.json to specify the location of the compile_commands.json. No other settings are configured for the C/C++ extension.

"C_Cpp.default.compileCommands": "${workspaceFolder}/compile_commands.json",

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions