cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

Load `cfg` files relative to executable before considering `FILESDIR`.

Open firewave opened this issue 3 years ago • 9 comments

This is a very old change and after reviewing the code for the loading of non-cfg files it turns out that the existing behavior is actually a bug. All the other code was already preferring the application dir to the FILESDIR.

Original commit message:

Load cfg files relative to executable before considering
  FILESDIR, such that the testrunner uses the local files instead of those
  from an installed cppcheck.

firewave avatar Aug 31 '22 08:08 firewave

This needs some unit tests to make sure this actually works as expected for all cases.

firewave avatar Sep 05 '22 08:09 firewave

In a installed Cppcheck .. it sounds best to look in the FILESDIR first. I am not sure if it should even look in the executable path if the FILESDIR is set. i.e. we should look in the /var/.. not in /usr/bin/..

danmar avatar Sep 09 '22 19:09 danmar

Old topic but not yet fixed.

Curious to add an absolute path in the code, event if it is configurable on build time. But it’s done, so hard to remove it without break anything

But here what we can add to current behaviour :

  • allow package builder to set FILESDIR on a relative path to cppcheck executable, this make cppcheck package relocatable
  • allow final user to define a CPPCHECK_FILESDIR environment variable to replace FILESDIR define at build time

Thought ?

ledocc avatar Jun 15 '23 19:06 ledocc

But here what we can add to current behaviour :

I feel I can accept both your suggestions.. if you feel that there is a real use case..

danmar avatar Jun 16 '23 08:06 danmar

We need a single proper implementation of the lookup and tests for that. We also need to document the lookup order. I will also try to get feedback on some known maintainers on how they use it and how they expect it to work.

  • allow package builder to set FILESDIR on a relative path to cppcheck executable, this make cppcheck package relocatable

Relative paths are bad idea.

  • allow final user to define a CPPCHECK_FILESDIR environment variable to replace FILESDIR define at build time

That makes sense.

firewave avatar Jul 28 '23 17:07 firewave

Relative paths are bad idea.

well this is how Cppcheck works in Windows. And the cppcheck premium also uses a relative path.

danmar avatar Aug 07 '23 14:08 danmar

I filed https://trac.cppcheck.net/ticket/12240 about this. The user configuration should always override the system one otherwise a local binary is not usable at all.

In a installed Cppcheck .. it sounds best to look in the FILESDIR first. I am not sure if it should even look in the executable path if the FILESDIR is set.

FILESDIR is a rather awkward approach to be honest but I understand the reasoning behind it.

I also agree that looking in the /usr/bin folder sounds suspicious but we should have consistent behavior first and tune it later on.

We should probably also add user folder lookup and a command-line option. So the order would look like this

  • command-line option (development case)
  • binary folder (development case)
  • user folder (user installation case)
  • system folder aka FILESDIR (default installation case)

The command-line option could help with comparing different configurations more easily without copying them around.

Since the binary folder only seems necessary for development we could add a build flag to disable it so installed binaries are "safer".

firewave avatar Dec 02 '23 13:12 firewave

After adding logging for this it shows that this is already working as intended.

looking for library 'none'
looking for library 'none.cfg'
looking for library '/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-17/bin/none.cfg' <-- executable dir
looking for library '/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-17/bin/../cfg/none.cfg'
looking for library '/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-17/bin/cfg/none.cfg'
looking for library '/mnt/s/GitHub/cppcheck-fw/cfg/none.cfg' <-- FILESDIR

The loop which processes the path is doing cfgfolders.pop_back() so it looks backwards so the hard-coded path is used last.

Not closing this yet as the additional concerns still need to be tracked in tickets.

firewave avatar May 22 '24 11:05 firewave

Not closing this yet as the additional concerns still need to be tracked in tickets.

good :+1:

danmar avatar May 23 '24 14:05 danmar