Browse Source

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

master
Lucas De Marchi 9 years ago
parent
commit
9e3ec3a16d
  1. 16
      Tools/ardupilotwaf/ardupilotwaf.py
  2. 4
      Tools/ardupilotwaf/boards.py
  3. 19
      Tools/ardupilotwaf/git_submodule.py
  4. 6
      Tools/ardupilotwaf/px4.py
  5. 22
      wscript

16
Tools/ardupilotwaf/ardupilotwaf.py

@ -5,7 +5,7 @@ from __future__ import print_function
from waflib import Logs, Options, Utils from waflib import Logs, Options, Utils
from waflib.Build import BuildContext from waflib.Build import BuildContext
from waflib.Configure import conf from waflib.Configure import conf
import os.path import os.path, os
SOURCE_EXTS = [ SOURCE_EXTS = [
'*.S', '*.S',
@ -204,6 +204,20 @@ def ap_find_tests(bld, use=[]):
cxxflags=['-Wno-undef'], 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 @conf
def ap_find_benchmarks(bld, use=[]): def ap_find_benchmarks(bld, use=[]):
if not bld.env.HAS_GBENCHMARK: if not bld.env.HAS_GBENCHMARK:

4
Tools/ardupilotwaf/boards.py

@ -139,7 +139,7 @@ class Board:
] ]
def build(self, bld): 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__)) Board = BoardMeta('Board', Board.__bases__, dict(Board.__dict__))
@ -375,6 +375,8 @@ class px4(Board):
def build(self, bld): def build(self, bld):
super(px4, self).build(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') bld.load('px4')
class px4_v1(px4): class px4_v1(px4):

19
Tools/ardupilotwaf/git_submodule.py

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

6
Tools/ardupilotwaf/px4.py

@ -17,11 +17,6 @@ def _load_dynamic_env_data(bld):
for name in ('cxx_flags', 'include_dirs', 'definitions'): for name in ('cxx_flags', 'include_dirs', 'definitions'):
_dynamic_env_data[name] = bldnode.find_node(name).read().split(';') _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') @feature('px4_ap_stlib', 'px4_ap_program')
@before_method('process_source') @before_method('process_source')
def px4_dynamic_env(self): 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.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['cxx_flags'])
self.env.prepend_value('CXXFLAGS', _dynamic_env_data['definitions']) self.env.prepend_value('CXXFLAGS', _dynamic_env_data['definitions'])
self.env.append_value('DEFINES', _dynamic_env_data['DEFINES'])
# Single static library # Single static library
# NOTE: This only works only for local static libraries dependencies - fake # NOTE: This only works only for local static libraries dependencies - fake

22
wscript

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

Loading…
Cancel
Save