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

View file

@ -6,7 +6,12 @@
╚─────────────────────────────────────────────────────────────────────────────*/
/* clang-format off */
/* Auto-generated by Programs/_freeze_importlib.c */
/*
* Auto-generated by
* m/third_party/python/freeze.com \
* third_party/python/Lib/importlib/_bootstrap.py \
* third_party/python/Python/importlib.inc
*/
const unsigned char _Py_M__importlib[] = {
99,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,

View file

@ -6,7 +6,12 @@
╚─────────────────────────────────────────────────────────────────────────────*/
/* clang-format off */
/* Auto-generated by Programs/_freeze_importlib.c */
/*
* Auto-generated by
* m/third_party/python/freeze.com \
* third_party/python/Lib/importlib/_bootstrap_external.py \
* third_party/python/Python/importlib_external.inc
*/
const unsigned char _Py_M__importlib_external[] = {
99,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,

View file

@ -386,8 +386,10 @@ THIRD_PARTY_PYTHON_A_OBJS = \
THIRD_PARTY_PYTHON_BINS = \
$(THIRD_PARTY_PYTHON_COMS) $(THIRD_PARTY_PYTHON_COMS:%=%.dbg)
THIRD_PARTY_PYTHON_COMS = \
o/$(MODE)/third_party/python/python.com
o/$(MODE)/third_party/python/python.com \
o/$(MODE)/third_party/python/freeze.com
THIRD_PARTY_PYTHON_A_CHECKS = \
$(THIRD_PARTY_PYTHON_A).pkg \
@ -436,6 +438,14 @@ o/$(MODE)/third_party/python/python.com.dbg: \
$(APE)
-@$(APELINK)
o/$(MODE)/third_party/python/freeze.com.dbg: \
$(THIRD_PARTY_PYTHON_A_DEPS) \
$(THIRD_PARTY_PYTHON_A) \
o/$(MODE)/third_party/python/Programs/_freeze_importlib.o \
$(CRT) \
$(APE)
-@$(APELINK)
$(THIRD_PARTY_PYTHON_A): \
third_party/python \
$(THIRD_PARTY_PYTHON_A).pkg \