mcatanzaro@igalia.com | 7c3eeb9 | 2017-11-20 23:51:54 +0000 | [diff] [blame] | 1 | import gettext |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 2 | import glob |
| 3 | import os.path |
| 4 | import sys |
mrobinson@webkit.org | 045ae21 | 2012-08-01 07:30:25 +0000 | [diff] [blame] | 5 | import __builtin__ |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 6 | |
| 7 | top_level_dir = None |
| 8 | |
| 9 | |
| 10 | def 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.com | e938925 | 2014-12-11 17:02:46 +0000 | [diff] [blame] | 17 | def get_dependencies_path(platform): |
| 18 | dependencies_dir = "%s%s" % ('Dependencies', platform.upper()) |
commit-queue@webkit.org | 50c9da2 | 2013-07-01 16:25:21 +0000 | [diff] [blame] | 19 | if 'WEBKIT_OUTPUTDIR' in os.environ: |
clopez@igalia.com | e938925 | 2014-12-11 17:02:46 +0000 | [diff] [blame] | 20 | return os.path.abspath(os.path.join(os.environ['WEBKIT_OUTPUTDIR'], dependencies_dir)) |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 21 | else: |
clopez@igalia.com | e938925 | 2014-12-11 17:02:46 +0000 | [diff] [blame] | 22 | return os.path.abspath(top_level_path('WebKitBuild', dependencies_dir)) |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 23 | |
| 24 | |
| 25 | def get_config_file_for_platform(platform): |
| 26 | return top_level_path('Tools', platform, 'jhbuildrc') |
| 27 | |
| 28 | |
| 29 | def enter_jhbuild_environment_if_available(platform): |
clopez@igalia.com | e938925 | 2014-12-11 17:02:46 +0000 | [diff] [blame] | 30 | if not os.path.exists(get_dependencies_path(platform)): |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 31 | return False |
| 32 | |
mrobinson@webkit.org | 36e900d | 2012-07-31 08:53:05 +0000 | [diff] [blame] | 33 | # 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.com | e938925 | 2014-12-11 17:02:46 +0000 | [diff] [blame] | 35 | source_path = os.path.join(get_dependencies_path(platform), "Source", "jhbuild") |
mrobinson@webkit.org | 36e900d | 2012-07-31 08:53:05 +0000 | [diff] [blame] | 36 | sys.path.insert(0, source_path) |
| 37 | |
carlosgc@webkit.org | 166e3f9 | 2015-12-08 09:12:29 +0000 | [diff] [blame] | 38 | # When loading jhbuild from the source checkout it fails if the SRCDIR, PKGDATADIR or DATADIR aren't present. |
mrobinson@webkit.org | 045ae21 | 2012-08-01 07:30:25 +0000 | [diff] [blame] | 39 | __builtin__.__dict__['SRCDIR'] = source_path |
carlosgc@webkit.org | 166e3f9 | 2015-12-08 09:12:29 +0000 | [diff] [blame] | 40 | __builtin__.__dict__['PKGDATADIR'] = None |
| 41 | __builtin__.__dict__['DATADIR'] = None |
mrobinson@webkit.org | 045ae21 | 2012-08-01 07:30:25 +0000 | [diff] [blame] | 42 | |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 43 | # We don't know the Python version, so we just assume that we can safely take the first one in the list. |
clopez@igalia.com | e938925 | 2014-12-11 17:02:46 +0000 | [diff] [blame] | 44 | site_packages_path = glob.glob(os.path.join(get_dependencies_path(platform), "Root", "lib", "*", "site-packages")) |
mrobinson@webkit.org | 36e900d | 2012-07-31 08:53:05 +0000 | [diff] [blame] | 45 | if len(site_packages_path): |
| 46 | site_packages_path = site_packages_path[0] |
| 47 | sys.path.insert(0, site_packages_path) |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 48 | |
| 49 | try: |
mrobinson@webkit.org | 36e900d | 2012-07-31 08:53:05 +0000 | [diff] [blame] | 50 | import jhbuild.config |
| 51 | from jhbuild.errors import FatalError |
mcatanzaro@igalia.com | 7c3eeb9 | 2017-11-20 23:51:54 +0000 | [diff] [blame] | 52 | gettext.install('jhbuild', localedir=os.path.join(source_path, 'mo'), unicode=True) |
carlosgc@webkit.org | 37f0be0 | 2015-11-16 17:31:38 +0000 | [diff] [blame] | 53 | config = jhbuild.config.Config(get_config_file_for_platform(platform), []) |
annulen@yandex.ru | 549ab04 | 2017-12-10 21:11:18 +0000 | [diff] [blame] | 54 | except FatalError as exception: |
mrobinson@webkit.org | 07a3e33 | 2012-07-30 17:17:36 +0000 | [diff] [blame] | 55 | sys.stderr.write('Could not load jhbuild config file: %s\n' % exception.args[0]) |
| 56 | return False |
| 57 | |
| 58 | return True |