| 1 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
import os |
| 5 |
|
| 6 |
from mozbuild.util import FileAvoidWrite |
| 7 |
|
| 8 |
header_template = """#pragma GCC system_header |
| 9 |
#pragma GCC visibility push(default) |
| 10 |
{includes} |
| 11 |
#pragma GCC visibility pop |
| 12 |
""" |
| 13 |
|
| 14 |
include_next_template = "#include_next <{header}>" |
| 15 |
|
| 16 |
|
| 17 |
# The 'unused' arg is the output file from the file_generate action. We actually |
| 18 |
# generate all the files in header_list |
| 19 |
def gen_wrappers(unused, outdir, *header_list): |
| 20 |
for header in header_list: |
| 21 |
with FileAvoidWrite(os.path.join(outdir, header)) as f: |
| 22 |
includes = include_next_template.format(header=header) |
| 23 |
if header == "wayland-util.h" or header == "pipewire/pipewire.h": |
| 24 |
# wayland-util.h in Wayland < 1.12 and pipewire.h > 1.4 include |
| 25 |
# math.h inside an extern "C" block, which breaks including the |
| 26 |
# header from C++. This was fixed in Wayland 1.12, but for versions |
| 27 |
# earlier than that, we work around that by force-including math.h |
| 28 |
# first. |
| 29 |
includes = "#include <math.h>\n" + includes |
| 30 |
elif header == "wayland-client.h": |
| 31 |
# The system wayland-client.h uses quote includes for |
| 32 |
# wayland-util.h, which means wayland-util.h is picked from the |
| 33 |
# directory containing wayland-client.h first, and there's no |
| 34 |
# way around that with -I, -isystem, or other flags. So, we |
| 35 |
# force to include it from our wrapper, before including the |
| 36 |
# system header, so that our wayland-util.h wrapper is picked |
| 37 |
# first. |
| 38 |
includes = '#include "wayland-util.h"\n' + includes |
| 39 |
f.write(header_template.format(includes=includes)) |