Debian Codegraph @

pypy/module/_cppyy/test/make_dict_win32.py

raw symbols SCIP
1 import glob, os, sys, subprocess
2
3 USES_PYTHON_CAPI = set(('pythonizables',))
4
5 fn = sys.argv[1]
6
7 if fn == 'all':
8 all_headers = glob.glob('*.h')
9 for header in all_headers:
10 res = os.system(" ".join(['python', sys.argv[0], header[:-2]]+sys.argv[2:]))
11 if res != 0:
12 sys.exit(res)
13 sys.exit(0)
14 else:
15 if fn[-4:] == '.cxx': fn = fn[:-4]
16 elif fn[-2:] == '.h': fn = fn[:-2]
17 if not os.path.exists(fn+'.h'):
18 print("file %s.h does not exist" % (fn,))
19 sys.exit(1)
20
21 uses_python_capi = False
22 if fn in USES_PYTHON_CAPI:
23 uses_python_capi = True
24
25 if os.path.exists(fn+'Dict.dll'):
26 dct_time = os.stat(fn+'Dict.dll').st_mtime
27 if not '-f' in sys.argv:
28 mustbuild = False
29 for ext in ['.h', '.cxx', '.xml']:
30 if os.stat(fn+ext).st_mtime > dct_time:
31 mustbuild = True
32 break
33 if not mustbuild:
34 sys.exit(0)
35
36 # cleanup
37 for fg in set(glob.glob(fn+"_rflx*") + glob.glob(fn+"Dict*") + \
38 glob.glob("*.obj") + glob.glob(fn+"Linkdef.h")):
39 os.remove(fg)
40
41 def _get_config_exec():
42 return [sys.executable, '-m', 'cppyy_backend._cling_config']
43
44 def get_config(what):
45 config_exec_args = _get_config_exec()
46 config_exec_args.append('--'+what)
47 cli_arg = subprocess.check_output(config_exec_args)
48 return cli_arg.decode("utf-8").strip()
49
50 def get_python_include_dir():
51 incdir = subprocess.check_output([sys.executable, '-c', "import sysconfig; print(sysconfig.get_path('include'))"])
52 return incdir.decode("utf-8").strip()
53
54 def get_python_lib_dir():
55 libdir = subprocess.check_output([sys.executable, '-c', "import sysconfig; print(sysconfig.get_path('stdlib'))"])
56 return os.path.join(os.path.dirname(libdir.decode("utf-8").strip()), 'libs')
57
58 # genreflex option
59 #DICTIONARY_CMD = "genreflex {fn}.h --selection={fn}.xml --rootmap={fn}Dict.rootmap --rootmap-lib={fn}Dict.dll".format(fn=fn)
60
61 with open(fn+'Linkdef.h', 'w') as linkdef:
62 linkdef.write("#ifdef __CLING__\n\n")
63 linkdef.write("#pragma link C++ defined_in %s.h;\n" % fn)
64 linkdef.write("\n#endif")
65
66 DICTIONARY_CMD = "python -m cppyy_backend._rootcling -f {fn}_rflx.cxx -rmf {fn}Dict.rootmap -rml {fn}Dict.dll {fn}.h {fn}Linkdef.h".format(fn=fn)
67 if os.system(DICTIONARY_CMD):
68 sys.exit(1)
69
70 import platform
71 if '64' in platform.architecture()[0]:
72 PLATFORMFLAG = '-D_AMD64_'
73 MACHINETYPE = 'X64'
74 else:
75 PLATFORMFLAG = '-D_X86_'
76 MACHINETYPE = 'IX86'
77
78 cppflags = get_config('cppflags')
79 if uses_python_capi:
80 cppflags += ' -I"' + get_python_include_dir() + '"'
81 BUILDOBJ_CMD_PART = "cl -O2 -nologo -TP -c -nologo " + cppflags + " -FIsehmap.h -Zc:__cplusplus -MD -GR -D_WINDOWS -DWIN32 " + PLATFORMFLAG + " -EHsc- -W3 -wd4141 -wd4291 -wd4244 -wd4049 -D_XKEYCHECK_H -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS {fn}.cxx -Fo{fn}.obj"
82 BUILDOBJ_CMD = BUILDOBJ_CMD_PART.format(fn=fn)
83 if os.system(BUILDOBJ_CMD):
84 sys.exit(1)
85 BUILDOBJ_CMD = BUILDOBJ_CMD_PART.format(fn=fn+'_rflx')
86 if os.system(BUILDOBJ_CMD):
87 sys.exit(1)
88
89 import cppyy_backend
90 CREATEDEF_CMD = "python bindexplib.py {fn} {fn}Dict".format(fn=fn)
91 if os.system(CREATEDEF_CMD):
92 sys.exit(1)
93
94 ldflags = ''
95 if uses_python_capi:
96 ldflags = ' /LIBPATH:"' + get_python_lib_dir() + '" '
97 CREATELIB_CMD = ("lib -nologo -MACHINE:" + MACHINETYPE + " -out:{fn}Dict.lib {fn}.obj {fn}_rflx.obj -def:{fn}Dict.def " + ldflags).format(fn=fn)
98 if os.system(CREATELIB_CMD):
99 sys.exit(1)
100
101 ldflags += get_config('ldflags')
102 LINKDLL_CMD = ("link -nologo {fn}.obj {fn}_rflx.obj -DLL -out:{fn}Dict.dll {fn}Dict.exp " + ldflags).format(fn=fn)
103 if os.system(LINKDLL_CMD):
104 sys.exit(1)
105
106 # cleanup
107 for fg in set(glob.glob(fn+"_rflx.cxx*") + glob.glob("*.obj") + glob.glob(fn+"Linkdef.h")):
108 os.remove(fg)