History log of /gem5/util/style.py
Revision Date Author Comments
# 13540:da30e62884ee 10-Jan-2019 Andrea Mondelli <andrea.mondelli@ucf.edu>

misc: updated shabang for python script

The default python on MacOS doesn’t have an alias to python2.
The official python version supported in gem5 is Python2.7.

This patch updates the shabang according to the version required in gem5.

Change-Id: I9533c0f7858b5b3cab0ef101be1ee5cd718105b0
Reviewed-on: https://gem5-review.googlesource.com/c/15375
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>


# 11828:36b064696175 10-Feb-2017 Jason Lowe-Power <jason@lowepower.com>

misc: Update #!env calls for python to explicit version

In some newer Linux distributions, env python default to Python 3.0. This
patch explicitly uses "python2" instead of just "python" for all scripts
that use #!

Reported-by: Sanchayan Maity <maitysanchayan@gmail.com>
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>


# 11717:27622f94fdcc 25-Nov-2016 Andreas Sandberg <andreas.sandberg@arm.com>

style: Add options to select checkers and apply fixes

Add an option, --checker/-c, to style.py that selects individual style
checkers to apply. When this option isn't specified, the script
defaults to all available style checkers. The option may be specified
multiple times to run multiple style checkers.

The option, --fix/-f, can be specified to automatically fix style
violations.

Change-Id: Id7597fba6b65cecfa17a88b1c87c8a4c8315af59
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Andreas Hansson <andreas.hansson@arm.com>


# 11409:72f80dd8b194 30-Mar-2016 Andreas Sandberg <andreas.sandberg@arm.com>

style: Add a style checker that doesn't depend on Mercurial

The current style checker script, hgstyle.py, assumes that it is being
run from Mercurial. This means that it depends on the Mercurial Python
libraries, which aren't necessarily present if using git. This
changeset adds a new style checker script, style.py, that has
been designed to be run from the command line.

The script has support for detecting which revision control system is
used and is able to query both git and Mercurial for changes. This
enables the script to operate on modified regions and/or all of the
modified files in the repository.

Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-by: Steve Reinhardt <steve.reinhardt@amd.com>


# 11401:55f9a21e34b4 30-Mar-2016 Andreas Sandberg <andreas.sandberg@arm.com>

scons, style: Rename style.py to hgstyle.py

The Mercurial style checker extensions are currently stored in
style.py. This is not ideal since they won't work with other version
control systems. This changeset renames style.py to hgstyle.py and
adds upgrade code to scons that automatically updates the hooks in
hgrc.

Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-by: Nathanael Premillieu <nathananel.premillieu@arm.com>
Reviewed-by: Steve Reinhardt <steve.reinhardt@amd.com>


# 11400:21ce6f5d4613 30-Mar-2016 Andreas Sandberg <andreas.sandberg@arm.com>

style: Remove unsupported style.py commands

Remove the unsupported style.py subcommands (fixwhite, chkwhite),
which leaves the chkformat command as the only remaining
command. Since the script now only supports one command, remove the
sub-command support altogether.

Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-by: Nathanael Premillieu <nathananel.premillieu@arm.com>


# 11396:ddfc7795d8f8 24-Mar-2016 Andreas Sandberg <andreas.sandberg@arm.com>

style: Strip newline when checking lines

The style checker incorrectly includes newlines when checking lines of
code, which effectively decreases the column limit by 1. This
changeset strips the newline character from before calling line
checkers.

Change-Id: I0a8c7707ece57d782d11cc86db4b8064db291ce0
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>


# 11322:01b16bab6675 06-Feb-2016 Steve Reinhardt <steve.reinhardt@amd.com>

util: added line length and boolean comparison style checkers

Added checkers for line length and boolean comparisons
(== true/== false) to the style script.


# 11319:7ca84595249c 06-Feb-2016 Steve Reinhardt <steve.reinhardt@amd.com>

util: clean up and extend style checker

Added a new Verifier object to check for and fix spacing
between if/while/for and following paren.

Restructured Verifier class to make it easier to add
new subclasses, particularly by using a global list of
verifiers to auto-generate command line options and
simplify the invocation loop.


