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).
This commit is contained in:
Steve Reinhardt 2011-06-02 21:23:02 -07:00
parent 2b1aa35e20
commit 5a78c2d001

View file

@ -199,53 +199,62 @@ main.AppendENVPath('PYTHONPATH', extra_python_paths)
hgdir = main.root.Dir(".hg") hgdir = main.root.Dir(".hg")
mercurial_style_message = """ mercurial_style_message = """
You're missing the M5 style hook. You're missing the gem5 style hook, which automatically checks your code
Please install the hook so we can ensure that all code fits a common style. against the gem5 style rules on hg commit and qrefresh commands. This
script will now install the hook in your .hg/hgrc file.
All you'd need to do is add the following lines to your repository .hg/hgrc Press enter to continue, or ctrl-c to abort: """
or your personal .hgrc
----------------
mercurial_style_hook = """
# The following lines were automatically added by gem5/SConstruct
# to provide the gem5 style-checking hooks
[extensions] [extensions]
style = %s/util/style.py style = %s/util/style.py
[hooks] [hooks]
pretxncommit.style = python:style.check_style pretxncommit.style = python:style.check_style
pre-qrefresh.style = python:style.check_style pre-qrefresh.style = python:style.check_style
""" % (main.root) # End of SConstruct additions
mercurial_bin_not_found = """ """ % (main.root.abspath)
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
"""
mercurial_lib_not_found = """ mercurial_lib_not_found = """
Mercurial libraries cannot be found, ignoring style hook Mercurial libraries cannot be found, ignoring style hook. If
If you are actually a M5 developer, please fix this and you are a gem5 developer, please fix this and run the style
run the style hook. It is important. hook. It is important.
""" """
if hgdir.exists(): # Check for style hook and prompt for installation if it's not there.
# Ensure that the style hook is in place. # 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: try:
ui = None
if not GetOption('ignore_style'):
from mercurial import ui from mercurial import ui
ui = ui.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: except ImportError:
print mercurial_lib_not_found 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: if not style_hook:
print mercurial_style_message 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) sys.exit(1)
else: hgrc_path = '%s/.hg/hgrc' % main.root.abspath
print ".hg directory not found" 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)
################################################### ###################################################
# #