mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Get Python compiler working
It turns out we needed a file length field.
This commit is contained in:
parent
38aece42ba
commit
cabb0a7ede
6 changed files with 6370 additions and 41 deletions
|
@ -26,8 +26,13 @@
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
int __zipos_fstat(const struct ZiposHandle *h, struct stat *st) {
|
int __zipos_fstat(const struct ZiposHandle *h, struct stat *st) {
|
||||||
ZTRACE("__zipos_fstat(%`'.*s)",
|
int rc;
|
||||||
ZIP_CFILE_NAMESIZE(__zipos_get()->map + h->cfile),
|
if (!(rc = __zipos_stat_impl(__zipos_get(), h->cfile, st))) {
|
||||||
ZIP_CFILE_NAME(__zipos_get()->map + h->cfile));
|
ZTRACE("__zipos_fstat(%`'.*s) → %ld",
|
||||||
return __zipos_stat_impl(__zipos_get(), h->cfile, st);
|
ZIP_CFILE_NAMESIZE(__zipos_get()->map + h->cfile),
|
||||||
|
ZIP_CFILE_NAME(__zipos_get()->map + h->cfile), st->st_size);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
10
third_party/python/Modules/getpath.c
vendored
10
third_party/python/Modules/getpath.c
vendored
|
@ -466,7 +466,7 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home,
|
||||||
static void
|
static void
|
||||||
calculate_path(void)
|
calculate_path(void)
|
||||||
{
|
{
|
||||||
#if 1
|
#if 0
|
||||||
static wchar_t delimiter[2] = {DELIM, '\0'};
|
static wchar_t delimiter[2] = {DELIM, '\0'};
|
||||||
static wchar_t separator[2] = {SEP, '\0'};
|
static wchar_t separator[2] = {SEP, '\0'};
|
||||||
/* ignore PYTHONPATH/PYTHONHOME for now */
|
/* ignore PYTHONPATH/PYTHONHOME for now */
|
||||||
|
@ -543,9 +543,9 @@ calculate_path(void)
|
||||||
wcsncpy(prefix,
|
wcsncpy(prefix,
|
||||||
L"third_party/python/Lib",
|
L"third_party/python/Lib",
|
||||||
MAXPATHLEN);
|
MAXPATHLEN);
|
||||||
/* wcsncpy(prefix, */
|
wcsncpy(prefix,
|
||||||
/* L"zip!third_party/python/Lib/", */
|
L"zip!.python",
|
||||||
/* MAXPATHLEN); */
|
MAXPATHLEN);
|
||||||
/* Avoid absolute path for exec_prefix */
|
/* Avoid absolute path for exec_prefix */
|
||||||
wcsncpy(exec_prefix, L"build/lib.linux-x86_64-3.6", MAXPATHLEN);
|
wcsncpy(exec_prefix, L"build/lib.linux-x86_64-3.6", MAXPATHLEN);
|
||||||
wcsncpy(package_path, L"Lib/site-packages", MAXPATHLEN);
|
wcsncpy(package_path, L"Lib/site-packages", MAXPATHLEN);
|
||||||
|
@ -610,7 +610,7 @@ calculate_path(void)
|
||||||
// printf("%ls\n", buf);
|
// printf("%ls\n", buf);
|
||||||
#else
|
#else
|
||||||
module_search_path = L"zip!.python/";
|
module_search_path = L"zip!.python/";
|
||||||
module_search_path = L"third_party/python/Lib/";
|
/* module_search_path = L"third_party/python/Lib/"; */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
third_party/python/Python/codecs.c
vendored
3
third_party/python/Python/codecs.c
vendored
|
@ -1556,6 +1556,9 @@ static int _PyCodecRegistry_Init(void)
|
||||||
interp->codec_error_registry == NULL)
|
interp->codec_error_registry == NULL)
|
||||||
Py_FatalError("can't initialize codec registry");
|
Py_FatalError("can't initialize codec registry");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX: terrible design!
|
||||||
|
*/
|
||||||
mod = PyImport_ImportModuleNoBlock("encodings");
|
mod = PyImport_ImportModuleNoBlock("encodings");
|
||||||
if (mod == NULL) {
|
if (mod == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
20
third_party/python/makegen.py
vendored
20
third_party/python/makegen.py
vendored
|
@ -605,6 +605,8 @@ ARTIFACTS = set()
|
||||||
|
|
||||||
def MakeDirs(d):
|
def MakeDirs(d):
|
||||||
if d + "/" not in ARTIFACTS:
|
if d + "/" not in ARTIFACTS:
|
||||||
|
if os.path.basename(d) != '__pycache__':
|
||||||
|
return
|
||||||
ARTIFACTS.add(d + "/")
|
ARTIFACTS.add(d + "/")
|
||||||
if d == "third_party/python/Lib":
|
if d == "third_party/python/Lib":
|
||||||
print()
|
print()
|
||||||
|
@ -643,24 +645,10 @@ for f in SAUCES:
|
||||||
"\t\to/$(MODE)/%s\n"
|
"\t\to/$(MODE)/%s\n"
|
||||||
"\t@$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<") % (c, c))
|
"\t@$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<") % (c, c))
|
||||||
ARTIFACTS.add(c)
|
ARTIFACTS.add(c)
|
||||||
elif os.path.isfile(f):
|
elif os.path.basename(f) == '__pycache__':
|
||||||
d = os.path.dirname(f)
|
|
||||||
MakeDirs(d)
|
|
||||||
b = os.path.basename(f)
|
|
||||||
c = "%s/%s" % (d, b)
|
|
||||||
print()
|
|
||||||
print(("o/$(MODE)/%s:\t\\\n"
|
|
||||||
"\t\t%s\t\\\n"
|
|
||||||
"\t\to/$(MODE)/%s/\n"
|
|
||||||
"\t@cp -f $< $@") % (c, f, d))
|
|
||||||
print(("o/$(MODE)/%s.zip.o:\t\\\n"
|
|
||||||
"\t\to/$(MODE)/%s\n"
|
|
||||||
"\t@$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<") % (c, c))
|
|
||||||
ARTIFACTS.add(c)
|
|
||||||
else:
|
|
||||||
MakeDirs(f)
|
MakeDirs(f)
|
||||||
ARTIFACTS.add(f + "/")
|
ARTIFACTS.add(f + "/")
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print("THIRD_PARTY_PYTHON_STDLIB_PY_OBJS =\t\\")
|
print("THIRD_PARTY_PYTHON_STDLIB_PYC_OBJS =\t\\")
|
||||||
print("\t" + "\t\\\n\t".join(sorted("o/$(MODE)/%s.zip.o" % (x) for x in ARTIFACTS)))
|
print("\t" + "\t\\\n\t".join(sorted("o/$(MODE)/%s.zip.o" % (x) for x in ARTIFACTS)))
|
||||||
|
|
20
third_party/python/pycomp.c
vendored
20
third_party/python/pycomp.c
vendored
|
@ -87,6 +87,21 @@ char *inpath;
|
||||||
char *outpath;
|
char *outpath;
|
||||||
bool optimize;
|
bool optimize;
|
||||||
|
|
||||||
|
char *
|
||||||
|
StripComponents(const char *path, int n)
|
||||||
|
{
|
||||||
|
const char *p;
|
||||||
|
while (n-- > 0) {
|
||||||
|
for (p = path; *p; ++p) {
|
||||||
|
if (*p == '/') {
|
||||||
|
path = p + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (char *)path;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GetOpts(int argc, char *argv[])
|
GetOpts(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -131,7 +146,7 @@ main(int argc, char *argv[])
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
size_t i, n;
|
size_t i, n;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *s, *p, m[8];
|
char *s, *p, m[12];
|
||||||
PyObject *code, *marshalled;
|
PyObject *code, *marshalled;
|
||||||
GetOpts(argc, argv);
|
GetOpts(argc, argv);
|
||||||
marshalled = 0;
|
marshalled = 0;
|
||||||
|
@ -144,7 +159,7 @@ main(int argc, char *argv[])
|
||||||
Py_FrozenFlag++;
|
Py_FrozenFlag++;
|
||||||
Py_SetProgramName(gc(utf8toutf32(argv[0], -1, 0)));
|
Py_SetProgramName(gc(utf8toutf32(argv[0], -1, 0)));
|
||||||
_Py_InitializeEx_Private(1, 0);
|
_Py_InitializeEx_Private(1, 0);
|
||||||
name = gc(xasprintf("zip!%s", inpath));
|
name = gc(xjoinpaths(".python", StripComponents(inpath, 3)));
|
||||||
code = Py_CompileStringExFlags(p, name, Py_file_input, NULL, 0);
|
code = Py_CompileStringExFlags(p, name, Py_file_input, NULL, 0);
|
||||||
if (!code) goto error;
|
if (!code) goto error;
|
||||||
marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION);
|
marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION);
|
||||||
|
@ -157,6 +172,7 @@ main(int argc, char *argv[])
|
||||||
WRITE16LE(m+0, 3379); /* Python 3.6rc1 */
|
WRITE16LE(m+0, 3379); /* Python 3.6rc1 */
|
||||||
WRITE16LE(m+2, READ16LE("\r\n"));
|
WRITE16LE(m+2, READ16LE("\r\n"));
|
||||||
WRITE32LE(m+4, st.st_mtim.tv_sec); /* tsk tsk y2038 */
|
WRITE32LE(m+4, st.st_mtim.tv_sec); /* tsk tsk y2038 */
|
||||||
|
WRITE32LE(m+8, n);
|
||||||
CHECK_EQ(sizeof(m), write(fd, m, sizeof(m)));
|
CHECK_EQ(sizeof(m), write(fd, m, sizeof(m)));
|
||||||
for (i = 0; i < n; i += rc) {
|
for (i = 0; i < n; i += rc) {
|
||||||
CHECK_NE(-1, (rc = write(fd, p + i, n - i)));
|
CHECK_NE(-1, (rc = write(fd, p + i, n - i)));
|
||||||
|
|
6345
third_party/python/python-stdlib.mk
vendored
6345
third_party/python/python-stdlib.mk
vendored
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue