Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1615)

Delta Between Two Patch Sets: src/wscript

Issue 2408042: Ns-3 BulkSendApplication (Closed)
Left Patch Set: Created 13 years, 5 months ago
Right Patch Set: Comment fixes, update documentation Created 13 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/helper/wscript ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 1 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2 2
3 import os, os.path 3 import os, os.path
4 import shutil 4 import shutil
5 import types 5 import types
6 import warnings 6 import warnings
7 7
8 import TaskGen 8 import TaskGen
9 import Task 9 import Task
10 import Options 10 import Options
11 import Build 11 import Build
12 import Utils 12 import Utils
13 import Constants
13 14
14 try: 15 try:
15 set 16 set
16 except NameError: 17 except NameError:
17 from sets import Set as set # Python 2.3 fallback 18 from sets import Set as set # Python 2.3 fallback
18 19
19 all_modules = ( 20 all_modules = (
20 'core', 21 'core',
21 'common', 22 'common',
22 'simulator', 23 'simulator',
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 conf.env.append_value('NS3_MODULE_PATH', blddir) 93 conf.env.append_value('NS3_MODULE_PATH', blddir)
93 if Options.options.enable_rpath: 94 if Options.options.enable_rpath:
94 conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (os.path.join(blddir),) ) 95 conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (os.path.join(blddir),) )
95 96
96 ## Used to link the 'test-runner' program with all of ns-3 code 97 ## Used to link the 'test-runner' program with all of ns-3 code
97 conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_ modules] 98 conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_ modules]
98 99
99 100
100 def create_ns3_module(bld, name, dependencies=()): 101 def create_ns3_module(bld, name, dependencies=()):
101 module = bld.new_task_gen('cxx', 'cc') 102 module = bld.new_task_gen('cxx', 'cc')
103 module.is_ns3_module = True
102 module.name = 'ns3-' + name 104 module.name = 'ns3-' + name
103 module.target = module.name 105 module.target = module.name
104 module.add_objects = ['ns3-' + dep for dep in dependencies] 106 module.add_objects = ['ns3-' + dep for dep in dependencies]
105 module.module_deps = list(dependencies) 107 module.module_deps = list(dependencies)
106 if not module.env['ENABLE_STATIC_NS3']: 108 if not module.env['ENABLE_STATIC_NS3']:
107 module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS']) 109 module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS'])
108 module.env.append_value('CCFLAGS', module.env['shlib_CXXFLAGS']) 110 module.env.append_value('CCFLAGS', module.env['shlib_CXXFLAGS'])
109 elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \ 111 elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \
110 os.uname()[4] == 'x86_64' and \ 112 os.uname()[4] == 'x86_64' and \
111 module.env['ENABLE_PYTHON_BINDINGS']: 113 module.env['ENABLE_PYTHON_BINDINGS']:
(...skipping 24 matching lines...) Expand all
136 138
137 139
138 class ns3header_taskgen(TaskGen.task_gen): 140 class ns3header_taskgen(TaskGen.task_gen):
139 """A set of NS-3 header files""" 141 """A set of NS-3 header files"""
140 COLOR = 'BLUE' 142 COLOR = 'BLUE'
141 def __init__(self, *args, **kwargs): 143 def __init__(self, *args, **kwargs):
142 super(ns3header_taskgen, self).__init__(*args, **kwargs) 144 super(ns3header_taskgen, self).__init__(*args, **kwargs)
143 self.install_path = None 145 self.install_path = None
144 self.sub_dir = None # if not None, header files will be published as ns3 /sub_dir/file.h 146 self.sub_dir = None # if not None, header files will be published as ns3 /sub_dir/file.h
145 self.module = None # module name 147 self.module = None # module name
148 self.mode = 'install'
146 149
147 def apply(self): 150 def apply(self):
148 if self.module is None: 151 if self.module is None:
149 raise Utils.WafError("'module' missing on ns3headers object %s" % se lf) 152 raise Utils.WafError("'module' missing on ns3headers object %s" % se lf)
150 ns3_dir_node = self.bld.path.find_dir("ns3") 153 ns3_dir_node = self.bld.path.find_dir("ns3")
151 if self.sub_dir is not None: 154 if self.sub_dir is not None:
152 ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir) 155 ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir)
153 for filename in set(self.to_list(self.source)): 156 for filename in set(self.to_list(self.source)):
154 src_node = self.path.find_resource(filename) 157 src_node = self.path.find_resource(filename)
155 if src_node is None: 158 if src_node is None:
156 raise Utils.WafError("source ns3 header file %s not found" % (fi lename,)) 159 raise Utils.WafError("source ns3 header file %s not found" % (fi lename,))
157 dst_node = ns3_dir_node.find_or_declare(os.path.basename(filename)) 160 dst_node = ns3_dir_node.find_or_declare(os.path.basename(filename))
158 assert dst_node is not None 161 assert dst_node is not None
159 task = self.create_task('ns3header', env=self.env) 162 task = self.create_task('ns3header', env=self.env)
160 task.set_inputs([src_node]) 163 task.mode = self.mode
161 task.set_outputs([dst_node]) 164 if self.mode == 'install':
165 task.set_inputs([src_node])
166 task.set_outputs([dst_node])
167 else:
168 task.header_to_remove = dst_node
162 169
163 class ns3header_task(Task.Task): 170 class ns3header_task(Task.Task):
164 before = 'cc cxx gen_ns3_module_header_task' 171 before = 'cc cxx gen_ns3_module_header_task'
165 color = 'BLUE' 172 color = 'BLUE'
173
174 def __str__(self):
175 "string to display to the user"
176 env = self.env
177 src_str = ' '.join([a.nice_path(env) for a in self.inputs])
178 tgt_str = ' '.join([a.nice_path(env) for a in self.outputs])
179 if self.outputs: sep = ' -> '
180 else: sep = ''
181 if self.mode == 'remove':
182 return 'rm-ns3-header %s\n' % (self.header_to_remove.bldpath(self.en v),)
183 return 'install-ns3-header: %s%s%s\n' % (src_str, sep, tgt_str)
184
185 def runnable_status(self):
186 if self.mode == 'remove':
187 if os.path.exists(self.header_to_remove.bldpath(self.env)):
188 return Constants.RUN_ME
189 else:
190 return Constants.SKIP_ME
191 else:
192 return super(ns3header_task, self).runnable_status()
193
166 def run(self): 194 def run(self):
167 assert len(self.inputs) == len(self.outputs) 195 if self.mode == 'install':
168 inputs = [node.srcpath(self.env) for node in self.inputs] 196 assert len(self.inputs) == len(self.outputs)
169 outputs = [node.bldpath(self.env) for node in self.outputs] 197 inputs = [node.srcpath(self.env) for node in self.inputs]
170 for src, dst in zip(inputs, outputs): 198 outputs = [node.bldpath(self.env) for node in self.outputs]
199 for src, dst in zip(inputs, outputs):
200 try:
201 os.chmod(dst, 0600)
202 except OSError:
203 pass
204 shutil.copy2(src, dst)
205 ## make the headers in builddir read-only, to prevent
206 ## accidental modification
207 os.chmod(dst, 0400)
208 return 0
209 else:
210 assert len(self.inputs) == 0
211 assert len(self.outputs) == 0
212 out_file_name = self.header_to_remove.bldpath(self.env)
171 try: 213 try:
172 os.chmod(dst, 0600) 214 os.unlink(out_file_name)
173 except OSError: 215 except OSError, ex:
174 pass 216 if ex.errno != 2:
175 shutil.copy2(src, dst) 217 raise
176 ## make the headers in builddir read-only, to prevent 218 return 0
177 ## accidental modification 219 ············
178 os.chmod(dst, 0400)
179 return 0
180
181 220
182 221
183 class gen_ns3_module_header_task(Task.Task): 222 class gen_ns3_module_header_task(Task.Task):
184 before = 'cc cxx' 223 before = 'cc cxx'
185 after = 'ns3header_task' 224 after = 'ns3header_task'
186 color = 'BLUE' 225 color = 'BLUE'
226
227 def runnable_status(self):
228 if self.mode == 'remove':
229 if os.path.exists(self.header_to_remove.bldpath(self.env)):
230 return Constants.RUN_ME
231 else:
232 return Constants.SKIP_ME
233 else:
234 return super(gen_ns3_module_header_task, self).runnable_status()
235
236 def __str__(self):
237 "string to display to the user"
238 env = self.env
239 src_str = ' '.join([a.nice_path(env) for a in self.inputs])
240 tgt_str = ' '.join([a.nice_path(env) for a in self.outputs])
241 if self.outputs: sep = ' -> '
242 else: sep = ''
243 if self.mode == 'remove':
244 return 'rm-module-header %s\n' % (self.header_to_remove.bldpath(self .env),)
245 return 'gen-module-header: %s%s%s\n' % (src_str, sep, tgt_str)
246
187 def run(self): 247 def run(self):
248 if self.mode == 'remove':
249 assert len(self.inputs) == 0
250 assert len(self.outputs) == 0
251 out_file_name = self.header_to_remove.bldpath(self.env)
252 try:
253 os.unlink(out_file_name)
254 except OSError, ex:
255 if ex.errno != 2:
256 raise
257 return 0
258 ········
188 assert len(self.outputs) == 1 259 assert len(self.outputs) == 1
260 out_file_name = self.outputs[0].bldpath(self.env)
189 header_files = [os.path.basename(node.abspath(self.env)) for node in sel f.inputs] 261 header_files = [os.path.basename(node.abspath(self.env)) for node in sel f.inputs]
190 outfile = file(self.outputs[0].bldpath(self.env), "w") 262 outfile = file(out_file_name, "w")
191 header_files.sort() 263 header_files.sort()
192 264
193 print >> outfile, """ 265 print >> outfile, """
194 #ifdef NS3_MODULE_COMPILATION 266 #ifdef NS3_MODULE_COMPILATION
195 # error "Do not include ns3 module aggregator headers from other modules; these are meant only for end user scripts." 267 # error "Do not include ns3 module aggregator headers from other modules; these are meant only for end user scripts."
196 #endif 268 #endif
197 269
198 #ifndef NS3_MODULE_%s 270 #ifndef NS3_MODULE_%s
199 """ % (self.module.upper().replace('-', '_'),) 271 """ % (self.module.upper().replace('-', '_'),)
200 272
201 # if self.module_deps: 273 # if self.module_deps:
202 # print >> outfile, "// Module dependencies:" 274 # print >> outfile, "// Module dependencies:"
203 # for dep in self.module_deps: 275 # for dep in self.module_deps:
204 # print >> outfile, "#include \"%s-module.h\"" % dep 276 # print >> outfile, "#include \"%s-module.h\"" % dep
205 277
206 print >> outfile 278 print >> outfile
207 print >> outfile, "// Module headers:" 279 print >> outfile, "// Module headers:"
208 for header in header_files: 280 for header in header_files:
209 print >> outfile, "#include \"%s\"" % (header,) 281 print >> outfile, "#include \"%s\"" % (header,)
210 282
211 print >> outfile, "#endif" 283 print >> outfile, "#endif"
212 284
213 outfile.close() 285 outfile.close()
214 return 0 286 return 0
215 287
216 def sig_explicit_deps(self): 288 def sig_explicit_deps(self):
217 m = Utils.md5() 289 self.m.update('\n'.join([node.abspath(self.env) for node in self.inputs] ))
218 m.update('\n'.join([node.abspath(self.env) for node in self.inputs])) 290 return self.m.digest()
219 return m.digest()
220 291
221 def unique_id(self): 292 def unique_id(self):
222 try: 293 try:
223 return self.uid 294 return self.uid
224 except AttributeError: 295 except AttributeError:
225 "this is not a real hot zone, but we want to avoid surprizes here" 296 "this is not a real hot zone, but we want to avoid surprizes here"
226 m = Utils.md5() 297 m = Utils.md5()
227 m.update("ns-3-module-header-%s" % self.module) 298 m.update("ns-3-module-header-%s" % self.module)
228 self.uid = m.digest() 299 self.uid = m.digest()
229 return self.uid 300 return self.uid
230 301
231 302
232 class ns3moduleheader_taskgen(TaskGen.task_gen): 303 class ns3moduleheader_taskgen(TaskGen.task_gen):
233 """ 304 """
234 Generates a 'ns3/foo-module.h' header file that includes all 305 Generates a 'ns3/foo-module.h' header file that includes all
235 public ns3 headers of a certain module. 306 public ns3 headers of a certain module.
236 """ 307 """
237 COLOR = 'BLUE' 308 COLOR = 'BLUE'
238 def __init__(self, *args, **kwargs): 309 def __init__(self, *args, **kwargs):
239 super(ns3moduleheader_taskgen, self).__init__(*args, **kwargs) 310 super(ns3moduleheader_taskgen, self).__init__(*args, **kwargs)
311 self.mode = 'install'
240 312
241 def apply(self): 313 def apply(self):
242 ## get all of the ns3 headers 314 ## get all of the ns3 headers
243 ns3_dir_node = self.bld.path.find_dir("ns3") 315 ns3_dir_node = self.bld.path.find_dir("ns3")
244 all_headers_inputs = [] 316 all_headers_inputs = []
245 found_the_module = False 317 found_the_module = False
246 for ns3headers in self.bld.all_task_gen: 318 for ns3headers in self.bld.all_task_gen:
247 if isinstance(ns3headers, ns3header_taskgen): 319 if isinstance(ns3headers, ns3header_taskgen):
248 if ns3headers.module != self.module: 320 if ns3headers.module != self.module:
249 continue 321 continue
250 found_the_module = True 322 found_the_module = True
251 for source in set(ns3headers.to_list(ns3headers.source)): 323 for source in set(ns3headers.to_list(ns3headers.source)):
252 source = os.path.basename(source) 324 source = os.path.basename(source)
253 node = ns3_dir_node.find_or_declare(os.path.basename(source) ) 325 node = ns3_dir_node.find_or_declare(os.path.basename(source) )
254 if node is None: 326 if node is None:
255 fatal("missing header file %s" % (source,)) 327 fatal("missing header file %s" % (source,))
256 all_headers_inputs.append(node) 328 all_headers_inputs.append(node)
257 if not found_the_module: 329 if not found_the_module:
258 raise Utils.WscriptError("error finding headers for module %s" % sel f.module) 330 raise Utils.WscriptError("error finding headers for module %s" % sel f.module)
259 if not all_headers_inputs: 331 if not all_headers_inputs:
260 return 332 return
261 module_obj = self.bld.name_to_obj("ns3-" + self.module, self.env)
262 assert module_obj is not None
263 all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self .module)] 333 all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self .module)]
264 task = self.create_task('gen_ns3_module_header', env=self.env) 334 task = self.create_task('gen_ns3_module_header', env=self.env)
265 task.set_inputs(all_headers_inputs)
266 task.set_outputs(all_headers_outputs)
267 task.module = self.module 335 task.module = self.module
268 task.module_deps = module_obj.module_deps 336 task.mode = self.mode
337 if self.mode == 'install':
338 task.set_inputs(all_headers_inputs)
339 task.set_outputs(all_headers_outputs)
340 module_obj = self.bld.name_to_obj("ns3-" + self.module, self.env)
341 assert module_obj is not None, self.module
342 task.module_deps = module_obj.module_deps
343 else:
344 task.header_to_remove = all_headers_outputs[0]
269 345
270 def install(self): 346 def install(self):
271 pass 347 pass
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b