Git Required For Build?

Hi. I am new to ArduPilot. I am trying to build ArduCopter from source, and I would like to be able to perform the build on a “stand-alone” setup, from source, without having the local git clone present.

I am able to get the source and peform a build no problem, when the git repository is locally present, using the following:

git clone https://github.com/ArduPilot/ardupilot ardupilot
cd ardupilot
git checkout ArduCopter-stable
git submodule update --init -recursive
./waf configure --board=navio2 --no-submodule-update
./waf copter

However, if I remove the top-level .git files and folders and try the build again (./waf copter), I get the output

Waf: Entering directory `/home/user/ardupilot/build/navio2'
Command ['/usr/bin/git', 'rev-parse', '--short=8', 'HEAD'] returned 128

I specified the --no-submodule-update configuration option to prevent checking for submodule updates, but it seems like the build process still needs a local git repository in order to build … ? Is there any way around this?

My motivation for this is that we use subversion, and I am trying to get the source into our local subversion repository. It seems cleaner for me to be able to just place the source into the repository, as opposed to needing to place the entire git clone into the repository. (I realize that my interface with the rest of the world for updates still needs to be git.)

Thanks
Joel

I put out a call to the dev team about this. If anyone has tried it, they didn’t admit to it…
There were two key issues identified: versioning, and automated submodule update.
You’ve identified and managed the second via the compile flag. The first you’d need to look into.
If we could convince you to use Git, we could be much more help!

I should point out that it looks like someone at one time considered some of this, because when I configure after removing the .git files, the output is

:
Checking for program 'python'                         : /usr/bin/python 
Checking for python version >= 2.7.0                  : 2.7.15 
Source is git repository                              : no 
Update submodules                                     : no 
Checking for program 'git'                            : /usr/bin/git 
:

So the build process has identified that the source is not a git repository, yet it still expects a git repository.

I guess what I was hoping to maybe hear in response to this was either “Git is so ingrained in our build process that you should not consider trying to look into this” or “It would not be that large of an effort to address this, and you may want to consider addressing it (and contributing the solution back).”

Thanks,
Joel

Did you make any progress in this topic? I have exactly the same problem as I cannot use git for managing my firmware.
Tanks. Sebastian

Hello,

No, and I don’t think that we will change anytime soon, as we use some git tools on build or debugging.
I think it exist some git-svn tools that will permit to use SVN, but I have never use them

We were able to get around the git dependencies as follows.

First, specify the --no-submodule-update configuration option.

Second, in Tools/ardupilotwaf/boards.py, in the build() method, modify the line

bld.ap_version_append_str('GIT_VERSION', bld.git_head_hash(short=True))

and replace the call go bld.git_head_hash(). You want to replace this call with whatever version information you want. GIT_VERSION is a #define in version.h, so the original statement is getting the git version and setting GIT_VERSION to that version. In our case we replaced GIT_VERSION with a different symbol, and we populate it via a new command line option that we added.

Now our build process does not automatically try to query git.

2 Likes

Could you please explicitly write, how this line should be modified ?
(i get this error although git exists in my cygwin installation)

You can simply replace this line with a hardcoded string, e.g.:
bld.ap_version_append_str(‘GIT_VERSION’, “1c6af7d7”)
Although using the option --no-submodule-update I had to do the same for the submodules (for example L.474 for ChibiOS).
For the version to enter I use a git-reference. You can find the version in .git\logs\HEAD or by using “git rev-parse --verify HEAD”. In the file its the second block (but I only use the first 8 digits, maybe someone used to git can help you what to actually use).

It looks like you will now also need to modify the code elsewhere, though I haven’t tracked down where yet.

necroing an old thread, in the event someone else arrives here from google search results…

This is what worked for me, there’s probably a more elegant/correct solution.

There could be innumerable locations in the source code in the future which make make use of the git_head_hash function call or one of its variants. Any easy way to get them all at once (at least as of right now) is to edit Tools/ardupilotwaf/git_submodule.py

Currently the _git_head_hash function looks like this:

def _git_head_hash(ctx, path, short=False):
    cmd = [ctx.env.get_flat('GIT'), 'rev-parse']
    if short:
        cmd.append('--short=8')
    cmd.append('HEAD')
    out = ctx.cmd_and_log(cmd, quiet=Context.BOTH, cwd=path)
    return out.strip()

I modified it to just immediately return a fake hash string:

def _git_head_hash(ctx, path, short=False):
    return "deadc0de"

You can edit this function as you see fit, that should handle all the Command ['/usr/bin/git', 'rev-parse', '--short=8', 'HEAD'] returned 128 errors reported during the build process.

2 Likes

Thanks, @jcorcoran This works well for me.

Using debug messages here I found that the problem is in executing _git_head_hash in ChibiOS submodule, so for me problem resolved with
git config --global --add safe.directory /cygdrive/d/copter/ardupilot.git/modules/ChibiOS