SConstruct (12243:c56b7387cddc) SConstruct (12244:33af7397d081)
1# -*- mode:python -*-
2
3# Copyright (c) 2013, 2015-2017 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

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

191if not ('CC' in main_dict_keys and 'CXX' in main_dict_keys):
192 print "No C++ compiler installed (package g++ on Ubuntu and RedHat)"
193 Exit(1)
194
195# add useful python code PYTHONPATH so it can be used by subprocesses
196# as well
197main.AppendENVPath('PYTHONPATH', extra_python_paths)
198
1# -*- mode:python -*-
2
3# Copyright (c) 2013, 2015-2017 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

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

191if not ('CC' in main_dict_keys and 'CXX' in main_dict_keys):
192 print "No C++ compiler installed (package g++ on Ubuntu and RedHat)"
193 Exit(1)
194
195# add useful python code PYTHONPATH so it can be used by subprocesses
196# as well
197main.AppendENVPath('PYTHONPATH', extra_python_paths)
198
199########################################################################
200#
201# Mercurial Stuff.
202#
203# If the gem5 directory is a mercurial repository, we should do some
204# extra things.
205#
206########################################################################
207
208hgdir = main.root.Dir(".hg")
209
210
211style_message = """
212You're missing the gem5 style hook, which automatically checks your code
213against the gem5 style rules on %s.
214This script will now install the hook in your %s.
215Press enter to continue, or ctrl-c to abort: """
216
217mercurial_style_message = """
218You're missing the gem5 style hook, which automatically checks your code
219against the gem5 style rules on hg commit and qrefresh commands.
220This script will now install the hook in your .hg/hgrc file.
221Press enter to continue, or ctrl-c to abort: """
222
223git_style_message = """
224You're missing the gem5 style or commit message hook. These hooks help
225to ensure that your code follows gem5's style rules on git commit.
226This script will now install the hook in your .git/hooks/ directory.
227Press enter to continue, or ctrl-c to abort: """
228
229mercurial_style_upgrade_message = """
230Your Mercurial style hooks are not up-to-date. This script will now
231try to automatically update them. A backup of your hgrc will be saved
232in .hg/hgrc.old.
233Press enter to continue, or ctrl-c to abort: """
234
235mercurial_style_hook = """
236# The following lines were automatically added by gem5/SConstruct
237# to provide the gem5 style-checking hooks
238[extensions]
239hgstyle = %s/util/hgstyle.py
240
241[hooks]
242pretxncommit.style = python:hgstyle.check_style
243pre-qrefresh.style = python:hgstyle.check_style
244# End of SConstruct additions
245
246""" % (main.root.abspath)
247
248mercurial_lib_not_found = """
249Mercurial libraries cannot be found, ignoring style hook. If
250you are a gem5 developer, please fix this and run the style
251hook. It is important.
252"""
253
254# Check for style hook and prompt for installation if it's not there.
255# Skip this if --ignore-style was specified, there's no interactive
256# terminal to prompt, or no recognized revision control system can be
257# found.
258ignore_style = GetOption('ignore_style') or not sys.stdin.isatty()
259
260# Try wire up Mercurial to the style hooks
261if not ignore_style and hgdir.exists():
262 style_hook = True
263 style_hooks = tuple()
264 hgrc = hgdir.File('hgrc')
265 hgrc_old = hgdir.File('hgrc.old')
266 try:
267 from mercurial import ui
268 ui = ui.ui()
269 ui.readconfig(hgrc.abspath)
270 style_hooks = (ui.config('hooks', 'pretxncommit.style', None),
271 ui.config('hooks', 'pre-qrefresh.style', None))
272 style_hook = all(style_hooks)
273 style_extension = ui.config('extensions', 'style', None)
274 except ImportError:
275 print mercurial_lib_not_found
276
277 if "python:style.check_style" in style_hooks:
278 # Try to upgrade the style hooks
279 print mercurial_style_upgrade_message
280 # continue unless user does ctrl-c/ctrl-d etc.
281 try:
282 raw_input()
283 except:
284 print "Input exception, exiting scons.\n"
285 sys.exit(1)
286 shutil.copyfile(hgrc.abspath, hgrc_old.abspath)
287 re_style_hook = re.compile(r"^([^=#]+)\.style\s*=\s*([^#\s]+).*")
288 re_style_extension = re.compile("style\s*=\s*([^#\s]+).*")
289 old, new = open(hgrc_old.abspath, 'r'), open(hgrc.abspath, 'w')
290 for l in old:
291 m_hook = re_style_hook.match(l)
292 m_ext = re_style_extension.match(l)
293 if m_hook:
294 hook, check = m_hook.groups()
295 if check != "python:style.check_style":
296 print "Warning: %s.style is using a non-default " \
297 "checker: %s" % (hook, check)
298 if hook not in ("pretxncommit", "pre-qrefresh"):
299 print "Warning: Updating unknown style hook: %s" % hook
300
301 l = "%s.style = python:hgstyle.check_style\n" % hook
302 elif m_ext and m_ext.group(1) == style_extension:
303 l = "hgstyle = %s/util/hgstyle.py\n" % main.root.abspath
304
305 new.write(l)
306 elif not style_hook:
307 print mercurial_style_message,
308 # continue unless user does ctrl-c/ctrl-d etc.
309 try:
310 raw_input()
311 except:
312 print "Input exception, exiting scons.\n"
313 sys.exit(1)
314 hgrc_path = '%s/.hg/hgrc' % main.root.abspath
315 print "Adding style hook to", hgrc_path, "\n"
316 try:
317 with open(hgrc_path, 'a') as f:
318 f.write(mercurial_style_hook)
319 except:
320 print "Error updating", hgrc_path
321 sys.exit(1)
322
323def install_git_style_hooks():
324 try:
325 gitdir = Dir(readCommand(
326 ["git", "rev-parse", "--git-dir"]).strip("\n"))
327 except Exception, e:
328 print "Warning: Failed to find git repo directory: %s" % e
329 return
330
331 git_hooks = gitdir.Dir("hooks")
332 def hook_exists(hook_name):
333 hook = git_hooks.File(hook_name)
334 return hook.exists()
335
336 def hook_install(hook_name, script):
337 hook = git_hooks.File(hook_name)
338 if hook.exists():
339 print "Warning: Can't install %s, hook already exists." % hook_name
340 return
341
342 if hook.islink():
343 print "Warning: Removing broken symlink for hook %s." % hook_name
344 os.unlink(hook.get_abspath())
345
346 if not git_hooks.exists():
347 mkdir(git_hooks.get_abspath())
348 git_hooks.clear()
349
350 abs_symlink_hooks = git_hooks.islink() and \
351 os.path.isabs(os.readlink(git_hooks.get_abspath()))
352
353 # Use a relative symlink if the hooks live in the source directory,
354 # and the hooks directory is not a symlink to an absolute path.
355 if hook.is_under(main.root) and not abs_symlink_hooks:
356 script_path = os.path.relpath(
357 os.path.realpath(script.get_abspath()),
358 os.path.realpath(hook.Dir(".").get_abspath()))
359 else:
360 script_path = script.get_abspath()
361
362 try:
363 os.symlink(script_path, hook.get_abspath())
364 except:
365 print "Error updating git %s hook" % hook_name
366 raise
367
368 if hook_exists("pre-commit") and hook_exists("commit-msg"):
369 return
370
371 print git_style_message,
372 try:
373 raw_input()
374 except:
375 print "Input exception, exiting scons.\n"
376 sys.exit(1)
377
378 git_style_script = File("util/git-pre-commit.py")
379 git_msg_script = File("ext/git-commit-msg")
380
381 hook_install("pre-commit", git_style_script)
382 hook_install("commit-msg", git_msg_script)
383
384# Try to wire up git to the style hooks
385if not ignore_style and main.root.Entry(".git").exists():
386 install_git_style_hooks()
387
388###################################################
389#
390# Figure out which configurations to set up based on the path(s) of
391# the target(s).
392#
393###################################################
394
395# Find default configuration & binary.

--- 1108 unchanged lines hidden ---
199###################################################
200#
201# Figure out which configurations to set up based on the path(s) of
202# the target(s).
203#
204###################################################
205
206# Find default configuration & binary.

--- 1108 unchanged lines hidden ---