-
Notifications
You must be signed in to change notification settings - Fork 59
/
check_curl.py
executable file
·37 lines (31 loc) · 1.03 KB
/
check_curl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
# coding: utf-8
import os
import sys
import subprocess
import tempfile
baseDir = os.path.abspath(os.path.dirname(__file__))
def check_curl():
buildDir = os.path.join(baseDir, 'build')
if not os.path.exists(buildDir):
os.makedirs(buildDir)
(fd, name) = tempfile.mkstemp(dir=buildDir, suffix='.h')
try:
handle = os.fdopen(fd, 'w')
handle.write('#include <curl/curl.h>')
handle.close()
# This command won't work for Windows or Android build environments but we
# don't want to use curl there anyway
command = ['/usr/bin/env', 'gcc', '-E', name]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.communicate()
if process.returncode:
# call failed, curl not available
sys.stdout.write('0')
else:
# call succeeded, curl can be used
sys.stdout.write('1')
finally:
os.remove(name)
if __name__ == '__main__':
check_curl()