Deleted Added
sdiff udiff text old ( 12244:33af7397d081 ) new ( 12558:81a22bff9cdc )
full compact
1# Copyright (c) 2013, 2015-2017 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 24 unchanged lines hidden (view full) ---

33# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41import re
42import sys
43
44import gem5_scons.util
45
46mercurial_style_message = """
47You're missing the gem5 style hook, which automatically checks your code
48against the gem5 style rules on hg commit and qrefresh commands.

--- 36 unchanged lines hidden (view full) ---

85 from mercurial import ui
86 ui = ui.ui()
87 ui.readconfig(hgrc.abspath)
88 style_hooks = (ui.config('hooks', 'pretxncommit.style', None),
89 ui.config('hooks', 'pre-qrefresh.style', None))
90 style_hook = all(style_hooks)
91 style_extension = ui.config('extensions', 'style', None)
92 except ImportError:
93 print mercurial_lib_not_found
94
95 if "python:style.check_style" in style_hooks:
96 # Try to upgrade the style hooks
97 print mercurial_style_upgrade_message
98 # continue unless user does ctrl-c/ctrl-d etc.
99 try:
100 raw_input()
101 except:
102 print "Input exception, exiting scons.\n"
103 sys.exit(1)
104 shutil.copyfile(hgrc.abspath, hgrc_old.abspath)
105 re_style_hook = re.compile(r"^([^=#]+)\.style\s*=\s*([^#\s]+).*")
106 re_style_extension = re.compile("style\s*=\s*([^#\s]+).*")
107 old, new = open(hgrc_old.abspath, 'r'), open(hgrc.abspath, 'w')
108 for l in old:
109 m_hook = re_style_hook.match(l)
110 m_ext = re_style_extension.match(l)
111 if m_hook:
112 hook, check = m_hook.groups()
113 if check != "python:style.check_style":
114 print "Warning: %s.style is using a non-default " \
115 "checker: %s" % (hook, check)
116 if hook not in ("pretxncommit", "pre-qrefresh"):
117 print "Warning: Updating unknown style hook: %s" % hook
118
119 l = "%s.style = python:hgstyle.check_style\n" % hook
120 elif m_ext and m_ext.group(1) == style_extension:
121 l = "hgstyle = %s/util/hgstyle.py\n" % env.root.abspath
122
123 new.write(l)
124 elif not style_hook:
125 print mercurial_style_message,
126 # continue unless user does ctrl-c/ctrl-d etc.
127 try:
128 raw_input()
129 except:
130 print "Input exception, exiting scons.\n"
131 sys.exit(1)
132 hgrc_path = '%s/.hg/hgrc' % env.root.abspath
133 print "Adding style hook to", hgrc_path, "\n"
134 try:
135 with open(hgrc_path, 'a') as f:
136 f.write(mercurial_style_hook_template % env.root.abspath)
137 except:
138 print "Error updating", hgrc_path
139 sys.exit(1)
140
141def generate(env):
142 if exists(env) and not gem5_scons.util.ignore_style():
143 install_style_hooks(env)
144
145def exists(env):
146 return env.Dir('#.hg').exists()