diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 1b435a77e8..ae5303dc71 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -110,6 +110,14 @@ SOURCES_RE = re.compile(r'sources \+?= \[(?P.*?)\]', FILE_PATH_RE = re.compile(r'"(?P(\w|\/)+)(?P\.\w+)"') +def FindSrcDirPath(starting_dir): + """Returns the abs path to the src/ dir of the project.""" + src_dir = starting_dir + while os.path.basename(src_dir) != 'src': + src_dir = os.path.normpath(os.path.join(src_dir, os.pardir)) + return src_dir + + @contextmanager def _AddToPath(*paths): original_sys_path = sys.path @@ -554,7 +562,7 @@ def CheckGnGen(input_api, output_api): with _AddToPath(input_api.os_path.join( input_api.PresubmitLocalPath(), 'tools_webrtc', 'presubmit_checks_lib')): from gn_check import RunGnCheck - errors = RunGnCheck(input_api.PresubmitLocalPath())[:5] + errors = RunGnCheck(FindSrcDirPath(input_api.PresubmitLocalPath()))[:5] if errors: return [output_api.PresubmitPromptWarning( 'Some #includes do not match the build dependency graph. Please run:\n' @@ -573,8 +581,8 @@ def CheckUnwantedDependencies(input_api, output_api, source_file_filter): # We need to wait until we have an input_api object and use this # roundabout construct to import checkdeps because this file is # eval-ed and thus doesn't have __file__. - checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(), - 'buildtools', 'checkdeps') + src_path = FindSrcDirPath(input_api.PresubmitLocalPath()) + checkdeps_path = input_api.os_path.join(src_path, 'buildtools', 'checkdeps') if not os.path.exists(checkdeps_path): return [output_api.PresubmitError( 'Cannot find checkdeps at %s\nHave you run "gclient sync" to ' diff --git a/tools_webrtc/autoroller/roll_deps.py b/tools_webrtc/autoroller/roll_deps.py index 11e1fb8cff..75a8addb40 100755 --- a/tools_webrtc/autoroller/roll_deps.py +++ b/tools_webrtc/autoroller/roll_deps.py @@ -19,6 +19,13 @@ import subprocess import sys import urllib2 +def FindSrcDirPath(): + """Returns the abs path to the src/ dir of the project.""" + src_dir = os.path.dirname(os.path.abspath(__file__)) + while os.path.basename(src_dir) != 'src': + src_dir = os.path.normpath(os.path.join(src_dir, os.pardir)) + return src_dir + # Skip these dependencies (list without solution name prefix). DONT_AUTOROLL_THESE = [ 'src/examples/androidtests/third_party/gradle', @@ -41,8 +48,7 @@ CLANG_REVISION_RE = re.compile(r'^CLANG_REVISION = \'(\d+)\'$') ROLL_BRANCH_NAME = 'roll_chromium_revision' SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) -CHECKOUT_SRC_DIR = os.path.realpath(os.path.join(SCRIPT_DIR, os.pardir, - os.pardir)) +CHECKOUT_SRC_DIR = FindSrcDirPath() CHECKOUT_ROOT_DIR = os.path.realpath(os.path.join(CHECKOUT_SRC_DIR, os.pardir)) sys.path.append(os.path.join(CHECKOUT_SRC_DIR, 'build')) diff --git a/tools_webrtc/libs/generate_licenses.py b/tools_webrtc/libs/generate_licenses.py index 7f2ec46aab..892fb46c05 100755 --- a/tools_webrtc/libs/generate_licenses.py +++ b/tools_webrtc/libs/generate_licenses.py @@ -21,6 +21,14 @@ import re import subprocess +def FindSrcDirPath(): + """Returns the abs path to the src/ dir of the project.""" + src_dir = os.path.dirname(os.path.abspath(__file__)) + while os.path.basename(src_dir) != 'src': + src_dir = os.path.normpath(os.path.join(src_dir, os.pardir)) + return src_dir + + LIB_TO_LICENSES_DICT = { 'abseil-cpp': ['third_party/abseil-cpp/LICENSE'], 'android_tools': ['third_party/android_tools/LICENSE'], @@ -62,8 +70,9 @@ LIB_TO_LICENSES_DICT = { } SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) -CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir)) -sys.path.append(os.path.join(CHECKOUT_ROOT, 'build')) +WEBRTC_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir)) +SRC_DIR = FindSrcDirPath() +sys.path.append(os.path.join(SRC_DIR, 'build')) import find_depot_tools THIRD_PARTY_LIB_REGEX = r'^.*/third_party/([\w\-+]+).*$' @@ -101,7 +110,7 @@ class LicenseBuilder(object): target, ] logging.debug("Running: %r", cmd) - output_json = subprocess.check_output(cmd, cwd=CHECKOUT_ROOT) + output_json = subprocess.check_output(cmd, cwd=WEBRTC_ROOT) logging.debug("Output: %s", output_json) return output_json @@ -147,7 +156,7 @@ class LicenseBuilder(object): output_license_file.write('# %s\n' % license_lib) output_license_file.write('```\n') for path in LIB_TO_LICENSES_DICT[license_lib]: - license_path = os.path.join(CHECKOUT_ROOT, path) + license_path = os.path.join(WEBRTC_ROOT, path) with open(license_path, 'r') as license_file: license_text = cgi.escape(license_file.read(), quote=True) output_license_file.write(license_text) diff --git a/tools_webrtc/presubmit_checks_lib/gn_check.py b/tools_webrtc/presubmit_checks_lib/gn_check.py index a81cc1c879..459dcd88ee 100644 --- a/tools_webrtc/presubmit_checks_lib/gn_check.py +++ b/tools_webrtc/presubmit_checks_lib/gn_check.py @@ -14,8 +14,15 @@ import sys import tempfile -SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) -SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir)) +def FindSrcDirPath(): + """Returns the abs path to the src/ dir of the project.""" + src_dir = os.path.dirname(os.path.abspath(__file__)) + while os.path.basename(src_dir) != 'src': + src_dir = os.path.normpath(os.path.join(src_dir, os.pardir)) + return src_dir + + +SRC_DIR = FindSrcDirPath() sys.path.append(os.path.join(SRC_DIR, 'build')) import find_depot_tools