2 # Copyright (C) 2011 Igalia S.L.
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 def script_path(*args):
31 script_dir = os.path.join(os.path.dirname(__file__), '..', 'Scripts')
32 return os.path.join(*(script_dir,) + args)
35 def top_level_path(*args):
36 return os.path.join(*((script_path('..', '..'),) + args))
39 def get_build_path(build_types=('Release', 'Debug')):
44 def is_valid_build_directory(path):
45 return os.path.exists(os.path.join(path, 'GNUmakefile')) or \
46 os.path.exists(os.path.join(path, 'Programs', 'DumpRenderTree'))
48 if len(sys.argv[1:]) > 1 and os.path.exists(sys.argv[-1]) and is_valid_build_directory(sys.argv[-1]):
51 # Debian and Ubuntu build both flavours of the library (with gtk2
52 # and with gtk3); they use directories build-2.0 and build-3.0 for
53 # that, which is not handled by the above cases; we check that the
54 # directory where we are called from is a valid build directory,
55 # which should handle pretty much all other non-standard cases.
56 build_dir = os.getcwd()
57 if is_valid_build_directory(build_dir):
60 for build_type in build_types:
61 build_dir = top_level_path('WebKitBuild', build_type)
62 if is_valid_build_directory(build_dir):
65 # distcheck builds in a directory named _build in the top-level path.
66 build_dir = top_level_path("_build")
67 if is_valid_build_directory(build_dir):
70 build_dir = top_level_path()
71 if is_valid_build_directory(build_dir):
74 build_dir = top_level_path("WebKitBuild")
75 if is_valid_build_directory(build_dir):
78 print('Could not determine build directory.')
82 def build_path_for_build_types(build_types, *args):
83 return os.path.join(*(get_build_path(build_types),) + args)
86 def build_path(*args):
87 return build_path_for_build_types(('Release', 'Debug'), *args)
90 def pkg_config_file_variable(package, variable):
91 process = subprocess.Popen(['pkg-config', '--variable=%s' % variable, package],
92 stdout=subprocess.PIPE)
93 stdout = process.communicate()[0].decode("utf-8")
94 if process.returncode:
99 def prefix_of_pkg_config_file(package):
100 return pkg_config_file_variable(package, 'prefix')
103 def gtk_version_of_pkg_config_file(pkg_config_path):
104 process = subprocess.Popen(['pkg-config', pkg_config_path, '--print-requires'],
105 stdout=subprocess.PIPE)
106 stdout = process.communicate()[0].decode("utf-8")
108 if 'gtk+-3.0' in stdout:
113 def parse_output_lines(fd, parse_line_callback):
118 rlist, wlist, xlist = select.select(read_set, [], [])
119 except select.error as e:
120 parse_line_callback("WARNING: error while waiting for fd %d to become readable\n" % fd)
121 parse_line_callback(" error code: %d, error message: %s\n" % (e[0], e[1]))
126 chunk = os.read(fd, 1024)
128 if e.errno == errno.EIO:
129 # Child process finished.
137 while '\n' in output:
138 pos = output.find('\n')
139 parse_line_callback(output[:pos + 1])
140 output = output[pos + 1:]
142 if not chunk and output:
143 parse_line_callback(output)