1 Star 0 Fork 0

ZyElite/depot_tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cros 3.67 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python3
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Wrapper for chromite tools.
The script is intend to be symlinked to any number of chromite tools, attempts
to find the path for chromite, and hands off to the right tool via exec if
possible.
It is intended to used strictly outside of the chroot.
"""
import os
import pathlib
import subprocess
import sys
# Min version of Python that we *want*. We warn for older versions.
MIN_PYTHON_VER_SOFT = (3, 8)
# Min version of Python that we *require*. We abort for older versions.
MIN_PYTHON_VER_HARD = (3, 6)
DEPOT_TOOLS_DIR = pathlib.Path(__file__).resolve().parent
# Directory where cros-specific CIPD packages are installed.
CIPD_CACHE_DIR = DEPOT_TOOLS_DIR / '.cipd_bin_cros_python2'
def _FindChromite(path):
"""Find the chromite dir in a repo, gclient, or submodule checkout."""
path = os.path.abspath(path)
# Depending on the checkout type (whether repo chromeos or gclient chrome)
# Chromite lives in a different location.
roots = (
('.repo', 'chromite/.git'),
('.gclient', 'src/third_party/chromite/.git'),
('src/.gitmodules', 'src/third_party/chromite/.git'),
)
while path != '/':
for root, chromite_git_dir in roots:
if all(os.path.exists(os.path.join(path, x))
for x in [root, chromite_git_dir]):
return os.path.dirname(os.path.join(path, chromite_git_dir))
path = os.path.dirname(path)
return None
def _MissingErrorOut(target):
sys.stderr.write("""ERROR: Couldn't find the chromite tool %s.
Please change to a directory inside your Chromium OS source tree
and retry. If you need to setup a Chromium OS source tree, see
https://chromium.googlesource.com/chromiumos/docs/+/HEAD/developer_guide.md
""" % target)
return 127
def _CheckPythonVersion():
"""Verify active Python is new enough."""
if sys.version_info >= MIN_PYTHON_VER_SOFT:
return
progname = os.path.basename(sys.argv[0])
print('%s: Chrome OS requires Python-%s+, but "%s" is "%s"' %
(progname, '.'.join(str(x) for x in MIN_PYTHON_VER_SOFT),
sys.executable, sys.version.replace('\n', ' ')),
file=sys.stderr)
if sys.version_info < MIN_PYTHON_VER_HARD:
print('%s: fatal: giving up since Python is too old.' % (progname,),
file=sys.stderr)
sys.exit(1)
print('warning: temporarily continuing anyways; you must upgrade soon to '
'maintain support.', file=sys.stderr)
def _BootstrapVpython27():
"""Installs the vpython2.7 packages into the cipd cache directory."""
subprocess.run(['cipd', 'ensure',
'-log-level', 'info',
'-ensure-file',
DEPOT_TOOLS_DIR / 'cipd_manifest_cros_python2.txt',
'-root', CIPD_CACHE_DIR],
check=True)
def main():
_CheckPythonVersion()
chromite_dir = _FindChromite(os.getcwd())
target = os.path.basename(sys.argv[0])
if chromite_dir is None:
return _MissingErrorOut(target)
path = os.path.join(chromite_dir, 'bin', target)
# Check to see if this is a script requiring vpython2.7.
with open(path, 'rb') as fp:
shebang = next(fp).strip()
interpreter = shebang.split()[-1]
if interpreter in (b'python', b'python2', b'python2.7', b'vpython'):
_BootstrapVpython27()
vpython = CIPD_CACHE_DIR / 'vpython'
args = [vpython]
if interpreter != b'vpython':
args.extend(['-vpython-spec', DEPOT_TOOLS_DIR / 'cros_python2.vpython'])
args.append(path)
path = vpython
else:
args = [path]
os.execv(path, args + sys.argv[1:])
if __name__ == '__main__':
sys.exit(main())
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Zy.Elite/depot_tools.git
git@gitee.com:Zy.Elite/depot_tools.git
Zy.Elite
depot_tools
depot_tools
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385