Removed astyle from webrtc_reformat since clang-format-chrome.py handles that now.

BUG=

Review URL: https://webrtc-codereview.appspot.com/1101009

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3519 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
phoglund@webrtc.org 2013-02-15 09:43:20 +00:00
parent 076fc12539
commit 17238576ba

View File

@ -10,43 +10,10 @@
"""WebRTC reformat script. """WebRTC reformat script.
This script is used to reformat WebRTC code from the old code style to Google This script is used to reformat WebRTC code from the old code style to Google
C++ code style. C++ code style. This script does not indent code; use clang-reformat-chrome.py
as described in go/webrtc/engineering/reformatting-gips---google.
You need to have astyle (http://astyle.sourceforge.net/) in your path. You also
need to put the following contents into ~/.astylerc:
# =======================COPY==============================================
# Google C++ style guide settings.
indent=spaces=2 # Indentation uses two spaces.
style=attach # Attach braces.
indent-switches
indent-preprocessor # Indent preprocessor continuation lines.
min-conditional-indent=0 # Align conditional continuation with "(".
# e.g. if (foo &&
# bar
max-instatement-indent=80 # Try not to mess with current alignment.
pad-oper # Padding around operators.
pad-header # Padding after if, for etc.
unpad-paren # No padding around parentheses.
align-pointer=type # e.g. int* foo
convert-tabs # Convert non-indentation tabs as well.
# The following are available in the unreleased svn repo.
# Behvaiour isn't quite what we'd like; more testing needed.
#max-code-length=80
#break-after-logical
lineend=linux
# =========================================================================
""" """
# TODO(mflodman)
# x s/type *var/type* var/g
# x : list indention -> 4 spaces.
__author__ = 'mflodman@webrtc.org (Magnus Flodman)' __author__ = 'mflodman@webrtc.org (Magnus Flodman)'
import fnmatch import fnmatch
@ -70,12 +37,6 @@ def DeCamelCase(text):
return text return text
def TrimLineEndings(text):
"""Removes trailing white spaces."""
pattern = re.compile(r'[ ]+(\n)')
return re.sub(pattern, r'\1', text)
def MoveUnderScore(text): def MoveUnderScore(text):
"""Moves the underscore from beginning of variable name to the end.""" """Moves the underscore from beginning of variable name to the end."""
# TODO(mflodman) Replace \1 with ?-expression. # TODO(mflodman) Replace \1 with ?-expression.
@ -91,12 +52,6 @@ def PostfixToPrefixInForLoops(text):
return re.sub(pattern, r'\1++\2)', text) return re.sub(pattern, r'\1++\2)', text)
def RemoveMultipleEmptyLines(text):
"""Remove all multiple blank lines."""
pattern = r'[\n]{3,}'
return re.sub(pattern, '\n\n', text)
def CPPComments(text): def CPPComments(text):
"""Remove all C-comments and replace with C++ comments.""" """Remove all C-comments and replace with C++ comments."""
@ -215,12 +170,6 @@ def AddWebrtcPrefixToOldSrcRelativePaths(text):
return re.sub(headers, AddWebrtcToOldSrcRelativePath, text) return re.sub(headers, AddWebrtcToOldSrcRelativePath, text)
def IndentLabels(text):
"""Indent public, protected and private one step (astyle doesn't)."""
pattern = re.compile('(?<=\n)(public:|protected:|private:)')
return re.sub(pattern, r' \1', text)
def FixIncludeGuards(text, file_name): def FixIncludeGuards(text, file_name):
"""Change include guard according to the stantard.""" """Change include guard according to the stantard."""
# Remove a possible webrtc/ from the path. # Remove a possible webrtc/ from the path.
@ -263,23 +212,14 @@ def main():
text = AddHeaderPath(text) text = AddHeaderPath(text)
text = AddWebrtcPrefixToOldSrcRelativePaths(text) text = AddWebrtcPrefixToOldSrcRelativePaths(text)
text = SortIncludeHeaders(text, filename) text = SortIncludeHeaders(text, filename)
text = RemoveMultipleEmptyLines(text)
text = TrimLineEndings(text)
# Remove the original file and re-create it with the reformatted content. # Remove the original file and re-create it with the reformatted content.
SaveFile(filename, text) SaveFile(filename, text)
# Fix tabs, indentation and '{' using astyle.
astyle_cmd = 'astyle'
if sys.platform == 'win32':
astyle_cmd += '.exe'
subprocess.call([astyle_cmd, '-n', '-q', filename])
if filename.endswith('.h'): if filename.endswith('.h'):
f = open(filename) f = open(filename)
text = f.read() text = f.read()
f.close() f.close()
text = IndentLabels(text)
text = FixIncludeGuards(text, filename) text = FixIncludeGuards(text, filename)
SaveFile(filename, text) SaveFile(filename, text)