5f88ed0531b6e0145c32f6374d4b197c5e43b5e1
[WebKit-https.git] / Tools / gtk / run-with-jhbuild
1 #!/usr/bin/env python
2 # Copyright (C) 2011 Igalia S.L.
3 # Copyright (C) 2012 Gustavo Noronha Silva <gns@gnome.org>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
19 import common
20 import os
21 import subprocess
22 import sys
23
24
25 jhbuild_revision = '1eedc423f75c605224b430579e4c303292199507'
26
27 installation_prefix = os.path.abspath(common.top_level_path('WebKitBuild', 'Dependencies', 'Root'))
28 source_path = os.path.abspath(common.top_level_path('WebKitBuild', 'Dependencies', 'Source'))
29 jhbuild_source_path = os.path.join(source_path, 'jhbuild')
30 jhbuild_path = common.top_level_path('WebKitBuild', 'Dependencies', 'Root', 'bin', 'jhbuild')
31
32
33 def jhbuild_installed():
34     return os.path.exists(jhbuild_path)
35
36
37 def jhbuild_cloned():
38     return os.path.exists(jhbuild_source_path)
39
40
41 def jhbuild_at_expected_revision():
42     process = subprocess.Popen(['git', 'rev-list', 'HEAD^..'], cwd=jhbuild_source_path,
43                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
44     output, err = process.communicate()
45     if process.returncode != 0:
46         raise Exception('failed to find jhbuild revision: %s' % err)
47
48     return output.strip() == jhbuild_revision
49
50
51 def update_jhbuild():
52     process = subprocess.Popen(['git', 'remote', 'update', 'origin'], cwd=jhbuild_source_path)
53     process.wait()
54     if process.returncode != 0:
55         raise Exception('jhbuild remote update origin failed with return code: %i' % process.returncode)
56
57     process = subprocess.Popen(['git', 'checkout', '%s' % jhbuild_revision],
58                                cwd=jhbuild_source_path)
59     process.wait()
60     if process.returncode != 0:
61         raise Exception('failed to checkout treeish %s: %i' % (jhbuild_revision, process.returncode))
62
63
64 def clone_jhbuild():
65     if not os.path.exists(source_path):
66         os.makedirs(source_path)
67     if not os.path.exists(installation_prefix):
68         os.makedirs(installation_prefix)
69
70     process = subprocess.Popen(['git', 'clone', 'git://git.gnome.org/jhbuild'], cwd=source_path)
71     process.wait()
72     if process.returncode != 0:
73         raise Exception('jhbuild git clone failed with return code: %i' % process.returncode)
74
75
76 def install_jhbuild():
77     # jhbuild is really unhappy about having MAKE defined to something like 'make -j4'
78     # so we just undefine it here.
79     env_without_make = dict(os.environ)
80     if 'MAKE' in env_without_make:
81         del env_without_make['MAKE']
82
83     process = subprocess.Popen(['./autogen.sh', '--prefix=%s' % installation_prefix],
84                                cwd=jhbuild_source_path, env=env_without_make)
85     process.wait()
86     if process.returncode != 0:
87         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
88
89     process = subprocess.Popen(['make', 'install'], cwd=jhbuild_source_path, env=env_without_make)
90     process.wait()
91     if process.returncode != 0:
92         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
93
94
95 def update_webkitgtk_libs():
96     process = subprocess.Popen(common.top_level_path('Tools', 'Scripts', 'update-webkitgtk-libs'))
97     process.wait()
98     if process.returncode != 0:
99         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
100
101
102 def ensure_jhbuild():
103     if not jhbuild_cloned():
104         clone_jhbuild()
105         update_jhbuild()
106         install_jhbuild()
107         update_webkitgtk_libs()
108     elif not jhbuild_installed() \
109             or not jhbuild_at_expected_revision():
110         update_jhbuild()
111         install_jhbuild()
112
113
114 ensure_jhbuild()
115
116
117 process = subprocess.Popen([jhbuild_path, '--no-interact', '-f', common.top_level_path('Tools', 'gtk', 'jhbuildrc'), 'run'] + sys.argv[1:])
118 process.wait()
119 sys.exit(process.returncode)
120
121
122