jhbuildutils.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import glob
  2. import os.path
  3. import sys
  4. import __builtin__
  5. top_level_dir = None
  6. def top_level_path(*args):
  7. global top_level_dir
  8. if not top_level_dir:
  9. top_level_dir = os.path.join(os.path.dirname(__file__), '..', '..')
  10. return os.path.join(*(top_level_dir,) + args)
  11. def get_dependencies_path():
  12. if 'WEBKITOUTPUTDIR' in os.environ:
  13. return os.path.abspath(os.path.join(os.environ['WEBKITOUTPUTDIR'], 'Dependencies'))
  14. else:
  15. return os.path.abspath(top_level_path('WebKitBuild', 'Dependencies'))
  16. def get_config_file_for_platform(platform):
  17. return top_level_path('Tools', platform, 'jhbuildrc')
  18. def enter_jhbuild_environment_if_available(platform):
  19. if not os.path.exists(get_dependencies_path()):
  20. return False
  21. # Sometimes jhbuild chooses to install in a way that reads the library from the source directory, so fall
  22. # back to that method.
  23. source_path = os.path.join(get_dependencies_path(), "Source", "jhbuild")
  24. sys.path.insert(0, source_path)
  25. # When loading jhbuild from the source checkout it fails if the SRCDIR variable is not set.
  26. __builtin__.__dict__['SRCDIR'] = source_path
  27. # We don't know the Python version, so we just assume that we can safely take the first one in the list.
  28. site_packages_path = glob.glob(os.path.join(get_dependencies_path(), "Root", "lib", "*", "site-packages"))
  29. if len(site_packages_path):
  30. site_packages_path = site_packages_path[0]
  31. sys.path.insert(0, site_packages_path)
  32. try:
  33. import jhbuild.config
  34. from jhbuild.errors import FatalError
  35. config = jhbuild.config.Config(get_config_file_for_platform(platform))
  36. except FatalError, exception:
  37. sys.stderr.write('Could not load jhbuild config file: %s\n' % exception.args[0])
  38. return False
  39. return True