-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsetup.py
59 lines (48 loc) · 2.11 KB
/
setup.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import platform
import sys
import setuptools
from setuptools import Extension
if platform.python_implementation() != "PyPy":
# We need to pass the -std=c99 to gcc and/or clang, but we shouldn't pass
# it to MSVC. There doesn't seem to be a simple way of setting
# compiler-specific compile arguments, but for practical purposes
# conditionally adding this argument on non-Windows platforms should be
# enough. If an edge case is found that prevents compilation on some
# systems, the end user should be able to set CFLAGS="-std=c99".
if not sys.platform.startswith("win"):
extra_compile_args = ["-std=c99"]
else:
extra_compile_args = []
c_extension = Extension(
"backports.zoneinfo._czoneinfo",
sources=["lib/zoneinfo_module.c"],
extra_compile_args=extra_compile_args,
)
setuptools.setup(ext_modules=[c_extension])
else:
setuptools.setup()
if "GCNO_TARGET_DIR" in os.environ:
import glob
gcno_files = glob.glob("**/*.gcno", recursive=True)
if gcno_files:
import shutil
target_dir = os.environ["GCNO_TARGET_DIR"]
os.makedirs(target_dir, exist_ok=True)
for gcno_file in gcno_files:
src = gcno_file
src_dir, filename = os.path.split(gcno_file)
new_target_dir = target_dir
# When using gcc-9, the files are created in some flat location
# with a naming convention where /path/to/file.gcda would be
# represented as ${BASEDIR}/#path#to#file.gcda. In gcc-7, the input
# directory is mirrored in the output directory, so the filename
# would be ${BASEDIR}/path/to/file.gcda. The gcno files need to
# have the same name and relative location as the gcda files,
# apparently.
if not filename.startswith("#"):
rel_src_dir = os.path.relpath(src_dir)
new_target_dir = os.path.join(target_dir, rel_src_dir)
os.makedirs(new_target_dir, exist_ok=True)
dst = os.path.join(new_target_dir, filename)
shutil.copy(src, dst)