From bd94bca008581d2884562f700ae818ab0f3b3635 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Tue, 14 Feb 2012 18:44:16 +0000 Subject: [PATCH] Bug 1355 - visualizer dependencies not detected at buildtime --- examples/tcp/wscript | 2 +- src/visualizer/wscript | 52 +++++++++++++++++++++++++++++++----------- wscript | 10 ++++++-- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/examples/tcp/wscript b/examples/tcp/wscript index ff733c24f..9351866fa 100644 --- a/examples/tcp/wscript +++ b/examples/tcp/wscript @@ -2,7 +2,7 @@ def build(bld): obj = bld.create_ns3_program('tcp-large-transfer', - ['point-to-point', 'applications', 'internet']) + ['visualizer', 'point-to-point', 'applications', 'internet']) obj.source = 'tcp-large-transfer.cc' obj = bld.create_ns3_program('tcp-nsc-lfn', diff --git a/src/visualizer/wscript b/src/visualizer/wscript index 8857f458e..67e77e18a 100644 --- a/src/visualizer/wscript +++ b/src/visualizer/wscript @@ -1,24 +1,53 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- import Options +required_python_modules = [ + 'gtk', + 'goocanvas', + 'pygraphviz', + ] + def configure(conf): # If Python was explicitly disabled, then add this module to the # list of modules that won't be built if they are enabled. - if Options.options.python_disable: + conf.env['ENABLE_PYVIZ'] = True + if not conf.check_optional_feature("python"): + conf.env['ENABLE_PYVIZ'] = False + conf.report_optional_feature("PyViz", "PyViz visualizer", + False, + "Python Bindings are needed but not enabled") conf.env['MODULES_NOT_BUILT'].append('visualizer') - -def build(bld): - # Don't do anything for this module if Python was explicitly - # disabled. - if 'visualizer' in bld.env['MODULES_NOT_BUILT']: return - headers = bld.new_task_gen(features=['ns3header']) - headers.module = 'visualizer' - headers.source = [ - ] + modules_missing = [] + for pymod in required_python_modules: + try: + conf.check_python_module(pymod) + except conf.errors.ConfigurationError: + modules_missing.append(pymod) + if modules_missing: + conf.report_optional_feature("PyViz", "PyViz visualizer", + False, "Missing python modules: %s" % (', '.join(modules_missing),)) + conf.env['ENABLE_PYVIZ'] = False + conf.env['MODULES_NOT_BUILT'].append('visualizer') + return + + conf.report_optional_feature("PyViz", "PyViz visualizer", True, None) + + +def build(bld): module = bld.create_ns3_module('visualizer', ['internet', 'wifi', 'point-to-point']) + headers = bld.new_task_gen(features=['ns3header']) + headers.module = 'visualizer' + + # Don't do anything more for this module if Python was explicitly + # disabled. + if not bld.env['ENABLE_PYVIZ']: + return + + + headers.source = [] # XXX This file was added so that static builds would work on # Darwin, which doesn't like modules with no source files. It @@ -32,9 +61,6 @@ def build(bld): 'model/dummy-file-for-static-builds.cc', ] - if not bld.env['ENABLE_PYTHON_BINDINGS']: - return - module.features.append('pyembed') #module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS']) #module.includes = '.' diff --git a/wscript b/wscript index 9ab3a5586..ea1b6b4d3 100644 --- a/wscript +++ b/wscript @@ -270,6 +270,11 @@ def _check_compilation_flag(conf, flag, mode='cxx', linkflags=None): def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled): conf.env.append_value('NS3_OPTIONAL_FEATURES', [(name, caption, was_enabled, reason_not_enabled)]) +def check_optional_feature(conf, name): + for (name1, caption, was_enabled, reason_not_enabled) in conf.env.NS3_OPTIONAL_FEATURES: + if name1 == name: + return was_enabled + raise KeyError("Feature %r not declared yet" % (name,)) # starting with waf 1.6, conf.check() becomes fatal by default if the # test fails, this alternative method makes the test non-fatal, as it @@ -287,6 +292,7 @@ def configure(conf): conf.check_nonfatal = types.MethodType(_check_nonfatal, conf) conf.check_compilation_flag = types.MethodType(_check_compilation_flag, conf) conf.report_optional_feature = types.MethodType(report_optional_feature, conf) + conf.check_optional_feature = types.MethodType(check_optional_feature, conf) conf.env['NS3_OPTIONAL_FEATURES'] = [] conf.check_tool('compiler_c') @@ -364,6 +370,8 @@ def configure(conf): conf.env['MODULES_NOT_BUILT'] = [] + conf.sub_config('bindings/python') + conf.sub_config('src') # Set the list of enabled modules. @@ -396,8 +404,6 @@ def configure(conf): if not conf.env['NS3_ENABLED_MODULES']: raise WafError('Exiting because the ' + not_built + ' module can not be built and it was the only one enabled.') - conf.sub_config('bindings/python') - conf.sub_config('src/mpi') # for suid bits