How to customize build for Microchip for running a static analysis tool?

How to customize build for Microchip for running a static analysis tool?


    Sep 18, 2018#1

    I have some projects using UEStudio for embedded development, specifically Microchip. I would like to be able to build my project via command line so I can run my static analysis tool with it. 

    Is there a build command equivalent to calling "make" in MPLABX?

    How do I use the UE generated Makefile (*.mak) to build the project? I notice there is a mymake.exe, but there is no -help option at all.


    Grand MasterGrand Master

      Sep 19, 2018#2

      I need some more facts about your environment to be able to help you with more detailed instructions.

      Which version of UEStudio do you use?

      The version information in About window can be selected and copied with Ctrl+C to clipboard.

      Do you use the preinstalled Microchip C Compiler configuration for your projects?

      The configuration can be customized to automatically run the static analysis tool after a successful build or a new make command is added to run the static analysis tool separately when you want it with automatic build before.

      Which GUI interface do you use - ribbon, toolbar/menu mode with contemporary menus or toolbar/menu mode with traditional menus?
      Best regards from an UC/UE/UES for Windows user from Austria


        Sep 20, 2018#3

        I am using  UEStudio '16 (x64) Version
        I am partially using the preinstalled Microchip C Compiler configuration for my project, had to modify the application file to match the actual compiler that I am using which is XC16.
        The static tool that I am using needs to capture the build process. Their recommended command line usage as follows,
        Usage:   cpptesttrace [options] [build command]
        Example: cpptesttrace [options] make all
        I tried doing this inside Application config file in [Build] section Cmd0. However, I can not get the cpptesttrace capture compile process because compilation happens before Cmd0 is even executed.
        I am looking for a build command that I can maybe add in the [Run Commands] of application config together with this cpptesttrace execution.
        I believe I am using ribbon.


        Grand MasterGrand Master

          Sep 23, 2018#4

          Thanks for the information. The task is much clearer now. This is a new use case on which I had to first think about it and make some tests to find out how to accomplish it.

          You are right regarding to usage of a project/user tool. It is not possible to modify the configuration file for this task for a static analysis with the tool because it is necessary that the static analysis tool runs the build process.

          First a batch file is required which can be stored everywhere and can be written independent on UEStudio / Microchip project. The batch file must contain at least following lines:

          Code: Select all

          @echo off
          setlocal EnableExtensions DisableDelayedExpansion
          if "%~1" == "" (
              echo Error: Project file name is required as parameter for %~f0.
              goto EndBatch
          set "PATH=C:\Path to Compiler XC16\bin;%PATH%"
          set "UESMAKEFILE=%~n1.mak"
          set "UESNOCMD=1"
          set "MYMAKESTOPAT=3"
          if exist "%UESMAKEFILE%" goto RunTool
          cd /D "%~dp1"
          if exist "%UESMAKEFILE%" goto RunTool
          echo ERROR: There is no make file "%UESMAKEFILE%" in "%CD%".
          goto EndBatch
          "C:\Path to cpptesttrace\cpptesttrace.exe" [options] "%ProgramFiles%\IDM Computer Solutions\UEStudio\mymake.exe" CLEAN ALL
          Environment variable PATH

          I suppose that you have clicked once in the past on ribbon tab Build in first ribbon group Settings on down arrow Set compiler paths and set in opened dialog window the XC16 compiler path for Microchip C Compiler or modified the application configs file for Microchip C Compiler and added the compiler path to the configuration file which UEStudio uses to create the project make file. For that reason it is necessary to do what UEStudio does before running a build: prepend local environment variable PATH with the compiler path.

          Compiler specific environment variables

          UEStudio sets also the environment variables specified in the configs file in section [Environment]. The standard configs file configs\Microchip C compiler\Application does not contain any lines in this section to define environment variables to set before running the build/compile. For that reason the batch file code above also does not set such environment variables. But if your customized configuration file for Microchip contains lines in section [Environment], the batch file must contain the appropriate lines to set also those environment variables on execution.

          Environment variable UESMAKEFILE

          mymake.exe in program files directory of UEStudio is called (via uespawn.dat which is in real an executable to capture output of make process) with nearly no parameters. The options for mymake.exe are defined via environment variables which UEStudio sets before calling mymake.exe. For that reason the batch file must set also at least those environment variables which are required by mymake.exe to successfully run the build.

          Most important environment variable for mymake.exe is UESMAKEFILE which must have the name of the make file generated by UEStudio before running a build/compilation. The batch file expects as first parameter the project file name. The make file generated by UEStudio has same file name as the *.prj project file, just the file extension is .mak instead of .prj. So the name of the make file can be derived from project file name.

          UEStudio sets the project directory as configured in Project Settings opened with a click on ribbon tab Project in first ribbon group Project on item Project settings as current directory before running the build/compilation and creates also the make file in this directory. The batch file expects that the current directory is the project directory and checks if the make file exists in this directory. In case of this condition is not true, it changes the current directory to directory of project file which works only on not using a UNC path as otherwise command pushd would be required with popd instead of command cd. Then the check for existence of make file is done once again with printing an error message if make file is again not present in current directory.

          Note: UEStudio creates the make file when necessary, i.e. on making a change in project settings, on list of project files changes, on switching between debug and release, etc. The batch file can't generate the make file. It expects that the make file was created before by UEStudio. So in worst case it could be in rare cases necessary to click in UEStudio first on ribbon tab Build in first ribbon group Settings on item Regenerate makefile to create it before running the tool which runs the batch file. Well, this is definitely never necessary on having run before a regular build/rebuild.

          Environment variable UESNOCMD

          This environment variable passes with value 0 or 1 the build option Show build commands when executing as it can be set by clicking on ribbon tab Build in second ribbon group Build on item Options for opening the Advanced Build Options. The default is to hide the build commands which means value 1 is assigned to environment variable UESNOCMD. Please use whatever you like.

          Environment variable MYMAKESTOPAT

          This environment variable defines after how many not successfully compiled modules (*.c or *.cpp files) the build process should be stopped by mymake.exe as it does not make sense most likely to continue the build process. The value assigned to the environment variable is the same as set for build option Stop build after X error module(s) in Advanced Build Options dialog window.

          It makes perhaps most sense for static analysis that value 1 is assigned to this environment variable as a static analysis of an entire project does not make much sense on build/compilation of any module fails.

          There are some more environment variables evaluated by mymake.exe, but I think those are not important for static analysis build.

          Command line options of mymake.exe

          mymake.exe is called by UEStudio with just CLEAN to clean the project like on clicking on ribbon tab Build in second ribbon group Build on item Clean. Just command line option ALL is used on running a Build. And the command line options CLEAN ALL are used together on running a Rebuild. I suggest to always run a rebuild in this case for static analysis.

          This batch file needs to be executed either by a configured user or project tool. The batch file must be called with project file name with full path and so it makes more sense to configure for each Microchip project a project tool for static analysis instead of a user tool because then it is impossible to run the user tool while no Microchip project currently opened in UEStudio. The project tool settings are always the same.

          So I suggest to click on ribbon tab Project in sixth ribbon group Tools on down arrow of item Project tools and click on popup menu on Configure tools.

          On tab Command

          Menu item name: Static analysis (for example)
          Command line: "Path to batch file\BatchFileName.bat" "%r"
          Working directory: %rp
          Toolbar bitmap/icon (file path): (let it empty or browse to a suitable image file)

          On tab Options

          Program type: DOS program
          Save active file: checked
          Save all files first: checked

          On tab Output

          Command output: Output to list box
          Show DOS box: unchecked
          Capture output: checked
          Replace selected text with: No replace

          Then the project tool is ready for execution by (customized) hotkey or chord, by a click on ribbon tab Project in sixth ribbon group Tools on appropriate item in popup menu opened on clicking on down arrow, via item on a customized ribbon tab, or after switching to Toolbar/Menu Mode (only contemporary menus available in UES v16.00) from menu Project - Project tools or a customized toolbar.
          Best regards from an UC/UE/UES for Windows user from Austria


            Sep 24, 2018#5

            Thank you so much! This is exactly the missing part that I have been trying to figure out. It's nice to be able to build it without even opening UEStudio once you have the mak file available.