2 # Copyright (C) 2011 Igalia S.L.
3 # Copyright (C) 2012 Gustavo Noronha Silva <gns@gnome.org>
4 # Copyright (C) 2012 Intel Corporation
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.
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.
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
29 def top_level_path(*args):
32 top_level_dir = os.path.join(os.path.dirname(__file__), '..', '..')
33 return os.path.join(*(top_level_dir,) + args)
36 jhbuild_revision = '1eedc423f75c605224b430579e4c303292199507'
38 if os.environ.has_key('WEBKITOUTPUTDIR'):
39 dependencies_path = os.path.abspath(os.path.join(os.environ['WEBKITOUTPUTDIR'], 'Dependencies'))
41 dependencies_path = os.path.abspath(top_level_path('WebKitBuild', 'Dependencies'))
43 installation_prefix = os.path.abspath(os.path.join(dependencies_path, 'Root'))
44 source_path = os.path.abspath(os.path.join(dependencies_path, 'Source'))
45 jhbuild_source_path = os.path.join(source_path, 'jhbuild')
46 jhbuild_path = os.path.join(installation_prefix, 'bin', 'jhbuild')
52 def jhbuild_installed():
53 return os.path.exists(jhbuild_path)
57 return os.path.exists(jhbuild_source_path)
60 def jhbuild_at_expected_revision():
61 process = subprocess.Popen(['git', 'rev-list', 'HEAD^..'], cwd=jhbuild_source_path,
62 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
63 output, err = process.communicate()
64 if process.returncode != 0:
65 raise Exception('failed to find jhbuild revision: %s' % err)
67 return output.strip() == jhbuild_revision
71 process = subprocess.Popen(['git', 'remote', 'update', 'origin'], cwd=jhbuild_source_path)
73 if process.returncode != 0:
74 raise Exception('jhbuild remote update origin failed with return code: %i' % process.returncode)
76 process = subprocess.Popen(['git', 'checkout', '%s' % jhbuild_revision],
77 cwd=jhbuild_source_path)
79 if process.returncode != 0:
80 raise Exception('failed to checkout treeish %s: %i' % (jhbuild_revision, process.returncode))
84 if not os.path.exists(source_path):
85 os.makedirs(source_path)
86 if not os.path.exists(installation_prefix):
87 os.makedirs(installation_prefix)
89 process = subprocess.Popen(['git', 'clone', 'git://git.gnome.org/jhbuild'], cwd=source_path)
91 if process.returncode != 0:
92 raise Exception('jhbuild git clone failed with return code: %i' % process.returncode)
95 def install_jhbuild():
96 process = subprocess.Popen(['bash', './autogen.sh', '--prefix=%s' % installation_prefix], cwd=jhbuild_source_path)
98 if process.returncode != 0:
99 raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
101 # This is a hackish approach to make the subprocess.Popen call even when people set
102 # MAKE to 'make -j3' instead of using the MAKEFLAGS environment variable.
103 make = shlex.split(os.environ.get('MAKE', 'make'))
105 process = subprocess.Popen(make + ['install'], cwd=jhbuild_source_path)
107 if process.returncode != 0:
108 raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
111 def update_webkit_libs_jhbuild():
112 process = subprocess.Popen([top_level_path('Tools', 'Scripts', 'update-webkit-libs-jhbuild'), '--' + platform])
114 if process.returncode != 0:
115 raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
118 def determine_platform():
119 if '--efl' in sys.argv:
121 if '--gtk' in sys.argv:
123 raise ValueError('No platform specified for jhbuild-wrapper.')
126 def ensure_jhbuild():
127 if not jhbuild_cloned():
131 update_webkit_libs_jhbuild()
132 elif not jhbuild_installed() \
133 or not jhbuild_at_expected_revision():
137 # Work-around the fact that we may get called from inside the jhbuild environment
138 # which will cause problems if we just cleaned the jhbuild install root
139 if os.environ.has_key('UNDER_JHBUILD'):
140 del os.environ['ACLOCAL_FLAGS']
143 platform = determine_platform()
144 except ValueError as e:
148 process = subprocess.Popen([jhbuild_path, '--no-interact', '-f', top_level_path('Tools', platform, 'jhbuildrc')] + sys.argv[2:])
150 sys.exit(process.returncode)