[SOLVED] Automatic versioning with preprocessor macros

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Automatic versioning with preprocessor macros

    Hi,

    we are using Segger Embedded Studio for developing software with Nordic microcontrollers. I would like to automatically add a string, containing the build configuration name (e.g. "Release") and the git hash of our git repository, to the preprocessor definitions.

    As an Example what I mean: In our eclipse projects we use the "shell" command to create preprocessor definitions that hold the git has and branch names. This would look like this:

    VERSION_INFO="${ConfigName}_$(shell git rev-parse --abbrev-ref HEAD)_$(shell git rev-parse --short HEAD)"

    The result is a string with a value like that: "Release_master_1ab3f12"

    Is there an equivalent in Segger Embedded Studio to the Eclipse "shell" command? I could not find anything in the Embedded Studio documentation. Or is there another solution how to get the Git Has as a string that can be used globally in our software?

    Thanks and best regards

    Bjoern
  • Hello Bjoern,

    Thank you for your inquiry.
    To pass e.g. versioning information during your build process we recommend using project macros which then can be defined as a preprocessor define:
    studio.segger.com/ide_project_macros.htm

    A thread discussing something similar can be found here:
    [SOLVED] User defined macros expansion


    To start your builds automatically via command line you can use emBuild:

    studio.segger.com/emBuild_building_with_a_project_file.htm


    Best regards,

    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi Nino,
    thanks for the quick reply. I tried to use the project macro but I don't think I understood correctly how to use the project macros. I did three things:

    1. I added the git command to parse the repo has as a project macro:

    Under: Project->Options->Code->Build->Projec Macros
    I added: GIT_MACRO=git rev-parse --abbrev-ref HEAD

    2. I added a preprocessor define using the macro:

    Under: Project->Options->Code->Preprocessor->Preprocessor Definitions
    I added: GIT_REV=$(GIT_MACRO)

    3. I tried to use the preprocessor definition in my code:
    static uint8_t testString[] = GIT_REV;


    If I do all that, then I get the compiler error: "'git' undeclared here (not in a function)"
    How do I tell Embedded Studio, that it should execute "git" in a command line? I did not find anything in the documentation.

    Best regards

    Bjoern

    The post was edited 5 times, last by bjoernSchmitz ().

  • Hi Bjoern,
    Unfortunately, it is not possible to set macros per shell.
    The only way we can think about how to achieve this would be via pre-build command (or via Combining Project),
    which calls a script to create a header with the variable in it.

    Would that be an option for you?

    Best regards,
    Fabian
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi Fabian,

    thanks for the reply, that's what I wanted to know. I also thought about the solution with a script executed during pre-build process, but was hoping there is an easier solution. We will choose this option then, as you suggested. You can mark this thread as solved.

    Thanks and best regards

    Bjoern
  • Hi Bjoern,
    Good to hear that you are up and running again.

    Best regards,
    Fabian
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.