ยปCore Development>Code coverage>Tools/freeze/winmakemakefile.py

Python code coverage for Tools/freeze/winmakemakefile.py

#countcontent
1n/aimport sys, os
2n/a
3n/a# Template used then the program is a GUI program
4n/aWINMAINTEMPLATE = """
5n/a#include <windows.h>
6n/a
7n/aint WINAPI WinMain(
8n/a HINSTANCE hInstance, // handle to current instance
9n/a HINSTANCE hPrevInstance, // handle to previous instance
10n/a LPSTR lpCmdLine, // pointer to command line
11n/a int nCmdShow // show state of window
12n/a )
13n/a{
14n/a extern int Py_FrozenMain(int, char **);
15n/a PyImport_FrozenModules = _PyImport_FrozenModules;
16n/a return Py_FrozenMain(__argc, __argv);
17n/a}
18n/a"""
19n/a
20n/aSERVICETEMPLATE = """
21n/aextern int PythonService_main(int, char **);
22n/a
23n/aint main( int argc, char **argv)
24n/a{
25n/a PyImport_FrozenModules = _PyImport_FrozenModules;
26n/a return PythonService_main(argc, argv);
27n/a}
28n/a"""
29n/a
30n/asubsystem_details = {
31n/a # -s flag : (C entry point template), (is it __main__?), (is it a DLL?)
32n/a 'console' : (None, 1, 0),
33n/a 'windows' : (WINMAINTEMPLATE, 1, 0),
34n/a 'service' : (SERVICETEMPLATE, 0, 0),
35n/a 'com_dll' : ("", 0, 1),
36n/a}
37n/a
38n/adef get_custom_entry_point(subsystem):
39n/a try:
40n/a return subsystem_details[subsystem][:2]
41n/a except KeyError:
42n/a raise ValueError("The subsystem %s is not known" % subsystem)
43n/a
44n/a
45n/adef makemakefile(outfp, vars, files, target):
46n/a save = sys.stdout
47n/a try:
48n/a sys.stdout = outfp
49n/a realwork(vars, files, target)
50n/a finally:
51n/a sys.stdout = save
52n/a
53n/adef realwork(vars, moddefns, target):
54n/a version_suffix = "%r%r" % sys.version_info[:2]
55n/a print("# Makefile for Microsoft Visual C++ generated by freeze.py script")
56n/a print()
57n/a print('target = %s' % target)
58n/a print('pythonhome = %s' % vars['prefix'])
59n/a print()
60n/a print('DEBUG=0 # Set to 1 to use the _d versions of Python.')
61n/a print('!IF $(DEBUG)')
62n/a print('debug_suffix=_d')
63n/a print('c_debug=/Zi /Od /DDEBUG /D_DEBUG')
64n/a print('l_debug=/DEBUG')
65n/a print('temp_dir=Build\\Debug')
66n/a print('!ELSE')
67n/a print('debug_suffix=')
68n/a print('c_debug=/Ox')
69n/a print('l_debug=')
70n/a print('temp_dir=Build\\Release')
71n/a print('!ENDIF')
72n/a print()
73n/a
74n/a print('# The following line assumes you have built Python using the standard instructions')
75n/a print('# Otherwise fix the following line to point to the library.')
76n/a print('pythonlib = "$(pythonhome)/pcbuild/python%s$(debug_suffix).lib"' % version_suffix)
77n/a print()
78n/a
79n/a # We only ever write one "entry point" symbol - either
80n/a # "main" or "WinMain". Therefore, there is no need to
81n/a # pass a subsystem switch to the linker as it works it
82n/a # out all by itself. However, the subsystem _does_ determine
83n/a # the file extension and additional linker flags.
84n/a target_link_flags = ""
85n/a target_ext = ".exe"
86n/a if subsystem_details[vars['subsystem']][2]:
87n/a target_link_flags = "-dll"
88n/a target_ext = ".dll"
89n/a
90n/a
91n/a print("# As the target uses Python%s.dll, we must use this compiler option!" % version_suffix)
92n/a print("cdl = /MD")
93n/a print()
94n/a print("all: $(target)$(debug_suffix)%s" % (target_ext))
95n/a print()
96n/a
97n/a print('$(temp_dir):')
98n/a print(r' if not exist $(temp_dir)\. mkdir $(temp_dir)')
99n/a print()
100n/a
101n/a objects = []
102n/a libs = ["shell32.lib", "comdlg32.lib", "wsock32.lib", "user32.lib", "oleaut32.lib"]
103n/a for moddefn in moddefns:
104n/a print("# Module", moddefn.name)
105n/a for file in moddefn.sourceFiles:
106n/a base = os.path.basename(file)
107n/a base, ext = os.path.splitext(base)
108n/a objects.append(base + ".obj")
109n/a print(r'$(temp_dir)\%s.obj: "%s"' % (base, file))
110n/a print("\t@$(CC) -c -nologo /Fo$* $(cdl) $(c_debug) /D BUILD_FREEZE", end=' ')
111n/a print('"-I$(pythonhome)/Include" "-I$(pythonhome)/PC" \\')
112n/a print("\t\t$(cflags) $(cdebug) $(cinclude) \\")
113n/a extra = moddefn.GetCompilerOptions()
114n/a if extra:
115n/a print("\t\t%s \\" % (' '.join(extra),))
116n/a print('\t\t"%s"' % file)
117n/a print()
118n/a
119n/a # Add .lib files this module needs
120n/a for modlib in moddefn.GetLinkerLibs():
121n/a if modlib not in libs:
122n/a libs.append(modlib)
123n/a
124n/a print("ADDN_LINK_FILES=", end=' ')
125n/a for addn in vars['addn_link']: print('"%s"' % (addn), end=' ')
126n/a print() ; print()
127n/a
128n/a print("OBJS=", end=' ')
129n/a for obj in objects: print(r'"$(temp_dir)\%s"' % (obj), end=' ')
130n/a print() ; print()
131n/a
132n/a print("LIBS=", end=' ')
133n/a for lib in libs: print('"%s"' % (lib), end=' ')
134n/a print() ; print()
135n/a
136n/a print("$(target)$(debug_suffix)%s: $(temp_dir) $(OBJS)" % (target_ext))
137n/a print("\tlink -out:$(target)$(debug_suffix)%s %s" %
138n/a (target_ext, target_link_flags), "@<<")
139n/a print("\t$(OBJS)")
140n/a print("\t$(LIBS)")
141n/a print("\t$(ADDN_LINK_FILES)")
142n/a print("\t$(pythonlib) $(lcustom) $(l_debug)")
143n/a print("\t$(resources)")
144n/a print("<<")
145n/a print()
146n/a print("clean:")
147n/a print("\t-del /f *.obj")
148n/a print("\t-del /f $(target).exe")