mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Fixing check_orphan_headers on Windows
There were too many assumptions of the fact that the check was running on Linux. BUG=webrtc:7635 NOTRY=True Review-Url: https://codereview.webrtc.org/2878733004 Cr-Commit-Position: refs/heads/master@{#18120}
This commit is contained in:
parent
cdcc6b3fe6
commit
26c26345c3
3 changed files with 43 additions and 19 deletions
|
@ -575,10 +575,7 @@ def _CommonChecks(input_api, output_api):
|
|||
results.extend(_CheckJSONParseErrors(input_api, output_api))
|
||||
results.extend(_RunPythonTests(input_api, output_api))
|
||||
results.extend(_CheckUsageOfGoogleProtobufNamespace(input_api, output_api))
|
||||
# Disabling this because it seems to have a bug when running on Windows.
|
||||
# TODO(mbonadei): fix this and re-enable this check.
|
||||
# BUG: https://bugs.chromium.org/p/webrtc/issues/detail?id=7635
|
||||
# results.extend(_CheckOrphanHeaders(input_api, output_api))
|
||||
results.extend(_CheckOrphanHeaders(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
import os
|
||||
import re
|
||||
import string
|
||||
|
||||
|
||||
# TARGET_RE matches a GN target, and extracts the target name and the contents.
|
||||
|
@ -112,5 +113,8 @@ def GetHeadersInBuildGnFileSources(file_content, target_abs_path):
|
|||
for source_file_match in SOURCE_FILE_RE.finditer(sources):
|
||||
source_file = source_file_match.group('source_file')
|
||||
if source_file.endswith('.h'):
|
||||
headers_in_sources.add(os.path.join(target_abs_path, source_file))
|
||||
source_file_tokens = string.split(source_file, '/')
|
||||
# pylint: disable=star-args
|
||||
headers_in_sources.add(os.path.join(target_abs_path,
|
||||
*source_file_tokens))
|
||||
return headers_in_sources
|
||||
|
|
|
@ -7,18 +7,34 @@
|
|||
# in the file PATENTS. All contributing project authors may
|
||||
# be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import check_orphan_headers
|
||||
|
||||
|
||||
def _GetRootBasedOnPlatform():
|
||||
if sys.platform.startswith('win'):
|
||||
return 'C:\\'
|
||||
else:
|
||||
return '/'
|
||||
|
||||
|
||||
def _GetPath(*path_chunks):
|
||||
return os.path.join(_GetRootBasedOnPlatform(),
|
||||
*path_chunks)
|
||||
|
||||
|
||||
class GetBuildGnPathFromFilePathTest(unittest.TestCase):
|
||||
|
||||
def testGetBuildGnFromSameDirectory(self):
|
||||
file_path = '/home/projects/webrtc/base/foo.h'
|
||||
expected_build_path = '/home/projects/webrtc/base/BUILD.gn'
|
||||
file_exists = lambda p: p == '/home/projects/webrtc/base/BUILD.gn'
|
||||
src_dir_path = '/home/projects/webrtc'
|
||||
file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.h')
|
||||
expected_build_path = _GetPath('home', 'projects', 'webrtc', 'base',
|
||||
'BUILD.gn')
|
||||
file_exists = lambda p: p == _GetPath('home', 'projects', 'webrtc',
|
||||
'base', 'BUILD.gn')
|
||||
src_dir_path = _GetPath('home', 'projects', 'webrtc')
|
||||
self.assertEqual(
|
||||
expected_build_path,
|
||||
check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
|
||||
|
@ -26,10 +42,12 @@ class GetBuildGnPathFromFilePathTest(unittest.TestCase):
|
|||
src_dir_path))
|
||||
|
||||
def testGetBuildPathFromParentDirectory(self):
|
||||
file_path = '/home/projects/webrtc/base/foo.h'
|
||||
expected_build_path = '/home/projects/webrtc/BUILD.gn'
|
||||
file_exists = lambda p: p == '/home/projects/webrtc/BUILD.gn'
|
||||
src_dir_path = '/home/projects/webrtc'
|
||||
file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.h')
|
||||
expected_build_path = _GetPath('home', 'projects', 'webrtc',
|
||||
'BUILD.gn')
|
||||
file_exists = lambda p: p == _GetPath('home', 'projects', 'webrtc',
|
||||
'BUILD.gn')
|
||||
src_dir_path = _GetPath('home', 'projects', 'webrtc')
|
||||
self.assertEqual(
|
||||
expected_build_path,
|
||||
check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
|
||||
|
@ -38,18 +56,18 @@ class GetBuildGnPathFromFilePathTest(unittest.TestCase):
|
|||
|
||||
def testExceptionIfNoBuildGnFilesAreFound(self):
|
||||
with self.assertRaises(check_orphan_headers.NoBuildGnFoundError):
|
||||
file_path = '/home/projects/webrtc/base/foo.h'
|
||||
file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.h')
|
||||
file_exists = lambda p: False
|
||||
src_dir_path = '/home/projects/webrtc'
|
||||
src_dir_path = _GetPath('home', 'projects', 'webrtc')
|
||||
check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
|
||||
file_exists,
|
||||
src_dir_path)
|
||||
|
||||
def testExceptionIfFilePathIsNotAnHeader(self):
|
||||
with self.assertRaises(check_orphan_headers.WrongFileTypeError):
|
||||
file_path = '/home/projects/webrtc/base/foo.cc'
|
||||
file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.cc')
|
||||
file_exists = lambda p: False
|
||||
src_dir_path = '/home/projects/webrtc'
|
||||
src_dir_path = _GetPath('home', 'projects', 'webrtc')
|
||||
check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
|
||||
file_exists,
|
||||
src_dir_path)
|
||||
|
@ -84,10 +102,15 @@ class GetHeadersInBuildGnFileSourcesTest(unittest.TestCase):
|
|||
sources = ["baz/foo.h"]
|
||||
}
|
||||
"""
|
||||
target_abs_path = _GetPath('a', 'b')
|
||||
self.assertEqual(
|
||||
set(['/a/b/foo.h', '/a/b/bar.h', '/a/b/baz/foo.h']),
|
||||
set([
|
||||
_GetPath('a', 'b', 'foo.h'),
|
||||
_GetPath('a', 'b', 'bar.h'),
|
||||
_GetPath('a', 'b', 'baz', 'foo.h'),
|
||||
]),
|
||||
check_orphan_headers.GetHeadersInBuildGnFileSources(file_content,
|
||||
'/a/b'))
|
||||
target_abs_path))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue