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 #1791

Conversation

tisoft
Copy link
Contributor

@tisoft tisoft commented 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 #1790


This change is Reviewable

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

@tisoft My understanding:

Think two cases should be handled:

  1. directory is absolute:
    a) path is absolute ==> use path as it is
    b) path is relative==> combine directory and path
  2. directory is relative:
    a) What is root in this case? directory realtive to JSON Compilation Database?
    ==> Make this somehow absolute.
    b) then same as above

What do you think?

@tisoft
Copy link
Contributor Author

tisoft commented Jan 21, 2020

Currently it is handled this way:

if the include path is absolute, it is used as is. If it is relative it is concatenated to directory. The cwd.resolve handles both cases:

return cwd.resolve(include).normalize().toString();

If directory is absolute, it is used as is, if directory is relative (and so the resulting concatenated path is also relative), it will be concatenated to the baseDir here:

This seems to be the correct way for me.

@guwirth
Copy link
Collaborator

guwirth commented Jan 21, 2020

@tisoft

baseDir is the interesting part:

  • JSON Compilation Databases / "directory": "." ==> would mean location of JSON Compilation Database file?
  • SQ definition of baseDir (https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/)
    • ... If the files to be analyzed are not in the directory where the analysis starts from, use the sonar.projectBaseDir property to move analysis to a different directory.
    • default of sonar.projectBaseDir is "where the analysis starts from" ==> where .property file is

In case .property file and JSON Compilation Database is in the same folder this would match.

@guwirth
Copy link
Collaborator

guwirth commented Jan 22, 2020

@tisoft: the tests are still failing. Our CI is partly running on Linux (Travis) and partly on Windows (AppVeyor). In case you are writing tests handling absolute paths you have to split it and you need special versions for each OS.

You find some samples here: https://github.com/SonarOpenCommunity/sonar-cxx/search?l=Java&q=windows

@guwirth
Copy link
Collaborator

guwirth commented Jan 25, 2020

close this see #1797

@guwirth guwirth closed this Jan 25, 2020
@guwirth guwirth mentioned this pull request Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Correctly Handle relative paths in JSON Compilation Databases
2 participants