[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:
@ -31,6 +31,9 @@ from collections import defaultdict
|
||||
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
CHROMIUM_DIRS = ['base', 'build', 'buildtools',
|
||||
'testing', 'third_party', 'tools']
|
||||
|
||||
TARGET_RE = re.compile(
|
||||
r'(?P<indentation_level>\s*)\w*\("(?P<target_name>\w*)"\) {$')
|
||||
|
||||
@ -88,7 +91,33 @@ def FixErrors(filename, missing_deps, deleted_sources):
|
||||
|
||||
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):
|
||||
"""Adapt paths so they work both in stand-alone WebRTC and Chromium tree.
|
||||
|
||||
To cope with varying top-level directory (WebRTC VS Chromium), we use:
|
||||
* relative paths for WebRTC modules.
|
||||
* absolute paths for shared ones.
|
||||
E.g. '//common_audio/...' -> '../../common_audio/'
|
||||
'//third_party/...' remains as is.
|
||||
|
||||
Args:
|
||||
base_path: current module path (E.g. '//video')
|
||||
dependency_path: path from root (E.g. '//rtc_base/time')
|
||||
dependency: target itself (E.g. 'timestamp_extrapolator')
|
||||
|
||||
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)
|
||||
|
||||
@ -102,8 +131,8 @@ def Rebase(base_path, dependency_path, dependency):
|
||||
first_difference = first_difference or shortest_length
|
||||
base_path = base_path[first_difference:]
|
||||
dependency_path = dependency_path[first_difference:]
|
||||
return (os.path.sep.join((['..'] * len(base_path)) + dependency_path) +
|
||||
':' + dependency)
|
||||
rebased = os.path.sep.join((['..'] * len(base_path)) + dependency_path)
|
||||
return rebased + ':' + dependency
|
||||
|
||||
def main():
|
||||
deleted_sources = set()
|
||||
|
Reference in New Issue
Block a user