Will now fix old src-relative paths so we go to webrtc/ paths.
We used to write paths relative to src, e.g. starting with video_engine/ etc, but now it should be webrtc/video_engine/. This script will now get that right. BUG= Review URL: https://webrtc-codereview.appspot.com/970006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3154 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
97dcf36a7b
commit
e3b2bc6c40
@ -141,9 +141,7 @@ def SortIncludeHeaders(text, filename):
|
|||||||
project_includes = []
|
project_includes = []
|
||||||
self_include = ''
|
self_include = ''
|
||||||
sys_pattern = re.compile('#include <')
|
sys_pattern = re.compile('#include <')
|
||||||
h_filename = re.sub(r'(\.cc)', r'.h', filename)
|
h_filename, _ = os.path.splitext(os.path.basename(filename))
|
||||||
# Remove a possible webrtc/ from the filename.
|
|
||||||
h_filename = re.sub(r'(webrtc\/)(.+)', r'\2', h_filename)
|
|
||||||
|
|
||||||
for item in includes:
|
for item in includes:
|
||||||
if re.search(h_filename, item):
|
if re.search(h_filename, item):
|
||||||
@ -175,25 +173,40 @@ def SortIncludeHeaders(text, filename):
|
|||||||
return return_text
|
return return_text
|
||||||
|
|
||||||
|
|
||||||
def AddPath(obj):
|
def AddPath(match):
|
||||||
"""Helper for adding file path for WebRTC header files, ignoring other."""
|
"""Helper for adding file path for WebRTC header files, ignoring other."""
|
||||||
file_name = obj.group(1) + '.h'
|
file_to_examine = match.group(1) + '.h'
|
||||||
# TODO(mflodman) Use current directory and find src.
|
# TODO(mflodman) Use current directory and find webrtc/.
|
||||||
for path, _, files in os.walk('./webrtc'):
|
for path, _, files in os.walk('./webrtc'):
|
||||||
for filename in files:
|
for filename in files:
|
||||||
if fnmatch.fnmatch(filename, file_name):
|
if fnmatch.fnmatch(filename, file_to_examine):
|
||||||
# Remove leading '/webrtc'
|
path_name = os.path.join(path, filename).replace('./', '')
|
||||||
path_name = os.path.join(path, filename)
|
return '#include "%s"\n' % path_name
|
||||||
return re.sub('(.+)(?<=webrtc/)(.+)', r'#include "\2"\n', path_name)
|
|
||||||
|
|
||||||
# No path found, return original string.
|
# No path found, return original string.
|
||||||
return '#include "'+ file_name + '"\n'
|
return '#include "'+ file_to_examine + '"\n'
|
||||||
|
|
||||||
|
|
||||||
def AddHeaderPath(text):
|
def AddHeaderPath(text):
|
||||||
"""Add path to all included header files."""
|
"""Add path to all included header files that have no path yet."""
|
||||||
hdr_name = re.compile('#include "(.+).h"\n')
|
headers = re.compile('#include "(.+).h"\n')
|
||||||
return re.sub(hdr_name, AddPath, text)
|
return re.sub(headers, AddPath, text)
|
||||||
|
|
||||||
|
|
||||||
|
def AddWebrtcToOldSrcRelativePath(match):
|
||||||
|
file_to_examine = match.group(1) + '.h'
|
||||||
|
path, filename = os.path.split(file_to_examine)
|
||||||
|
dirs_in_webrtc = [name for name in os.listdir('./webrtc')
|
||||||
|
if os.path.isdir(os.path.join('./webrtc', name))]
|
||||||
|
for dir_in_webrtc in dirs_in_webrtc:
|
||||||
|
if path.startswith(dir_in_webrtc):
|
||||||
|
return '#include "%s"\n' % os.path.join('webrtc', path, filename)
|
||||||
|
return '#include "%s"\n' % file_to_examine
|
||||||
|
|
||||||
|
def AddWebrtcPrefixToOldSrcRelativePaths(text):
|
||||||
|
"""For all paths starting with for instance video_engine, add webrtc/."""
|
||||||
|
headers = re.compile('#include "(.+).h"\n')
|
||||||
|
return re.sub(headers, AddWebrtcToOldSrcRelativePath, text)
|
||||||
|
|
||||||
|
|
||||||
def IndentLabels(text):
|
def IndentLabels(text):
|
||||||
@ -241,6 +254,7 @@ def main():
|
|||||||
text = MoveUnderScore(text)
|
text = MoveUnderScore(text)
|
||||||
text = CPPComments(text)
|
text = CPPComments(text)
|
||||||
text = AddHeaderPath(text)
|
text = AddHeaderPath(text)
|
||||||
|
text = AddWebrtcPrefixToOldSrcRelativePaths(text)
|
||||||
text = SortIncludeHeaders(text, filename)
|
text = SortIncludeHeaders(text, filename)
|
||||||
text = RemoveMultipleEmptyLines(text)
|
text = RemoveMultipleEmptyLines(text)
|
||||||
text = TrimLineEndings(text)
|
text = TrimLineEndings(text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user