diff --git a/libuavcan/CMakeLists.txt b/libuavcan/CMakeLists.txt index 81f1114c53..b27702d701 100644 --- a/libuavcan/CMakeLists.txt +++ b/libuavcan/CMakeLists.txt @@ -34,7 +34,7 @@ endif () execute_process(COMMAND ./setup.py build WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/dsdl_compiler) set(DSDLC_INPUTS "test/dsdl_test/root_ns_a" "test/dsdl_test/root_ns_b" "${CMAKE_SOURCE_DIR}/../dsdl/uavcan") set(DSDLC_OUTPUT "include/dsdlc_generated") -add_custom_target(dsdlc dsdl_compiler/uavcan_dsdlc ${DSDLC_INPUTS} -O${DSDLC_OUTPUT} +add_custom_target(dsdlc dsdl_compiler/libuavcan_dsdlc ${DSDLC_INPUTS} -O${DSDLC_OUTPUT} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) include_directories(${DSDLC_OUTPUT}) diff --git a/libuavcan/dsdl_compiler/uavcan_dsdlc b/libuavcan/dsdl_compiler/libuavcan_dsdlc similarity index 87% rename from libuavcan/dsdl_compiler/uavcan_dsdlc rename to libuavcan/dsdl_compiler/libuavcan_dsdlc index 0aa6ec6216..5b47830260 100755 --- a/libuavcan/dsdl_compiler/uavcan_dsdlc +++ b/libuavcan/dsdl_compiler/libuavcan_dsdlc @@ -1,13 +1,19 @@ #!/usr/bin/env python3 # -# UAVCAN DSDL compiler -# Probably it will be extended in future to add support for different programming languages. +# UAVCAN DSDL compiler for libuavcan # # Copyright (C) 2014 Pavel Kirienko # import os, sys, logging, argparse +RUNNING_FROM_SRC_DIR = os.path.abspath(__file__).endswith(os.path.join('libuavcan', 'dsdl_compiler', 'uavcan_dsdlc')) +if RUNNING_FROM_SRC_DIR: + print('Running from the source directory') + scriptdir = os.path.dirname(os.path.abspath(__file__)) + sys.path.append(os.path.join(scriptdir, '..', '..', 'pyuavcan')) + sys.path.append(os.path.join(scriptdir)) + def configure_logging(verbosity): fmt = '%(message)s' level = { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG }.get(verbosity or 0, logging.DEBUG) @@ -17,13 +23,6 @@ def die(text): print(text, file=sys.stderr) exit(1) -RUNNING_FROM_SRC_DIR = os.path.abspath(__file__).endswith(os.path.join('libuavcan', 'dsdl_compiler', 'uavcan_dsdlc')) -if RUNNING_FROM_SRC_DIR: - print('Running from the source directory') - scriptdir = os.path.dirname(os.path.abspath(__file__)) - sys.path.append(os.path.join(scriptdir, '..', '..', 'pyuavcan')) - sys.path.append(os.path.join(scriptdir)) - DEFAULT_OUTDIR = './dsdlc_generated' DESCRIPTION = '''UAVCAN DSDL compiler. Takes an input directory that contains an hierarchy of DSDL @@ -38,9 +37,15 @@ args = argparser.parse_args() configure_logging(args.verbose) +try: + extra_incdir = os.environ['UAVCAN_DSDL_INCLUDE_PATH'].split(':') + logging.info('Additional include directories: %s', extra_incdir) + args.incdir += extra_incdir +except KeyError: + pass + from libuavcan_dsdl_compiler import run as dsdlc_run try: - # TODO: collect include dirs from environment variable UAVCAN_DSDL_INCLUDE dsdlc_run(args.source_dir, args.incdir, args.outdir) except Exception as ex: logging.error('Compiler failure', exc_info=True) diff --git a/libuavcan/dsdl_compiler/setup.py b/libuavcan/dsdl_compiler/setup.py index 0b236890ab..6ebbc639b7 100755 --- a/libuavcan/dsdl_compiler/setup.py +++ b/libuavcan/dsdl_compiler/setup.py @@ -3,12 +3,12 @@ from distutils.core import setup args = dict( - name='uavcan_dsdlc', + name='libuavcan_dsdl_compiler', version='0.1', description='UAVCAN DSDL compiler for libuavcan', packages=['libuavcan_dsdl_compiler'], package_data={'libuavcan_dsdl_compiler': ['data_type_template.tmpl']}, - scripts=['uavcan_dsdlc'], + scripts=['libuavcan_dsdlc'], requires=['mako', 'pyuavcan'], author='Pavel Kirienko', author_email='pavel.kirienko@gmail.com',