summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorSteve Reinhardt <steve.reinhardt@amd.com>2011-06-02 21:23:02 -0700
committerSteve Reinhardt <steve.reinhardt@amd.com>2011-06-02 21:23:02 -0700
commit5a78c2d001e24d31d09e272b2a17b81146699cda (patch)
treed11f256ffdd8f471695f0f482ac015a9a8f17a72 /SConstruct
parent2b1aa35e209a76515763e7e7d7a0fe6a8267bebf (diff)
downloadgem5-5a78c2d001e24d31d09e272b2a17b81146699cda.tar.xz
SConstruct: automatically update .hg/hgrc with style hooks.
Seems easier than pestering people about it. Note also that path is now absolute, so you don't get errors when invoking hg from subdirectories. Also whacked unused mercurial_bin_not_found message (the code that used this was deleted a couple months ago in rev 5138d1e453f1).
Diffstat (limited to 'SConstruct')
-rwxr-xr-xSConstruct71
1 files changed, 40 insertions, 31 deletions
diff --git a/SConstruct b/SConstruct
index de5777bb5..a5a5aa0f1 100755
--- a/SConstruct
+++ b/SConstruct
@@ -199,53 +199,62 @@ main.AppendENVPath('PYTHONPATH', extra_python_paths)
hgdir = main.root.Dir(".hg")
mercurial_style_message = """
-You're missing the M5 style hook.
-Please install the hook so we can ensure that all code fits a common style.
-
-All you'd need to do is add the following lines to your repository .hg/hgrc
-or your personal .hgrc
-----------------
-
+You're missing the gem5 style hook, which automatically checks your code
+against the gem5 style rules on hg commit and qrefresh commands. This
+script will now install the hook in your .hg/hgrc file.
+Press enter to continue, or ctrl-c to abort: """
+
+mercurial_style_hook = """
+# The following lines were automatically added by gem5/SConstruct
+# to provide the gem5 style-checking hooks
[extensions]
style = %s/util/style.py
[hooks]
pretxncommit.style = python:style.check_style
pre-qrefresh.style = python:style.check_style
-""" % (main.root)
+# End of SConstruct additions
-mercurial_bin_not_found = """
-Mercurial binary cannot be found, unfortunately this means that we
-cannot easily determine the version of M5 that you are running and
-this makes error messages more difficult to collect. Please consider
-installing mercurial if you choose to post an error message
-"""
+""" % (main.root.abspath)
mercurial_lib_not_found = """
-Mercurial libraries cannot be found, ignoring style hook
-If you are actually a M5 developer, please fix this and
-run the style hook. It is important.
+Mercurial libraries cannot be found, ignoring style hook. If
+you are a gem5 developer, please fix this and run the style
+hook. It is important.
"""
-if hgdir.exists():
- # Ensure that the style hook is in place.
+# Check for style hook and prompt for installation if it's not there.
+# Skip this if --ignore-style was specified, there's no .hg dir to
+# install a hook in, or there's no interactive terminal to prompt.
+if not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
+ style_hook = True
try:
- ui = None
- if not GetOption('ignore_style'):
- from mercurial import ui
- ui = ui.ui()
+ from mercurial import ui
+ ui = ui.ui()
+ ui.readconfig(hgdir.File('hgrc').abspath)
+ style_hook = ui.config('hooks', 'pretxncommit.style', None) and \
+ ui.config('hooks', 'pre-qrefresh.style', None)
except ImportError:
print mercurial_lib_not_found
- if ui is not None:
- ui.readconfig(hgdir.File('hgrc').abspath)
- style_hook = ui.config('hooks', 'pretxncommit.style', None)
-
- if not style_hook:
- print mercurial_style_message
+ if not style_hook:
+ print mercurial_style_message,
+ # continue unless user does ctrl-c/ctrl-d etc.
+ try:
+ raw_input()
+ except:
+ print "Input exception, exiting scons.\n"
sys.exit(1)
-else:
- print ".hg directory not found"
+ hgrc_path = '%s/.hg/hgrc' % main.root.abspath
+ print "Adding style hook to", hgrc_path, "\n"
+ try:
+ hgrc = open(hgrc_path, 'a')
+ hgrc.write(mercurial_style_hook)
+ hgrc.close()
+ except:
+ print "Error updating", hgrc_path
+ sys.exit(1)
+
###################################################
#