a29b60c2f90f2bacdc19c0780e7484ecff5383d5
[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 = '24a7dd8e2be84026bf3b303321adad371a694b23'
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     if "GREP_OPTIONS" in os.environ:
79         del os.environ['GREP_OPTIONS']
80     process = subprocess.Popen(['bash', './autogen.sh', '--prefix=%s' % installation_prefix], cwd=jhbuild_source_path)
81     process.wait()
82     if process.returncode != 0:
83         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
84
85     # This is a hackish approach to make the subprocess.Popen call even when people set
86     # MAKE to 'make -j3' instead of using the MAKEFLAGS environment variable.
87     make = shlex.split(os.environ.get('MAKE', 'make'))
88
89     process = subprocess.Popen(make + ['install'], cwd=jhbuild_source_path)
90     process.wait()
91     if process.returncode != 0:
92         raise Exception('jhbuild configure failed with return code: %i' % process.returncode)
93
94
95 def determine_platform():
96     if '--efl' in sys.argv:
97         return "efl";
98     if '--gtk' in sys.argv:
99         return "gtk";
100     raise ValueError('No platform specified for jhbuild-wrapper.')
101
102
103 def ensure_jhbuild(platform):
104     if not jhbuild_cloned():
105         clone_jhbuild()
106         update_jhbuild()
107         install_jhbuild()
108     elif not jhbuild_installed() \
109             or not jhbuild_at_expected_revision():
110         update_jhbuild()
111         install_jhbuild()
112
113 # Work-around the fact that we may get called from inside the jhbuild environment
114 # which will cause problems if we just cleaned the jhbuild install root
115 if os.environ.has_key('UNDER_JHBUILD'):
116     del os.environ['ACLOCAL_FLAGS']
117
118 try:
119     platform = determine_platform()
120 except ValueError as e:
121     sys.exit(e)
122 ensure_jhbuild(platform)
123
124 os.execve(jhbuild_path, [jhbuild_path, '--no-interact', '-f', jhbuildutils.get_config_file_for_platform(platform)] + sys.argv[2:], os.environ)