# 10692:ab81a0feab55 11-Feb-2015 Andreas Sandberg <Andreas.Sandberg@ARM.com>

style: Fix broken m5format command

The m5format command didn't actually work due to parameter handling
issues and missing language detection. This changeset fixes those
issues and cleans up some of the code to shared between the style
checker and the format checker.


# 10691:65da28dee7cf 11-Feb-2015 Andreas Sandberg <Andreas.Sandberg@ARM.com>

style: Fix incorrect style checker option name

The style used to support the option -w to automatically fix white
space issues. However, this option was actually wired up to fix all
styles issues the checker encountered. This changeset cleans up the
code that handles automatic fixing and adds an option to fix all
issues, and separate options for white spaces and include ordering.


# 10674:e2f9644a7738 03-Feb-2015 Andreas Sandberg <Andreas.Sandberg@ARM.com>

style: Update the style checker to handle new include order

As of August 2014, the gem5 style guide mandates that a source file's
primary header is included first in that source file. This helps to
ensure that the header file does not depend on include file ordering
and avoids surprises down the road when someone tries to reuse code.

In the new order, include files are grouped into the following blocks:
* Primary header file (e.g., foo.hh for foo.cc)
* Python headers
* C system/stdlib includes
* C++ stdlib includes
* Include files in the gem5 source tree

Just like before, include files within a block are required to be
sorted in alphabetical order.

This changeset updates the style checker to enforce the new order.


# 10294:b58f6afe14c5 26-Aug-2014 Andreas Sandberg <Andreas.Sandberg@ARM.com>

style: Add support for a style ignore list and ignore ext/

There are some directories within the repository where we don't want
to enforce our coding style. Specifically, we don't want the style
hooks to warn whenever we update external code in the ext/ directory.


# 10293:62c95c428a3d 26-Aug-2014 Andreas Sandberg <Andreas.Sandberg@ARM.com>

style: Fixup strange semantics in hg m5style

The 'hg m5style' command had some rather strange semantics. When
called without arguments, it applied the style checker to all added
files and modified regions of modified files. However, when providing
a list of files, it used that list as an ignore list instead of
specifically checking those files.

This patch makes the m5style command behave more like other Mercurial
commands where the arguments are used to specify which files to work
on instead of which files to ignore.


# 10237:b2850bdcec07 09-Jun-2014 Joel Hestness <jthestness@gmail.com>

Util: Do not style check symlinks

The style checker used to traverse symlinks if they pointed to files, which can
result in style checker failure if the pointed-to file doesn't exist. This
style check is actually unnecessary, since symlinks either point to other files
that are already style checked, or files outside gem5, which shouldn't be
checked. Skip symlinks.


# 9135:64d4c9d8a384 27-Jul-2012 Nathanael Premillieu <npremill@irisa.fr>

util: Fix issues with style checker.


# 9081:bbb0132f0369 29-Jun-2012 Matt Evans <matt.evans@arm.com>

Style: Make style.py's invalid warning print which file caused the infraction.


# 8583:d182a475a668 24-Sep-2011 Steve Reinhardt <steve.reinhardt@amd.com>

style.py: don't die on empty files


# 8326:8b0eee09deaf 25-May-2011 Nathan Binkert <nate@binkert.org>

style: Make the style hook work in directories other than the root.


# 8238:d8ec0a7b3f0c 17-Apr-2011 Nathan Binkert <nate@binkert.org>

style: fix all_regions code and remove bogus region type


# 8237:b83e07b4541d 17-Apr-2011 Nathan Binkert <nate@binkert.org>

style: remove extra debugging print


# 8228:59d3bfa85f16 15-Apr-2011 Nathan Binkert <nate@binkert.org>

style: add sort_includes to the style hook


# 8227:f3aaa2470b5a 15-Apr-2011 Nathan Binkert <nate@binkert.org>

style: move style verifiers into classes


# 8226:bca419132437 15-Apr-2011 Nathan Binkert <nate@binkert.org>

style: add a user interface wrapper class
makes things work both with mercurial and stand alone with stdio


# 7834:7107a2f3e53a 13-Jan-2011 Gabe Black <gblack@eecs.umich.edu>

