ac4d77c755fe6b08d780e35983ff2f1947b51e43
[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 #
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
20 import os
21 import subprocess
22 import sys
23
24
25 top_level_dir = None
26
27
28 def top_level_path(*args):
29     global top_level_dir
30     if not top_level_dir:
31         top_level_dir = os.path.join(os.path.dirname(__file__), '..', '..')
32     return os.path.join(*(top_level_dir,) + args)
33
34
35 jhbuild_revision = '1eedc423f75c605224b430579e4c303292199507'
36
37 installation_prefix = os.path.abspath(top_level_path('WebKitBuild', 'Dependencies', 'Root'))
38 source_path = os.path.abspath(top_level_path('WebKitBuild', 'Dependencies', 'Source'))
39 jhbuild_source_path = os.path.join(source_path, 'jhbuild')
40 jhbuild_path = top_level_path('WebKitBuild', 'Dependencies', 'Root', 'bin', 'jhbuild')
41 platform = None;
42
43
44 def jhbuild_installed():
45     return os.path.exists(jhbuild_path)
46
47
48 def jhbuild_cloned():
49     return os.path.exists(jhbuild_source_path)
50
51
52 def jhbuild_at_expected_revision():
53     process = subprocess.Popen(['git', 'rev-list', 'HEAD^..'], cwd=jhbuild_source_path,
54                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
55     output, err = process.communicate()
56     if process.returncode != 0:
57         raise Exception('failed to find jhbuild revision: %s' % err)
58
59     return output.strip() == jhbuild_revision
60
61
62 def update_jhbuild():
63     process = subprocess.Popen(['git', 'remote', 'update', 'origin'], cwd=jhbuild_source_path)
64     process.wait()
65     if process.returncode != 0:
66         raise Exception('jhbuild remote update origin failed with return code: %i' % process.returncode)
67
68     process = subprocess.Popen(['git', 'checkout', '%s' % jhbuild_revision],
69                                cwd=jhbuild_source_path)
70     process.wait()
71     if process.returncode != 0:
72         raise Exception('failed to checkout treeish %s: %i' % (jhbuild_revision, process.returncode))
73
74
75 def clone_jhbuild():
76     if not os.path.exists(source_path):
77         os.makedirs(source_path)
78     if not os.path.exists(installation_prefix):
79         os.makedirs(installation_prefix)
80
81     process = subprocess.Popen(['git', 'clone', 'git://git.gnome.org/jhbuild'], cwd=source_path)
82     process.wait()
83     if process.returncode != 0:
84         raise Exception('jhbuild git clone failed with return code: %i' % process.returncode)
85
86
87 def install_jhbuild():
88     # jhbuild is really unhappy about having MAKE defined to something like 'make -j4'
89     # so we just undefine it here.
90     env_without_make = dict(os.environ)
91     if 'MAKE' in env_without_make:
92         del env_without_make['MAKE']
93
94     process = subprocess.Popen(['bash', './autogen.sh', '--prefix=%s' % installation_prefix],
95                                cwd=jhbuild_source_path, env=env_without_make)
96     process.wait()
97     if process.returncode != 0:
98         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
99
100     process = subprocess.Popen(['make', 'install'], cwd=jhbuild_source_path, env=env_without_make)
101     process.wait()
102     if process.returncode != 0:
103         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
104
105
106 def update_webkit_libs_jhbuild():
107     process = subprocess.Popen([top_level_path('Tools', 'Scripts', 'update-webkit-libs-jhbuild'), '--' + platform])
108     process.wait()
109     if process.returncode != 0:
110         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
111
112
113 def determine_platform():
114     if '--efl' in sys.argv:
115         return "efl";
116     if '--gtk' in sys.argv:
117         return "gtk";
118     raise ValueError('No platform specified for jhbuild-wrapper.')
119
120
121 def ensure_jhbuild():
122     if not jhbuild_cloned():
123         clone_jhbuild()
124         update_jhbuild()
125         install_jhbuild()
126         update_webkit_libs_jhbuild()
127     elif not jhbuild_installed() \
128             or not jhbuild_at_expected_revision():
129         update_jhbuild()
130         install_jhbuild()
131
132 try:
133     platform = determine_platform()
134 except ValueError as e:
135     sys.exit(e)
136 ensure_jhbuild()
137
138 process = subprocess.Popen([jhbuild_path, '--no-interact', '-f', top_level_path('Tools', platform, 'jhbuildrc'), 'run'] + sys.argv[2:])
139 process.wait()
140 sys.exit(process.returncode)