Skip to content

Commit cc75e67

Browse files
committed
Make --__fix-cwd optional and suppress unnecessary delay load warnings
1 parent 3fb030f commit cc75e67

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

_msbuild.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def main_exe(name):
101101
ItemDefinition('Link',
102102
SubSystem='CONSOLE',
103103
DelayLoadDLLs=f'{DLL_NAME}.dll;ole32.dll;shell32.dll;advapi32.dll',
104+
DisableSpecificWarnings=Prepend('4199;'),
104105
),
105106
INCLUDE_TMPDIR,
106107
Manifest('default.manifest'),
@@ -122,6 +123,7 @@ def mainw_exe(name):
122123
ItemDefinition('Link',
123124
SubSystem='WINDOWS',
124125
DelayLoadDLLs=f'{DLL_NAME}.dll;ole32.dll;shell32.dll;advapi32.dll',
126+
DisableSpecificWarnings=Prepend('4199;'),
125127
),
126128
INCLUDE_TMPDIR,
127129
ItemDefinition('ClCompile', PreprocessorDefinitions=Prepend(f'EXE_NAME=L"{name}";')),

src/pymanager/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
#define PY_WINDOWED 0
2525
#endif
2626

27+
// Uncomment to add the --__fix-cwd private argument, which will reset the
28+
// working directory to the script location or user documents/profile before
29+
// running Python.
30+
//#define ENABLE_FIX_CWD
31+
2732
struct {
2833
PyObject *mod;
2934
PyObject *no_install_found_error;
@@ -484,6 +489,7 @@ locate_runtime(
484489
}
485490

486491

492+
#ifdef ENABLE_FIX_CWD
487493
static int
488494
fix_working_directory(const std::wstring &script)
489495
{
@@ -512,6 +518,7 @@ fix_working_directory(const std::wstring &script)
512518
}
513519
return hr;
514520
}
521+
#endif
515522

516523

517524
int
@@ -535,7 +542,9 @@ wmain(int argc, wchar_t **argv)
535542

536543
const wchar_t *default_cmd;
537544
bool use_commands, use_cli_tag, use_shebangs, use_autoinstall;
545+
#ifdef ENABLE_FIX_CWD
538546
bool fix_cwd = false;
547+
#endif
539548
per_exe_settings(argc, argv, &default_cmd, &use_commands, &use_cli_tag, &use_shebangs, &use_autoinstall);
540549

541550
if (use_commands) {
@@ -551,10 +560,12 @@ wmain(int argc, wchar_t **argv)
551560
// We handle 'exec' in native code, so it won't be in the above list
552561
if (!wcscmp(argv[1], L"exec")) {
553562
skip_argc += 1;
563+
#ifdef ENABLE_FIX_CWD
554564
if (!wcscmp(argv[2], L"--__fix-cwd")) {
555565
fix_cwd = true;
556566
skip_argc += 1;
557567
}
568+
#endif
558569
use_cli_tag = argc >= 3;
559570
use_shebangs = argc >= 3;
560571
default_cmd = NULL;
@@ -606,12 +617,14 @@ wmain(int argc, wchar_t **argv)
606617
// Theoretically shouldn't matter, but might help reduce memory usage.
607618
close_python();
608619

620+
#ifdef ENABLE_FIX_CWD
609621
if (fix_cwd) {
610622
err = fix_working_directory(script);
611623
if (err) {
612624
fprintf(stderr, "[WARN] Failed to fix working directory (0x%08X).\n", err);
613625
}
614626
}
627+
#endif
615628

616629
err = launch(executable.c_str(), args.c_str(), skip_argc, &exitCode);
617630

0 commit comments

Comments
 (0)