summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2016-03-30 15:35:33 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2016-03-30 15:35:33 +0100
commit588ecad91914a861d04dd83d2fea070b3ba4b24b (patch)
tree3bbbebaa3e234f5018a812077ab50adff0bb56ce
parent5f9c0f8a24784443355f9f6cb54946b96347ac4e (diff)
downloadgem5-588ecad91914a861d04dd83d2fea070b3ba4b24b.tar.xz
scons: Automatically install the git style hook
Add a check in the main SConscript that installs the git pre-commit hook in util/ if git is used. Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Curtis Dunham <curtis.dunham@arm.com> [andreas.sandberg@arm.com: Cleanups suggested by Steve] Reviewed-by: Steve Reinhardt <steve.reinhardt@amd.com> --HG-- extra : rebase_source : 4b805cdd74bc5442a65abf8a62e3e341f352c04e
-rwxr-xr-xSConstruct42
1 files changed, 36 insertions, 6 deletions
diff --git a/SConstruct b/SConstruct
index ae0fc4b6c..7bfdf5e25 100755
--- a/SConstruct
+++ b/SConstruct
@@ -1,6 +1,6 @@
# -*- mode:python -*-
-# Copyright (c) 2013, 2015 ARM Limited
+# Copyright (c) 2013, 2015, 2016 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
@@ -260,13 +260,18 @@ main.AppendENVPath('PYTHONPATH', extra_python_paths)
########################################################################
hgdir = main.root.Dir(".hg")
+gitdir = main.root.Dir(".git")
-mercurial_style_message = """
+
+style_message = """
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.
+script will now install the hook in your %s.
Press enter to continue, or ctrl-c to abort: """
+mercurial_style_message = style_message % ".hg/hgrc file"
+git_style_message = style_message % ".git/hooks/ directory"
+
mercurial_style_upgrade_message = """
Your Mercurial style hooks are not up-to-date. This script will now
try to automatically update them. A backup of your hgrc will be saved
@@ -293,9 +298,13 @@ hook. It is important.
"""
# 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():
+# Skip this if --ignore-style was specified, there's no interactive
+# terminal to prompt, or no recognized revision control system can be
+# found.
+ignore_style = GetOption('ignore_style') or not sys.stdin.isatty()
+
+# Try wire up Mercurial to the style hooks
+if not ignore_style and hgdir.exists():
style_hook = True
style_hooks = tuple()
hgrc = hgdir.File('hgrc')
@@ -359,6 +368,27 @@ if not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
print "Error updating", hgrc_path
sys.exit(1)
+# Try to wire up git to the style hooks
+git_pre_commit_hook = gitdir.File("hooks/pre-commit")
+if not ignore_style and gitdir.exists() and not git_pre_commit_hook.exists():
+ git_style_script = File("util/git-pre-commit.py")
+
+ print git_style_message,
+ try:
+ raw_input()
+ except:
+ print "Input exception, exiting scons.\n"
+ sys.exit(1)
+
+ try:
+ rel_style_script = os.path.relpath(
+ git_style_script.get_abspath(),
+ git_pre_commit_hook.Dir(".").get_abspath())
+ os.symlink(rel_style_script, git_pre_commit_hook.get_abspath())
+ except:
+ print "Error updating git pre-commit hook"
+ raise
+ sys.exit(1)
###################################################
#