SConstruct (11342:a4d19e7cd26d) SConstruct (11401:55f9a21e34b4)
1# -*- mode:python -*-
2
3# Copyright (c) 2013, 2015 ARM Limited
4# All rights reserved.
5#
6# The license below extends only to copyright in the software and shall
7# not be construed as granting a license to any other intellectual
8# property including but not limited to intellectual property relating

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

107 http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation
108"""
109 raise
110
111# Global Python includes
112import itertools
113import os
114import re
1# -*- mode:python -*-
2
3# Copyright (c) 2013, 2015 ARM Limited
4# All rights reserved.
5#
6# The license below extends only to copyright in the software and shall
7# not be construed as granting a license to any other intellectual
8# property including but not limited to intellectual property relating

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

107 http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation
108"""
109 raise
110
111# Global Python includes
112import itertools
113import os
114import re
115import shutil
115import subprocess
116import sys
117
118from os import mkdir, environ
119from os.path import abspath, basename, dirname, expanduser, normpath
120from os.path import exists, isdir, isfile
121from os.path import join as joinpath, split as splitpath
122

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

261hgdir = main.root.Dir(".hg")
262
263mercurial_style_message = """
264You're missing the gem5 style hook, which automatically checks your code
265against the gem5 style rules on hg commit and qrefresh commands. This
266script will now install the hook in your .hg/hgrc file.
267Press enter to continue, or ctrl-c to abort: """
268
116import subprocess
117import sys
118
119from os import mkdir, environ
120from os.path import abspath, basename, dirname, expanduser, normpath
121from os.path import exists, isdir, isfile
122from os.path import join as joinpath, split as splitpath
123

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

262hgdir = main.root.Dir(".hg")
263
264mercurial_style_message = """
265You're missing the gem5 style hook, which automatically checks your code
266against the gem5 style rules on hg commit and qrefresh commands. This
267script will now install the hook in your .hg/hgrc file.
268Press enter to continue, or ctrl-c to abort: """
269
270mercurial_style_upgrade_message = """
271Your Mercurial style hooks are not up-to-date. This script will now
272try to automatically update them. A backup of your hgrc will be saved
273in .hg/hgrc.old.
274Press enter to continue, or ctrl-c to abort: """
275
269mercurial_style_hook = """
270# The following lines were automatically added by gem5/SConstruct
271# to provide the gem5 style-checking hooks
272[extensions]
276mercurial_style_hook = """
277# The following lines were automatically added by gem5/SConstruct
278# to provide the gem5 style-checking hooks
279[extensions]
273style = %s/util/style.py
280hgstyle = %s/util/hgstyle.py
274
275[hooks]
281
282[hooks]
276pretxncommit.style = python:style.check_style
277pre-qrefresh.style = python:style.check_style
283pretxncommit.style = python:hgstyle.check_style
284pre-qrefresh.style = python:hgstyle.check_style
278# End of SConstruct additions
279
280""" % (main.root.abspath)
281
282mercurial_lib_not_found = """
283Mercurial libraries cannot be found, ignoring style hook. If
284you are a gem5 developer, please fix this and run the style
285hook. It is important.
286"""
287
288# Check for style hook and prompt for installation if it's not there.
289# Skip this if --ignore-style was specified, there's no .hg dir to
290# install a hook in, or there's no interactive terminal to prompt.
291if not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
292 style_hook = True
285# End of SConstruct additions
286
287""" % (main.root.abspath)
288
289mercurial_lib_not_found = """
290Mercurial libraries cannot be found, ignoring style hook. If
291you are a gem5 developer, please fix this and run the style
292hook. It is important.
293"""
294
295# Check for style hook and prompt for installation if it's not there.
296# Skip this if --ignore-style was specified, there's no .hg dir to
297# install a hook in, or there's no interactive terminal to prompt.
298if not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
299 style_hook = True
300 style_hooks = tuple()
301 hgrc = hgdir.File('hgrc')
302 hgrc_old = hgdir.File('hgrc.old')
293 try:
294 from mercurial import ui
295 ui = ui.ui()
303 try:
304 from mercurial import ui
305 ui = ui.ui()
296 ui.readconfig(hgdir.File('hgrc').abspath)
297 style_hook = ui.config('hooks', 'pretxncommit.style', None) and \
298 ui.config('hooks', 'pre-qrefresh.style', None)
306 ui.readconfig(hgrc.abspath)
307 style_hooks = (ui.config('hooks', 'pretxncommit.style', None),
308 ui.config('hooks', 'pre-qrefresh.style', None))
309 style_hook = all(style_hooks)
310 style_extension = ui.config('extensions', 'style', None)
299 except ImportError:
300 print mercurial_lib_not_found
301
311 except ImportError:
312 print mercurial_lib_not_found
313
302 if not style_hook:
314 if "python:style.check_style" in style_hooks:
315 # Try to upgrade the style hooks
316 print mercurial_style_upgrade_message
317 # continue unless user does ctrl-c/ctrl-d etc.
318 try:
319 raw_input()
320 except:
321 print "Input exception, exiting scons.\n"
322 sys.exit(1)
323 shutil.copyfile(hgrc.abspath, hgrc_old.abspath)
324 re_style_hook = re.compile(r"^([^=#]+)\.style\s*=\s*([^#\s]+).*")
325 re_style_extension = re.compile("style\s*=\s*([^#\s]+).*")
326 with open(hgrc_old.abspath, 'r') as old, \
327 open(hgrc.abspath, 'w') as new:
328
329 for l in old:
330 m_hook = re_style_hook.match(l)
331 m_ext = re_style_extension.match(l)
332 if m_hook:
333 hook, check = m_hook.groups()
334 if check != "python:style.check_style":
335 print "Warning: %s.style is using a non-default " \
336 "checker: %s" % (hook, check)
337 if hook not in ("pretxncommit", "pre-qrefresh"):
338 print "Warning: Updating unknown style hook: %s" % hook
339
340 l = "%s.style = python:hgstyle.check_style\n" % hook
341 elif m_ext and m_ext.group(1) == style_extension:
342 l = "hgstyle = %s/util/hgstyle.py\n" % main.root.abspath
343
344 new.write(l)
345 elif not style_hook:
303 print mercurial_style_message,
304 # continue unless user does ctrl-c/ctrl-d etc.
305 try:
306 raw_input()
307 except:
308 print "Input exception, exiting scons.\n"
309 sys.exit(1)
310 hgrc_path = '%s/.hg/hgrc' % main.root.abspath
311 print "Adding style hook to", hgrc_path, "\n"
312 try:
346 print mercurial_style_message,
347 # continue unless user does ctrl-c/ctrl-d etc.
348 try:
349 raw_input()
350 except:
351 print "Input exception, exiting scons.\n"
352 sys.exit(1)
353 hgrc_path = '%s/.hg/hgrc' % main.root.abspath
354 print "Adding style hook to", hgrc_path, "\n"
355 try:
313 hgrc = open(hgrc_path, 'a')
314 hgrc.write(mercurial_style_hook)
315 hgrc.close()
356 with open(hgrc_path, 'a') as f:
357 f.write(mercurial_style_hook)
316 except:
317 print "Error updating", hgrc_path
318 sys.exit(1)
319
320
321###################################################
322#
323# Figure out which configurations to set up based on the path(s) of

--- 1135 unchanged lines hidden ---
358 except:
359 print "Error updating", hgrc_path
360 sys.exit(1)
361
362
363###################################################
364#
365# Figure out which configurations to set up based on the path(s) of

--- 1135 unchanged lines hidden ---