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