Hash :
b5d34da0
Author :
Date :
2022-04-11T18:17:03
Add src/tests/py_utils/ for utils, angle_path_util for imports. Detect if angle or chromium checkout when adding deps paths, so that random paths from above angle_root don't get added to sys.path when imported from an angle checkout. Bug: angleproject:6854 Change-Id: I4cd3334a2313d921f8651de7056f4f3798b8e072 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3582978 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
# Copyright 2022 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import posixpath
import sys
ANGLE_ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
def _AddToPathIfNeeded(path):
if path not in sys.path:
sys.path.insert(0, path)
def AddDepsDirToPath(posixpath_from_root):
relative_path = os.path.join(*posixpath.split(posixpath_from_root))
full_path = os.path.join(ANGLE_ROOT_DIR, relative_path)
if not os.path.exists(full_path):
# Assume Chromium checkout
chromium_root_dir = os.path.abspath(os.path.join(ANGLE_ROOT_DIR, '..', '..'))
full_path = os.path.join(chromium_root_dir, relative_path)
assert os.path.exists(full_path)
_AddToPathIfNeeded(full_path)