Fix API test after r241728
[WebKit-https.git] / Tools / jhbuild / jhbuild-wrapper
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 # Copyright (C) 2012, 2013 Nokia Corporation and/or its subsidiary(-ies).
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
21 import jhbuildutils
22 import os
23 import shlex
24 import subprocess
25 import sys
26
27 jhbuild_revision = 'b1d2ebdef165435c048c59192a32ba69d4f2c6dd'
28
29 def determine_platform():
30     if '--gtk' in sys.argv:
31         return "gtk";
32     if '--wpe' in sys.argv:
33         return "wpe"
34     raise ValueError('No platform specified for jhbuild-wrapper.')
35
36 try:
37     platform = determine_platform()
38 except ValueError as e:
39     sys.exit(e)
40
41 dependencies_path = jhbuildutils.get_dependencies_path(platform)
42 installation_prefix = os.path.abspath(os.path.join(dependencies_path, 'Root'))
43 source_path = os.path.abspath(os.path.join(dependencies_path, 'Source'))
44 jhbuild_source_path = os.path.join(source_path, 'jhbuild')
45 jhbuild_path = os.path.join(installation_prefix, 'bin', 'jhbuild')
46
47 def jhbuild_installed():
48     return os.path.exists(jhbuild_path)
49
50
51 def jhbuild_cloned():
52     return os.path.exists(jhbuild_source_path)
53
54
55 def jhbuild_at_expected_revision():
56     process = subprocess.Popen(['git', 'rev-list', 'HEAD^..'], cwd=jhbuild_source_path,
57                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
58     output, err = process.communicate()
59     if process.returncode != 0:
60         raise Exception('failed to find jhbuild revision: %s' % err)
61
62     return output.strip() == jhbuild_revision
63
64
65 def update_jhbuild():
66     process = subprocess.Popen(['git', 'remote', 'update', 'origin'], cwd=jhbuild_source_path)
67     process.wait()
68     if process.returncode != 0:
69         raise Exception('jhbuild remote update origin failed with return code: %i' % process.returncode)
70
71     process = subprocess.Popen(['git', 'checkout', '%s' % jhbuild_revision],
72                                cwd=jhbuild_source_path)
73     process.wait()
74     if process.returncode != 0:
75         raise Exception('failed to checkout treeish %s: %i' % (jhbuild_revision, process.returncode))
76
77
78 def clone_jhbuild():
79     if not os.path.exists(source_path):
80         os.makedirs(source_path)
81     if not os.path.exists(installation_prefix):
82         os.makedirs(installation_prefix)
83
84     # Use only 1 thread to workaround a QEMU bug - see http://webkit.org/b/143095 for details.
85     process = subprocess.Popen(['git', 'clone', '--config', 'pack.threads=1', 'https://git.gnome.org/browse/jhbuild'], cwd=source_path)
86     process.wait()
87     if process.returncode != 0:
88         raise Exception('jhbuild git clone failed with return code: %i' % process.returncode)
89
90
91 def install_jhbuild():
92     if "GREP_OPTIONS" in os.environ:
93         del os.environ['GREP_OPTIONS']
94     process = subprocess.Popen(['bash', './autogen.sh', '--prefix=%s' % installation_prefix], cwd=jhbuild_source_path)
95     process.wait()
96     if process.returncode != 0:
97         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
98
99     # This is a hackish approach to make the subprocess.Popen call even when people set
100     # MAKE to 'make -j3' instead of using the MAKEFLAGS environment variable.
101     make = shlex.split(os.environ.get('MAKE', 'make'))
102
103     process = subprocess.Popen(make + ['install'], cwd=jhbuild_source_path)
104     process.wait()
105     if process.returncode != 0:
106         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
107
108 def ensure_jhbuild(platform):
109     if not jhbuild_cloned():
110         clone_jhbuild()
111         update_jhbuild()
112         install_jhbuild()
113     elif not jhbuild_installed() \
114             or not jhbuild_at_expected_revision():
115         update_jhbuild()
116         install_jhbuild()
117
118 # Work-around the fact that we may get called from inside the jhbuild environment
119 # which will cause problems if we just cleaned the jhbuild install root
120 if os.environ.has_key('UNDER_JHBUILD') and os.environ.has_key('ACLOCAL_FLAGS'):
121     del os.environ['ACLOCAL_FLAGS']
122
123 ensure_jhbuild(platform)
124
125 os.execve(jhbuild_path, [jhbuild_path, '--exit-on-error', '--no-interact', '-f', jhbuildutils.get_config_file_for_platform(platform)] + sys.argv[2:], os.environ)