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 = [(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# |
269SimObject.fixed = True 270 |
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): |
288 if fullname == 'm5.defines': |
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) |
298 if source is not None and fullname.startswith('m5.objects'): |
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 |
313 if fullname == 'm5.defines': 314 mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) |
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 |
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. |
335importer = DictImporter(PySource.modules) 336sys.meta_path[0:0] = [ importer ] 337 |
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 |
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 |
379# buildEnv flags. |
380def makeDefinesPyFile(target, source, env): |
381 build_env, hg_info = [ x.get_contents() for x in source ] |
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 |
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 --- |