SConscript (6240:ceb4c8a5e7a2) SConscript (6654:4c84e771cca7)
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 35 unchanged lines hidden (view full) ---

44# This file defines how to build a particular configuration of M5
45# based on variable settings in the 'env' build environment.
46
47Import('*')
48
49# Children need to see the environment
50Export('env')
51
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 35 unchanged lines hidden (view full) ---

44# This file defines how to build a particular configuration of M5
45# based on variable settings in the 'env' build environment.
46
47Import('*')
48
49# Children need to see the environment
50Export('env')
51
52build_env = dict([(opt, env[opt]) for opt in export_vars])
52build_env = [(opt, env[opt]) for opt in export_vars]
53
54########################################################################
55# Code for adding source files of various types
56#
57class SourceMeta(type):
58 def __init__(cls, name, bases, dict):
59 super(SourceMeta, cls).__init__(name, bases, dict)
60 cls.all = []

--- 200 unchanged lines hidden (view full) ---

261for opt in export_vars:
262 env.ConfigFile(opt)
263
264########################################################################
265#
266# Prevent any SimObjects from being added after this point, they
267# should all have been added in the SConscripts above
268#
53
54########################################################################
55# Code for adding source files of various types
56#
57class SourceMeta(type):
58 def __init__(cls, name, bases, dict):
59 super(SourceMeta, cls).__init__(name, bases, dict)
60 cls.all = []

--- 200 unchanged lines hidden (view full) ---

