0

I have my nice recipe that fetch from a git repository the master. I have configured my sources and cmake as in this guide: http://brianmilco.blogspot.it/2012/11/cmake-automatically-use-git-tags-as.html

and the objective is to have printed the git hash of the current build.

If i compile it on my pc everything works fine but when I cross compile I have GIT-NOTFOUND in the variable.

Do you know of a workaround / a bitbake way for doing it?

UPDATE: where I do the compile on my computer git status says "nothing to commit" on the bitbake checkout directory if I do the same command it says:

git status
HEAD detached at f47fc96
nothing to commit, working directory clean

I think that the problem could be the fact that it is in detached mode?

andyinno
  • 1,021
  • 2
  • 9
  • 24
  • Git is not found. I don't know how this is relatd to cross compilation, as it should be unrelated. This is a pure CMake/Git question, all the other tags are not relevant. – usr1234567 Dec 11 '15 at 10:35
  • 2
    It looks like your toolchain file, which is used in cross-compilation, prevents `find_package(Git)` to search git executable via `find_program`. E.g., it sets variable [CMAKE_FIND_ROOT_PATH_MODE_PROGRAM](https://cmake.org/cmake/help/v3.0/variable/CMAKE_FIND_ROOT_PATH_MODE_PROGRAM.html) to ONLY. – Tsyvarev Dec 11 '15 at 13:44
  • "git-describe --tags" should work even when detached... – Jussi Kukkonen Dec 11 '15 at 14:39

2 Answers2

0

cmake.bbclass does out-of-tree builds by default, so there's a fairly good chance that your git invocation is running in WORKDIR/build and not the git clone. You can verify this by printing the current working directory before running git, and if that is the problem then you'll have to cd to the source tree before running git.

Note that this isn't a cross-compilation-specific issue, out-of-tree builds are recommended for reliability in general.

Ross Burton
  • 3,516
  • 13
  • 12
  • I always do out of tree builds, no I don't think that the problem is there, I think it's more dependent on the fact that if I cd into the bitbaked source dir and I do a git status I find: git status HEAD detached at f47fc96 nothing to commit, working directory clean So... it is in detached mode while if I try directly it states that I have everything committed. – andyinno Dec 11 '15 at 12:42
0

I made some tests and after reading all the messages I went out with a VBH that at least works. I am putting it here if someone will find the same situation in the future.

I don't know exactly where the problem came from but... when bitbake is executing the recipe it cannot find the git executable (Probably because it does not use the one installed on the pc but because the path is altered. The workaround is to add:

if (NOT GIT_FOUND)
    set(GIT_EXECUTABLE "/usr/bin/git")
    set(GIT_FOUND true)
endif() 

after

if(NOT GIT_FOUND)
    find_package(Git QUIET)
endif()

the problem is that in this way the path is hardcoded so it is not portable. For now... I think that this is a nice place where to find a git executable but it could not work on many systems. So it is not portable and error prone.

andyinno
  • 1,021
  • 2
  • 9
  • 24