itom-project / itom

itom core repository
https://itom-project.github.io/
Other
14 stars 5 forks source link

Wrong git version number from ItomBuildMacros for plugins #276

Closed twip-os closed 5 months ago

twip-os commented 7 months ago

When the plugins are configured the cmake macro itom_init_plugin_library writes in the gitVersion.h the git version of the top level git repository (itom-project) and not the git version of the submodul (plugins).

As far as i can trace the error it happens in ItomBuildMacros.cmake in the macro itom_fetch_git_commit_hash in line 464ff The macro looks for the file /.git/index and if it does not find this file in the current direcotry it goes one level up and sets the working directory there. But for a git repository sturcture with submodules the /.git/index obviously only exists in the top level git. And therefor the working directy for the plugins project is set to the folder of the top level git and the git version is retrieved for that.

Why is it necessary to go to the folder with the /.git/index file? When testing from the git bash, the correct git version with the git log command is even retrieved when one is in a subfolder of a specific git.

Can this loop to reset the working directory be removed? Or will that cause some other errors?

magro11 commented 6 months ago

I also think that we can set the WORKING_DIRECTORY of


execute_process(
    COMMAND "${GIT_EXECUTABLE}" log -1 --format=%H HEAD 
    WORKING_DIRECTORY "${WORKINGDIR}"
    RESULT_VARIABLE res
    OUTPUT_VARIABLE GITCOMMITHASH
    ERROR_QUIET
    OUTPUT_STRIP_TRAILING_WHITESPACE)```

to ${CMAKE_SOURCE_DIR}, as it is initialized.

However, we need to find a solution for the part:

```cmake

#always mark this project as outdated if the .git/index file changed.
#see also: https://cmake.org/pipermail/cmake/2018-October/068389.html
set_property(GLOBAL APPEND
    PROPERTY CMAKE_CONFIGURE_DEPENDS
    "${WORKINGDIR}/.git/index")

The background is, that the project must always be outdated in the compile if any git change was executed. The idea was to let the project depend on the .git/index file. In case of distinct itom, plugins, designerplugins... projects, this can be done by watching the .git/index file. In case of the itom-project project with different submodules, there is only the .git/index file in the itom-project. Should be let every project depend on this? I also have seen that a .git file is also placed in every submodule. Should be let the project depend on this?

@BBertschinger : do you have an idea what would be better?

twip-os commented 6 months ago

I found the posibility of using git rev-parse --git-dir. This results in /.git for the top module and in /.git/modules/ for the submodules. So it gives the path where the index file lies correctly for every module.

magro11 commented 6 months ago

Ah cool, then let's try this. I hope that I will find time to fix this during next weekend.

magro11 commented 6 months ago

The pull request #278 should fix this issue. Now the corresponding git-index file is determined based on git rev-parse --git-dir and the commit hash is always obtained based on the CURRENT_SOURCE_DIR variable in CMake, hence, based on the root directory of every single plugin. This should work both for single plugins projects as well as for the itom-project main project with submodules.

However, it can also be, that different plugins within the same repository have different git commit hashes, e.g. if the latest commit only contains changes in one plugin. Then, all other plugins are based on an older commit. From my perspective, this is ok and correct.

magro11 commented 5 months ago

Fixed in pull request #278. Issue will be closed.