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

[analyzer] Add support the CC_ANALYZER_BIN env var #4057

Merged
merged 4 commits into from
Oct 26, 2023

Conversation

Szelethus
Copy link
Contributor

This environmental variable can be used the specify the absolute path of
an analyzer. Similar to #4041, but this is the only solution we can
realistically get though the door.

Here is a glimpse of how the error messages look like:

$ CC_ANALYZER_BIN="gccldjkfg:/usr/bi++-13;clangsa;g++:g" CodeChecker check -b "gcc double-free.c -c" -o resultNative/ --analyzers=gcc -c -e extreme
[INFO 2023-10-24 15:22] - Starting build...
[INFO 2023-10-24 15:22] - Using CodeChecker ld-logger.
[INFO 2023-10-24 15:22] - Build finished successfully.
[ERROR 2023-10-24 15:22] - Unsupported analyzer_name name 'gccldjkfg' given to CC_ANALYZER_BIN!
[ERROR 2023-10-24 15:22] - '/usr/bi++-13' is not a path to an analyzer binary given to CC_ANALYZER_BIN!
[ERROR 2023-10-24 15:22] - Analyzer binary in wrong format: clangsa, should be <analyzer>:</path/to/bin/>
[ERROR 2023-10-24 15:22] - Unsupported analyzer_name name 'g++' given to CC_ANALYZER_BIN!
[ERROR 2023-10-24 15:22] - 'g' is not a path to an analyzer binary given to CC_ANALYZER_BIN!
[INFO 2023-10-24 15:22] - The value of CC_ANALYZER_BIN should be in the format of CC_ANALYZER_BIN='<analyzer1>:/path/to/bin1;<analyzer2>:/path/to/bin2'
$ CodeChecker analyzers -o table
---------------------------------------------------------------------------------------
Name       | Path                                                             | Version
---------------------------------------------------------------------------------------
clangsa    | /home/eumakri/Documents/llvm-project/releaseBuild/bin/clang-17   | 16.0.4 
clang-tidy | /home/eumakri/Documents/llvm-project/releaseBuild/bin/clang-tidy | 16.0.4 
cppcheck   | /usr/bin/cppcheck                                                | 2.7    
gcc        | /usr/lib/ccache/g++                                              | 11.4.0 
---------------------------------------------------------------------------------------
[WARNING 2023-10-24 15:24] - Can't analyze with 'gcc': Incompatible version: GCC binary found is too old at v11.4.0; minimum version is 13.0.0. Maybe try setting an absolute path to a different analyzer binary via the env variable CC_ANALYZER_BIN?

Depends on #4056.

@Szelethus Szelethus added the analyzer 📈 Related to the analyze commands (analysis driver) label Oct 24, 2023
@Szelethus Szelethus added this to the release 6.23.0 milestone Oct 24, 2023
Copy link
Member

@dkrupp dkrupp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me something is still not OK.

export CC_ANLAYZER_BIN=gcc:/usr/bin/gcc-13
 $ CodeChecker analyzers
 clangsa /local/workspace/llvm-project/build/bin/clang-16   18.0.0
 clang-tidy /local/workspace/llvm-project/build/bin/clang-tidy 18.0.0
 cppcheck /usr/bin/cppcheck                                  1.90
 gcc /usr/bin/x86_64-linux-gnu-g++-9                    9.4.0
[WARNING 2023-10-24 20:16] - Can't analyze with 'gcc': Incompatible version: GCC binary found is too old at v9.4.0; minimum version is 13.0.0. Maybe try setting an absolute path to a different analyzer binary via the env variable CC_ANALYZER_BIN?

am I doing something wrong?

Copy link
Member

@dkrupp dkrupp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested:
-checker listing
-analyzer binary specification through env var
-checker disable
-analysis

All seems to work.
The following followup tickets were created:
#4060
#4059
tmux analysis asserts with gcc

otherwise: LGTM

This environmental variable can be used the specify the absolute path of
an analyzer. Similar to Ericsson#4041, but this is the only solution we can
realistically get though the door.
Copy link
Contributor

@vodorok vodorok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following stackrace when no binary is set and I invoke CodeChecker analyzers

Traceback (most recent call last):
  File "/ws/codechecker/build/CodeChecker/lib/python3/codechecker_common/cli.py", line 209, in main
    sys.exit(args.func(args))
  File "/ws/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/cmd/analyzers.py", line 190, in main
    version = analyzer_class.get_binary_version(check_env)
  File "/ws/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzers/cppcheck/analyzer.py", line 88, in get_binary_version
    version = [self.analyzer_binary(), '--version']
  File "/ws/codechecker/build/CodeChecker/lib/python3/codechecker_analyzer/analyzers/cppcheck/analyzer.py", line 82, in analyzer_binary
    return analyzer_context.get_context() \
KeyError: 'cppcheck'

This error does not appear on master.

Cppcheck was not in the path.

AnalyzerContext keeps track of the binaries for each analyzer. However,
if the binary isn't found, we don't map None to the respective analyzer,
we simply skip it. This lead to key errors when we called the version
getter function, which I fixed in this patch.
@Szelethus Szelethus requested a review from vodorok October 26, 2023 14:06
Copy link
Contributor

@vodorok vodorok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I am really nitpicking here, but in the future, maybe we can print binary not found in place of the ERROR word, instead of adding a separate warning.

CodeChecker analyzers
 clangsa /usr/lib/llvm-10/bin/clang      10.0.0
 clang-tidy /usr/lib/llvm-10/bin/clang-tidy 10.0.0
 cppcheck                                 ERROR
 gcc /usr/bin/x86_64-linux-gnu-g++-9 9.4.0
[WARNING 2023-10-26 16:55] - Can't analyze with 'cppcheck': Failed to detect analyzer binary!
[WARNING 2023-10-26 16:55] - Can't analyze with 'gcc': Incompatible version: GCC binary found is too old at v9.4.0; minimum version is 13.0.0. Maybe try setting an absolute path to a different analyzer binary via the env variable CC_ANALYZER_BIN?

@vodorok vodorok merged commit afbb40b into Ericsson:master Oct 26, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer 📈 Related to the analyze commands (analysis driver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants