From 76c2e50d3bb9198e4e8c024ff0b46616ec1b9a9f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 24 Oct 2019 02:52:29 +0000 Subject: [PATCH] simplify the chromite wrappers The support/ dir has only ever been used to host a single CrOS file. We can move that to `cros` (which is the primary tool in the CrOS world), and have the few other wrapped programs point to that. Bug: None Change-Id: I3ba3cc7375d357d62fb464e1b6dc37e73bc83cb5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1876639 Reviewed-by: Nodir Turakulov Commit-Queue: Mike Frysinger --- cbuildbot | 2 +- chrome_set_ver | 2 +- cros | 61 +++++++++++++++++++++++++++++++++++++++- cros_sdk | 2 +- support/chromite_wrapper | 60 --------------------------------------- 5 files changed, 63 insertions(+), 64 deletions(-) mode change 120000 => 100755 cros delete mode 100755 support/chromite_wrapper diff --git a/cbuildbot b/cbuildbot index 3a4369de9c..a876afe9bd 120000 --- a/cbuildbot +++ b/cbuildbot @@ -1 +1 @@ -support/chromite_wrapper \ No newline at end of file +cros \ No newline at end of file diff --git a/chrome_set_ver b/chrome_set_ver index 3a4369de9c..a876afe9bd 120000 --- a/chrome_set_ver +++ b/chrome_set_ver @@ -1 +1 @@ -support/chromite_wrapper \ No newline at end of file +cros \ No newline at end of file diff --git a/cros b/cros deleted file mode 120000 index 3a4369de9c..0000000000 --- a/cros +++ /dev/null @@ -1 +0,0 @@ -support/chromite_wrapper \ No newline at end of file diff --git a/cros b/cros new file mode 100755 index 0000000000..8c37ef1c79 --- /dev/null +++ b/cros @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# 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 sys + + +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 main(): + 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) + os.execv(path, [path] + sys.argv[1:]) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/cros_sdk b/cros_sdk index 3a4369de9c..a876afe9bd 120000 --- a/cros_sdk +++ b/cros_sdk @@ -1 +1 @@ -support/chromite_wrapper \ No newline at end of file +cros \ No newline at end of file diff --git a/support/chromite_wrapper b/support/chromite_wrapper deleted file mode 100755 index 8c37ef1c79..0000000000 --- a/support/chromite_wrapper +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -# 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 sys - - -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 main(): - 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) - os.execv(path, [path] + sys.argv[1:]) - - -if __name__ == '__main__': - sys.exit(main())