blob: cf74a6e5173639987041f26b9b41ec14e6e12ce9 [file] [log] [blame]
Aviv Keshet39853bd2016-09-22 15:12:05 -07001#!/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
8from __future__ import print_function
9
10import os
11import sys
12import 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.
18from 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 Keshetb7519e12016-10-04 00:50:00 -070027from chromite.lib import constants
Aviv Keshet39853bd2016-09-22 15:12:05 -070028
29_CHROMITE_DIR = constants.CHROMITE_DIR
30_IN_VENV = 'IN_CHROMITE_VENV'
31
32
33if __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)