[GN] Fix dependency rebasing in BUILD.gn files.

This CL ensures we properly points to deps shared with chromium,
e.g. '//third_party/abseil-cpp...' and not '../third_party/abseil-cpp...'

NB: This is only applied to dependencies which were missing,
    and doesn't fix existing ones.

Bug: webrtc:10037
Change-Id: If4bbb00df39401c65def9d56e36e5feb5d67b9dd
Reviewed-on: https://webrtc-review.googlesource.com/c/111600
Commit-Queue: Yves Gerey <yvesg@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25762}
This commit is contained in:
Yves Gerey
2018-11-22 14:01:23 +01:00
committed by Commit Bot
parent 254d869c00
commit 14dfe7f288

View File

@ -31,6 +31,9 @@ from collections import defaultdict
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
CHROMIUM_DIRS = ['base', 'build', 'buildtools',
'testing', 'third_party', 'tools']
TARGET_RE = re.compile( TARGET_RE = re.compile(
r'(?P<indentation_level>\s*)\w*\("(?P<target_name>\w*)"\) {$') r'(?P<indentation_level>\s*)\w*\("(?P<target_name>\w*)"\) {$')
@ -88,22 +91,48 @@ def FixErrors(filename, missing_deps, deleted_sources):
Run(['gn', 'format', filename]) Run(['gn', 'format', filename])
def FirstNonEmpty(iterable):
"""Return first item which evaluates to True, or fallback to None."""
return next((x for x in iterable if x), None)
def Rebase(base_path, dependency_path, dependency): def Rebase(base_path, dependency_path, dependency):
base_path = base_path.split(os.path.sep) """Adapt paths so they work both in stand-alone WebRTC and Chromium tree.
dependency_path = dependency_path.split(os.path.sep)
first_difference = None To cope with varying top-level directory (WebRTC VS Chromium), we use:
shortest_length = min(len(dependency_path), len(base_path)) * relative paths for WebRTC modules.
for i in range(shortest_length): * absolute paths for shared ones.
if dependency_path[i] != base_path[i]: E.g. '//common_audio/...' -> '../../common_audio/'
first_difference = i '//third_party/...' remains as is.
break
first_difference = first_difference or shortest_length Args:
base_path = base_path[first_difference:] base_path: current module path (E.g. '//video')
dependency_path = dependency_path[first_difference:] dependency_path: path from root (E.g. '//rtc_base/time')
return (os.path.sep.join((['..'] * len(base_path)) + dependency_path) + dependency: target itself (E.g. 'timestamp_extrapolator')
':' + dependency)
Returns:
Full target path (E.g. '../rtc_base/time:timestamp_extrapolator').
"""
root = FirstNonEmpty(dependency_path.split('/'))
if root in CHROMIUM_DIRS:
# Chromium paths must remain absolute. E.g. //third_party//abseil-cpp...
rebased = dependency_path
else:
base_path = base_path.split(os.path.sep)
dependency_path = dependency_path.split(os.path.sep)
first_difference = None
shortest_length = min(len(dependency_path), len(base_path))
for i in range(shortest_length):
if dependency_path[i] != base_path[i]:
first_difference = i
break
first_difference = first_difference or shortest_length
base_path = base_path[first_difference:]
dependency_path = dependency_path[first_difference:]
rebased = os.path.sep.join((['..'] * len(base_path)) + dependency_path)
return rebased + ':' + dependency
def main(): def main():
deleted_sources = set() deleted_sources = set()