40bbb0101ca47c7d6ab6dd071748ab610ada3bd9
[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 jhbuildutils
21 import os
22 import shlex
23 import subprocess
24 import sys
25
26 jhbuild_revision = '1eedc423f75c605224b430579e4c303292199507'
27
28 dependencies_path = jhbuildutils.get_dependencies_path()
29 installation_prefix = os.path.abspath(os.path.join(dependencies_path, 'Root'))
30 source_path = os.path.abspath(os.path.join(dependencies_path, 'Source'))
31 jhbuild_source_path = os.path.join(source_path, 'jhbuild')
32 jhbuild_path = os.path.join(installation_prefix, 'bin', 'jhbuild')
33
34 def jhbuild_installed():
35     return os.path.exists(jhbuild_path)
36
37
38 def jhbuild_cloned():
39     return os.path.exists(jhbuild_source_path)
40
41
42 def jhbuild_at_expected_revision():
43     process = subprocess.Popen(['git', 'rev-list', 'HEAD^..'], cwd=jhbuild_source_path,
44                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45     output, err = process.communicate()
46     if process.returncode != 0:
47         raise Exception('failed to find jhbuild revision: %s' % err)
48
49     return output.strip() == jhbuild_revision
50
51
52 def update_jhbuild():
53     process = subprocess.Popen(['git', 'remote', 'update', 'origin'], cwd=jhbuild_source_path)
54     process.wait()
55     if process.returncode != 0:
56         raise Exception('jhbuild remote update origin failed with return code: %i' % process.returncode)
57
58     process = subprocess.Popen(['git', 'checkout', '%s' % jhbuild_revision],
59                                cwd=jhbuild_source_path)
60     process.wait()
61     if process.returncode != 0:
62         raise Exception('failed to checkout treeish %s: %i' % (jhbuild_revision, process.returncode))
63
64
65 def clone_jhbuild():
66     if not os.path.exists(source_path):
67         os.makedirs(source_path)
68     if not os.path.exists(installation_prefix):
69         os.makedirs(installation_prefix)
70
71     process = subprocess.Popen(['git', 'clone', 'git://git.gnome.org/jhbuild'], cwd=source_path)
72     process.wait()
73     if process.returncode != 0:
74         raise Exception('jhbuild git clone failed with return code: %i' % process.returncode)
75
76
77 def install_jhbuild():
78     process = subprocess.Popen(['bash', './autogen.sh', '--prefix=%s' % installation_prefix], cwd=jhbuild_source_path)
79     process.wait()
80     if process.returncode != 0:
81         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
82
83     # This is a hackish approach to make the subprocess.Popen call even when people set
84     # MAKE to 'make -j3' instead of using the MAKEFLAGS environment variable.
85     make = shlex.split(os.environ.get('MAKE', 'make'))
86
87     process = subprocess.Popen(make + ['install'], cwd=jhbuild_source_path)
88     process.wait()
89     if process.returncode != 0:
90         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
91
92
93 def determine_platform():
94     if '--efl' in sys.argv:
95         return "efl";
96     if '--gtk' in sys.argv:
97         return "gtk";
98     raise ValueError('No platform specified for jhbuild-wrapper.')
99
100
101 def ensure_jhbuild(platform):
102     if not jhbuild_cloned():
103         clone_jhbuild()
104         update_jhbuild()
105         install_jhbuild()
106     elif not jhbuild_installed() \
107             or not jhbuild_at_expected_revision():
108         update_jhbuild()
109         install_jhbuild()
110
111 # Work-around the fact that we may get called from inside the jhbuild environment
112 # which will cause problems if we just cleaned the jhbuild install root
113 if os.environ.has_key('UNDER_JHBUILD'):
114     del os.environ['ACLOCAL_FLAGS']
115
116 try:
117     platform = determine_platform()
118 except ValueError as e:
119     sys.exit(e)
120 ensure_jhbuild(platform)
121
122 os.execve(jhbuild_path, [jhbuild_path, '--no-interact', '-f', jhbuildutils.get_config_file_for_platform(platform)] + sys.argv[2:], os.environ)