diff options
Diffstat (limited to 'Programs/_freeze_importlib.c')
-rw-r--r-- | Programs/_freeze_importlib.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c index b72fcf4..42749db 100644 --- a/Programs/_freeze_importlib.c +++ b/Programs/_freeze_importlib.c @@ -12,6 +12,7 @@ #include <unistd.h> #endif +int Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ /* To avoid a circular dependency on frozen.o, we create our own structure of frozen modules instead, left deliberately blank so as to avoid @@ -33,13 +34,14 @@ const char header[] = "/* Auto-generated by Programs/_freeze_importlib.c */"; int main(int argc, char *argv[]) { - char *inpath, *outpath; + char *inpath, *outpath, *code_name; FILE *infile = NULL, *outfile = NULL; struct _Py_stat_struct status; size_t text_size, data_size, n; char *text = NULL; unsigned char *data; PyObject *code = NULL, *marshalled = NULL; + int is_bootstrap = 1; PyImport_FrozenModules = _PyImport_FrozenModules; @@ -82,8 +84,14 @@ main(int argc, char *argv[]) /* Don't install importlib, since it could execute outdated bytecode. */ _Py_InitializeEx_Private(1, 0); - code = Py_CompileStringExFlags(text, "<frozen importlib._bootstrap>", - Py_file_input, NULL, 0); + if (strstr(inpath, "_external") != NULL) { + is_bootstrap = 0; + } + + code_name = is_bootstrap ? + "<frozen importlib._bootstrap>" : + "<frozen importlib._bootstrap_external>"; + code = Py_CompileStringExFlags(text, code_name, Py_file_input, NULL, 0); if (code == NULL) goto error; free(text); @@ -106,7 +114,11 @@ main(int argc, char *argv[]) goto error; } fprintf(outfile, "%s\n", header); - fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n"); + if (is_bootstrap) + fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n"); + else + fprintf(outfile, + "const unsigned char _Py_M__importlib_external[] = {\n"); for (n = 0; n < data_size; n += 16) { size_t i, end = Py_MIN(n + 16, data_size); fprintf(outfile, " "); |