1# -*- mode:python -*-
2
3# Copyright (c) 2013, 2015, 2016 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

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

255# Mercurial Stuff.
256#
257# If the gem5 directory is a mercurial repository, we should do some
258# extra things.
259#
260########################################################################
261
262hgdir = main.root.Dir(".hg")
263gitdir = main.root.Dir(".git")
263
264
265style_message = """
266You're missing the gem5 style hook, which automatically checks your code
267against the gem5 style rules on %s.
268This script will now install the hook in your %s.
269Press enter to continue, or ctrl-c to abort: """
270

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

362 print "Adding style hook to", hgrc_path, "\n"
363 try:
364 with open(hgrc_path, 'a') as f:
365 f.write(mercurial_style_hook)
366 except:
367 print "Error updating", hgrc_path
368 sys.exit(1)
369
371# Try to wire up git to the style hooks
372git_pre_commit_hook = gitdir.File("hooks/pre-commit")
373if not ignore_style and gitdir.exists() and not git_pre_commit_hook.exists():
370def install_git_style_hooks():
371 try:
372 gitdir = Dir(readCommand(
373 ["git", "rev-parse", "--git-dir"]).strip("\n"))
374 except Exception, e:
375 print "Warning: Failed to find git repo directory: %s" % e
376 return
377
378 git_hooks = gitdir.Dir("hooks")
379 git_pre_commit_hook = git_hooks.File("pre-commit")
380 git_style_script = File("util/git-pre-commit.py")
381
382 if git_pre_commit_hook.exists():
383 return
384
385 print git_style_message,
386 try:
387 raw_input()
388 except:
389 print "Input exception, exiting scons.\n"
390 sys.exit(1)
391
383 try:
384 rel_style_script = os.path.relpath(
392 if not git_hooks.exists():
393 mkdir(git_hooks.get_abspath())
394
395 # Use a relative symlink if the hooks live in the source directory
396 if git_pre_commit_hook.is_under(main.root):
397 script_path = os.path.relpath(
398 git_style_script.get_abspath(),
399 git_pre_commit_hook.Dir(".").get_abspath())
387 os.symlink(rel_style_script, git_pre_commit_hook.get_abspath())
400 else:
401 script_path = git_style_script.get_abspath()
402
403 try:
404 os.symlink(script_path, git_pre_commit_hook.get_abspath())
405 except:
406 print "Error updating git pre-commit hook"
407 raise
391 sys.exit(1)
408
409# Try to wire up git to the style hooks
410if not ignore_style and main.root.Entry(".git").exists():
411 install_git_style_hooks()
412
413###################################################
414#
415# Figure out which configurations to set up based on the path(s) of
416# the target(s).
417#
418###################################################
419
420# Find default configuration & binary.

--- 1130 unchanged lines hidden ---