-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.py
executable file
·110 lines (83 loc) · 2.66 KB
/
prepare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python2
#
# (c) 2018 Max Prokhorov, Lazar Obradovic
#
# Install PlatformIO and necessary frameworks, platforms and libs.
from ConfigParser import ConfigParser
import os
import sys
import shutil
import subprocess
import tempfile
INO = "void setup(){}\nvoid loop(){}\n"
def c_print(msg):
print('\x1b[0;33m{}\x1b[0m'.format(msg))
def get_pio_libraries(cwd, platformio_ini="platformio.ini"):
path = os.path.join(cwd, platformio_ini)
parser = ConfigParser()
parser.read(path)
libs = parser.get("common", "lib_deps").split("\n")[1:]
return libs
def pio_prepare(cwd, libraries, platforms):
def run(exit_code):
def wrapper(cmd):
code = 1
try:
c_print("Running: {}".format(' '.join(cmd)))
code = subprocess.call(cmd, cwd=cwd)
except OSError as e:
print(e, ' '.join(cmd))
return (code == 0)
return wrapper
def after(path):
def wrapper(_):
shutil.rmtree(path)
return True
return wrapper
# - explicitly install required libraries so each job has lib dependencies ready
# - run dummy project to test compiler and install tool-scons
commands = [
[run(0), ["platformio", "lib", "install", "--silent"] + libraries],
[run(0), ["npm", "install", "--only=dev"]],
[run(0), ["node", "node_modules/gulp/bin/gulp.js"]]
]
for platform in platforms:
tmpdir = tempfile.mkdtemp()
srcdir = os.path.join(tmpdir, "src")
os.mkdir(srcdir)
with open(os.path.join(srcdir, "dummy.ino"), "w") as f:
f.write(INO)
commands.extend(
[
[
run(0),
[
"platformio",
"init",
"-d", tmpdir,
"-b", "esp01_1m",
"-O", "platform={}".format(platform),
],
],
[run(0), ["platformio", "run", "-s", "-d", tmpdir]],
[after(tmpdir), None]
]
)
for runner, cmd in commands:
if not runner(cmd):
return False
return True
if __name__ == "__main__":
root = os.environ.get("CI_PROJECT_DIR")
if not root:
root = os.getcwd()
_, rel_path = sys.argv
base = os.path.join(root, rel_path)
libs = get_pio_libraries(cwd=base)
c_print(">>> Preparing dependencies <<<")
if not pio_prepare(
cwd=base,
libraries=libs,
platforms=("espressif8266@1.5.0", "espressif8266@1.7.3"),
):
sys.exit(1)