waf: define git versions in a generated ap_version.h header

This commit is contained in:
Lucas De Marchi 2016-05-05 19:16:23 -03:00
parent baa287e5e5
commit 9e3ec3a16d
5 changed files with 53 additions and 16 deletions

View File

@ -5,7 +5,7 @@ from __future__ import print_function
from waflib import Logs, Options, Utils
from waflib.Build import BuildContext
from waflib.Configure import conf
import os.path
import os.path, os
SOURCE_EXTS = [
'*.S',
@ -204,6 +204,20 @@ def ap_find_tests(bld, use=[]):
cxxflags=['-Wno-undef'],
)
_versions = []
@conf
def ap_version_append_str(ctx, k, v):
ctx.env['AP_VERSION_ITEMS'] += [(k, '"{}"'.format(os.environ.get(k, v)))]
@conf
def write_version_header(ctx, tgt):
with open(tgt, 'w') as f:
print('#pragma once\n', file=f)
for k, v in ctx.env['AP_VERSION_ITEMS']:
print('#define {} {}'.format(k, v), file=f)
@conf
def ap_find_benchmarks(bld, use=[]):
if not bld.env.HAS_GBENCHMARK:

View File

@ -139,7 +139,7 @@ class Board:
]
def build(self, bld):
pass
bld.ap_version_append_str('GIT_VERSION', bld.git_head_hash(short=True))
Board = BoardMeta('Board', Board.__bases__, dict(Board.__dict__))
@ -375,6 +375,8 @@ class px4(Board):
def build(self, bld):
super(px4, self).build(bld)
bld.ap_version_append_str('NUTTX_GIT_VERSION', bld.git_submodule_head_hash('PX4NuttX', short=True))
bld.ap_version_append_str('PX4_GIT_VERSION', bld.git_submodule_head_hash('PX4Firmware', short=True))
bld.load('px4')
class px4_v1(px4):

View File

@ -104,9 +104,20 @@ def git_submodule(bld, git_submodule, **kw):
return bld(**kw)
@conf
def git_submodule_head_hash(self, name):
module_node = self.srcnode.make_node(os.path.join('modules', name))
cmd = self.env.get_flat('GIT'), 'rev-parse', 'HEAD'
out = self.cmd_and_log(cmd, quiet=Context.BOTH, cwd=module_node.abspath())
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()
@conf
def git_submodule_head_hash(self, name, short=False):
module_node = self.srcnode.make_node(os.path.join('modules', name))
return _git_head_hash(self, module_node.abspath(), short=short)
@conf
def git_head_hash(self, short=False):
return _git_head_hash(self, self.srcnode.abspath(), short=short)

View File

@ -17,11 +17,6 @@ def _load_dynamic_env_data(bld):
for name in ('cxx_flags', 'include_dirs', 'definitions'):
_dynamic_env_data[name] = bldnode.find_node(name).read().split(';')
_dynamic_env_data['DEFINES'] = [
'NUTTX_GIT_VERSION="%s"' % os.environ.get('NUTTX_GIT_VERSION', bld.git_submodule_head_hash('PX4NuttX')[:8]),
'PX4_GIT_VERSION="%s"' % os.environ.get('PX4_GIT_VERSION', bld.git_submodule_head_hash('PX4Firmware')[:8]),
]
@feature('px4_ap_stlib', 'px4_ap_program')
@before_method('process_source')
def px4_dynamic_env(self):
@ -36,7 +31,6 @@ def px4_dynamic_env(self):
self.env.append_value('INCLUDES', _dynamic_env_data['include_dirs'])
self.env.prepend_value('CXXFLAGS', _dynamic_env_data['cxx_flags'])
self.env.prepend_value('CXXFLAGS', _dynamic_env_data['definitions'])
self.env.append_value('DEFINES', _dynamic_env_data['DEFINES'])
# Single static library
# NOTE: This only works only for local static libraries dependencies - fake

22
wscript
View File

@ -19,12 +19,10 @@ from waflib import Build, ConfigSet, Context, Utils
# pastable. Add the 'export waf="$PWD/waf"' trick to be copy-pastable
# as well.
# TODO: replace defines with the use of a generated config.h file
# TODO: replace defines with the use of the generated ap_config.h file
# this makes recompilation at least when defines change. which might
# be sufficient.
# TODO: set git version as part of build preparation.
def init(ctx):
env = ConfigSet.ConfigSet()
try:
@ -160,6 +158,10 @@ def _build_dynamic_sources(bld):
],
)
bld.env.prepend_value('INCLUDES', [
bld.bldnode.abspath(),
])
def _build_common_taskgens(bld):
# NOTE: Static library with vehicle set to UNKNOWN, shared by all
# the tools and examples. This is the first step until the
@ -221,6 +223,11 @@ def _build_recursion(bld):
for d in dirs_to_recurse:
bld.recurse(d)
def _write_version_header(tsk):
bld = tsk.generator.bld
return bld.write_version_header(tsk.outputs[0].abspath())
def build(bld):
config_header = Utils.h_file(bld.bldnode.make_node('ap_config.h').abspath())
@ -247,6 +254,15 @@ def build(bld):
_build_recursion(bld)
bld(
name='ap_version',
target='ap_version.h',
vars=['AP_VERSION_ITEMS'],
rule=_write_version_header,
group='dynamic_sources',
)
ardupilotwaf.build_command('check',
program_group_list='all',
doc='builds all programs and run tests',