microsoft / microsoft/vscode-cpptools
Support compiler querying (fo scripts) that depend on a particular current working directory
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
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",
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing compiler querying with the workspace setting C_Cpp.default.compileCommands and the supplied compile_commands.json entry. Trace how the extension launches the compiler and uses the entry's directory field. Done means the wrapper script can resolve its workspace-relative compiler path during querying without the fallback errors shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, typescript
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100