[GTK] Add a non-subprocess jhbuild environment and use it for run-gtk-tests
[WebKit-https.git] / Tools / jhbuild / jhbuildutils.py
1 import glob
2 import os.path
3 import sys
4
5 top_level_dir = None
6
7
8 def top_level_path(*args):
9     global top_level_dir
10     if not top_level_dir:
11         top_level_dir = os.path.join(os.path.dirname(__file__), '..', '..')
12     return os.path.join(*(top_level_dir,) + args)
13
14
15 def get_dependencies_path():
16     if 'WEBKITOUTPUTDIR' in os.environ:
17         return os.path.abspath(os.path.join(os.environ['WEBKITOUTPUTDIR'], 'Dependencies'))
18     else:
19         return os.path.abspath(top_level_path('WebKitBuild', 'Dependencies'))
20
21
22 def get_config_file_for_platform(platform):
23     return top_level_path('Tools', platform, 'jhbuildrc')
24
25
26 def enter_jhbuild_environment_if_available(platform):
27     if not os.path.exists(get_dependencies_path()):
28         return False
29
30     # We don't know the Python version, so we just assume that we can safely take the first one in the list.
31     site_packages_path = glob.glob(os.path.join(get_dependencies_path(), "Root", "lib", "*", "site-packages"))
32     if not len(site_packages_path):
33         return False
34
35     site_packages_path = site_packages_path[0]
36     sys.path.insert(0, site_packages_path)
37
38     import jhbuild.config
39     from jhbuild.errors import FatalError
40
41     try:
42         config = jhbuild.config.Config(get_config_file_for_platform(platform))
43     except FatalError, exception:
44         sys.stderr.write('Could not load jhbuild config file: %s\n' % exception.args[0])
45         return False
46
47     return True