python3 package for sculpt
Provides recipes for deploying python3 on sculpt. Also adds the feature of triggering the execution of python scripts on ROM updates (see python3.run).
This commit is contained in:
committed by
Norman Feske
parent
a5d06a5ce8
commit
a67a5de5ef
5
recipes/pkg/python3/README
Normal file
5
recipes/pkg/python3/README
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
Python interpreter version 3
|
||||
|
||||
This package runs a non-interactive python interpreter. The programm will execute
|
||||
a file `hello.py` provided a File_system session.
|
||||
6
recipes/pkg/python3/archives
Normal file
6
recipes/pkg/python3/archives
Normal file
@@ -0,0 +1,6 @@
|
||||
_/raw/python3
|
||||
_/src/libc
|
||||
_/src/libpython3
|
||||
_/src/python3
|
||||
_/src/vfs
|
||||
_/src/vfs_jitterentropy
|
||||
1
recipes/pkg/python3/hash
Normal file
1
recipes/pkg/python3/hash
Normal file
@@ -0,0 +1 @@
|
||||
2018-07-03 c2dd737dddf6f94e923806cb769d47b26a0d8d17
|
||||
17
recipes/pkg/python3/runtime
Normal file
17
recipes/pkg/python3/runtime
Normal file
@@ -0,0 +1,17 @@
|
||||
<runtime ram="32M" caps="200" binary="python3" config="python3.config">
|
||||
|
||||
<requires> <file_system/> <rtc /> </requires>
|
||||
|
||||
<content>
|
||||
<rom label="python3"/>
|
||||
<rom label="python3.lib.so"/>
|
||||
<rom label="python3.config"/>
|
||||
<rom label="ld.lib.so"/>
|
||||
<rom label="vfs.lib.so"/>
|
||||
<rom label="vfs_jitterentropy.lib.so"/>
|
||||
<rom label="libc.lib.so"/>
|
||||
<rom label="libm.lib.so"/>
|
||||
<rom label="python3.tar"/>
|
||||
</content>
|
||||
|
||||
</runtime>
|
||||
4
recipes/raw/python3/content.mk
Normal file
4
recipes/raw/python3/content.mk
Normal file
@@ -0,0 +1,4 @@
|
||||
content: python3.config
|
||||
|
||||
python3.config:
|
||||
cp $(REP_DIR)/recipes/raw/python3/$@ $@
|
||||
1
recipes/raw/python3/hash
Normal file
1
recipes/raw/python3/hash
Normal file
@@ -0,0 +1 @@
|
||||
2018-07-03 37f7f0945ff5a585afff1c4f4c43cab0a104e2bb
|
||||
18
recipes/raw/python3/python3.config
Normal file
18
recipes/raw/python3/python3.config
Normal file
@@ -0,0 +1,18 @@
|
||||
<config>
|
||||
<pythonpath name="/python/Lib/:" />
|
||||
<file name="hello.py" />
|
||||
<vfs>
|
||||
<dir name="dev">
|
||||
<log/>
|
||||
<jitterentropy name="urandom" />
|
||||
<jitterentropy name="random" />
|
||||
<rtc/>
|
||||
<zero/>
|
||||
</dir>
|
||||
<dir name="python">
|
||||
<tar name="python3.tar" />
|
||||
</dir>
|
||||
<fs />
|
||||
</vfs>
|
||||
<libc stdin="/dev/zero" stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
|
||||
</config>
|
||||
@@ -1 +1 @@
|
||||
2018-06-26 ed89744a780cb71d1c3f2fdfe52d6c90bc87c919
|
||||
2018-07-03 9f3f71ff1b0534b62b1a5328962a45487bbf83a3
|
||||
|
||||
@@ -1 +1 @@
|
||||
2018-06-26 beb1cff416381790963ca24d3d2d1d0d3b24d1c8
|
||||
2018-07-03 4fc9571da9b41bf0c36391cecd5f630e91923695
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
if {![have_spec x86]} {
|
||||
puts "Run script is only supported on x86"; exit 0 }
|
||||
|
||||
proc depot_user {} { return [get_cmd_arg --depot-user local] }
|
||||
|
||||
create_boot_directory
|
||||
|
||||
import_from_depot [depot_user]/pkg/python3
|
||||
|
||||
#
|
||||
# Build
|
||||
@@ -15,13 +20,11 @@ if {![have_spec x86]} {
|
||||
|
||||
build {
|
||||
core init
|
||||
app/python3
|
||||
lib/vfs/jitterentropy
|
||||
drivers/timer
|
||||
drivers/rtc
|
||||
server/dynamic_rom
|
||||
}
|
||||
|
||||
create_boot_directory
|
||||
|
||||
#
|
||||
# Generate config
|
||||
@@ -49,11 +52,41 @@ set config {
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides> <service name="Rtc"/> </provides>
|
||||
</start>
|
||||
<start name="python3">
|
||||
<resource name="RAM" quantum="16M"/>
|
||||
<start name="dynamic_rom">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides> <service name="ROM" /> </provides>
|
||||
<config>
|
||||
<pythonpath name="/python/Lib:" />
|
||||
<file name="hello.py" />
|
||||
<rom name="hello.py">
|
||||
<inline>
|
||||
print(" \r\n\r");
|
||||
print(" -============================-");
|
||||
print(" || ||");
|
||||
print(" || Python Core 3 ||");
|
||||
print(" || ||");
|
||||
print(" || Genode 18.05 ||");
|
||||
print(" || ||");
|
||||
print(" -============================-");
|
||||
print(" \r");
|
||||
print(" 2018 by Genode Labs www.genode-labs.com");
|
||||
print(" \r\n\r");
|
||||
</inline>
|
||||
<sleep milliseconds="4000" />
|
||||
<inline>
|
||||
print("Hello again")
|
||||
</inline>
|
||||
<sleep milliseconds="4000" />
|
||||
</rom>
|
||||
</config>
|
||||
</start>
|
||||
<start name="python3" caps="200">
|
||||
<resource name="RAM" quantum="16M"/>
|
||||
<route>
|
||||
<service name="ROM" label="hello.py"> <child name="dynamic_rom" /> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
<config>
|
||||
<pythonpath name="/python/Lib/:" />
|
||||
<file name="hello.py" on-rom-update="hello.py" />
|
||||
<vfs>
|
||||
<dir name="dev">
|
||||
<log/>
|
||||
@@ -65,19 +98,7 @@ set config {
|
||||
<dir name="python">
|
||||
<tar name="python3.tar" />
|
||||
</dir>
|
||||
<inline name="hello.py">
|
||||
print(" \r\n\r");
|
||||
print(" -============================-");
|
||||
print(" || ||");
|
||||
print(" || Python Core 3 ||");
|
||||
print(" || ||");
|
||||
print(" || Genode 17.11 ||");
|
||||
print(" || ||");
|
||||
print(" -============================-");
|
||||
print(" \r");
|
||||
print(" 2018 by Genode Labs www.genode-labs.com");
|
||||
print(" \r\n\r");
|
||||
</inline>
|
||||
<rom name="hello.py" />
|
||||
</vfs>
|
||||
<libc stdin="/dev/zero" stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
|
||||
</config>
|
||||
@@ -92,15 +113,12 @@ install_config $config
|
||||
#
|
||||
|
||||
# generic modules
|
||||
set boot_modules {
|
||||
append boot_modules {
|
||||
core init
|
||||
ld.lib.so libc.lib.so libm.lib.so python3.lib.so
|
||||
python3
|
||||
vfs_jitterentropy.lib.so
|
||||
ld.lib.so
|
||||
timer
|
||||
rtc_drv
|
||||
python3.tar
|
||||
vfs.lib.so
|
||||
dynamic_rom
|
||||
}
|
||||
|
||||
build_boot_image $boot_modules
|
||||
@@ -111,7 +129,7 @@ build_boot_image $boot_modules
|
||||
|
||||
append qemu_args " -nographic "
|
||||
|
||||
run_genode_until {.*Executed .*} 60
|
||||
run_genode_until {.*Hello again.*} 60
|
||||
|
||||
grep_output {python3\] }
|
||||
compare_output_to {
|
||||
@@ -120,7 +138,7 @@ compare_output_to {
|
||||
[init -> python3] || ||
|
||||
[init -> python3] || Python Core 3 ||
|
||||
[init -> python3] || ||
|
||||
[init -> python3] || Genode 17.11 ||
|
||||
[init -> python3] || Genode 18.05 ||
|
||||
[init -> python3] || ||
|
||||
[init -> python3] -============================-
|
||||
[init -> python3]
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace Python
|
||||
{
|
||||
struct Rom_watcher;
|
||||
struct Main;
|
||||
}
|
||||
|
||||
@@ -33,8 +34,10 @@ struct Python::Main
|
||||
Genode::Env &_env;
|
||||
|
||||
Genode::Attached_rom_dataspace _config = { _env, "config" };
|
||||
Genode::Constructible<Genode::Rom_connection> _update { };
|
||||
|
||||
void _handle_config()
|
||||
|
||||
int _execute()
|
||||
{
|
||||
enum {
|
||||
MAX_NAME_LEN = 128
|
||||
@@ -42,14 +45,24 @@ struct Python::Main
|
||||
|
||||
char filename[MAX_NAME_LEN];
|
||||
|
||||
if (_config.xml().has_sub_node("file")) {
|
||||
Genode::Xml_node script = _config.xml().sub_node("file");
|
||||
Genode::Xml_node script = _config.xml().sub_node("file");
|
||||
script.attribute("name").value(filename, sizeof(filename));
|
||||
|
||||
script.attribute("name").value(filename, sizeof(filename));
|
||||
} else {
|
||||
Genode::error("Need <file name=\"filename\"> as argument!");
|
||||
return;
|
||||
}
|
||||
FILE * fp = fopen(filename, "r");
|
||||
|
||||
Genode::log("Starting python ...");
|
||||
int res = PyRun_SimpleFile(fp, filename);
|
||||
Genode::log("Executed '", Genode::Cstring(filename), "'");
|
||||
|
||||
fclose(fp);
|
||||
return res;
|
||||
}
|
||||
|
||||
void _initialize()
|
||||
{
|
||||
enum {
|
||||
MAX_NAME_LEN = 128
|
||||
};
|
||||
|
||||
wchar_t wbuf[MAX_NAME_LEN];
|
||||
|
||||
@@ -70,26 +83,59 @@ struct Python::Main
|
||||
Py_VerboseFlag = 1;
|
||||
}
|
||||
|
||||
mbstowcs(wbuf, filename, strlen(filename));
|
||||
|
||||
FILE * fp = fopen(filename, "r");
|
||||
//fp._flags = __SRD;
|
||||
Py_SetProgramName(wbuf);
|
||||
//don't need the 'site' module
|
||||
Py_NoSiteFlag = 1;
|
||||
//don't support interactive mode, yet
|
||||
Py_InteractiveFlag = 0;
|
||||
Py_Initialize();
|
||||
}
|
||||
|
||||
Genode::log("Starting python ...");
|
||||
PyRun_SimpleFile(fp, filename);
|
||||
Genode::log("Executed '", Genode::Cstring(filename), "'");
|
||||
void _finalize()
|
||||
{
|
||||
Py_Finalize();
|
||||
}
|
||||
|
||||
void _handle_config()
|
||||
{
|
||||
_initialize();
|
||||
|
||||
if (_config.xml().has_sub_node("file")) {
|
||||
Genode::Xml_node filenode = _config.xml().sub_node("file");
|
||||
if (filenode.has_attribute("on-rom-update")) {
|
||||
char rom_name[128];
|
||||
filenode.attribute("on-rom-update").value(rom_name, sizeof(rom_name));
|
||||
|
||||
_update.construct(_env, rom_name);
|
||||
_update->sigh(_trigger_handler);
|
||||
|
||||
if (_update->dataspace().valid())
|
||||
_execute();
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
_execute();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Genode::error("Need <file name=\"filename\"> as argument!");
|
||||
}
|
||||
|
||||
/* if there was a on-rom-update attribute, we finalize and wait for next config update */
|
||||
_finalize();
|
||||
}
|
||||
|
||||
void _handle_trigger()
|
||||
{
|
||||
Libc::with_libc([&] () { _execute(); });
|
||||
}
|
||||
|
||||
Genode::Signal_handler<Main> _config_handler {
|
||||
_env.ep(), *this, &Main::_handle_config };
|
||||
|
||||
Genode::Signal_handler<Main> _trigger_handler {
|
||||
_env.ep(), *this, &Main::_handle_trigger };
|
||||
|
||||
Main(Genode::Env &env) : _env(env)
|
||||
{
|
||||
_config.sigh(_config_handler);
|
||||
|
||||
Reference in New Issue
Block a user