blob: fd4faea100ddeab86794c6a2142e044bcdeba1bc [file] [log] [blame]
mcatanzaro@igalia.com7c3eeb92017-11-20 23:51:54 +00001import gettext
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +00002import glob
3import os.path
4import sys
mrobinson@webkit.org045ae212012-08-01 07:30:25 +00005import __builtin__
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +00006
7top_level_dir = None
8
9
10def top_level_path(*args):
11 global top_level_dir
12 if not top_level_dir:
13 top_level_dir = os.path.join(os.path.dirname(__file__), '..', '..')
14 return os.path.join(*(top_level_dir,) + args)
15
16
clopez@igalia.come9389252014-12-11 17:02:46 +000017def get_dependencies_path(platform):
18 dependencies_dir = "%s%s" % ('Dependencies', platform.upper())
commit-queue@webkit.org50c9da22013-07-01 16:25:21 +000019 if 'WEBKIT_OUTPUTDIR' in os.environ:
clopez@igalia.come9389252014-12-11 17:02:46 +000020 return os.path.abspath(os.path.join(os.environ['WEBKIT_OUTPUTDIR'], dependencies_dir))
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +000021 else:
clopez@igalia.come9389252014-12-11 17:02:46 +000022 return os.path.abspath(top_level_path('WebKitBuild', dependencies_dir))
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +000023
24
25def get_config_file_for_platform(platform):
26 return top_level_path('Tools', platform, 'jhbuildrc')
27
28
29def enter_jhbuild_environment_if_available(platform):
clopez@igalia.come9389252014-12-11 17:02:46 +000030 if not os.path.exists(get_dependencies_path(platform)):
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +000031 return False
32
mrobinson@webkit.org36e900d2012-07-31 08:53:05 +000033 # Sometimes jhbuild chooses to install in a way that reads the library from the source directory, so fall
34 # back to that method.
clopez@igalia.come9389252014-12-11 17:02:46 +000035 source_path = os.path.join(get_dependencies_path(platform), "Source", "jhbuild")
mrobinson@webkit.org36e900d2012-07-31 08:53:05 +000036 sys.path.insert(0, source_path)
37
carlosgc@webkit.org166e3f92015-12-08 09:12:29 +000038 # When loading jhbuild from the source checkout it fails if the SRCDIR, PKGDATADIR or DATADIR aren't present.
mrobinson@webkit.org045ae212012-08-01 07:30:25 +000039 __builtin__.__dict__['SRCDIR'] = source_path
carlosgc@webkit.org166e3f92015-12-08 09:12:29 +000040 __builtin__.__dict__['PKGDATADIR'] = None
41 __builtin__.__dict__['DATADIR'] = None
mrobinson@webkit.org045ae212012-08-01 07:30:25 +000042
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +000043 # We don't know the Python version, so we just assume that we can safely take the first one in the list.
clopez@igalia.come9389252014-12-11 17:02:46 +000044 site_packages_path = glob.glob(os.path.join(get_dependencies_path(platform), "Root", "lib", "*", "site-packages"))
mrobinson@webkit.org36e900d2012-07-31 08:53:05 +000045 if len(site_packages_path):
46 site_packages_path = site_packages_path[0]
47 sys.path.insert(0, site_packages_path)
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +000048
49 try:
mrobinson@webkit.org36e900d2012-07-31 08:53:05 +000050 import jhbuild.config
51 from jhbuild.errors import FatalError
mcatanzaro@igalia.com7c3eeb92017-11-20 23:51:54 +000052 gettext.install('jhbuild', localedir=os.path.join(source_path, 'mo'), unicode=True)
carlosgc@webkit.org37f0be02015-11-16 17:31:38 +000053 config = jhbuild.config.Config(get_config_file_for_platform(platform), [])
annulen@yandex.ru549ab042017-12-10 21:11:18 +000054 except FatalError as exception:
mrobinson@webkit.org07a3e332012-07-30 17:17:36 +000055 sys.stderr.write('Could not load jhbuild config file: %s\n' % exception.args[0])
56 return False
57
58 return True