Skip to content

Commit

Permalink
Tools/ardupilotwaf: add support to retrieve hash length of various sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshanne committed Jan 8, 2025
1 parent fc31442 commit 85e9698
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ def pre_build(self, bld):
self.embed_ROMFS_files(bld)

def build(self, bld):
git_hash_ext = bld.git_head_hash(short=True, hash_abbrev=16)
bld.ap_version_append_str('GIT_VERSION', bld.git_head_hash(short=True))
bld.ap_version_append_str('GIT_VERSION_EXTENDED', git_hash_ext)
bld.ap_version_append_int('GIT_VERSION_INT', int("0x" + bld.git_head_hash(short=True), base=16))
bld.ap_version_append_str('AP_BUILD_ROOT', bld.srcnode.abspath())
import time
Expand Down
12 changes: 6 additions & 6 deletions Tools/ardupilotwaf/git_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ def _post_fun(bld):
def git_submodule_post_fun(bld):
bld.add_post_fun(_post_fun)

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

@conf
def git_submodule_head_hash(self, name, short=False):
def git_submodule_head_hash(self, name, short=False, hash_abbrev=8):
module_node = self.srcnode.make_node(os.path.join('modules', name))
return _git_head_hash(self, module_node.abspath(), short=short)
return _git_head_hash(self, module_node.abspath(), short=short, hash_abbrev=hash_abbrev)

@conf
def git_head_hash(self, short=False):
return _git_head_hash(self, self.srcnode.abspath(), short=short)
def git_head_hash(self, short=False, hash_abbrev=8):
return _git_head_hash(self, self.srcnode.abspath(), short=short, hash_abbrev=hash_abbrev)

0 comments on commit 85e9698

Please sign in to comment.