Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/ardupilotwaf/hal_common.py
4182 views
1
"""
2
Waf tool for functions common to the esp32, Linux and ChibiOS builds.
3
4
AP_FLAKE8_CLEAN
5
"""
6
7
import os
8
import pickle
9
import sys
10
11
12
def load_env_vars(env, kv_handler=None):
13
'''optionally load extra environment variables from env.py in the build directory'''
14
env_py = os.path.join(env.BUILDROOT, 'env.py')
15
if not os.path.exists(env_py):
16
print("No env.py found")
17
return
18
e = pickle.load(open(env_py, 'rb'))
19
for kv in e.items():
20
if kv_handler is not None:
21
kv_handler(env, kv)
22
continue
23
load_env_vars_handle_kv_pair(env, kv)
24
25
26
def load_env_vars_handle_kv_pair(env, kv_pair):
27
'''handle a key/value pair out of the pickled environment dictionary'''
28
(k, v) = kv_pair
29
if k in env:
30
if isinstance(env[k], dict):
31
a = v.split('=')
32
env[k][a[0]] = '='.join(a[1:])
33
print("env updated %s=%s" % (k, v))
34
elif isinstance(env[k], list):
35
env[k].append(v)
36
print("env appended %s=%s" % (k, v))
37
else:
38
env[k] = v
39
print("env added %s=%s" % (k, v))
40
else:
41
env[k] = v
42
print("env set %s=%s" % (k, v))
43
44
45
def common_dynamic_env(self):
46
# The generated files from configuration possibly don't exist if it's just
47
# a list command (TODO: figure out a better way to address that).
48
if self.bld.cmd == 'list':
49
return
50
51
def exec_command(self, cmd, **kw):
52
kw['stdout'] = sys.stdout
53
return super(exec_command, self).exec_command(cmd, **kw)
54
55