Style checker: Fix a couple bugs in style.py.


# 7828:817c662677d1 10-Jan-2011 Nathan Binkert <nate@binkert.org>

style: prevent the style hook from aborting uncleanly because of an exception


# 7827:49b7d40ee88a 10-Jan-2011 Nathan Binkert <nate@binkert.org>

style: clean up style hook code a bit

I've renamed the check_whitespace operation to check_style. You're going to
need to change your .hg/hgrc file. While you're at it, add a pre-qrefresh
hook please.


# 7807:15553b536bd6 30-Dec-2010 Nathan Binkert <nate@binkert.org>

style: make style hook work with pre-qrefresh and update to use new code
clean up the code a little bit while we're at it.

I recommend that everyone adds the pre-qrefresh hook below since it
will make qref run the style hook and not just commit/qpush

[extensions]
style = <m5 path>/util/style.py

[hooks]
pretxncommit.style = python:style.check_whitespace
pre-qrefresh.style = python:style.check_whitespace


# 6868:c7eb55c68529 23-Jan-2010 Nathan Binkert <nate@binkert.org>

style_hook: Fix the style hook
Re-enable it and update it for more modern versions of mercurial.


# 6846:60e0df8086f0 17-Sep-2009 Polina Dudnik <pdudnik@cs.wisc.edu>

Functionality migrated to sequencer.


# 6825:104115ebc206 21-Aug-2009 pdudnik@gmail.com

[mq]: first_patch


# 6021:6df0633d883b 09-Apr-2009 Nathan Binkert <nate@binkert.org>

style: fix style hook for some newer versions of mercurial.


# 5792:72c3f3e914c1 13-Jan-2009 Ali Saidi <saidi@eecs.umich.edu>

Fix style hook for Mercurial >= 1.1


# 5747:ffded3077c63 15-Nov-2008 Clint Smullen <cws3k@cs.virginia.edu>

Remove the pointless, repository destroying assertion and just have the script check every line in the file if it cannot get context information.


# 5465:4cff095bbf2b 14-Jun-2008 Nathan Binkert <nate@binkert.org>

Add hg commands for style check so you can check at times other than commit


# 5309:4d3a6e086488 11-Dec-2007 Steve Reinhardt <stever@gmail.com>

Fix minor bug in util/style.py


# 4984:1cbcac3f8144 21-Aug-2007 Nathan Binkert <nate@binkert.org>

style: fix style hook when run from a repo subdir.
Before this fix, the style hook would blow up when you did a qrefresh to add
a new file, but executed the qrefresh from a repository sub directory.


# 4980:b386c80ceb05 14-Aug-2007 Nathan Binkert <nate@binkert.org>

style: Don't try to fix files that should be ignored.
The style hook was ignoring new files, but processing all modified
files.


# 4794:88afe390fc0f 29-Jul-2007 Gabe Black <gblack@eecs.umich.edu>

Merge with head. style.py was also missing an argument in one call to modified_lines.


# 4784:e8b1f87b3a85 29-Jul-2007 Nathan Binkert <nate@binkert.org>

Work around a mercurial bug in bdiff.blocks


# 4782:50a634ae064a 28-Jul-2007 Nathan Binkert <nate@binkert.org>

style: fix stupid bugs


# 4781:59a75bd0ddf4 28-Jul-2007 Nathan Binkert <nate@binkert.org>

style: Check/Fix whitespace on SCons files


# 4761:4bb357497886 23-Jul-2007 Nathan Binkert <nate@binkert.org>

Allow the fixwhite stuff to work when committing from a subdir


# 4745:33b409225928 22-Jul-2007 Nathan Binkert <nate@binkert.org>

do proper style checks for merged files


# 4744:4a08d0c0f929 22-Jul-2007 Nathan Binkert <nate@binkert.org>

fix the style fixing thing


# 4678:fd95d7ddd1ee 22-Jul-2007 Nathan Binkert <nate@binkert.org>

Add code to turn the style stuff into a mercurial hook.
Nag the user during compile if they have an hg cloned copy of M5, have
mercurial installed, but don't have the style hook enabled.