261for opt in export_vars:
262 env.ConfigFile(opt)
263
264########################################################################
265#
266# Prevent any SimObjects from being added after this point, they
267# should all have been added in the SConscripts above
268#
269SimObject.fixed = True
270
269class DictImporter(object):
270 '''This importer takes a dictionary of arbitrary module names that
271 map to arbitrary filenames.'''
272 def __init__(self, modules):
273 self.modules = modules
274 self.installed = set()
275
276 def __del__(self):
277 self.unload()
278
279 def unload(self):
280 import sys
281 for module in self.installed:
282 del sys.modules[module]
283 self.installed = set()
284
285 def find_module(self, fullname, path):
271class DictImporter(object):
272 '''This importer takes a dictionary of arbitrary module names that
273 map to arbitrary filenames.'''
274 def __init__(self, modules):
275 self.modules = modules
276 self.installed = set()
277
278 def __del__(self):
279 self.unload()
280
281 def unload(self):
282 import sys
283 for module in self.installed:
284 del sys.modules[module]
285 self.installed = set()
286
287 def find_module(self, fullname, path):
286 if fullname == 'defines':
288 if fullname == 'm5.defines':
287 return self
288
289 if fullname == 'm5.objects':
290 return self
291
292 if fullname.startswith('m5.internal'):
293 return None
294
295 source = self.modules.get(fullname, None)
289 return self
290
291 if fullname == 'm5.objects':
292 return self
293
294 if fullname.startswith('m5.internal'):
295 return None
296
297 source = self.modules.get(fullname, None)
296 if source is not None and exists(source.snode.abspath):
298 if source is not None and fullname.startswith('m5.objects'):
297 return self
298
299 return None
300
301 def load_module(self, fullname):
302 mod = imp.new_module(fullname)
303 sys.modules[fullname] = mod
304 self.installed.add(fullname)
305
306 mod.__loader__ = self
307 if fullname == 'm5.objects':
308 mod.__path__ = fullname.split('.')
309 return mod
310
299 return self
300
301 return None
302
303 def load_module(self, fullname):
304 mod = imp.new_module(fullname)
305 sys.modules[fullname] = mod
306 self.installed.add(fullname)
307
308 mod.__loader__ = self
309 if fullname == 'm5.objects':
310 mod.__path__ = fullname.split('.')
311 return mod
312
311 if fullname == 'defines':
312 mod.__dict__['buildEnv'] = build_env
313 if fullname == 'm5.defines':
314 mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env)
313 return mod
314
315 source = self.modules[fullname]
316 if source.modname == '__init__':
317 mod.__path__ = source.modpath
318 mod.__file__ = source.snode.abspath
319
320 exec file(source.snode.abspath, 'r') in mod.__dict__
321
322 return mod
323
315 return mod
316
317 source = self.modules[fullname]
318 if source.modname == '__init__':
319 mod.__path__ = source.modpath
320 mod.__file__ = source.snode.abspath
321
322 exec file(source.snode.abspath, 'r') in mod.__dict__
323
324 return mod
325
326import m5.SimObject
327import m5.params
328
329m5.SimObject.clear()
330m5.params.clear()
331
324# install the python importer so we can grab stuff from the source
325# tree itself. We can't have SimObjects added after this point or
326# else we won't know about them for the rest of the stuff.
332# install the python importer so we can grab stuff from the source
333# tree itself. We can't have SimObjects added after this point or
334# else we won't know about them for the rest of the stuff.
327SimObject.fixed = True
328importer = DictImporter(PySource.modules)
329sys.meta_path[0:0] = [ importer ]
330
335importer = DictImporter(PySource.modules)
336sys.meta_path[0:0] = [ importer ]
337
331import m5
332
333# import all sim objects so we can populate the all_objects list
334# make sure that we're working with a list, then let's sort it
335for modname in SimObject.modnames:
336 exec('from m5.objects import %s' % modname)
337
338# we need to unload all of the currently imported modules so that they
339# will be re-imported the next time the sconscript is run
340importer.unload()
341sys.meta_path.remove(importer)
342
343sim_objects = m5.SimObject.allClasses
344all_enums = m5.params.allEnums
345
346all_params = {}
347for name,obj in sorted(sim_objects.iteritems()):
348 for param in obj._params.local.values():
338# import all sim objects so we can populate the all_objects list
339# make sure that we're working with a list, then let's sort it
340for modname in SimObject.modnames:
341 exec('from m5.objects import %s' % modname)
342
343# we need to unload all of the currently imported modules so that they
344# will be re-imported the next time the sconscript is run
345importer.unload()
346sys.meta_path.remove(importer)
347
348sim_objects = m5.SimObject.allClasses
349all_enums = m5.params.allEnums
350
351all_params = {}
352for name,obj in sorted(sim_objects.iteritems()):
353 for param in obj._params.local.values():
354 # load the ptype attribute now because it depends on the
355 # current version of SimObject.allClasses, but when scons
356 # actually uses the value, all versions of
357 # SimObject.allClasses will have been loaded
358 param.ptype
359
349 if not hasattr(param, 'swig_decl'):
350 continue
351 pname = param.ptype_str
352 if pname not in all_params:
353 all_params[pname] = param
354
355########################################################################
356#
357# calculate extra dependencies
358#
359module_depends = ["m5", "m5.SimObject", "m5.params"]
360depends = [ PySource.modules[dep].tnode for dep in module_depends ]
361
362########################################################################
363#
364# Commands for the basic automatically generated python files
365#
366
367# Generate Python file containing a dict specifying the current
360 if not hasattr(param, 'swig_decl'):
361 continue
362 pname = param.ptype_str
363 if pname not in all_params:
364 all_params[pname] = param
365
366########################################################################
367#
368# calculate extra dependencies
369#
370module_depends = ["m5", "m5.SimObject", "m5.params"]
371depends = [ PySource.modules[dep].tnode for dep in module_depends ]
372
373########################################################################
374#
375# Commands for the basic automatically generated python files
376#
377
378# Generate Python file containing a dict specifying the current
368# build_env flags.
379# buildEnv flags.
369def makeDefinesPyFile(target, source, env):
380def makeDefinesPyFile(target, source, env):
370 f = file(str(target[0]), 'w')
371 build_env, hg_info = [ x.get_contents() for x in source ]
381 build_env, hg_info = [ x.get_contents() for x in source ]
372 print >>f, "buildEnv = %s" % build_env
373 print >>f, "hgRev = '%s'" % hg_info
374 f.close()
375
382
383 code = m5.util.code_formatter()
384 code("""
385import m5.internal
386import m5.util
387
388buildEnv = m5.util.SmartDict($build_env)
389hgRev = '$hg_info'
390
391compileDate = m5.internal.core.compileDate
392for k,v in m5.internal.core.__dict__.iteritems():
393 if k.startswith('flag_'):
394 setattr(buildEnv, k[5:], v)
395""")
396 code.write(str(target[0]))
397
376defines_info = [ Value(build_env), Value(env['HG_INFO']) ]
377# Generate a file with all of the compile options in it
378env.Command('python/m5/defines.py', defines_info, makeDefinesPyFile)
379PySource('m5', 'python/m5/defines.py')
380
381# Generate python file containing info about the M5 source code
382def makeInfoPyFile(target, source, env):
383 f = file(str(target[0]), 'w')

--- 677 unchanged lines hidden ---
398defines_info = [ Value(build_env), Value(env['HG_INFO']) ]
399# Generate a file with all of the compile options in it
400env.Command('python/m5/defines.py', defines_info, makeDefinesPyFile)
401PySource('m5', 'python/m5/defines.py')
402
403# Generate python file containing info about the M5 source code
404def makeInfoPyFile(target, source, env):
405 f = file(str(target[0]), 'w')

--- 677 unchanged lines hidden ---