Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # Copyright 2016 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 | |
| 6 | """Wrapper around chromite executable scripts that use virtualenv.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | import sys |
| 12 | import wrapper |
| 13 | |
| 14 | # TODO(akeshet): This transitively imports a bunch of other dependencies, |
| 15 | # including cbuildbot.contants. Ideally we wouldn't need that much junk in this |
| 16 | # wrapper, and importing all that prior to entering the virtualenv might |
| 17 | # actually cause issues. |
| 18 | from chromite.lib import cros_build_lib |
| 19 | |
| 20 | # TODO(akeshet): Since we are using the above lib which imports |
| 21 | # cbuildbot.constants anyway, we might as well make use of it in determining |
| 22 | # CHROMITE_PATH. If we want to eliminate this import, we can duplicate the |
| 23 | # chromite path finding code. It would look something like this: |
| 24 | # path = os.path.dirname(os.path.realpath(__file__)) |
| 25 | # while not os.path.exists(os.path.join(path, 'PRESUBMIT.cfg')): |
| 26 | # path = os.path.dirname(path) |
Aviv Keshet | b7519e1 | 2016-10-04 00:50:00 -0700 | [diff] [blame^] | 27 | from chromite.lib import constants |
Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 28 | |
| 29 | _CHROMITE_DIR = constants.CHROMITE_DIR |
| 30 | _IN_VENV = 'IN_CHROMITE_VENV' |
| 31 | |
| 32 | |
| 33 | if __name__ == '__main__': |
| 34 | if _IN_VENV in os.environ: |
| 35 | wrapper.DoMain() |
| 36 | else: |
| 37 | create_cmd = os.path.join(_CHROMITE_DIR, 'venv', 'create_env.sh') |
| 38 | cros_build_lib.RunCommand([create_cmd]) |
| 39 | python_cmd = os.path.join(_CHROMITE_DIR, 'venv', 'venv', 'bin', 'python') |
| 40 | cmd = [python_cmd] + sys.argv |
| 41 | o = cros_build_lib.RunCommand( |
| 42 | cmd, extra_env={_IN_VENV: '1'}, |
| 43 | mute_output=False, error_code_ok=True) |
| 44 | exit(o.returncode) |