Nuitka-winsvc 1.6.6__cp310-cp310-win_amd64.whl → 1.7.5__cp310-cp310-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {Nuitka_winsvc-1.6.6.dist-info → Nuitka_winsvc-1.7.5.dist-info}/METADATA +1 -1
- {Nuitka_winsvc-1.6.6.dist-info → Nuitka_winsvc-1.7.5.dist-info}/RECORD +84 -81
- nuitka/Builtins.py +7 -1
- nuitka/MainControl.py +4 -0
- nuitka/OptionParsing.py +5 -3
- nuitka/Options.py +17 -2
- nuitka/Serialization.py +28 -5
- nuitka/Version.py +2 -2
- nuitka/build/Backend.scons +16 -3
- nuitka/build/CCompilerVersion.scons +1 -1
- nuitka/build/DataComposerInterface.py +15 -9
- nuitka/build/Onefile.scons +1 -1
- nuitka/build/SconsCompilerSettings.py +1 -0
- nuitka/build/SconsProgress.py +11 -2
- nuitka/build/SconsSpawn.py +15 -15
- nuitka/build/include/nuitka/builtins.h +2 -0
- nuitka/build/include/nuitka/filesystem_paths.h +4 -0
- nuitka/build/include/nuitka/helper/attributes.h +3 -0
- nuitka/build/include/nuitka/helper/import_hard.h +6 -0
- nuitka/build/include/nuitka/helpers.h +1 -1
- nuitka/build/include/nuitka/safe_string_ops.h +10 -3
- nuitka/build/static_src/CompiledCodeHelpers.c +0 -200
- nuitka/build/static_src/HelpersAttributes.c +185 -8
- nuitka/build/static_src/HelpersFilesystemPaths.c +528 -7
- nuitka/build/static_src/HelpersImportHard.c +38 -0
- nuitka/build/static_src/HelpersSafeStrings.c +6 -278
- nuitka/build/static_src/MainProgram.c +273 -73
- nuitka/build/static_src/MetaPathBasedLoaderResourceReaderFiles.c +6 -0
- nuitka/build/static_src/OnefileBootstrap.c +19 -36
- nuitka/build/static_src/OnefileSplashScreen.cpp +1 -0
- nuitka/code_generation/AttributeCodes.py +42 -23
- nuitka/code_generation/CodeGeneration.py +4 -0
- nuitka/code_generation/FunctionCodes.py +18 -3
- nuitka/code_generation/GlobalConstants.py +8 -1
- nuitka/code_generation/PackageResourceCodes.py +40 -0
- nuitka/code_generation/templates/CodeTemplatesModules.py +1 -7
- nuitka/freezer/DllDependenciesMacOS.py +18 -1
- nuitka/freezer/IncludedDataFiles.py +6 -10
- nuitka/importing/ImportResolving.py +6 -0
- nuitka/importing/Recursion.py +24 -68
- nuitka/nodes/AttributeNodes.py +72 -19
- nuitka/nodes/ChildrenHavingMixins.py +203 -234
- nuitka/nodes/ExpressionBasesGenerated.py +136 -0
- nuitka/nodes/HardImportNodesGenerated.py +94 -0
- nuitka/nodes/ImportHardNodes.py +3 -3
- nuitka/nodes/ImportNodes.py +14 -4
- nuitka/nodes/ModuleNodes.py +4 -2
- nuitka/nodes/PackageMetadataNodes.py +12 -10
- nuitka/nodes/PackageResourceNodes.py +115 -0
- nuitka/nodes/TypeNodes.py +5 -1
- nuitka/plugins/PluginBase.py +32 -8
- nuitka/plugins/Plugins.py +44 -7
- nuitka/plugins/standard/AntiBloatPlugin.py +166 -72
- nuitka/plugins/standard/DataFilesPlugin.py +10 -0
- nuitka/plugins/standard/DllFilesPlugin.py +1 -2
- nuitka/plugins/standard/MatplotlibPlugin.py +24 -22
- nuitka/plugins/standard/MultiprocessingPlugin.py +5 -12
- nuitka/plugins/standard/OptionsNannyPlugin.py +2 -2
- nuitka/plugins/standard/PySidePyQtPlugin.py +18 -6
- nuitka/plugins/standard/PywebViewPlugin.py +4 -2
- nuitka/plugins/standard/TkinterPlugin.py +3 -0
- nuitka/plugins/standard/TransformersPlugin.py +11 -1
- nuitka/plugins/standard/TrioPlugin.py +6 -66
- nuitka/plugins/standard/standard.nuitka-package.config.yml +367 -21
- nuitka/plugins/standard/stdlib3.nuitka-package.config.yml +16 -4
- nuitka/specs/HardImportSpecs.py +6 -0
- nuitka/tools/data_composer/DataComposer.py +25 -27
- nuitka/tools/general/find_module/FindModuleCode.py +5 -2
- nuitka/tools/podman/Podman.py +53 -0
- nuitka/tools/podman/__init__.py +18 -0
- nuitka/tools/podman/__main__.py +255 -0
- nuitka/tools/specialize/SpecializePython.py +37 -3
- nuitka/tools/testing/RuntimeTracing.py +4 -0
- nuitka/tree/Building.py +1 -1
- nuitka/tree/ReformulationFunctionStatements.py +137 -10
- nuitka/utils/Execution.py +11 -1
- nuitka/utils/ModuleNames.py +1 -1
- nuitka/utils/SharedLibraries.py +7 -7
- {Nuitka_winsvc-1.6.6.data → Nuitka_winsvc-1.7.5.data}/scripts/nuitka-run.bat +0 -0
- {Nuitka_winsvc-1.6.6.data → Nuitka_winsvc-1.7.5.data}/scripts/nuitka.bat +0 -0
- {Nuitka_winsvc-1.6.6.dist-info → Nuitka_winsvc-1.7.5.dist-info}/LICENSE.txt +0 -0
- {Nuitka_winsvc-1.6.6.dist-info → Nuitka_winsvc-1.7.5.dist-info}/WHEEL +0 -0
- {Nuitka_winsvc-1.6.6.dist-info → Nuitka_winsvc-1.7.5.dist-info}/entry_points.txt +0 -0
- {Nuitka_winsvc-1.6.6.dist-info → Nuitka_winsvc-1.7.5.dist-info}/top_level.txt +0 -0
|
@@ -15,17 +15,39 @@
|
|
|
15
15
|
// See the License for the specific language governing permissions and
|
|
16
16
|
// limitations under the License.
|
|
17
17
|
//
|
|
18
|
+
// Tools for working with file, and paths cross platform
|
|
19
|
+
// for use in both onefile bootstrap and python compiled
|
|
20
|
+
// program.
|
|
21
|
+
|
|
22
|
+
#if defined(__APPLE__)
|
|
23
|
+
#include <dlfcn.h>
|
|
24
|
+
#include <libgen.h>
|
|
25
|
+
#include <mach-o/dyld.h>
|
|
26
|
+
#endif
|
|
18
27
|
|
|
19
28
|
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
|
20
29
|
#include <sys/sysctl.h>
|
|
21
30
|
#endif
|
|
22
31
|
|
|
32
|
+
#if !defined(_WIN32)
|
|
33
|
+
#include <dlfcn.h>
|
|
34
|
+
#include <fcntl.h>
|
|
35
|
+
#include <libgen.h>
|
|
36
|
+
#include <pwd.h>
|
|
37
|
+
#include <stdlib.h>
|
|
38
|
+
#include <strings.h>
|
|
39
|
+
#include <sys/mman.h>
|
|
40
|
+
#include <sys/time.h>
|
|
41
|
+
#include <unistd.h>
|
|
42
|
+
#endif
|
|
43
|
+
|
|
23
44
|
// We are using in onefile bootstrap as well, so copy it.
|
|
24
45
|
#ifndef Py_MIN
|
|
25
46
|
#define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))
|
|
26
47
|
#endif
|
|
27
48
|
|
|
28
49
|
#include "nuitka/filesystem_paths.h"
|
|
50
|
+
#include "nuitka/safe_string_ops.h"
|
|
29
51
|
|
|
30
52
|
filename_char_t *getBinaryPath(void) {
|
|
31
53
|
static filename_char_t binary_filename[MAXPATHLEN];
|
|
@@ -157,8 +179,6 @@ int64_t getFileSize(FILE_HANDLE file_handle) {
|
|
|
157
179
|
}
|
|
158
180
|
|
|
159
181
|
#if !defined(_WIN32)
|
|
160
|
-
#include <fcntl.h>
|
|
161
|
-
#include <unistd.h>
|
|
162
182
|
#if defined(__APPLE__)
|
|
163
183
|
#include <copyfile.h>
|
|
164
184
|
#else
|
|
@@ -267,11 +287,6 @@ bool renameFile(filename_char_t const *source, filename_char_t const *dest) {
|
|
|
267
287
|
#endif
|
|
268
288
|
}
|
|
269
289
|
|
|
270
|
-
#if !defined(_WIN32)
|
|
271
|
-
#include <fcntl.h>
|
|
272
|
-
#include <sys/mman.h>
|
|
273
|
-
#endif
|
|
274
|
-
|
|
275
290
|
#include "nuitka/checksum_tools.h"
|
|
276
291
|
|
|
277
292
|
#if defined(_WIN32)
|
|
@@ -435,3 +450,509 @@ uint32_t getFileCRC32(filename_char_t const *filename) {
|
|
|
435
450
|
|
|
436
451
|
return result;
|
|
437
452
|
}
|
|
453
|
+
|
|
454
|
+
#ifdef _WIN32
|
|
455
|
+
|
|
456
|
+
static DWORD Nuitka_GetFinalPathNameByHandleW(HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags) {
|
|
457
|
+
typedef DWORD(WINAPI * pfnGetFinalPathNameByHandleW)(HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath,
|
|
458
|
+
DWORD dwFlags);
|
|
459
|
+
|
|
460
|
+
pfnGetFinalPathNameByHandleW fnGetFinalPathNameByHandleW =
|
|
461
|
+
(pfnGetFinalPathNameByHandleW)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "GetFinalPathNameByHandleW");
|
|
462
|
+
|
|
463
|
+
if (fnGetFinalPathNameByHandleW != NULL) {
|
|
464
|
+
return fnGetFinalPathNameByHandleW(hFile, lpszFilePath, cchFilePath, dwFlags);
|
|
465
|
+
} else {
|
|
466
|
+
// There are no symlinks before Windows Vista.
|
|
467
|
+
return 0;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
static void resolveFileSymbolicLink(wchar_t *resolved_filename, wchar_t const *filename, DWORD resolved_filename_size,
|
|
472
|
+
bool resolve_symlinks) {
|
|
473
|
+
// Resolve any symbolic links in the filename.
|
|
474
|
+
// Copies the resolved path over the top of the parameter.
|
|
475
|
+
|
|
476
|
+
if (resolve_symlinks) {
|
|
477
|
+
// Open the file in the most non-exclusive way possible
|
|
478
|
+
HANDLE file_handle = CreateFileW(filename, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
|
|
479
|
+
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
480
|
+
|
|
481
|
+
if (unlikely(file_handle == INVALID_HANDLE_VALUE)) {
|
|
482
|
+
abort();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// In case, the Windows API for symlinks does not yet exist, just used
|
|
486
|
+
// the unresolved one.
|
|
487
|
+
copyStringSafeW(resolved_filename, filename, resolved_filename_size);
|
|
488
|
+
|
|
489
|
+
// Resolve the path, get the result with a drive letter
|
|
490
|
+
DWORD len = Nuitka_GetFinalPathNameByHandleW(file_handle, resolved_filename, resolved_filename_size,
|
|
491
|
+
FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
|
|
492
|
+
|
|
493
|
+
CloseHandle(file_handle);
|
|
494
|
+
|
|
495
|
+
if (unlikely(len >= resolved_filename_size)) {
|
|
496
|
+
abort();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Avoid network filenames added by just the resolution, revert it if
|
|
500
|
+
// they are pointing to local drive.
|
|
501
|
+
if (wcsncmp(resolved_filename, L"\\\\?\\", 4) == 0) {
|
|
502
|
+
if (wcscmp(resolved_filename + 4, filename) == 0) {
|
|
503
|
+
copyStringSafeW(resolved_filename, filename, resolved_filename_size);
|
|
504
|
+
} else if (resolved_filename[5] == L':') {
|
|
505
|
+
copyStringSafeW(resolved_filename, resolved_filename + 4, resolved_filename_size);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
} else {
|
|
509
|
+
copyStringSafeW(resolved_filename, filename, resolved_filename_size);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
#else
|
|
514
|
+
|
|
515
|
+
static void resolveFileSymbolicLink(char *resolved_filename, char const *filename, size_t resolved_filename_size,
|
|
516
|
+
bool resolve_symlinks) {
|
|
517
|
+
if (resolve_symlinks) {
|
|
518
|
+
// At least on macOS, realpath cannot allocate a buffer, itself, so lets
|
|
519
|
+
// use a local one, only on Linux we could use NULL argument and have a
|
|
520
|
+
// malloc of the resulting value.
|
|
521
|
+
char buffer[MAXPATHLEN];
|
|
522
|
+
|
|
523
|
+
char *result = realpath(filename, buffer);
|
|
524
|
+
|
|
525
|
+
if (unlikely(result == NULL)) {
|
|
526
|
+
abort();
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
copyStringSafe(resolved_filename, buffer, resolved_filename_size);
|
|
530
|
+
} else {
|
|
531
|
+
copyStringSafe(resolved_filename, filename, resolved_filename_size);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
#endif
|
|
535
|
+
|
|
536
|
+
#ifdef _WIN32
|
|
537
|
+
wchar_t const *getBinaryFilenameWideChars(bool resolve_symlinks) {
|
|
538
|
+
static wchar_t binary_filename[MAXPATHLEN + 1];
|
|
539
|
+
static bool init_done = false;
|
|
540
|
+
|
|
541
|
+
if (init_done == false) {
|
|
542
|
+
DWORD res = GetModuleFileNameW(NULL, binary_filename, sizeof(binary_filename) / sizeof(wchar_t));
|
|
543
|
+
assert(res != 0);
|
|
544
|
+
|
|
545
|
+
// Resolve any symlinks we were invoked via
|
|
546
|
+
resolveFileSymbolicLink(binary_filename, binary_filename, sizeof(binary_filename) / sizeof(wchar_t),
|
|
547
|
+
resolve_symlinks);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return binary_filename;
|
|
551
|
+
}
|
|
552
|
+
#endif
|
|
553
|
+
|
|
554
|
+
#ifdef _WIN32
|
|
555
|
+
extern wchar_t const *getBinaryFilenameWideChars(bool resolve_symlinks);
|
|
556
|
+
|
|
557
|
+
char const *getBinaryFilenameHostEncoded(bool resolve_symlinks) {
|
|
558
|
+
static char *binary_filename = NULL;
|
|
559
|
+
static char *binary_filename_resolved = NULL;
|
|
560
|
+
|
|
561
|
+
char *binary_filename_target;
|
|
562
|
+
|
|
563
|
+
if (resolve_symlinks) {
|
|
564
|
+
binary_filename_target = binary_filename_resolved;
|
|
565
|
+
} else {
|
|
566
|
+
binary_filename_target = binary_filename;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (binary_filename_target != NULL) {
|
|
570
|
+
return binary_filename_target;
|
|
571
|
+
}
|
|
572
|
+
wchar_t const *w = getBinaryFilenameWideChars(resolve_symlinks);
|
|
573
|
+
|
|
574
|
+
DWORD bufsize = WideCharToMultiByte(CP_ACP, 0, w, -1, NULL, 0, NULL, NULL);
|
|
575
|
+
assert(bufsize != 0);
|
|
576
|
+
|
|
577
|
+
binary_filename_target = (char *)malloc(bufsize + 1);
|
|
578
|
+
assert(binary_filename_target);
|
|
579
|
+
|
|
580
|
+
DWORD res2 = WideCharToMultiByte(CP_ACP, 0, w, -1, binary_filename_target, bufsize, NULL, NULL);
|
|
581
|
+
assert(res2 != 0);
|
|
582
|
+
|
|
583
|
+
if (unlikely(res2 > bufsize)) {
|
|
584
|
+
abort();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
return (char const *)binary_filename_target;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
#else
|
|
591
|
+
char const *getBinaryFilenameHostEncoded(bool resolve_symlinks) {
|
|
592
|
+
const int buffer_size = MAXPATHLEN + 1;
|
|
593
|
+
|
|
594
|
+
static char binary_filename[MAXPATHLEN + 1] = {0};
|
|
595
|
+
static char binary_filename_resolved[MAXPATHLEN + 1] = {0};
|
|
596
|
+
|
|
597
|
+
char *binary_filename_target;
|
|
598
|
+
|
|
599
|
+
if (resolve_symlinks) {
|
|
600
|
+
binary_filename_target = binary_filename_resolved;
|
|
601
|
+
} else {
|
|
602
|
+
binary_filename_target = binary_filename;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (*binary_filename_target != 0) {
|
|
606
|
+
return binary_filename_target;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
#if defined(__APPLE__)
|
|
610
|
+
uint32_t bufsize = buffer_size;
|
|
611
|
+
int res = _NSGetExecutablePath(binary_filename_target, &bufsize);
|
|
612
|
+
|
|
613
|
+
if (unlikely(res != 0)) {
|
|
614
|
+
abort();
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// Resolve any symlinks we were invoked via
|
|
618
|
+
resolveFileSymbolicLink(binary_filename_target, binary_filename_target, buffer_size, resolve_symlinks);
|
|
619
|
+
|
|
620
|
+
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
|
|
621
|
+
/* Not all of FreeBSD has /proc file system, so use the appropriate
|
|
622
|
+
* "sysctl" instead.
|
|
623
|
+
*/
|
|
624
|
+
int mib[4];
|
|
625
|
+
mib[0] = CTL_KERN;
|
|
626
|
+
mib[1] = KERN_PROC;
|
|
627
|
+
mib[2] = KERN_PROC_PATHNAME;
|
|
628
|
+
mib[3] = -1;
|
|
629
|
+
size_t cb = buffer_size;
|
|
630
|
+
int res = sysctl(mib, 4, binary_filename_target, &cb, NULL, 0);
|
|
631
|
+
|
|
632
|
+
if (unlikely(res != 0)) {
|
|
633
|
+
abort();
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Resolve any symlinks we were invoked via
|
|
637
|
+
resolveFileSymbolicLink(binary_filename_target, binary_filename_target, buffer_size, resolve_symlinks);
|
|
638
|
+
#else
|
|
639
|
+
/* The remaining platforms, mostly Linux or compatible. */
|
|
640
|
+
|
|
641
|
+
/* The "readlink" call does not terminate result, so fill zeros there, then
|
|
642
|
+
* it is a proper C string right away. */
|
|
643
|
+
memset(binary_filename_target, 0, buffer_size);
|
|
644
|
+
ssize_t res = readlink("/proc/self/exe", binary_filename_target, buffer_size - 1);
|
|
645
|
+
|
|
646
|
+
if (unlikely(res == -1)) {
|
|
647
|
+
abort();
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Resolve any symlinks we were invoked via
|
|
651
|
+
resolveFileSymbolicLink(binary_filename_target, binary_filename_target, buffer_size, resolve_symlinks);
|
|
652
|
+
#endif
|
|
653
|
+
|
|
654
|
+
return binary_filename_target;
|
|
655
|
+
}
|
|
656
|
+
#endif
|
|
657
|
+
|
|
658
|
+
#if defined(_WIN32)
|
|
659
|
+
|
|
660
|
+
// Note: Keep this separate line, must be included before other Windows headers.
|
|
661
|
+
#include <windows.h>
|
|
662
|
+
|
|
663
|
+
#include <shlobj.h>
|
|
664
|
+
#include <shlwapi.h>
|
|
665
|
+
|
|
666
|
+
// For less complete C compilers.
|
|
667
|
+
#ifndef CSIDL_LOCAL_APPDATA
|
|
668
|
+
#define CSIDL_LOCAL_APPDATA 28
|
|
669
|
+
#endif
|
|
670
|
+
#ifndef CSIDL_PROFILE
|
|
671
|
+
#define CSIDL_PROFILE 40
|
|
672
|
+
#endif
|
|
673
|
+
|
|
674
|
+
// spell-checker: ignore csidl
|
|
675
|
+
|
|
676
|
+
static bool appendStringCSIDLPathW(wchar_t *target, int csidl_id, size_t buffer_size) {
|
|
677
|
+
wchar_t path_buffer[MAX_PATH];
|
|
678
|
+
#if !defined(_M_ARM64)
|
|
679
|
+
int res = SHGetFolderPathW(NULL, csidl_id, NULL, 0, path_buffer);
|
|
680
|
+
|
|
681
|
+
if (res != S_OK) {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
#else
|
|
685
|
+
DWORD res = 0;
|
|
686
|
+
if (csidl_id == CSIDL_PROFILE) {
|
|
687
|
+
res = GetEnvironmentVariableW(L"USERPROFILE", path_buffer, sizeof(path_buffer));
|
|
688
|
+
} else if (csidl_id == CSIDL_LOCAL_APPDATA) {
|
|
689
|
+
res = GetEnvironmentVariableW(L"LOCALAPPDATA", path_buffer, sizeof(path_buffer));
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (res == 0 || res > sizeof(path_buffer)) {
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
#endif
|
|
696
|
+
appendWStringSafeW(target, path_buffer, buffer_size);
|
|
697
|
+
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
bool expandTemplatePathW(wchar_t *target, wchar_t const *source, size_t buffer_size) {
|
|
702
|
+
target[0] = 0;
|
|
703
|
+
|
|
704
|
+
wchar_t var_name[1024];
|
|
705
|
+
wchar_t *w = NULL;
|
|
706
|
+
|
|
707
|
+
while (*source != 0) {
|
|
708
|
+
if (*source == '%') {
|
|
709
|
+
if (w == NULL) {
|
|
710
|
+
w = var_name;
|
|
711
|
+
*w = 0;
|
|
712
|
+
|
|
713
|
+
source++;
|
|
714
|
+
|
|
715
|
+
continue;
|
|
716
|
+
} else {
|
|
717
|
+
*w = 0;
|
|
718
|
+
|
|
719
|
+
bool is_path = false;
|
|
720
|
+
|
|
721
|
+
if (wcsicmp(var_name, L"TEMP") == 0) {
|
|
722
|
+
GetTempPathW((DWORD)buffer_size, target);
|
|
723
|
+
is_path = true;
|
|
724
|
+
} else if (wcsicmp(var_name, L"PROGRAM") == 0) {
|
|
725
|
+
#if _NUITKA_ONEFILE_TEMP_BOOL == 1
|
|
726
|
+
appendWStringSafeW(target, __wargv[0], buffer_size);
|
|
727
|
+
#else
|
|
728
|
+
if (!GetModuleFileNameW(NULL, target, (DWORD)buffer_size)) {
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
#endif
|
|
732
|
+
} else if (wcsicmp(var_name, L"PROGRAM_BASE") == 0) {
|
|
733
|
+
if (expandTemplatePathW(target, L"%PROGRAM%", buffer_size - wcslen(target)) == false) {
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
size_t length = wcslen(target);
|
|
738
|
+
|
|
739
|
+
if ((length >= 4) && (wcsicmp(target + length - 4, L".exe") == 0)) {
|
|
740
|
+
target[length - 4] = 0;
|
|
741
|
+
}
|
|
742
|
+
} else if (wcsicmp(var_name, L"PID") == 0) {
|
|
743
|
+
char pid_buffer[128];
|
|
744
|
+
snprintf(pid_buffer, sizeof(pid_buffer), "%d", GetCurrentProcessId());
|
|
745
|
+
|
|
746
|
+
appendStringSafeW(target, pid_buffer, buffer_size);
|
|
747
|
+
} else if (wcsicmp(var_name, L"HOME") == 0) {
|
|
748
|
+
if (appendStringCSIDLPathW(target, CSIDL_PROFILE, buffer_size) == false) {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
is_path = true;
|
|
752
|
+
} else if (wcsicmp(var_name, L"CACHE_DIR") == 0) {
|
|
753
|
+
if (appendStringCSIDLPathW(target, CSIDL_LOCAL_APPDATA, buffer_size) == false) {
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
is_path = true;
|
|
757
|
+
#ifdef NUITKA_COMPANY_NAME
|
|
758
|
+
} else if (wcsicmp(var_name, L"COMPANY") == 0) {
|
|
759
|
+
appendWStringSafeW(target, L"" NUITKA_COMPANY_NAME, buffer_size);
|
|
760
|
+
#endif
|
|
761
|
+
#ifdef NUITKA_PRODUCT_NAME
|
|
762
|
+
} else if (wcsicmp(var_name, L"PRODUCT") == 0) {
|
|
763
|
+
appendWStringSafeW(target, L"" NUITKA_PRODUCT_NAME, buffer_size);
|
|
764
|
+
#endif
|
|
765
|
+
#ifdef NUITKA_VERSION_COMBINED
|
|
766
|
+
} else if (wcsicmp(var_name, L"VERSION") == 0) {
|
|
767
|
+
appendWStringSafeW(target, L"" NUITKA_VERSION_COMBINED, buffer_size);
|
|
768
|
+
#endif
|
|
769
|
+
} else if (wcsicmp(var_name, L"TIME") == 0) {
|
|
770
|
+
char time_buffer[1024];
|
|
771
|
+
|
|
772
|
+
__int64 time = 0;
|
|
773
|
+
assert(sizeof(time) == sizeof(FILETIME));
|
|
774
|
+
GetSystemTimeAsFileTime((LPFILETIME)&time);
|
|
775
|
+
|
|
776
|
+
snprintf(time_buffer, sizeof(time_buffer), "%lld", time);
|
|
777
|
+
|
|
778
|
+
appendStringSafeW(target, time_buffer, buffer_size);
|
|
779
|
+
} else {
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// Skip over appended stuff.
|
|
784
|
+
while (*target) {
|
|
785
|
+
target++;
|
|
786
|
+
buffer_size -= 1;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
if (is_path) {
|
|
790
|
+
while (*(target - 1) == FILENAME_SEP_CHAR) {
|
|
791
|
+
target--;
|
|
792
|
+
*target = 0;
|
|
793
|
+
buffer_size += 1;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
w = NULL;
|
|
798
|
+
source++;
|
|
799
|
+
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
if (w != NULL) {
|
|
805
|
+
*w++ = *source++;
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (buffer_size < 1) {
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
*target++ = *source++;
|
|
814
|
+
buffer_size -= 1;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
*target = 0;
|
|
818
|
+
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
#else
|
|
823
|
+
|
|
824
|
+
bool expandTemplatePath(char *target, char const *source, size_t buffer_size) {
|
|
825
|
+
target[0] = 0;
|
|
826
|
+
|
|
827
|
+
char var_name[1024];
|
|
828
|
+
char *w = NULL;
|
|
829
|
+
|
|
830
|
+
while (*source != 0) {
|
|
831
|
+
if (*source == '%') {
|
|
832
|
+
if (w == NULL) {
|
|
833
|
+
w = var_name;
|
|
834
|
+
*w = 0;
|
|
835
|
+
|
|
836
|
+
source++;
|
|
837
|
+
|
|
838
|
+
continue;
|
|
839
|
+
} else {
|
|
840
|
+
*w = 0;
|
|
841
|
+
|
|
842
|
+
bool is_path = false;
|
|
843
|
+
|
|
844
|
+
if (strcasecmp(var_name, "TEMP") == 0) {
|
|
845
|
+
char const *tmp_dir = getenv("TMPDIR");
|
|
846
|
+
if (tmp_dir == NULL) {
|
|
847
|
+
tmp_dir = "/tmp";
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
appendStringSafe(target, tmp_dir, buffer_size);
|
|
851
|
+
is_path = true;
|
|
852
|
+
} else if (strcasecmp(var_name, "PROGRAM") == 0) {
|
|
853
|
+
char const *exe_name = getBinaryFilenameHostEncoded(false);
|
|
854
|
+
|
|
855
|
+
appendStringSafe(target, exe_name, buffer_size);
|
|
856
|
+
} else if (strcasecmp(var_name, "PROGRAM_BASE") == 0) {
|
|
857
|
+
if (expandTemplatePath(target, "%PROGRAM%", buffer_size - strlen(target)) == false) {
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
size_t length = strlen(target);
|
|
862
|
+
|
|
863
|
+
if ((length >= 4) && (strcasecmp(target + length - 4, ".exe") == 0)) {
|
|
864
|
+
target[length - 4] = 0;
|
|
865
|
+
}
|
|
866
|
+
} else if (strcasecmp(var_name, "PID") == 0) {
|
|
867
|
+
char pid_buffer[128];
|
|
868
|
+
|
|
869
|
+
snprintf(pid_buffer, sizeof(pid_buffer), "%d", getpid());
|
|
870
|
+
|
|
871
|
+
appendStringSafe(target, pid_buffer, buffer_size);
|
|
872
|
+
} else if (strcasecmp(var_name, "HOME") == 0) {
|
|
873
|
+
char const *home_path = getenv("HOME");
|
|
874
|
+
|
|
875
|
+
if (home_path == NULL) {
|
|
876
|
+
struct passwd *pw_data = getpwuid(getuid());
|
|
877
|
+
|
|
878
|
+
if (unlikely(pw_data == NULL)) {
|
|
879
|
+
return false;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
home_path = pw_data->pw_dir;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
appendStringSafe(target, home_path, buffer_size);
|
|
886
|
+
is_path = true;
|
|
887
|
+
} else if (strcasecmp(var_name, "CACHE_DIR") == 0) {
|
|
888
|
+
if (expandTemplatePath(target, "%HOME%", buffer_size - strlen(target)) == false) {
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
appendCharSafe(target, '/', buffer_size);
|
|
893
|
+
appendStringSafe(target, ".cache", buffer_size);
|
|
894
|
+
is_path = true;
|
|
895
|
+
#ifdef NUITKA_COMPANY_NAME
|
|
896
|
+
} else if (strcasecmp(var_name, "COMPANY") == 0) {
|
|
897
|
+
appendStringSafe(target, NUITKA_COMPANY_NAME, buffer_size);
|
|
898
|
+
#endif
|
|
899
|
+
#ifdef NUITKA_PRODUCT_NAME
|
|
900
|
+
} else if (strcasecmp(var_name, "PRODUCT") == 0) {
|
|
901
|
+
appendStringSafe(target, NUITKA_PRODUCT_NAME, buffer_size);
|
|
902
|
+
#endif
|
|
903
|
+
#ifdef NUITKA_VERSION_COMBINED
|
|
904
|
+
} else if (strcasecmp(var_name, "VERSION") == 0) {
|
|
905
|
+
appendStringSafe(target, NUITKA_VERSION_COMBINED, buffer_size);
|
|
906
|
+
#endif
|
|
907
|
+
} else if (strcasecmp(var_name, "TIME") == 0) {
|
|
908
|
+
char time_buffer[1024];
|
|
909
|
+
|
|
910
|
+
struct timeval current_time;
|
|
911
|
+
gettimeofday(¤t_time, NULL);
|
|
912
|
+
snprintf(time_buffer, sizeof(time_buffer), "%ld_%ld", current_time.tv_sec,
|
|
913
|
+
(long)current_time.tv_usec);
|
|
914
|
+
|
|
915
|
+
appendStringSafe(target, time_buffer, buffer_size);
|
|
916
|
+
} else {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
// Skip over appended stuff.
|
|
920
|
+
while (*target) {
|
|
921
|
+
target++;
|
|
922
|
+
buffer_size -= 1;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
if (is_path) {
|
|
926
|
+
while (*(target - 1) == FILENAME_SEP_CHAR) {
|
|
927
|
+
target--;
|
|
928
|
+
*target = 0;
|
|
929
|
+
buffer_size += 1;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
w = NULL;
|
|
934
|
+
source++;
|
|
935
|
+
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
if (w != NULL) {
|
|
941
|
+
*w++ = *source++;
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
if (buffer_size < 1) {
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
*target++ = *source++;
|
|
950
|
+
buffer_size -= 1;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
*target = 0;
|
|
954
|
+
|
|
955
|
+
return true;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
#endif
|
|
@@ -439,3 +439,41 @@ PyObject *IMPORT_HARD_TYPING(void) {
|
|
|
439
439
|
return module_import_hard_typing;
|
|
440
440
|
}
|
|
441
441
|
#endif
|
|
442
|
+
|
|
443
|
+
/* C helper for hard import of module "unittest" import. */
|
|
444
|
+
PyObject *IMPORT_HARD_UNITTEST(void) {
|
|
445
|
+
static PyObject *module_import_hard_unittest = NULL;
|
|
446
|
+
|
|
447
|
+
if (module_import_hard_unittest == NULL) {
|
|
448
|
+
module_import_hard_unittest = PyImport_ImportModule("unittest");
|
|
449
|
+
|
|
450
|
+
if (unlikely(module_import_hard_unittest == NULL)) {
|
|
451
|
+
#ifndef __NUITKA_NO_ASSERT__
|
|
452
|
+
PyErr_PrintEx(0);
|
|
453
|
+
#endif
|
|
454
|
+
NUITKA_CANNOT_GET_HERE("failed hard import of 'unittest'");
|
|
455
|
+
abort();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return module_import_hard_unittest;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/* C helper for hard import of module "unittest.mock" import. */
|
|
463
|
+
PyObject *IMPORT_HARD_UNITTEST__MOCK(void) {
|
|
464
|
+
static PyObject *module_import_hard_unittest__mock = NULL;
|
|
465
|
+
|
|
466
|
+
if (module_import_hard_unittest__mock == NULL) {
|
|
467
|
+
module_import_hard_unittest__mock = PyImport_ImportModule("unittest.mock");
|
|
468
|
+
|
|
469
|
+
if (unlikely(module_import_hard_unittest__mock == NULL)) {
|
|
470
|
+
#ifndef __NUITKA_NO_ASSERT__
|
|
471
|
+
PyErr_PrintEx(0);
|
|
472
|
+
#endif
|
|
473
|
+
NUITKA_CANNOT_GET_HERE("failed hard import of 'unittest.mock'");
|
|
474
|
+
abort();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return module_import_hard_unittest__mock;
|
|
479
|
+
}
|