Merge branch 'fix-macos-notification-api-detection' of https://github.com/Luflosi/kitty into master

This commit is contained in:
Kovid Goyal 2020-10-19 16:00:38 +05:30
commit d9b292f808
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -13,6 +13,7 @@ import shutil
import subprocess
import sys
import sysconfig
import tempfile
import time
from contextlib import suppress
from functools import partial
@ -211,25 +212,26 @@ def get_sanitize_args(cc: str, ccver: Tuple[int, int]) -> List[str]:
return sanitize_args
def test_compile(cc: str, *cflags: str, src: Optional[str] = None) -> bool:
def test_compile(cc: str, *cflags: str, src: Optional[str] = None, lang: str = 'c') -> bool:
src = src or 'int main(void) { return 0; }'
p = subprocess.Popen(
[cc] + list(cflags) + ['-x', 'c', '-o', os.devnull, '-'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.PIPE
)
stdin = p.stdin
assert stdin is not None
try:
stdin.write(src.encode('utf-8'))
stdin.close()
except BrokenPipeError:
return False
return p.wait() == 0
with tempfile.TemporaryDirectory() as tdir:
p = subprocess.Popen(
[cc] + list(cflags) + ['-x', lang, '-o', os.devnull, '-'], cwd=tdir,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.PIPE,
)
stdin = p.stdin
assert stdin is not None
try:
stdin.write(src.encode('utf-8'))
stdin.close()
except BrokenPipeError:
return False
return p.wait() == 0
def first_successful_compile(cc: str, *cflags: str, src: Optional[str] = None) -> str:
def first_successful_compile(cc: str, *cflags: str, src: Optional[str] = None, lang: str = 'c') -> str:
for x in cflags:
if test_compile(cc, *shlex.split(x), src=src):
if test_compile(cc, *shlex.split(x), src=src, lang=lang):
return x
return ''
@ -340,7 +342,10 @@ def kitty_env() -> Env:
platform_libs = [
'-framework', 'CoreText', '-framework', 'CoreGraphics',
]
user_notifications_framework = first_successful_compile(ans.cc, '-framework UserNotifications')
test_program_src = '''#include <UserNotifications/UserNotifications.h>
int main(void) { return 0; }\n'''
user_notifications_framework = first_successful_compile(ans.cc, ' -framework UserNotifications',
src=test_program_src, lang='objective-c')
if user_notifications_framework:
platform_libs.extend(shlex.split(user_notifications_framework))
else: