wscript
changeset 537 e8a4183dfe00
child 600 fd944dbf33c6
equal deleted inserted replaced
536:059cec00b41e 537:e8a4183dfe00
       
     1 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
       
     2 import os
       
     3 
       
     4 import Params
       
     5 import Object
       
     6 import Action
       
     7 import Common
       
     8 import shutil
       
     9 import subprocess
       
    10 
       
    11 Params.g_autoconfig = 1
       
    12 
       
    13 # the following two variables are used by the target "waf dist"
       
    14 VERSION = '3.0.1'
       
    15 APPNAME = 'ns-3-waf'
       
    16 
       
    17 # these variables are mandatory ('/' are converted automatically)
       
    18 srcdir = '.'
       
    19 blddir = 'build'
       
    20 
       
    21 class Ns3Header(Object.genobj):
       
    22     """A public NS-3 header file"""
       
    23     def __init__(self, env=None):
       
    24         Object.genobj.__init__(self, 'other')
       
    25         self.inst_var = 'INCLUDEDIR'
       
    26         self.inst_dir = 'ns3'
       
    27         self.env = env
       
    28         if not self.env:
       
    29             self.env = Params.g_build.m_allenvs['default']
       
    30 
       
    31     def apply(self):
       
    32         ns3_dir_node = Params.g_build.m_srcnode.find_dir("ns3")
       
    33         inputs = []
       
    34         outputs = []
       
    35         for filename in self.to_list(self.source):
       
    36             src_node = self.path.find_source(filename)
       
    37             if src_node is None:
       
    38                 Params.fatal("source ns3 header file %s not found" % (filename,))
       
    39             dst_node = ns3_dir_node.find_build(os.path.basename(filename))
       
    40             assert dst_node is not None
       
    41             inputs.append(src_node)
       
    42             outputs.append(dst_node)
       
    43         task = self.create_task('ns3_headers', self.env, 1)
       
    44         task.set_inputs(inputs)
       
    45         task.set_outputs(outputs)
       
    46 
       
    47     def install(self):
       
    48         for i in self.m_tasks:
       
    49             current = Params.g_build.m_curdirnode
       
    50             lst = map(lambda a: a.relpath_gen(current), i.m_outputs)
       
    51             Common.install_files(self.inst_var, self.inst_dir, lst)
       
    52 
       
    53 def _ns3_headers_inst(task):
       
    54     assert len(task.m_inputs) == len(task.m_outputs)
       
    55     inputs = [node.srcpath(task.m_env) for node in task.m_inputs]
       
    56     outputs = [node.bldpath(task.m_env) for node in task.m_outputs]
       
    57     for src, dst in zip(inputs, outputs):
       
    58         try:
       
    59             os.chmod(dst, 0600)
       
    60         except OSError:
       
    61             pass
       
    62         shutil.copy2(src, dst)
       
    63         ## make the headers in builddir read-only, to prevent
       
    64         ## accidental modification
       
    65         os.chmod(dst, 0400)
       
    66     return 0
       
    67 
       
    68 def init():
       
    69     Object.register('ns3header', Ns3Header)
       
    70     Action.Action('ns3_headers', func=_ns3_headers_inst, color='BLUE')
       
    71 
       
    72 def set_options(opt):
       
    73     # options provided by the modules
       
    74     if not opt.tool_options('msvc'):
       
    75         opt.tool_options('g++')
       
    76 
       
    77     opt.add_option('--enable-gcov',
       
    78                    help=('Enable code coverage analysis'),
       
    79                    action="store_true", default=False,
       
    80                    dest='enable_gcov')
       
    81 
       
    82     opt.add_option('--lcov-report',
       
    83                    help=('Generate a code coverage report '
       
    84                          '(use this option at build time, not in configure)'),
       
    85                    action="store_true", default=False,
       
    86                    dest='lcov_report')
       
    87 
       
    88     opt.add_option('--doxygen',
       
    89                    help=('Run doxygen to generate html documentation from source comments'),
       
    90                    action="store_true", default=False,
       
    91                    dest='doxygen')
       
    92 
       
    93     # options provided in a script in a subdirectory named "src"
       
    94     opt.sub_options('src')
       
    95 
       
    96 
       
    97 def configure(conf):
       
    98     if not conf.check_tool('msvc'):
       
    99         if not conf.check_tool('g++'):
       
   100             Params.fatal("No suitable compiler found")
       
   101 
       
   102 
       
   103     # create the second environment, set the variant and set its name
       
   104     variant_env = conf.env.copy()
       
   105     variant_name = Params.g_options.debug_level.lower()
       
   106 
       
   107     if Params.g_options.enable_gcov:
       
   108         variant_name += '-gcov'
       
   109         variant_env.append_value('CCFLAGS', '-fprofile-arcs')
       
   110         variant_env.append_value('CCFLAGS', '-ftest-coverage')
       
   111         variant_env.append_value('CXXFLAGS', '-fprofile-arcs')
       
   112         variant_env.append_value('CXXFLAGS', '-ftest-coverage')
       
   113         variant_env.append_value('LINKFLAGS', '-fprofile-arcs')
       
   114     
       
   115     conf.env['NS3_ACTIVE_VARIANT'] = variant_name
       
   116     variant_env['NS3_ACTIVE_VARIANT'] = variant_name
       
   117     variant_env.set_variant(variant_name)
       
   118     conf.set_env_name(variant_name, variant_env)
       
   119     conf.setenv(variant_name)
       
   120 
       
   121     variant_env.append_value('CXXDEFINES', 'RUN_SELF_TESTS')
       
   122     if 'debug' in Params.g_options.debug_level.lower():
       
   123         variant_env.append_value('CXXDEFINES', 'NS3_DEBUG_ENABLE')
       
   124         variant_env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
       
   125 
       
   126     conf.sub_config('src')
       
   127 
       
   128 
       
   129 def build(bld):
       
   130     variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
       
   131     variant_env = bld.env_of_name(variant_name)
       
   132     bld.m_allenvs['default'] = variant_env # switch to the active variant
       
   133     # process subfolders from here
       
   134     bld.add_subdirs('src')
       
   135     bld.add_subdirs('samples utils')
       
   136 
       
   137 
       
   138 def shutdown():
       
   139     import UnitTest
       
   140     ut = UnitTest.unit_test()
       
   141     ut.change_to_testfile_dir = True
       
   142     ut.want_to_see_test_output = True
       
   143     ut.want_to_see_test_error = True
       
   144     ut.run()
       
   145     #ut.print_results()
       
   146 
       
   147     if Params.g_options.lcov_report:
       
   148         env = Params.g_build.env_of_name('default')
       
   149         variant_name = env['NS3_ACTIVE_VARIANT']
       
   150 
       
   151         if 'gcov' not in variant_name:
       
   152             Params.fatal("project not configured for code coverage;"
       
   153                          " reconfigure with --enable-gcov")
       
   154         
       
   155         os.chdir(blddir)
       
   156         try:
       
   157             lcov_report_dir = os.path.join(variant_name, 'lcov-report')
       
   158             create_dir_command = "rm -rf " + lcov_report_dir
       
   159             create_dir_command += " && mkdir " + lcov_report_dir + ";"
       
   160 
       
   161             if subprocess.Popen(create_dir_command, shell=True).wait():
       
   162                 raise SystemExit(1)
       
   163 
       
   164             info_file = os.path.join(lcov_report_dir, variant_name + '.info')
       
   165             lcov_command = "../utils/lcov/lcov -c -d . -o " + info_file
       
   166             lcov_command += " --source-dirs=" + os.getcwd()
       
   167             lcov_command += ":" + os.path.join(
       
   168                 os.getcwd(), variant_name, 'include')
       
   169             if subprocess.Popen(lcov_command, shell=True).wait():
       
   170                 raise SystemExit(1)
       
   171 
       
   172             genhtml_command = "../utils/lcov/genhtml -o " + lcov_report_dir
       
   173             genhtml_command += " " + info_file
       
   174             if subprocess.Popen(genhtml_command, shell=True).wait():
       
   175                 raise SystemExit(1)
       
   176         finally:
       
   177             os.chdir("..")
       
   178 
       
   179     if Params.g_options.doxygen:
       
   180         doxygen_config = os.path.join('doc', 'doxygen.conf')
       
   181         if subprocess.Popen(['doxygen', doxygen_config]).wait():
       
   182             raise SystemExit(1)
       
   183