• AVR Freaks

Hot!Windows/Linux path separator for makeCustomizationPreStep

Author
Nathan Knotts
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2015/01/21 15:06:27
  • Location: 0
  • Status: offline
2015/01/21 15:32:23 (permalink)
0

Windows/Linux path separator for makeCustomizationPreStep

I have been developing my MPLAB X project in Linux. My project has a pre-build script to insert version information into a header. 
 
I now have a Windows developer on the team. Ideally, the project will be committed to source control (git) and we can both contribute. 
 
Besides the pre-build script, this process works without any extra work. For the build script, Linux has a shell script and Windows has a batch file. I found a solution that allows me to place the contents of the shell script and the batch file in the same file (). I've tested this and it works great!
 
The problem I'm having is with makeCustomizationPreStep in configuration.xml
 
On Linux, this works great.
<makeCustomizationPreStep>../scripts/generate_version_header.bat</makeCustomizationPreStep>
 
However, this does not work on Windows and I had to change it to
<makeCustomizationPreStep>..\scripts\generate_version_header.bat</makeCustomizationPreStep>
 
From the MPLABX User's Guide - 
If you plan on using MPLAB X IDE on different platforms (Windows, Mac, or Linux
operating systems), be aware of these issues:
• Use the forward slash “/” in relative paths. The backslash “\” works only on
Windows OS platforms. Example: #include headers/myheader.h
 
I am using the forward slash everywhere else. It does not cause any issue in the source code or other places in configuration.xml. However, for makeCustomizationPreStep, the forward slash only works for Linux and the backslash only works for Windows.
 
My question is: is there a platform agnostic path separator I can use in configuration.xml. As an alternative, is there anyway of enabling certain features based on OS detection - that is, have a script definition for Linux and and script definition for Windows.
#1

10 Replies Related Threads

    aschen0866
    Super Member
    • Total Posts : 4505
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/01/21 16:30:41 (permalink)
    +1 (1)
    I don't have an answer for the platform agnostic path separator you are asking. However, if you place the batch file in the project folder (i.e., the .X folder), you wouldn't need any additional path.
    #2
    Nathan Knotts
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2015/01/21 15:06:27
    • Location: 0
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/01/21 18:03:34 (permalink)
    0
    That is definitely a valid solution. The only problem is I have several projects living in a single top level folder where the script lives. This solution would require me to copy my script everywhere it is used. This is not the end of the world and it may very well be what I need to do. Thank you for the suggestion.
    #3
    Nathan Knotts
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2015/01/21 15:06:27
    • Location: 0
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/01/22 04:53:19 (permalink)
    0
    I have tested this solution and it did not work. On Linux, the command requires a "./" prefix while Windows requires a ".\" prefix
    #4
    JoshuaHartwig
    Super Member
    • Total Posts : 357
    • Reward points : 0
    • Joined: 2014/02/10 10:58:13
    • Location: 0
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/01/22 07:31:52 (permalink)
    0
    It should work if you invoke the .bat/shell script directly without any path in front of it.  Revert all your manual changes to the configuration.xml and open up the Project Properties -> Building.  Add the checkmark telling it to execute the prebuild step and put this in the textbox:
     
    Prebuild Step
    generate_version_header.bat

     
    This is the easiest way to invoke pre/post build scripts that I've found.  If you still have troubles invoking the script, you might need deeper support.

    MPLab X red squiggles can lie.  What does the Compiler output say?
    XC8 update missing PLIBs?  Now are a separate download.  Code Configurator recommended for new projects.
    #5
    davekw7x
    Entropy++
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/01/22 08:13:18 (permalink)
    0
    Nathan Knotts
    On Linux, the command requires a "./" prefix while Windows requires a ".\" prefix
     
     
    How about having your Windows wonk install Cygwin so that bash will be available?
     
    Then, assuming that your Linux system has bash (don't they all?), try something like the following:
     
    <makeCustomizationPreStep>
    bash ../scripts/generate_version_header.bat
    </makeCustomizationPreStep>
     
     
     
    Works for me on my Centos 6.6 Linux workstation and also on my creaky (like me) old Windows XP box.
     
    YMMV (Your Mileage May Vary)
     
     
    Regards,
     
    Dave
    post edited by davekw7x - 2015/01/22 08:22:54

    Sometimes I just can't help myself...
    #6
    aschen0866
    Super Member
    • Total Posts : 4505
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/01/22 08:41:50 (permalink)
    0
    Nathan Knotts
    I have tested this solution and it did not work. On Linux, the command requires a "./" prefix while Windows requires a ".\" prefix


    What Joshua said is correct. You shouldn't need either ".\" or "./" in front of your batch file cal. The make process always runs from the project directory (the .X folder) anyway.
    #7
    Jose Diaz
    Administrator
    • Total Posts : 1676
    • Reward points : 0
    • Joined: 2010/06/23 11:10:56
    • Location: 0
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/01/27 11:20:46 (permalink)
    0
    I think we can do better. I'll enter a bug report on this.
    Thanks
    Jose
     
    #8
    Jose Diaz
    Administrator
    • Total Posts : 1676
    • Reward points : 0
    • Joined: 2010/06/23 11:10:56
    • Location: 0
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/03/30 09:49:41 (permalink)
    0
    How about a macro like this for Linux:
    OS_FILE_SEPARATOR=/

    and like this for Windows:
    OS_FILE_SEPARATOR=\\

    The macro will be added to the list and used like this:
     Attachments are not available: Download requirements not met

    Attachment(s)

    Attachments are not available: Download requirements not met
    #9
    Jose Diaz
    Administrator
    • Total Posts : 1676
    • Reward points : 0
    • Joined: 2010/06/23 11:10:56
    • Location: 0
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2015/03/30 10:07:13 (permalink)
    +1 (1)
    The reason the "/" does not work in the case of a pre-post line is that the line is passed to the native shell. And the native shell (cmd,exe) in Windows does not like in that particular case "../scripts/script.bat".
    We do not use a shell (from Cygwin or MSYS) because doing that slows down the build process. Actually, the first versions of MPLAB used a shell and we had to get rid of it because of speed issues.
    What is interesting is that when using "/" in windows calls (like the compiler processing "include "t/t.h") the "/" does work. It is only the cmd,exe that does not work.
    Jose
    #10
    sl149q
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2013/09/24 15:42:30
    • Location: 0
    • Status: offline
    Re: Windows/Linux path separator for makeCustomizationPreStep 2019/11/06 16:00:22 (permalink)
    0
    Here it is four years later and this appears to be unsolved.

    A better solution would be to have two additional configuration.xml properties:
      makeCustomizationPreStepShellmakeCustomizationPreStepBat
    The Shell version would be used on Linux and MacOS. The Bat version on Windows.


    #11
    Jump to:
    © 2019 APG vNext Commercial Version 4.5