Skip to content

Option to resolve build diagnostics relative to workspace folder #1401

Description

@i-ky

Brief Issue Summary

It is a known problem that achieving reproducible builds with CMake requires hacks and workarounds, especially if compiler in use does not support -ffile-prefix-map. In our project we apply some trickery to ensure that compiler is always invoked from the source root with a relative path to source file. As a result of that, compiler prints all errors and warnings with paths relative to the source root instead of absolute paths or paths relative to build directory:

[build] some/path/relative/to/source/root/foo.cpp:12:2: error: #error test
[build]  #error test
[build]   ^

This confuses CMake Tools, if extension detects that path is relative, it appends it to build directory. In Problems tab we see something like:

foo.cpp build/directory/some/path/relative/to/source/root
#error test GCC [12, 2]

Some relevant code:

const file_diags = consumer.compileConsumer.resolveDiagnostics(drv.binaryDir);

resolveDiagnostics(basePath: string): FileDiagnostic[] {

const filepath = util.resolvePath(raw_diag.file, basePath);

const relFilePath = vscode.Uri.file(util.resolvePath(rel.file, basePath));

export function resolvePath(inpath: string, base: string) {
const abspath = path.isAbsolute(inpath) ? inpath : path.join(base, inpath);
// Even absolute paths need to be normalized since they could contain rogue .. and .
return lightNormalizePath(abspath);
}

Expected:

We need some sort of configuration option to be able to resolve compiler diagnostics relative to the source root.

Apparent Behavior:

Currently, diagnostics are reported with wrong file path and cannot be opened by clicking on them.

Unable to open 'foo.cpp': Unable to read file '/workspace/folder/build/directory/some/path/relative/to/source/root/foo.cpp' (Error: Unable to resolve non-existing file '/workspace/folder/build/directory/some/path/relative/to/source/root/foo.cpp').

Platform and Versions

  • Operating System: Ubuntu 16.04
  • CMake Version: 3.15.5
  • VSCode Version: 1.47.3
  • CMake Tools Extension Version: 0.29.0
  • Compiler/Toolchain: GCC 4.9.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature: buildenhancementan enhancement to the product that is either not present or an improvement to an existing featurehelp wantedwe currently are not planning work on this and would like help from the open source communitystale-exemptto use with close-stale-issues and close-old-issues bot

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions