Skip to content

Load cfg files relative to executable before considering FILESDIR. #4424

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

Closed
wants to merge 1 commit into from

Conversation

firewave
Copy link
Collaborator

@firewave firewave commented Aug 31, 2022

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 firewave marked this pull request as draft September 5, 2022 08:07
@firewave
Copy link
Collaborator Author

firewave commented Sep 5, 2022

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

@danmar
Copy link
Owner

danmar commented Sep 9, 2022

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/..

@ledocc
Copy link

ledocc commented Jun 15, 2023

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 ?

@danmar
Copy link
Owner

danmar commented Jun 16, 2023

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..

@firewave
Copy link
Collaborator Author

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.

@danmar
Copy link
Owner

danmar commented Aug 7, 2023

Relative paths are bad idea.

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

@firewave
Copy link
Collaborator Author

firewave commented Dec 2, 2023

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".

nlebedenco added a commit to nutmeg-project/cppcheck that referenced this pull request Mar 31, 2024
…a relative path.

A second macro BINDIR can be used in combination to indicate an optional binary folder
where the program is installed (e.g. the bin part from /usr/bin).

When FILESDIR is a relative path, the computed files dir will be the concatenation of
the executable parent path [- BINDIR>] + <FILESDIR>. If FILESDIR is an absolute path,
it is used unmodified.

This is a possible solution to danmar#4424.
@firewave
Copy link
Collaborator Author

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.

@danmar
Copy link
Owner

danmar commented May 23, 2024

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

good 👍

@firewave
Copy link
Collaborator Author

Closing as there is a much better understanding and test coverage of what it is going on - as well as various fixes. Any future discussion should be done in #7613.

@firewave firewave closed this Jun 29, 2025
@firewave firewave deleted the filesdir branch June 29, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants