Commit ea98ebbe authored by Mike Frysinger's avatar Mike Frysinger Committed by Commit Bot

chromite_wrapper: modernize a bit

This file hasn't been updated in over 6 years.  The backwards compat
logic in here dates back to pre-R20 releases, and the only boards we
released that long ago are EOL now.  So scrub all the unused code to
simplify it.

While we're here, fix a few style issues, and update the docs.

Bug: 997354
Test: `cros help` still works
Change-Id: Id226cd73f045972b88e7bc5926a415f567d1e41c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1875488Reviewed-by: 's avatarMike Nichols <mikenichols@chromium.org>
Reviewed-by: 's avatarAlex Klein <saklein@chromium.org>
Reviewed-by: 's avatarNodir Turakulov <nodir@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
parent efd15ecf
......@@ -10,24 +10,11 @@ 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.
If you're looking at a copy and want to know where the original looks at, look
here:
http://git.chromium.org/gitweb/?p=chromite.git;a=blob;f=bin/chromite
Since this script is _copied_, it should remain small and not use internal libs.
"""
import errno
import os
import sys
# Due to historical reasons, and the fact depot_tools ToT is used by older
# factory branches (lacking chromite script cleanups), note we have to
# fallback to some odd import locations. This is the only reason for the
# fallback code- any/all new scripts symlinked to this script *must* exist
# in chromite/bin/ .
def _FindChromite(path):
"""Find the chromite dir in a repo, gclient, or submodule checkout."""
......@@ -35,9 +22,9 @@ def _FindChromite(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'),
('.repo', 'chromite/.git'),
('.gclient', 'src/third_party/chromite/.git'),
('src/.gitmodules', 'src/third_party/chromite/.git'),
)
while path != '/':
......@@ -50,12 +37,11 @@ def _FindChromite(path):
def _MissingErrorOut(target):
sys.stderr.write(
"""ERROR: Couldn't find the chromite tool %s.
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
http://www.chromium.org/chromium-os/developer-guide
https://chromium.googlesource.com/chromiumos/docs/+/HEAD/developer_guide.md
""" % target)
return 127
......@@ -67,30 +53,8 @@ def main():
return _MissingErrorOut(target)
path = os.path.join(chromite_dir, 'bin', target)
try:
os.execv(path, [path] + sys.argv[1:])
except EnvironmentError as e:
if e.errno not in (errno.ENOENT, errno.EPERM):
raise
# Reaching here means it's either a bad target, or we're working against
# an old (pre 6be2efcf5bb575b03862113eec097c44d8d7f93e) revision of
# chromite. Fallback to trying to import it; this code works at least as
# far back as branch 0.11.241.B; likely further.
os.execv(path, [path] + sys.argv[1:])
if target == 'cbuildbot':
target = 'chromite.buildbot.cbuildbot'
else:
target = 'chromite.bin.%s' % (target,)
# Adjust the path importation so we can import our our target.
sys.path.insert(0, os.path.dirname(chromite_dir))
try:
module = __import__(target, fromlist=['main'])
except ImportError:
return _MissingErrorOut(target)
return module.main()
if __name__ == '__main__':
sys.exit(main())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment