Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-52864

Cppcheck plugin fails to resolve files in details view

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • cppcheck-plugin
    • None

      In the cppcheck details view it is no longer possible to click on a file to show the source code. Switching back to 1.21 fixes the problem (also with the data generated with 1.23) so I assume the lookup code is somehow screwed up.

          [JENKINS-52864] Cppcheck plugin fails to resolve files in details view

          I have some issues with cppcheck plugin when my job run in a slave node. Apparently, cppcheck store the full path off the source file based on the file system in the slave node, but the plugin runs on master node. Also I wish to use pipeline. I find a very simple work around that works with pipeline and slave node:

          1) run the cppcheck

          2) use https://github.com/danmar/cppcheck/tree/master/htmlreport to build html results 

          3) publish html on jenkins with Html Publish Plugin

          Example:

          cppcheck.exe .\ --force --xml-version=2 -q 2> cppcheck-result.xml
          python cppcheck-htmlreport --file=cppcheck-result.xml --title=Embedded --report-dir=.\cppcheckResult --report-dir=.\ --source-encoding="iso8859-1"

          The disadvantage for this approach is :

          • missing the tables, trend and graphical as result from the build
          • use of space in master node, once the target source files with errors will be stored on it.

          reference: https://dunterov.github.io/cppcheck/

           

          Aricio Joi Junior added a comment - I have some issues with cppcheck plugin when my job run in a slave node. Apparently, cppcheck store the full path off the source file based on the file system in the slave node, but the plugin runs on master node. Also I wish to use pipeline. I find a very simple work around that works with pipeline and slave node: 1) run the cppcheck 2) use https://github.com/danmar/cppcheck/tree/master/htmlreport to build html results  3) publish html on jenkins with Html Publish Plugin Example: cppcheck.exe .\ --force --xml-version=2 -q 2> cppcheck-result.xml python cppcheck-htmlreport --file=cppcheck-result.xml --title=Embedded --report-dir=.\cppcheckResult --report-dir=.\ --source-encoding="iso8859-1" The disadvantage for this approach is : missing the tables, trend and graphical as result from the build use of space in master node, once the target source files with errors will be stored on it. reference:  https://dunterov.github.io/cppcheck/  

          Mike Pumford added a comment -

          Seeing the same thing on my setup (again since 1.21). Based on the error output it the plugin seems to be assuming that the workspaces paths are the same on the build slave as on the master. This isn't true in our setup as the build slave does not have access to the master filesystem at all.

           

          However jenkins itself seems to have no problem displaying the workspace through the workspace link.

          Mike Pumford added a comment - Seeing the same thing on my setup (again since 1.21). Based on the error output it the plugin seems to be assuming that the workspaces paths are the same on the build slave as on the master. This isn't true in our setup as the build slave does not have access to the master filesystem at all.   However jenkins itself seems to have no problem displaying the workspace through the workspace link.

          Mike Pumford added a comment - - edited

          While doing some jenkins updates I've now dug into this a little more deeply and I can now see exactly why the files are not being displayed. If I go to one of the summary view panes e.g.( cppcheckResult/source.all) I get an error like:

          Can't read file: /var/jenkins_home/jobs/<job-directory>/jobs/<jobname>/workspace-files/ed57db50.tmp

          However if I go and look at the jenkins_home on the masterI can see that the path should actually be:

          /var/jenkins_home/jobs/<job-directory>/jobs/<jobname>/builds/<build-number>/workspace-files/ed57db50.tmp

          So it just looks like the plugin is generating the wrong filesystem path( its missing the builds/<buildnumber> bit) and it has nothing to do with the difference in FS path between the jenkins master and the build slave as I get the same issue even if I make cppcheck produce workspace root relative paths for its errors using:

          -rp=$WORKSPACE

          In the cppcheck command line arguments.

          Mike Pumford added a comment - - edited While doing some jenkins updates I've now dug into this a little more deeply and I can now see exactly why the files are not being displayed. If I go to one of the summary view panes e.g.( cppcheckResult/source.all) I get an error like: Can't read file: /var/jenkins_home/jobs/<job-directory>/jobs/<jobname>/workspace-files/ed57db50.tmp However if I go and look at the jenkins_home on the masterI can see that the path should actually be: /var/jenkins_home/jobs/<job-directory>/jobs/<jobname>/builds/<build-number>/workspace-files/ed57db50.tmp So it just looks like the plugin is generating the wrong filesystem path( its missing the builds/<buildnumber> bit) and it has nothing to do with the difference in FS path between the jenkins master and the build slave as I get the same issue even if I make cppcheck produce workspace root relative paths for its errors using: -rp=$WORKSPACE In the cppcheck command line arguments.

          Petri Soininen added a comment - - edited

          Thanks mike_pumford, this helped me one step forward, this patch in cppcheck-plugin on top of cppcheck-1.25 helped me to navigate to workspace files when build is done in agent:

          diff --git a/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java b/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java
          index eaf32d4..f199beb 100644
          --- a/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java
          +++ b/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java
          @@ -106,6 +106,7 @@ public class CppcheckWorkspaceFile implements Serializable {
               public String getTempName(final Run<?, ?> owner) {
                   if (fileName != null) {
                       return owner.getParent().getRootDir().getAbsolutePath() + "/"
          +                    + "builds/" + owner.getNumber() + "/"
                               + DIR_WORKSPACE_FILES + "/"
                               + Integer.toHexString(fileName.hashCode()) + ".tmp";
                   }

          i.e. one liner needed:

              + "builds/" + owner.getNumber() + "/"

          Tested only with agent build by now. Update: master build (pipeline) seems to work ok.

          "Show issues highlighted on a single page" is still broken but this might be different issue. Update: before this change there is "Can't read file: /var/lib/.../<hash>.tmp" where the related lines should be. With this patch there is broken HTML code in "<div class="line"...</div>"place of source code detail i.e. source code lines are read from correct place but returned HTML format from CppcheckSourceAll.getRelatedLines() seems broken.

          Petri Soininen added a comment - - edited Thanks mike_pumford , this helped me one step forward, this patch in cppcheck-plugin on top of cppcheck-1.25 helped me to navigate to workspace files when build is done in agent: diff --git a/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java b/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java index eaf32d4..f199beb 100644 --- a/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java +++ b/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java @@ -106,6 +106,7 @@ public class CppcheckWorkspaceFile implements Serializable { public String getTempName( final Run<?, ?> owner) { if (fileName != null ) { return owner.getParent().getRootDir().getAbsolutePath() + "/" + + "builds/" + owner.getNumber() + "/" + DIR_WORKSPACE_FILES + "/" + Integer .toHexString(fileName.hashCode()) + ".tmp" ; } i.e. one liner needed: + "builds/" + owner.getNumber() + "/" Tested only with agent build by now. Update: master build (pipeline) seems to work ok. "Show issues highlighted on a single page" is still broken but this might be different issue. Update: before this change there is "Can't read file: /var/lib/.../<hash>.tmp" where the related lines should be. With this patch there is broken HTML code in "<div class="line"...</div>"place of source code detail i.e. source code lines are read from correct place but returned HTML format from CppcheckSourceAll.getRelatedLines() seems broken.

            marcosteffan Marco Steffan
            chehrlic Christian Ehrlicher
            Votes:
            6 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: