Skip to content

Commit d27d14e

Browse files
naveen521kklazka
authored andcommitted
Build venvlauncher.exe from PC/launcher.c
- Use function available in original msvcrt.dll _wdupenv_s -> _wgetenv_s fread_s -> fread - Add a test for checking the new launchers
1 parent 3b7cbbf commit d27d14e

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

Makefile.pre.in

+12-8
Original file line numberDiff line numberDiff line change
@@ -724,20 +724,24 @@ pythonw_exe.o: $(srcdir)/PC/pythonw_exe.rc
724724
python_nt.o: $(srcdir)/PC/python_nt.rc
725725
$(WINDRES) $(RCFLAGS) -DORIGINAL_FILENAME=\\\"$(DLLLIBRARY)\\\" -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/python_nt.rc $@
726726

727+
venvlauncher.o: $(srcdir)/PC/pylauncher.rc
728+
$(WINDRES) $(RCFLAGS) -DPY_ICON -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/pylauncher.rc $@
729+
730+
venvwlauncher.o: $(srcdir)/PC/pylauncher.rc
731+
$(WINDRES) $(RCFLAGS) -DPYW_ICON -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/pylauncher.rc $@
732+
727733
$(BUILDPYTHONW): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) pythonw_exe.o
728734
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -municode -mwindows -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) pythonw_exe.o
729735

730736
# Build the interpreter
731737
$(BUILDPYTHON): Programs/python.o $(LINK_PYTHON_DEPS) python_exe.o
732738
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -municode -o $@ Programs/python.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS) python_exe.o
733739

734-
# FIXME: build these from PC/launcher.c instead
735-
$(BUILDVENVLAUNCHER): $(BUILDPYTHON)
736-
cp $(BUILDPYTHON) $(BUILDVENVLAUNCHER)
740+
$(BUILDVENVLAUNCHER): $(BUILDPYTHON) venvlauncher.o $(srcdir)/PC/launcher.c
741+
$(LINKCC) -D_CONSOLE -DVENV_REDIRECT -DPYTHON_EXECUTABLE_WITH_VERSION="L\"python$(LDVERSION)$(EXE)\"" -municode -static -static-libgcc -static-libstdc++ venvlauncher.o $(srcdir)/PC/launcher.c -o $@ -lversion
737742

738-
# FIXME: build these from PC/launcher.c instead
739-
$(BUILDVENVWLAUNCHER): $(BUILDPYTHONW)
740-
cp $(BUILDPYTHONW) $(BUILDVENVWLAUNCHER)
743+
$(BUILDVENVWLAUNCHER): $(BUILDPYTHONW) venvwlauncher.o $(srcdir)/PC/launcher.c
744+
$(LINKCC) -D_WINDOWS -DVENV_REDIRECT -DPYTHON_EXECUTABLE_WITH_VERSION="L\"pythonw$(LDVERSION)$(EXE)\"" -mwindows -municode -static -static-libgcc -static-libstdc++ venvwlauncher.o $(srcdir)/PC/launcher.c -o $@ -lversion
741745

742746
platform: $(PYTHON_FOR_BUILD_DEPS) pybuilddir.txt
743747
$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
@@ -1844,8 +1848,8 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
18441848
if test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
18451849
$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
18461850
$(INSTALL_PROGRAM) $(BUILDPYTHONW) $(DESTDIR)$(BINDIR)/python3w$(EXE); \
1847-
$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(VENVLAUNCHERDIR)/python$(EXE); \
1848-
$(INSTALL_PROGRAM) $(BUILDPYTHONW) $(DESTDIR)$(VENVLAUNCHERDIR)/pythonw$(EXE); \
1851+
$(INSTALL_PROGRAM) $(BUILDVENVLAUNCHER) $(DESTDIR)$(VENVLAUNCHERDIR)/python$(EXE); \
1852+
$(INSTALL_PROGRAM) $(BUILDVENVWLAUNCHER) $(DESTDIR)$(VENVLAUNCHERDIR)/pythonw$(EXE); \
18491853
else \
18501854
$(INSTALL_PROGRAM) $(STRIPFLAG) Mac/pythonw $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
18511855
fi

PC/launcher.c

+19-14
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ static wchar_t * get_env(wchar_t * key)
155155
#else
156156
#if defined(_WINDOWS)
157157

158-
#define PYTHON_EXECUTABLE L"pythonw.exe"
158+
#define PYTHON_EXECUTABLE PYTHON_EXECUTABLE_WITH_VERSION
159159
#define EXECUTABLEPATH_VALUE L"WindowedExecutablePath"
160160

161161
#else
162162

163-
#define PYTHON_EXECUTABLE L"python.exe"
163+
#define PYTHON_EXECUTABLE PYTHON_EXECUTABLE_WITH_VERSION
164164
#define EXECUTABLEPATH_VALUE L"ExecutablePath"
165165

166166
#endif
@@ -925,7 +925,7 @@ static COMMAND path_command;
925925
static COMMAND * find_on_path(wchar_t * name)
926926
{
927927
wchar_t * pathext;
928-
size_t varsize;
928+
size_t requiredSize;
929929
wchar_t * context = NULL;
930930
wchar_t * extension;
931931
COMMAND * result = NULL;
@@ -942,18 +942,23 @@ static COMMAND * find_on_path(wchar_t * name)
942942
}
943943
else {
944944
/* No extension - search using registered extensions. */
945-
rc = _wdupenv_s(&pathext, &varsize, L"PATHEXT");
946-
if (rc == 0) {
947-
extension = wcstok_s(pathext, L";", &context);
948-
while (extension) {
949-
len = SearchPathW(NULL, name, extension, MSGSIZE, path_command.value, NULL);
950-
if (len) {
951-
result = &path_command;
952-
break;
945+
_wgetenv_s(&requiredSize, NULL, 0, L"PATHEXT");
946+
if (requiredSize > 0) {
947+
pathext = (wchar_t *)malloc(requiredSize * sizeof(wchar_t));
948+
/* No extension - search using registered extensions. */
949+
rc = _wgetenv_s(&requiredSize, pathext, requiredSize, L"PATHEXT");
950+
if (rc == 0) {
951+
extension = wcstok_s(pathext, L";", &context);
952+
while (extension) {
953+
len = SearchPathW(NULL, name, extension, MSGSIZE, path_command.value, NULL);
954+
if (len) {
955+
result = &path_command;
956+
break;
957+
}
958+
extension = wcstok_s(NULL, L";", &context);
953959
}
954-
extension = wcstok_s(NULL, L";", &context);
960+
free(pathext);
955961
}
956-
free(pathext);
957962
}
958963
}
959964
return result;
@@ -1913,7 +1918,7 @@ process(int argc, wchar_t ** argv)
19131918
if (_wfopen_s(&f, venv_cfg_path, L"r")) {
19141919
error(RC_BAD_VENV_CFG, L"Cannot read '%ls'", venv_cfg_path);
19151920
}
1916-
cb = fread_s(buffer, sizeof(buffer), sizeof(buffer[0]),
1921+
cb = fread(buffer, sizeof(buffer[0]),
19171922
sizeof(buffer) / sizeof(buffer[0]), f);
19181923
fclose(f);
19191924

PC/pylauncher.rc

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
1 RT_MANIFEST "python.manifest"
1313

1414
#if defined(PY_ICON)
15-
1 ICON DISCARDABLE "icons\python.ico"
15+
1 ICON DISCARDABLE "icons/python.ico"
1616
#elif defined(PYW_ICON)
17-
1 ICON DISCARDABLE "icons\pythonw.ico"
17+
1 ICON DISCARDABLE "icons/pythonw.ico"
1818
#else
19-
1 ICON DISCARDABLE "icons\launcher.ico"
20-
2 ICON DISCARDABLE "icons\py.ico"
21-
3 ICON DISCARDABLE "icons\pyc.ico"
22-
4 ICON DISCARDABLE "icons\pyd.ico"
23-
5 ICON DISCARDABLE "icons\python.ico"
24-
6 ICON DISCARDABLE "icons\pythonw.ico"
25-
7 ICON DISCARDABLE "icons\setup.ico"
19+
1 ICON DISCARDABLE "icons/launcher.ico"
20+
2 ICON DISCARDABLE "icons/py.ico"
21+
3 ICON DISCARDABLE "icons/pyc.ico"
22+
4 ICON DISCARDABLE "icons/pyd.ico"
23+
5 ICON DISCARDABLE "icons/python.ico"
24+
6 ICON DISCARDABLE "icons/pythonw.ico"
25+
7 ICON DISCARDABLE "icons/setup.ico"
2626
#endif
2727

2828
1 USAGE "launcher-usage.txt"
@@ -64,4 +64,4 @@ BEGIN
6464
BEGIN
6565
VALUE "Translation", 0x0, 1200
6666
END
67-
END
67+
END

mingw_smoketests.py

+12
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ def test_venv_creation(self):
194194
assert os.path.exists(os.path.join(tmp, "bin", "python3.exe"))
195195
subprocess.check_call([shutil.which("bash.exe"), os.path.join(tmp, "bin", "activate")])
196196

197+
# This will not work in in-tree build
198+
if not sysconfig.is_python_build():
199+
op = subprocess.check_output(
200+
[
201+
os.path.join(tmp, "bin", "python.exe"),
202+
"-c",
203+
"print('Hello World')"
204+
],
205+
cwd=tmp,
206+
)
207+
assert op.decode().strip() == "Hello World"
208+
197209
def test_has_mktime(self):
198210
from time import mktime, gmtime
199211
mktime(gmtime())

0 commit comments

Comments
 (0)