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

Correctly Handle relative paths in JSON Compilation Databases #1790

Closed
tisoft opened this issue Jan 20, 2020 · 2 comments · Fixed by #1797
Closed

Correctly Handle relative paths in JSON Compilation Databases #1790

tisoft opened this issue Jan 20, 2020 · 2 comments · Fixed by #1797
Assignees
Milestone

Comments

@tisoft
Copy link
Contributor

tisoft commented Jan 20, 2020

Description

According to the specification, all paths specified in a JSON Compilation database must either be absolute, or relative to the location given in directory. Currently they are either absolute or relative to the build base dir.

Steps to reproduce the problem

Example compile-commands.json:

[
  {
    "directory": "/builds/gitlab/company/product-name-gui/libraries/product-name",
    "file": "data/FormFrameInfo.cpp",
    "output": "../build/product-name/obj/FormFrameInfo.o",
    "arguments": [
      "/usr/bin/clang-7.0.1",
      "-xc++",
      "data/FormFrameInfo.cpp",
      "--driver-mode=g++",
      "-c",
      "-pipe",
      "-Wall",
      "-O2",
      "-D",
      "_REENTRANT",
      "-Wall",
      "-W",
      "-fPIC",
      "-I",
      ".",
      "-I",
      "../../global",
      "-I",
      "../../plugins/include",
      "-isystem",
      "/usr/include/qt5",
      "-isystem",
      "/usr/include/qt5/QtUiTools",
      "-isystem",
      "/usr/include/qt5/QtWidgets",
      "-isystem",
      "/usr/include/qt5/QtX11Extras",
      "-isystem",
      "/usr/include/qt5/QtGui",
      "-isystem",
      "/usr/include/qt5/QtNetwork",
      "-isystem",
      "/usr/include/qt5/QtCore",
      "-I",
      "../build/product-name/moc",
      "-isystem",
      "/usr/include/libdrm",
      "-I",
      "../build/product-name/ui",
      "-I",
      "/usr/lib64/qt5/mkspecs/linux-clang",
      "-o",
      "../build/product-name/obj/FormFrameInfo.o",
      "--target=x86_64-unknown-linux-gnu"
    ]
  }
]

Expected behavior

The following includes are resolved:

/builds/gitlab/company/product-name-gui/libraries/product-name
/builds/gitlab/company/product-name-gui/global
/builds/gitlab/company/product-name-gui/plugins/include
/builds/gitlab/company/product-name-gui/libraries/build/product-name/moc
/builds/gitlab/company/product-name-gui/libraries/build/product-name/ui

Actual behavior

The following includes are resolved:

/builds/gitlab/company/product-name-gui
/builds/gitlab/global
/builds/gitlab/plugins/include
/builds/gitlab/company/build/product-name/moc
/builds/gitlab/company/build/product-name/ui

Known workarounds

It would probably be possible to preprocess the json, to only include absolte paths, but haven't tried that.

LOG file

10:51:14.452 DEBUG: compilation unit settings for: '/builds/gitlab/company/product-name-gui/libraries/product-name/data/FormFrameInfo.cpp'
10:51:14.452 DEBUG: storing include root: '/builds/gitlab/company/product-name-gui'
10:51:14.452 WARN: the include root '/builds/gitlab/global' doesn't exist
10:51:14.453 WARN: the include root '/builds/gitlab/plugins/include' doesn't exist
10:51:14.453 WARN: the include root '/builds/gitlab/company/build/product-name/moc' doesn't exist
10:51:14.453 WARN: the include root '/builds/gitlab/company/build/product-name/ui' doesn't exist

Related information

  • cxx plugin version: Current master (7a07985)
  • SonarQube version?: 7.9.1
tisoft added a commit to tisoft/sonar-cxx that referenced this issue Jan 20, 2020
According to the specification, all paths specified in a JSON Compilation
database must either be absolute, or relative to the location given
in the directory field.

Fixes SonarOpenCommunity#1790
tisoft added a commit to tisoft/sonar-cxx that referenced this issue Jan 20, 2020
According to the specification, all paths specified in a JSON Compilation
database must either be absolute, or relative to the location given
in the directory field.

Fixes SonarOpenCommunity#1790
@guwirth
Copy link
Collaborator

guwirth commented Jan 21, 2020

Hi @tisoft,

thanks for investigation. Had not the time to look deeper into it. Only some general hints:

The important thing I wanna say is that the files of the JSON Compilation Database can't be outside of "root". Your solution should take this into account.

Will look more detailed into it latest tomorrow.

Regards,

@guwirth
Copy link
Collaborator

guwirth commented Jan 25, 2020

Think two cases should be handled:

  1. directory is absolute:
    a) include is absolute ==> use include as it is
    b) include is relative==> combine directory and include
  2. directory is relative:
    a) directory relativ to sonar.projectBaseDir. Default of sonar.projectBaseDir is "where the analysis starts from" ==> where .property file is
    b) then same as above

@guwirth guwirth changed the title Relative paths in JSON Compilation database are treated relative to projectBaseDir instead of relative to the directory element inside the JSOn file Correctly Handle relative paths in JSON Compilation Databases Jan 25, 2020
@guwirth guwirth self-assigned this Jan 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment