Get freeze importlib program working

This commit is contained in:
Justine Tunney 2021-08-17 01:27:03 -07:00
parent 795d6fd6cd
commit d522a88def
4 changed files with 51 additions and 15 deletions

View file

@ -4,22 +4,22 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/assert.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/compile.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/marshal.h"
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pythonrun.h"
/* clang-format off */
/* This is built as a stand-alone executable by the Makefile, and helps turn
Lib/importlib/_bootstrap.py into a frozen module in Python/importlib.h
*/
#include <Python.h>
#include <marshal.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef MS_WINDOWS
#include <unistd.h>
#endif
/* To avoid a circular dependency on frozen.o, we create our own structure
of frozen modules instead, left deliberately blank so as to avoid
unintentional import of a stale version of _frozen_importlib. */
@ -35,7 +35,23 @@ static const struct _frozen _PyImport_FrozenModules[] = {
const struct _frozen *PyImport_FrozenModules;
#endif
const char header[] = "/* Auto-generated by Programs/_freeze_importlib.c */";
#define HEADER "\
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│\n\
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi\n\
\n\
Python 3 \n\
https://docs.python.org/3/license.html \n\
*/\n\
/* clang-format off */\n\
\n\
/*\n\
* Auto-generated by\n\
* %s \\\n\
* %s \\\n\
* %s\n\
*/\n\
\n\
"
int
main(int argc, char *argv[])
@ -120,7 +136,7 @@ main(int argc, char *argv[])
fprintf(stderr, "cannot open '%s' for writing\n", outpath);
goto error;
}
fprintf(outfile, "%s\n", header);
fprintf(outfile, HEADER, argv[0], argv[1], argv[2]);
if (is_bootstrap)
fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n");
else