changeset 3a2aebf01bf3 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=3a2aebf01bf3
description:
        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:

 SConstruct |  72 +++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 41 insertions(+), 31 deletions(-)

diffs (98 lines):

diff -r 9228e00459d4 -r 3a2aebf01bf3 SConstruct
--- a/SConstruct        Thu Jun 02 17:36:21 2011 -0700
+++ b/SConstruct        Thu Jun 02 21:23:02 2011 -0700
@@ -199,53 +199,62 @@
 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.
+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: """
 
-All you'd need to do is add the following lines to your repository .hg/hgrc
-or your personal .hgrc
-----------------
-
+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 a gem5 developer, please fix this and run the style
+hook. It is important.
 """
 
-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.
-"""
-
-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,
+        # continue unless user does ctrl-c/ctrl-d etc.
+        try:
+            raw_input()
+        except:
+            print "Input exception, exiting scons.\n"
+            sys.exit(1)
+        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)
 
-        if not style_hook:
-            print mercurial_style_message
-            sys.exit(1)
-else:
-    print ".hg directory not found"
 
 ###################################################
 #
_______________________________________________
gem5-dev mailing list
gem5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to