2020-05-22 14:58:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2020 Igalia S.L.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
# Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
import os
|
2020-09-16 16:39:23 +00:00
|
|
|
import itertools
|
2020-05-22 14:58:41 +00:00
|
|
|
import shlex
|
2021-02-11 09:29:22 +00:00
|
|
|
import stat
|
2020-05-22 14:58:41 +00:00
|
|
|
import sys
|
|
|
|
import tempfile
|
2021-01-27 09:05:59 +00:00
|
|
|
import json
|
2020-05-22 14:58:41 +00:00
|
|
|
|
|
|
|
scriptdir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
2021-02-11 09:29:22 +00:00
|
|
|
def read_lines(fd: int):
|
|
|
|
new_fd = os.dup(fd)
|
|
|
|
pos = os.lseek(fd, 0, os.SEEK_CUR)
|
|
|
|
try:
|
|
|
|
with os.fdopen(new_fd, 'r') as handle:
|
|
|
|
data = handle.read()
|
|
|
|
lines = data.split('\x00')
|
|
|
|
for line in lines:
|
|
|
|
yield line
|
|
|
|
except Exception as e:
|
|
|
|
print("Error reading brwap arguments", file=sys.stderr)
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
finally:
|
|
|
|
os.lseek(fd, pos, os.SEEK_SET)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-22 14:58:41 +00:00
|
|
|
def main(args: list) -> int:
|
|
|
|
tmpdir = tempfile.gettempdir()
|
|
|
|
source_root = os.path.normpath(os.path.abspath(os.path.join(scriptdir, '../../')))
|
2021-01-27 09:05:59 +00:00
|
|
|
build_root = os.path.join(source_root, 'WebKitBuild')
|
2020-05-22 14:58:41 +00:00
|
|
|
bind_mounts = {
|
|
|
|
"/app/webkit": source_root,
|
|
|
|
# Access to /run/host is required by the crash log reporter.
|
2020-05-25 08:33:09 +00:00
|
|
|
f"/run/host{tmpdir}": f"{tmpdir}",
|
|
|
|
"/run/shm": "/dev/shm",
|
2020-05-22 14:58:41 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 09:29:22 +00:00
|
|
|
args_idx = args.index('--args')
|
|
|
|
arg_fd = int(args[args_idx + 1])
|
|
|
|
|
|
|
|
lines = read_lines(arg_fd)
|
|
|
|
|
2021-02-11 17:09:48 +00:00
|
|
|
environ = os.environ.copy()
|
2021-02-11 09:29:22 +00:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
arg = next(lines)
|
|
|
|
if arg == '--setenv':
|
|
|
|
key = next(lines)
|
|
|
|
value = next(lines)
|
|
|
|
environ[key] = value
|
|
|
|
except StopIteration:
|
|
|
|
break
|
2021-01-27 09:05:59 +00:00
|
|
|
|
|
|
|
flatpak_user_dir = environ.get("WEBKIT_FLATPAK_USER_DIR")
|
2020-05-25 08:33:09 +00:00
|
|
|
if flatpak_user_dir:
|
|
|
|
bind_mounts["/var/tmp"] = os.path.join(flatpak_user_dir, "var", "tmp")
|
|
|
|
|
2020-05-22 14:58:41 +00:00
|
|
|
try_bind_mounts = {
|
|
|
|
"/run/icecc": "/var/run/icecc"
|
|
|
|
}
|
|
|
|
|
2021-01-27 09:05:59 +00:00
|
|
|
build_path = environ.get("WEBKIT_BUILD_DIR_BIND_MOUNT")
|
2020-05-22 14:58:41 +00:00
|
|
|
if build_path:
|
|
|
|
dest, src = build_path.split(":")
|
|
|
|
try_bind_mounts[dest] = src
|
|
|
|
|
2021-01-27 09:05:59 +00:00
|
|
|
coredumps_dir = environ.get("WEBKIT_CORE_DUMPS_DIRECTORY")
|
2020-05-22 14:58:41 +00:00
|
|
|
if coredumps_dir:
|
|
|
|
try_bind_mounts[coredumps_dir] = coredumps_dir
|
|
|
|
|
2021-01-27 09:05:59 +00:00
|
|
|
xdg_runtime_dir = environ.get("XDG_RUNTIME_DIR")
|
2020-09-17 18:07:45 +00:00
|
|
|
if xdg_runtime_dir:
|
|
|
|
pw_socket = os.path.join(xdg_runtime_dir, "pipewire-0")
|
|
|
|
try_bind_mounts[pw_socket] = pw_socket
|
|
|
|
|
2020-05-22 14:58:41 +00:00
|
|
|
bwrap_args = ["bwrap", ]
|
|
|
|
for dst, src in bind_mounts.items():
|
2020-09-16 16:39:23 +00:00
|
|
|
bwrap_args.extend(("--bind", src, dst))
|
2020-05-22 14:58:41 +00:00
|
|
|
|
|
|
|
for dst, src in try_bind_mounts.items():
|
2020-09-16 16:39:23 +00:00
|
|
|
bwrap_args.extend(("--bind-try", src, dst))
|
2020-05-22 14:58:41 +00:00
|
|
|
|
2021-02-22 12:20:16 +00:00
|
|
|
display = environ.get("WEBKIT_FLATPAK_DISPLAY")
|
|
|
|
if display:
|
|
|
|
bwrap_args.extend(("--setenv", "DISPLAY", display))
|
|
|
|
|
2021-01-27 09:05:59 +00:00
|
|
|
for env in environ.keys():
|
2020-06-23 15:48:20 +00:00
|
|
|
if env.startswith("LC_") or env == "LANGUAGE":
|
2020-09-16 16:39:23 +00:00
|
|
|
bwrap_args.extend(("--unsetenv", env))
|
2020-06-23 15:48:20 +00:00
|
|
|
|
2021-02-22 12:27:44 +00:00
|
|
|
if environ.get("WEBKIT_FLATPAK_LD_PRELOAD"):
|
|
|
|
os.environ["LD_PRELOAD"] = environ["WEBKIT_FLATPAK_LD_PRELOAD"]
|
|
|
|
|
2020-09-16 16:39:23 +00:00
|
|
|
command_line = ' '.join(map(shlex.quote, itertools.chain(bwrap_args, args)))
|
2020-09-14 09:51:24 +00:00
|
|
|
|
2020-05-29 13:58:01 +00:00
|
|
|
# os.system return code behaves like os.wait. A 16 bit number with the
|
|
|
|
# signal in the lower byte and, if the signal is zero, the exit code in
|
|
|
|
# the high byte.
|
|
|
|
return os.system(command_line) >> 8
|
2020-05-22 14:58:41 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main(sys.argv[1:]))
|