jhbuild-wrapper 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/env python
  2. # Copyright (C) 2011 Igalia S.L.
  3. # Copyright (C) 2012 Gustavo Noronha Silva <gns@gnome.org>
  4. # Copyright (C) 2012 Intel Corporation
  5. #
  6. # This library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 2 of the License, or (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with this library; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. import jhbuildutils
  20. import os
  21. import shlex
  22. import subprocess
  23. import sys
  24. jhbuild_revision = '496974221c3a8ac4fbbc3b0a577c71cac224130d'
  25. dependencies_path = jhbuildutils.get_dependencies_path()
  26. installation_prefix = os.path.abspath(os.path.join(dependencies_path, 'Root'))
  27. source_path = os.path.abspath(os.path.join(dependencies_path, 'Source'))
  28. jhbuild_source_path = os.path.join(source_path, 'jhbuild')
  29. jhbuild_path = os.path.join(installation_prefix, 'bin', 'jhbuild')
  30. def jhbuild_installed():
  31. return os.path.exists(jhbuild_path)
  32. def jhbuild_cloned():
  33. return os.path.exists(jhbuild_source_path)
  34. def jhbuild_at_expected_revision():
  35. process = subprocess.Popen(['git', 'rev-list', 'HEAD^..'], cwd=jhbuild_source_path,
  36. stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  37. output, err = process.communicate()
  38. if process.returncode != 0:
  39. raise Exception('failed to find jhbuild revision: %s' % err)
  40. return output.strip() == jhbuild_revision
  41. def update_jhbuild():
  42. process = subprocess.Popen(['git', 'remote', 'update', 'origin'], cwd=jhbuild_source_path)
  43. process.wait()
  44. if process.returncode != 0:
  45. raise Exception('jhbuild remote update origin failed with return code: %i' % process.returncode)
  46. process = subprocess.Popen(['git', 'checkout', '%s' % jhbuild_revision],
  47. cwd=jhbuild_source_path)
  48. process.wait()
  49. if process.returncode != 0:
  50. raise Exception('failed to checkout treeish %s: %i' % (jhbuild_revision, process.returncode))
  51. def clone_jhbuild():
  52. if not os.path.exists(source_path):
  53. os.makedirs(source_path)
  54. if not os.path.exists(installation_prefix):
  55. os.makedirs(installation_prefix)
  56. process = subprocess.Popen(['git', 'clone', 'git://git.gnome.org/jhbuild'], cwd=source_path)
  57. process.wait()
  58. if process.returncode != 0:
  59. raise Exception('jhbuild git clone failed with return code: %i' % process.returncode)
  60. def install_jhbuild():
  61. process = subprocess.Popen(['bash', './autogen.sh', '--prefix=%s' % installation_prefix], cwd=jhbuild_source_path)
  62. process.wait()
  63. if process.returncode != 0:
  64. raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
  65. # This is a hackish approach to make the subprocess.Popen call even when people set
  66. # MAKE to 'make -j3' instead of using the MAKEFLAGS environment variable.
  67. make = shlex.split(os.environ.get('MAKE', 'make'))
  68. process = subprocess.Popen(make + ['install'], cwd=jhbuild_source_path)
  69. process.wait()
  70. if process.returncode != 0:
  71. raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
  72. def determine_platform():
  73. if '--efl' in sys.argv:
  74. return "efl";
  75. if '--gtk' in sys.argv:
  76. return "gtk";
  77. raise ValueError('No platform specified for jhbuild-wrapper.')
  78. def ensure_jhbuild(platform):
  79. if not jhbuild_cloned():
  80. clone_jhbuild()
  81. update_jhbuild()
  82. install_jhbuild()
  83. elif not jhbuild_installed() \
  84. or not jhbuild_at_expected_revision():
  85. update_jhbuild()
  86. install_jhbuild()
  87. # Work-around the fact that we may get called from inside the jhbuild environment
  88. # which will cause problems if we just cleaned the jhbuild install root
  89. if os.environ.has_key('UNDER_JHBUILD'):
  90. del os.environ['ACLOCAL_FLAGS']
  91. try:
  92. platform = determine_platform()
  93. except ValueError as e:
  94. sys.exit(e)
  95. ensure_jhbuild(platform)
  96. os.execve(jhbuild_path, [jhbuild_path, '--no-interact', '-f', jhbuildutils.get_config_file_for_platform(platform)] + sys.argv[2:], os.environ)