Deleted Added
sdiff udiff text old ( 6240:ceb4c8a5e7a2 ) new ( 6654:4c84e771cca7 )
full compact
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])
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#
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):
286 if fullname == '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)
296 if source is not None and exists(source.snode.abspath):
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
311 if fullname == 'defines':
312 mod.__dict__['buildEnv'] = 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
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.
327SimObject.fixed = True
328importer = DictImporter(PySource.modules)
329sys.meta_path[0:0] = [ importer ]
330
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():
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
368# build_env flags.
369def makeDefinesPyFile(target, source, env):
370 f = file(str(target[0]), 'w')
371 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
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 ---