cros 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Wrapper for chromite tools.
  6. The script is intend to be symlinked to any number of chromite tools, attempts
  7. to find the path for chromite, and hands off to the right tool via exec if
  8. possible.
  9. It is intended to used strictly outside of the chroot.
  10. """
  11. import os
  12. import sys
  13. def _FindChromite(path):
  14. """Find the chromite dir in a repo, gclient, or submodule checkout."""
  15. path = os.path.abspath(path)
  16. # Depending on the checkout type (whether repo chromeos or gclient chrome)
  17. # Chromite lives in a different location.
  18. roots = (
  19. ('.repo', 'chromite/.git'),
  20. ('.gclient', 'src/third_party/chromite/.git'),
  21. ('src/.gitmodules', 'src/third_party/chromite/.git'),
  22. )
  23. while path != '/':
  24. for root, chromite_git_dir in roots:
  25. if all(os.path.exists(os.path.join(path, x))
  26. for x in [root, chromite_git_dir]):
  27. return os.path.dirname(os.path.join(path, chromite_git_dir))
  28. path = os.path.dirname(path)
  29. return None
  30. def _MissingErrorOut(target):
  31. sys.stderr.write("""ERROR: Couldn't find the chromite tool %s.
  32. Please change to a directory inside your Chromium OS source tree
  33. and retry. If you need to setup a Chromium OS source tree, see
  34. https://chromium.googlesource.com/chromiumos/docs/+/HEAD/developer_guide.md
  35. """ % target)
  36. return 127
  37. def main():
  38. chromite_dir = _FindChromite(os.getcwd())
  39. target = os.path.basename(sys.argv[0])
  40. if chromite_dir is None:
  41. return _MissingErrorOut(target)
  42. path = os.path.join(chromite_dir, 'bin', target)
  43. os.execv(path, [path] + sys.argv[1:])
  44. if __name__ == '__main__':
  45. sys.exit(main())