summaryrefslogtreecommitdiffstats
path: root/tools/clang
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-04 17:48:18 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-04 17:48:18 +0000
commit8da5890fa9c662875c01e5b8b048c9d73b7c285e (patch)
tree5dd46a0726673e187e2b4bdd3665c1d40024a15b /tools/clang
parent56c07272c32cd7266d0dc8ef200439d8c3583043 (diff)
downloadchromium_src-8da5890fa9c662875c01e5b8b048c9d73b7c285e.zip
chromium_src-8da5890fa9c662875c01e5b8b048c9d73b7c285e.tar.gz
chromium_src-8da5890fa9c662875c01e5b8b048c9d73b7c285e.tar.bz2
Have run_tool.py automatically invoke clang-format-diff.py if available.
This makes for nicer code and removes the extra post-processing step. It also provides more granular warnings; simply returning the formatter across the entire diff will provide cryptic errors like missing { at line 540. BUG= Review URL: https://codereview.chromium.org/13605003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192359 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/clang')
-rw-r--r--tools/clang/empty_string/tests/test-expected.cc13
-rwxr-xr-xtools/clang/scripts/run_tool.py22
2 files changed, 24 insertions, 11 deletions
diff --git a/tools/clang/empty_string/tests/test-expected.cc b/tools/clang/empty_string/tests/test-expected.cc
index e915625..7fd9613 100644
--- a/tools/clang/empty_string/tests/test-expected.cc
+++ b/tools/clang/empty_string/tests/test-expected.cc
@@ -12,17 +12,17 @@ void TestDeclarations() { std::string a, b("abc"), c; }
// Tests for std::string allocated with new.
void TestNew() {
std::string* a = new std::string,
- *b = new std::string("abc"),
- *c = new std::string,
- *d = new std::string();
+ *b = new std::string("abc"),
+ *c = new std::string,
+ *d = new std::string();
}
// Tests for std::string construction in initializer lists.
class TestInitializers {
public:
- TestInitializers() {}
- TestInitializers(bool) {}
- TestInitializers(double) : b("cat"), c() {}
+ TestInitializers() {}
+ TestInitializers(bool) {}
+ TestInitializers(double) : b("cat"), c() {}
private:
std::string a;
@@ -43,4 +43,3 @@ void TestWideTemporaries(const std::wstring& reference_argument,
TestWideTemporaries(std::wstring(), std::wstring());
TestWideTemporaries(std::wstring(), std::wstring());
}
-
diff --git a/tools/clang/scripts/run_tool.py b/tools/clang/scripts/run_tool.py
index 597c825..903235d 100755
--- a/tools/clang/scripts/run_tool.py
+++ b/tools/clang/scripts/run_tool.py
@@ -183,11 +183,14 @@ class _CompilerDispatcher(object):
sys.stdout.flush()
-def _ApplyEdits(edits):
+def _ApplyEdits(edits, clang_format_diff_path):
"""Apply the generated edits.
Args:
edits: A dict mapping filenames to Edit instances that apply to that file.
+ clang_format_diff_path: Path to the clang-format-diff.py helper to help
+ automatically reformat diffs to avoid style violations. Pass None if the
+ clang-format step should be skipped.
"""
edit_count = 0
for k, v in edits.iteritems():
@@ -210,6 +213,10 @@ def _ApplyEdits(edits):
f.seek(0)
f.truncate()
f.write(contents)
+ if clang_format_diff_path:
+ if subprocess.call('git diff -U0 %s | python %s -style=Chromium' % (
+ k, clang_format_diff_path), shell=True) != 0:
+ print 'clang-format failed for %s' % k
print 'Applied %d edits to %d files' % (edit_count, len(edits))
@@ -266,6 +273,14 @@ def main(argv):
print ' <path 1> <path2> ... can be used to filter what files are edited'
return 1
+ clang_format_diff_path = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ '../../../third_party/llvm/tools/clang/tools/clang-format',
+ 'clang-format-diff.py')
+ # TODO(dcheng): Allow this to be controlled with a flag as well.
+ if not os.path.isfile(clang_format_diff_path):
+ clang_format_diff_path = None
+
filenames = frozenset(_GetFilesFromGit(argv[2:]))
# Filter out files that aren't C/C++/Obj-C/Obj-C++.
extensions = frozenset(('.c', '.cc', '.m', '.mm'))
@@ -277,9 +292,8 @@ def main(argv):
# useful to modify files that aren't under source control--typically, these
# are generated files or files in a git submodule that's not part of Chromium.
_ApplyEdits({k : v for k, v in dispatcher.edits.iteritems()
- if k in filenames})
- # TODO(dcheng): Consider clang-formatting the result to avoid egregious style
- # violations.
+ if k in filenames},
+ clang_format_diff_path)
if dispatcher.failed_count != 0:
return 2
return 0