Allow changing the source used by test_compile

This commit is contained in:
Kovid Goyal 2018-04-20 21:02:05 +05:30
parent 23077fd6a6
commit ea9b431386
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -141,16 +141,17 @@ def get_sanitize_args(cc, ccver):
return sanitize_args
def test_compile(cc, *cflags):
def test_compile(cc, *cflags, src=None):
with tempfile.NamedTemporaryFile(suffix='.c') as f:
f.write(b'int main(void) { return 0; }')
src = src or 'int main(void) { return 0; }'
f.write(src.encode('utf-8'))
f.flush()
return subprocess.Popen([cc] + list(cflags) + [f.name, '-o', os.devnull]).wait() == 0
def first_successful_compile(cc, *cflags):
def first_successful_compile(cc, *cflags, src=None):
for x in cflags:
if test_compile(cc, *shlex.split(x)):
if test_compile(cc, *shlex.split(x), src=src):
return x
return ''