Mercurial > code > home > repos > homeauto
diff service/iot2/tasks.py @ 689:e3eceee54937
introduce capnp, more build, some demos
Ignore-this: 29801e9e9f8a85fd0d822207c6eacce1
author | drewp@bigasterisk.com |
---|---|
date | Thu, 23 Jan 2020 21:00:47 -0800 |
parents | 7ac46dc29517 |
children | ae8ad2b758e2 |
line wrap: on
line diff
--- a/service/iot2/tasks.py Tue Jan 21 23:59:45 2020 -0800 +++ b/service/iot2/tasks.py Thu Jan 23 21:00:47 2020 -0800 @@ -1,51 +1,104 @@ from invoke import task from pathlib import Path +PY_ENV = f'build/py' +NIM_ENV = f'build/nim' +NIM_BIN = f'{NIM_ENV}/bin' +PY_SITE_PACKAGES = f'{PY_ENV}/lib/python3.7/site-packages' +SOME_PY_DEP = Path(f'{PY_SITE_PACKAGES}/standardservice') + @task def nim_install(ctx): - if Path('nim-1.0.4/bin/nim').exists(): + if Path(f'{NIM_BIN}/nim').exists(): return - ctx.run(f'curl https://nim-lang.org/download/nim-1.0.4-linux_x64.tar.xz | xz -dc | tar x') + ctx.run(f'curl https://nim-lang.org/download/nim-1.0.4-linux_x64.tar.xz | ' + f'xz -dc | ' + f'tar --extract --strip-components=1 --one-top-level={NIM_ENV}') @task def py_install(ctx): - if Path('env/bin/python').exists(): + if Path(f'{PY_ENV}/bin/python').exists(): return - ctx.run(f'mkdir -p env') - ctx.run(f'virtualenv -p /usr/bin/python3.7 env') + ctx.run(f'mkdir -p {PY_ENV}') + ctx.run(f'virtualenv -p /usr/bin/python3.7 {PY_ENV}') + # now .../wheel is newer than requirements.txt @task(pre=[py_install]) def py_deps(ctx): - pip_install_ran = Path('env/lib/python3.7/site-packages/wheel').stat().st_mtime + pip_install_ever_ran = SOME_PY_DEP.exists() + pip_install_last_ran = Path(f'{PY_SITE_PACKAGES}/wheel').stat().st_mtime requirements = Path('requirements.txt').stat().st_mtime - if pip_install_ran > requirements: + if pip_install_ever_ran and pip_install_last_ran > requirements: return - ctx.run(f'env/bin/pip install --quiet --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt') + ctx.run(f'{PY_ENV}/bin/pip install ' + #f'--quiet ' + f'--index-url https://projects.bigasterisk.com/ ' + f'--extra-index-url https://pypi.org/simple ' + f'-r requirements.txt') @task(pre=[nim_install]) def nim_deps(ctx): - pkgs = ['nimpy-0.1.0'] - if all(Path(f'~/.nimble/pkgs/{pkg}').expanduser().exists() for pkg in pkgs): + pkgs = [('nimpy', 'nimpy-0.1.0'), + ('https://github.com/avsej/capnp.nim.git', 'capnp-0.0.3'), + ] + if all(Path(f'~/.nimble/pkgs/{pkg[1]}').expanduser().exists() for pkg in pkgs): return - plain_names = ' '.join(p.split('-')[0] for p in pkgs) - ctx.run(f'nim-1.0.4/bin/nimble install {plain_names}', pty=True) + plain_names = ' '.join(p[0] for p in pkgs) + ctx.run(f'{NIM_BIN}/nimble install -y {plain_names}', pty=True) + ctx.run(f'ln -s ~/.nimble/bin/capnpc ~/.nimble/bin/capnpc-nim') -@task(pre=[nim_install]) +@task(pre=[nim_deps]) def nim_build_x86(ctx): - ctx.run(f'nim-1.0.4/bin/nim c --out:iot2_linux_x86 iot2_linux.nim', pty=True) + ctx.run(f'{NIM_BIN}/nim compile ' + f'--out:build/iot2_linux_x86 ' + f'iot2_linux.nim', + pty=True) @task def arm_cross_compiler_install(ctx): + if Path('/usr/share/crossbuild-essential-armhf/list').exists(): + return ctx.run(f'sudo apt install -y crossbuild-essential-armhf', pty=True) -@task(pre=[nim_install]) +@task(pre=[arm_cross_compiler_install, nim_install]) def nim_build_arm(ctx): - ctx.run(f'nim-1.0.4/bin/nim c --cpu:arm --out:iot2_linux_arm iot2_linux.nim', pty=True) + ctx.run(f'{NIM_BIN}/nim compile ' + f'--cpu:arm ' + f'--out:build/iot2_linux_arm ' + f'iot2_linux.nim', + pty=True) @task(pre=[py_deps, nim_build_x86]) def local_run(ctx): - ctx.run(f'./iot2_linux_x86') + ctx.run(f'build/iot2_linux_x86') + +@task +def nim_build_esp32(ctx): + ctx.run(f'{NIM_BIN}/nim compile ' + f'--cpu:arm ' + f'--os:standalone ' + #f'--deadCodeElim:on ' + # --gc:refc|v2|markAndSweep|boehm|go|none|regions + f'--gc:stack ' + f'--compileOnly:on ' + f'--noMain ' + f'--nimcache:build/nimcache ' + f'--embedsrc:on ' + f'--verbosity:3 ' + #f'-d:release ' + f'iot2_esp32.nim') + ctx.run(f'') + +@task +def install_nim_capnp(ctx): + ctx.run(f'git clone git@github.com:drewp/capnp.nim.git build/capnp.nim') + ctx.run(f'cd build/capnp.nim; ./build.sh') + ctx.run(f'cd build/capnp.nim; bin/nim c capnp/capnpc.nim') + +@task +def messages_build_nim(ctx): + ctx.run(f'capnp compile -o ./build/capnp.nim/capnp/capnpc messages.capnp > build/messages.nim') # pack this into docker for pushing to Pi