diff --git a/src/SConscript b/src/SConscript index cb523aa94..fed0355cf 100644 --- a/src/SConscript +++ b/src/SConscript @@ -272,7 +272,7 @@ class DictImporter(object): self.installed = set() def find_module(self, fullname, path): - if fullname == '__scons': + if fullname == 'defines': return self if fullname == 'm5.objects': @@ -296,8 +296,8 @@ class DictImporter(object): mod.__path__ = fullname.split('.') return mod - if fullname == '__scons': - mod.__dict__['m5_build_env'] = build_env + if fullname == 'defines': + mod.__dict__['buildEnv'] = build_env return mod srcfile = self.modules[fullname] @@ -358,13 +358,51 @@ depends = [ File(py_modules[dep]) for dep in module_depends ] # Commands for the basic automatically generated python files # +scons_dir = str(SCons.Node.FS.default_fs.SConstruct_dir) + +hg_info = ("Unknown", "Unknown", "Unknown") +hg_demandimport = False +try: + if not exists(scons_dir) or not isdir(scons_dir) or \ + not exists(joinpath(scons_dir, ".hg")): + raise ValueError(".hg directory not found") + + import mercurial.demandimport, mercurial.hg, mercurial.ui + import mercurial.util, mercurial.node + hg_demandimport = True + + repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir) + rev = mercurial.node.nullrev + repo.changelog.count() + changenode = repo.changelog.node(rev) + changes = repo.changelog.read(changenode) + id = mercurial.node.hex(changenode) + date = mercurial.util.datestr(changes[2]) + + hg_info = (rev, id, date) +except ImportError, e: + print "Mercurial not found" +except ValueError, e: + print e +except Exception, e: + print "Other mercurial exception: %s" % e + +if hg_demandimport: + mercurial.demandimport.disable() + # Generate Python file containing a dict specifying the current # build_env flags. def makeDefinesPyFile(target, source, env): f = file(str(target[0]), 'w') - print >>f, "m5_build_env = ", source[0] + build_env, hg_info = [ x.get_contents() for x in source ] + print >>f, "buildEnv = %s" % build_env + print >>f, "hgRev, hgId, hgDate = %s" % hg_info f.close() +defines_info = [ Value(build_env), Value(hg_info) ] +# Generate a file with all of the compile options in it +env.Command('python/m5/defines.py', defines_info, makeDefinesPyFile) +PySource('m5', 'python/m5/defines.py') + # Generate python file containing info about the M5 source code def makeInfoPyFile(target, source, env): f = file(str(target[0]), 'w') @@ -373,6 +411,12 @@ def makeInfoPyFile(target, source, env): print >>f, "%s = %s" % (src, repr(data)) f.close() +# Generate a file that wraps the basic top level files +env.Command('python/m5/info.py', + [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], + makeInfoPyFile) +PySource('m5', 'python/m5/info.py') + # Generate the __init__.py file for m5.objects def makeObjectsInitFile(target, source, env): f = file(str(target[0]), 'w') @@ -382,16 +426,6 @@ def makeObjectsInitFile(target, source, env): print >>f, 'from %s import *' % module.get_contents() f.close() -# Generate a file with all of the compile options in it -env.Command('python/m5/defines.py', Value(build_env), makeDefinesPyFile) -PySource('m5', 'python/m5/defines.py') - -# Generate a file that wraps the basic top level files -env.Command('python/m5/info.py', - [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], - makeInfoPyFile) -PySource('m5', 'python/m5/info.py') - # Generate an __init__.py file for the objects package env.Command('python/m5/objects/__init__.py', [ Value(o) for o in sort_list(sim_object_modfiles) ], @@ -821,43 +855,6 @@ env.Command('base/traceflags.hh', flags, traceFlagsHH) env.Command('base/traceflags.cc', flags, traceFlagsCC) Source('base/traceflags.cc') -# Generate program_info.cc -def programInfo(target, source, env): - def gen_file(target, rev, node, date): - pi_stats = file(target, 'w') - print >>pi_stats, 'const char *hgRev = "%s:%s";' % (rev, node) - print >>pi_stats, 'const char *hgDate = "%s";' % date - pi_stats.close() - - target = str(target[0]) - scons_dir = str(source[0].get_contents()) - try: - import mercurial.demandimport, mercurial.hg, mercurial.ui - import mercurial.util, mercurial.node - if not exists(scons_dir) or not isdir(scons_dir) or \ - not exists(joinpath(scons_dir, ".hg")): - raise ValueError - repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir) - rev = mercurial.node.nullrev + repo.changelog.count() - changenode = repo.changelog.node(rev) - changes = repo.changelog.read(changenode) - date = mercurial.util.datestr(changes[2]) - - gen_file(target, rev, mercurial.node.hex(changenode), date) - - mercurial.demandimport.disable() - except ImportError: - gen_file(target, "Unknown", "Unknown", "Unknown") - - except: - print "in except" - gen_file(target, "Unknown", "Unknown", "Unknown") - mercurial.demandimport.disable() - -env.Command('base/program_info.cc', - Value(str(SCons.Node.FS.default_fs.SConstruct_dir)), - programInfo) - # embed python files. All .py files that have been indicated by a # PySource() call in a SConscript need to be embedded into the M5 # library. To do that, we compile the file to byte code, marshal the @@ -974,14 +971,8 @@ def make_objs(sources, env, static): # recompiled whenever anything else does date_obj = XObject('base/date.cc') - # Make the generation of program_info.cc dependend on all - # the other cc files and the compiling of program_info.cc - # dependent on all the objects but program_info.o - pinfo_obj = XObject('base/program_info.cc') - env.Depends('base/program_info.cc', sources) env.Depends(date_obj, objs) - env.Depends(pinfo_obj, objs) - objs.extend([date_obj, pinfo_obj]) + objs.append(date_obj) return objs # Function to create a new build environment as clone of current diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 7b071bccd..4151d1a13 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -77,18 +77,18 @@ env.update(os.environ) # importing *you*). try: import internal - running_m5 = True except ImportError: - running_m5 = False + internal = None -if running_m5: - import defines - build_env.update(defines.m5_build_env) -else: - import __scons - build_env.update(__scons.m5_build_env) +import defines +build_env.update(defines.buildEnv) + +if internal: + defines.compileDate = internal.core.compileDate + for k,v in internal.core.__dict__.iteritems(): + if k.startswith('flag_'): + setattr(defines, k[5:], v) -if running_m5: from event import * from simulate import * from main import options, main diff --git a/src/python/swig/core.i b/src/python/swig/core.i index 566998639..c567bea4d 100644 --- a/src/python/swig/core.i +++ b/src/python/swig/core.i @@ -41,15 +41,24 @@ #include "sim/startup.hh" extern const char *compileDate; -std::vector compileFlags(); -extern const char *hgRev; -extern const char *hgDate; + +#ifdef DEBUG +const bool flag_DEBUG = true; +#else +const bool flag_DEBUG = false; +#endif +#ifdef NDEBUG +const bool flag_NDEBUG = true; +#else +const bool flag_NDEBUG = false; +#endif +const bool flag_TRACING_ON = TRACING_ON; + inline void disableAllListeners() { ListenSocket::disableAll(); } %} %include "stdint.i" %include "std_string.i" -%include "std_vector.i" %include "sim/host.hh" void setOutputDir(const std::string &dir); @@ -59,12 +68,9 @@ void disableAllListeners(); %immutable compileDate; char *compileDate; - -namespace std { %template(StringVector) vector; } -std::vector compileFlags(); - -char *hgRev; -char *hgDate; +const bool flag_DEBUG; +const bool flag_NDEBUG; +const bool flag_TRACING_ON; void setClockFrequency(Tick ticksPerSecond); diff --git a/src/sim/SConscript b/src/sim/SConscript index 48200161c..750007947 100644 --- a/src/sim/SConscript +++ b/src/sim/SConscript @@ -36,7 +36,6 @@ SimObject('System.py') SimObject('InstTracer.py') Source('async.cc') -Source('compile_info.cc') Source('core.cc') Source('debug.cc') Source('eventq.cc') diff --git a/src/sim/compile_info.cc b/src/sim/compile_info.cc deleted file mode 100644 index 482972f9f..000000000 --- a/src/sim/compile_info.cc +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2008 The Hewlett-Packard Development Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Nathan Binkert - * Steve Reinhardt - */ - -#include -#include - -std::vector -compileFlags() -{ - static const char *flags[] = { -#ifdef DEBUG - "DEBUG", -#endif -#ifdef NDEBUG - "NDEBUG", -#endif -#if TRACING_ON - "TRACING_ON", -#endif - }; - - std::vector result; - for (int i = 0; i < sizeof(flags) / sizeof(flags[0]); ++i) - result.push_back(flags[i]); - - return result; -} -