python3: base-nova compatibility

The vfs is now populated with the python libs using a tar file system.
This is necessary because providing the zip from the rom did not work on NOVA.
The issue here is that python's zipimporter uses fseek with SEEK_END to
find the zip header. Unfortunately, the file size cannot be correctly
determined from the ROM session (see #1920) so that the fseek fails.
This commit is contained in:
Johannes Schlatow
2018-06-26 17:35:57 +02:00
committed by Norman Feske
parent e6ee017e18
commit ea789fda0c
4 changed files with 21 additions and 8 deletions

View File

@@ -207,11 +207,17 @@ $(PYTHON3_ZIP):
$(MSG_MERGE)$(notdir $@) $(MSG_MERGE)$(notdir $@)
$(VERBOSE)cd $(PYTHON_DIR)/Lib; zip -rq $(PYTHON3_ZIP) * $(VERBOSE)cd $(PYTHON_DIR)/Lib; zip -rq $(PYTHON3_ZIP) *
PYTHON3_TAR = $(BUILD_BASE_DIR)/bin/python3.tar
$(PYTHON3_TAR):
$(MSG_MERGE)$(notdir $@)
$(VERBOSE)tar cfh $@ -C $(PYTHON_DIR) Lib
# #
# Generate python3.zip at the build stage, not the dependency stage, of the # Generate python3.zip at the build stage, not the dependency stage, of the
# build system. # build system.
# #
ifeq ($(called_from_lib_mk),yes) ifeq ($(called_from_lib_mk),yes)
python3.lib.tag: $(PYTHON3_ZIP) python3.lib.tag: $(PYTHON3_ZIP) $(PYTHON3_TAR)
endif endif

View File

@@ -35,6 +35,7 @@ set config {
<service name="RM"/> <service name="RM"/>
<service name="CPU"/> <service name="CPU"/>
<service name="LOG"/> <service name="LOG"/>
<service name="IO_PORT"/>
</parent-provides> </parent-provides>
<default-route> <default-route>
<any-service> <parent/> <any-child/> </any-service> <any-service> <parent/> <any-child/> </any-service>
@@ -51,7 +52,7 @@ set config {
<start name="python3"> <start name="python3">
<resource name="RAM" quantum="16M"/> <resource name="RAM" quantum="16M"/>
<config> <config>
<pythonpath name="lib/python3.zip" /> <pythonpath name="/python/Lib:" />
<file name="hello.py" /> <file name="hello.py" />
<vfs> <vfs>
<dir name="dev"> <dir name="dev">
@@ -61,8 +62,8 @@ set config {
<rtc/> <rtc/>
<zero/> <zero/>
</dir> </dir>
<dir name="lib"> <dir name="python">
<rom name="python3.zip" /> <tar name="python3.tar" />
</dir> </dir>
<inline name="hello.py"> <inline name="hello.py">
print(" \r\n\r"); print(" \r\n\r");
@@ -93,12 +94,12 @@ install_config $config
# generic modules # generic modules
set boot_modules { set boot_modules {
core init core init
ld.lib.so libc.lib.so libm.lib.so python3.lib.so posix.lib.so ld.lib.so libc.lib.so libm.lib.so python3.lib.so
python3 python3
vfs_jitterentropy.lib.so vfs_jitterentropy.lib.so
timer timer
rtc_drv rtc_drv
python3.zip python3.tar
vfs.lib.so vfs.lib.so
} }

View File

@@ -63,6 +63,13 @@ struct Python::Main
Py_SetPath(wbuf); Py_SetPath(wbuf);
} }
if (_config.xml().has_attribute("verbose")) {
bool verbose;
_config.xml().attribute("verbose").value(&verbose);
if (verbose)
Py_VerboseFlag = 1;
}
mbstowcs(wbuf, filename, strlen(filename)); mbstowcs(wbuf, filename, strlen(filename));
FILE * fp = fopen(filename, "r"); FILE * fp = fopen(filename, "r");
@@ -90,7 +97,6 @@ struct Python::Main
} }
}; };
void Libc::Component::construct(Libc::Env &env) void Libc::Component::construct(Libc::Env &env)
{ {
Libc::with_libc([&] () { static Python::Main main(env); }); Libc::with_libc([&] () { static Python::Main main(env); });

View File

@@ -1,4 +1,4 @@
TARGET = python3 TARGET = python3
LIBS = python3 libc LIBS = base python3 libc
REQUIRES = x86 REQUIRES = x86
SRC_CC = main.cc SRC_CC = main.cc