# HG changeset patch
# User Ali Saidi <[EMAIL PROTECTED]>
# Date 1211490125 14400
# Node ID b9683f2d6b0cb9288bc5f107b193ee617310fce8
# Parent fc6b6643b9c611ee5367a3db99b0705e74d9b06d
HG: Add compiled hg revision and date to the standard M5 output.
diff --git a/src/SConscript b/src/SConscript
--- a/src/SConscript
+++ b/src/SConscript
@@ -333,6 +333,15 @@ env.Command('base/traceflags.cc', flags,
env.Command('base/traceflags.cc', flags, generate.traceFlagsCC)
Source('base/traceflags.cc')
+# Generate hginfo.cc
+# Anything we pass as a source gets setup as a dependence so rather than
+# passing the SConscript/hg dir/etc we just squirrel away the SConstruct
+# directory in the environment and retrieve it later. This seems to
+# be the only reliable way to get the information if we're building in
+# a directory outside of the m5 directory
+env['SConstructDir'] = str(SCons.Node.FS.default_fs.SConstruct_dir)
+env.Command('base/hginfo.cc', None, generate.hgInfo)
+
# Build the zip file
py_compiled = []
py_zip_depends = []
@@ -365,11 +374,20 @@ envList = []
# date.cc.
def make_objs(sources, env):
objs = [env.Object(s) for s in sources]
+
# make date.cc depend on all other objects so it always gets
# recompiled whenever anything else does
date_obj = env.Object('base/date.cc')
+
+ # Abuse the SCons dependence code to make the generation
+ # of hginfo.cc dependend on all the other cc files and the
+ # compiling of hginfo.cc dependent on all the objects
+ # but hginfo.o
+ hg_obj = env.Object('base/hginfo.cc')
+ env.Depends('base/hginfo.cc', sources)
env.Depends(date_obj, objs)
- objs.append(date_obj)
+ env.Depends(hg_obj, objs)
+ objs.extend([date_obj,hg_obj])
return objs
# Function to create a new build environment as clone of current
diff --git a/src/python/generate.py b/src/python/generate.py
--- a/src/python/generate.py
+++ b/src/python/generate.py
@@ -32,8 +32,7 @@ import sys
import sys
import zipfile
-from os.path import basename
-from os.path import exists
+from os.path import basename, exists, isdir, join
class DictImporter(object):
'''This importer takes a dictionary of arbitrary module names that
@@ -528,3 +527,39 @@ extern const Flags *compoundFlags[];
'''
f.close()
+
+ def hgInfo(self, target, source, env):
+ try:
+ # The SConscript squirrels away the SConstructDir variable in the
+ # env for us. We can't pass it as a source parameter because that
+ # would setup a depedence between everything in the directory and
+ # above and this file.
+
+ scons_dir = env['SConstructDir']
+ import mercurial.hg, mercurial.ui, mercurial.util, mercurial.node
+ if not exists(scons_dir) or not isdir(scons_dir) or \
+ not exists(join(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])
+
+ hg_stats = file(str(target[0]), 'w')
+ print >>hg_stats, 'const char *hgRev = "%s:%s";' % (rev,
mercurial.node.hex(changenode))
+ print >>hg_stats, 'const char *hgDate = "%s";' % date
+ hg_stats.close()
+ mercurial.demandimport.disable()
+ except ImportError:
+ pass
+ except:
+ hg_stats = file(str(target[0]), 'w')
+ print >>hg_stats, 'const char *hgRev = "Unknown";'
+ print >>hg_stats, 'const char *hgDate = "Unknown";'
+ hg_stats.close()
+ mercurial.demandimport.disable()
+
+
+
+
diff --git a/src/python/m5/main.py b/src/python/m5/main.py
--- a/src/python/m5/main.py
+++ b/src/python/m5/main.py
@@ -269,6 +269,10 @@ def main():
print "M5 compiled %s" % internal.core.cvar.compileDate;
print "M5 started %s" % datetime.datetime.now().ctime()
print "M5 executing on %s" % socket.gethostname()
+
+ print "M5 revision %s" % internal.core.cvar.hgRev
+ print "M5 commit date %s" % internal.core.cvar.hgDate
+
print "command line:",
for argv in sys.argv:
print argv,
diff --git a/src/python/swig/core.i b/src/python/swig/core.i
--- a/src/python/swig/core.i
+++ b/src/python/swig/core.i
@@ -39,6 +39,8 @@
#include "sim/startup.hh"
extern const char *compileDate;
+extern const char *hgRev;
+extern const char *hgDate;
%}
%include "stdint.i"
@@ -51,6 +53,8 @@ void doExitCleanup();
void doExitCleanup();
char *compileDate;
+char *hgRev;
+char *hgDate;
void setClockFrequency(Tick ticksPerSecond);
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev