Mercurial > code > home > repos > homeauto
annotate service/iot2/tasks.py @ 728:17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
Ignore-this: d43cda6cf70930a20864cae066f11739
author | drewp@bigasterisk.com |
---|---|
date | Thu, 23 Jan 2020 23:46:34 -0800 |
parents | ae8ad2b758e2 |
children | 810ca0863490 |
rev | line source |
---|---|
688 | 1 from invoke import task |
2 from pathlib import Path | |
728
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
3 import os |
688 | 4 |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
5 PY_ENV = f'build/py' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
6 NIM_ENV = f'build/nim' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
7 NIM_BIN = f'{NIM_ENV}/bin' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
8 PY_SITE_PACKAGES = f'{PY_ENV}/lib/python3.7/site-packages' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
9 SOME_PY_DEP = Path(f'{PY_SITE_PACKAGES}/standardservice') |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
10 |
688 | 11 @task |
12 def nim_install(ctx): | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
13 if Path(f'{NIM_BIN}/nim').exists(): |
688 | 14 return |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
15 ctx.run(f'curl https://nim-lang.org/download/nim-1.0.4-linux_x64.tar.xz | ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
16 f'xz -dc | ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
17 f'tar --extract --strip-components=1 --one-top-level={NIM_ENV}') |
688 | 18 |
19 @task | |
20 def py_install(ctx): | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
21 if Path(f'{PY_ENV}/bin/python').exists(): |
688 | 22 return |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
23 ctx.run(f'mkdir -p {PY_ENV}') |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
24 ctx.run(f'virtualenv -p /usr/bin/python3.7 {PY_ENV}') |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
25 # now .../wheel is newer than requirements.txt |
688 | 26 |
27 @task(pre=[py_install]) | |
28 def py_deps(ctx): | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
29 pip_install_ever_ran = SOME_PY_DEP.exists() |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
30 pip_install_last_ran = Path(f'{PY_SITE_PACKAGES}/wheel').stat().st_mtime |
688 | 31 requirements = Path('requirements.txt').stat().st_mtime |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
32 if pip_install_ever_ran and pip_install_last_ran > requirements: |
688 | 33 return |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
34 ctx.run(f'{PY_ENV}/bin/pip install ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
35 #f'--quiet ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
36 f'--index-url https://projects.bigasterisk.com/ ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
37 f'--extra-index-url https://pypi.org/simple ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
38 f'-r requirements.txt') |
688 | 39 |
40 @task(pre=[nim_install]) | |
41 def nim_deps(ctx): | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
42 pkgs = [('nimpy', 'nimpy-0.1.0'), |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
43 ('https://github.com/avsej/capnp.nim.git', 'capnp-0.0.3'), |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
44 ] |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
45 if all(Path(f'~/.nimble/pkgs/{pkg[1]}').expanduser().exists() for pkg in pkgs): |
688 | 46 return |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
47 plain_names = ' '.join(p[0] for p in pkgs) |
691
ae8ad2b758e2
iot2: WIP still. more messages schema
drewp@bigasterisk.com
parents:
689
diff
changeset
|
48 print('todo: on initial install, this may need to be run a few times') |
ae8ad2b758e2
iot2: WIP still. more messages schema
drewp@bigasterisk.com
parents:
689
diff
changeset
|
49 ctx.run(f'{NIM_BIN}/nimble install -y {plain_names}', |
ae8ad2b758e2
iot2: WIP still. more messages schema
drewp@bigasterisk.com
parents:
689
diff
changeset
|
50 pty=True, env={'PATH': f'/usr/bin:{NIM_BIN}'}) |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
51 ctx.run(f'ln -s ~/.nimble/bin/capnpc ~/.nimble/bin/capnpc-nim') |
688 | 52 |
53 | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
54 @task(pre=[nim_deps]) |
688 | 55 def nim_build_x86(ctx): |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
56 ctx.run(f'{NIM_BIN}/nim compile ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
57 f'--out:build/iot2_linux_x86 ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
58 f'iot2_linux.nim', |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
59 pty=True) |
688 | 60 |
61 @task | |
62 def arm_cross_compiler_install(ctx): | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
63 if Path('/usr/share/crossbuild-essential-armhf/list').exists(): |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
64 return |
688 | 65 ctx.run(f'sudo apt install -y crossbuild-essential-armhf', pty=True) |
66 | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
67 @task(pre=[arm_cross_compiler_install, nim_install]) |
688 | 68 def nim_build_arm(ctx): |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
69 ctx.run(f'{NIM_BIN}/nim compile ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
70 f'--cpu:arm ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
71 f'--out:build/iot2_linux_arm ' |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
72 f'iot2_linux.nim', |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
73 pty=True) |
688 | 74 |
75 @task(pre=[py_deps, nim_build_x86]) | |
76 def local_run(ctx): | |
689
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
77 ctx.run(f'build/iot2_linux_x86') |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
78 |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
79 @task |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
80 def install_nim_capnp(ctx): |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
81 ctx.run(f'git clone git@github.com:drewp/capnp.nim.git build/capnp.nim') |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
82 ctx.run(f'cd build/capnp.nim; ./build.sh') |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
83 ctx.run(f'cd build/capnp.nim; bin/nim c capnp/capnpc.nim') |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
84 |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
85 @task |
e3eceee54937
introduce capnp, more build, some demos
drewp@bigasterisk.com
parents:
688
diff
changeset
|
86 def messages_build_nim(ctx): |
728
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
87 ctx.run(f'capnp compile ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
88 f'-o ./build/capnp.nim/capnp/capnpc ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
89 f'messages.capnp > build/messages.nim') |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
90 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
91 if 0: |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
92 # maybe esp32 should be done as extra c files in an esphome build, |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
93 # not ESP-IDF from scratch |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
94 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
95 @task |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
96 def setup_esp_build(ctx): |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
97 if not Path('build/esp-idf').exists(): |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
98 ctx.run(f'git clone --recursive https://github.com/espressif/esp-idf build/esp-idf') |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
99 if not Path('build/esp/').exists(): |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
100 ctx.run(f'cd build/esp-idf; IDF_TOOLS_PATH=../esp ./install.sh') |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
101 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
102 esp_env = {'IDF_TOOLS_PATH': '../build/esp', |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
103 'PATH': os.environ['PATH'] + ':' + str(Path('build/esp/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/').absolute())} |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
104 esp_port = '/dev/ttyUSB0' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
105 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
106 @task(pre=[setup_esp_build]) |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
107 def nim_build_esp32(ctx): |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
108 ctx.run(f'{NIM_BIN}/nim compile ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
109 f'esp32_main/iot2_esp32.nim') |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
110 ctx.run(f'cd esp32_main; ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
111 f'. ../build/esp-idf/export.sh; ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
112 f'idf.py build', env=esp_env) |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
113 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
114 @task(pre=[nim_build_esp32]) |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
115 def esp32_flash(ctx): |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
116 ctx.run(f'cd esp32_main; ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
117 f'. ../build/esp-idf/export.sh; ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
118 f'idf.py -p {esp_port} flash', env=esp_env) |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
119 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
120 @task(pre=[nim_build_esp32]) |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
121 def esp32_monitor(ctx): |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
122 ctx.run(f'cd esp32_main; ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
123 f'. ../build/esp-idf/export.sh; ' |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
124 f'idf.py -p {esp_port} monitor', env=esp_env) |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
125 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
126 |
17ff9322328b
an attempt as ESP-IDF build (doesn't work) calling a nim-generated main function (also doesn't work)
drewp@bigasterisk.com
parents:
691
diff
changeset
|
127 |
688 | 128 |
129 | |
130 # pack this into docker for pushing to Pi | |
131 | |
132 # apt install -y sshfs | |
133 # sshfs drewp@10.2.0.110:/my/proj/homeauto/service/iot2 /mnt | |
134 # cd /mnt | |
135 # ./iot2_linux_arm |