diff options
author | Andreas Sandberg <Andreas.Sandberg@ARM.com> | 2015-02-03 14:25:50 -0500 |
---|---|---|
committer | Andreas Sandberg <Andreas.Sandberg@ARM.com> | 2015-02-03 14:25:50 -0500 |
commit | 9aad5b45690adae9f1208b6d3cc8dfc670d54543 (patch) | |
tree | 9d9fd4604b950747c296816c21fe1258fbbe91bd /util/style.py | |
parent | fe200c24875d7f9484b539add6d9e75df06720f4 (diff) | |
download | gem5-9aad5b45690adae9f1208b6d3cc8dfc670d54543.tar.xz |
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.
Diffstat (limited to 'util/style.py')
-rw-r--r-- | util/style.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/util/style.py b/util/style.py index 6ad0399ad..1c16682d7 100644 --- a/util/style.py +++ b/util/style.py @@ -158,11 +158,9 @@ class StdioUI(UserInterface): sys.stdout.write(string) class Verifier(object): - def __init__(self, ui, repo=None): + def __init__(self, ui, repo): self.ui = ui self.repo = repo - if repo is None: - self.wctx = None def __getattr__(self, attr): if attr in ('prompt', 'write'): @@ -180,8 +178,7 @@ class Verifier(object): raise AttributeError def open(self, filename, mode): - if self.repo: - filename = self.repo.wjoin(filename) + filename = self.repo.wjoin(filename) try: f = file(filename, mode) @@ -192,6 +189,8 @@ class Verifier(object): return f def skip(self, filename): + filename = self.repo.wjoin(filename) + # We never want to handle symlinks, so always skip them: If the location # pointed to is a directory, skip it. If the location is a file inside # the gem5 directory, it will be checked as a file, so symlink can be @@ -447,7 +446,7 @@ def do_check_style(hgui, repo, *pats, **opts): if result == 'a': return True elif result == 'f': - func(repo.wjoin(name), regions) + func(name, regions) return False @@ -476,18 +475,16 @@ def do_check_style(hgui, repo, *pats, **opts): else: files = [ (fn, all_regions) for fn in added + modified + clean ] - whitespace = Whitespace(ui) - sorted_includes = SortedIncludes(ui) + whitespace = Whitespace(ui, repo) + sorted_includes = SortedIncludes(ui, repo) for fname, mod_regions in files: if not opt_no_ignore and check_ignores(fname): continue - fpath = joinpath(repo.root, fname) - - if whitespace.apply(fpath, prompt, mod_regions): + if whitespace.apply(fname, prompt, mod_regions): return True - if sorted_includes.apply(fpath, prompt, mod_regions): + if sorted_includes.apply(fname, prompt, mod_regions): return True return False |