Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/ardupilotwaf/linux.py
4182 views
1
# encoding: utf-8
2
3
"""
4
Waf tool for Linux build
5
6
AP_FLAKE8_CLEAN
7
"""
8
9
from waflib.TaskGen import after_method, before_method, feature
10
11
import os
12
import sys
13
import traceback
14
15
import hal_common
16
17
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_Linux/hwdef/scripts'))
18
import linux_hwdef # noqa:501
19
20
21
@feature('linux_ap_library', 'linux_ap_program')
22
@before_method('process_source')
23
def linux_dynamic_env(self):
24
hal_common.common_dynamic_env(self)
25
26
27
@feature('linux_ap_program')
28
@after_method('process_source')
29
def linux_firmware(self):
30
pass
31
32
33
def load_env_vars(env):
34
'''optionally load extra environment variables from env.py in the build directory'''
35
hal_common.load_env_vars(env)
36
37
38
def configure(cfg):
39
40
def srcpath(path):
41
return cfg.srcnode.make_node(path).abspath()
42
43
def bldpath(path):
44
return bldnode.make_node(path).abspath()
45
46
env = cfg.env
47
bldnode = cfg.bldnode.make_node(cfg.variant)
48
env.SRCROOT = srcpath('')
49
env.BUILDROOT = bldpath('')
50
51
def srcpath(path):
52
return cfg.srcnode.make_node(path).abspath()
53
54
def bldpath(path):
55
return bldnode.make_node(path).abspath()
56
env.AP_PROGRAM_FEATURES += ['linux_ap_program']
57
58
try:
59
generate_hwdef_h(env)
60
except Exception as e:
61
print(get_exception_stacktrace(e))
62
cfg.fatal("Failed to generate hwdef")
63
load_env_vars(cfg.env)
64
65
66
def get_exception_stacktrace(e):
67
ret = "%s\n" % e
68
ret += ''.join(traceback.format_exception(type(e),
69
e,
70
tb=e.__traceback__))
71
return ret
72
73
74
def generate_hwdef_h(env):
75
'''run linux_hwdef.py'''
76
hwdef_dir = os.path.join(env.SRCROOT, 'libraries/AP_HAL_Linux/hwdef')
77
78
if len(env.HWDEF) == 0:
79
env.HWDEF = os.path.join(hwdef_dir, env.BOARD, 'hwdef.dat')
80
hwdef_out = env.BUILDROOT
81
if not os.path.exists(hwdef_out):
82
os.mkdir(hwdef_out)
83
hwdef = [env.HWDEF]
84
if env.HWDEF_EXTRA:
85
hwdef.append(env.HWDEF_EXTRA)
86
lh = linux_hwdef.LinuxHWDef(
87
outdir=hwdef_out,
88
hwdef=hwdef,
89
quiet=False,
90
)
91
lh.run()
92
93
94
def pre_build(bld):
95
'''pre-build hook to change dynamic sources'''
96
load_env_vars(bld.env)
97
if bld.env.HAL_NUM_CAN_IFACES:
98
bld.get_board().with_can = True
99
if bld.env.WITH_LITTLEFS:
100
bld.get_board().with_littlefs = True
101
hwdef_h = os.path.join(bld.env.BUILDROOT, 'hwdef.h')
102
if not os.path.exists(hwdef_h):
103
print("Generating hwdef.h")
104
try:
105
generate_hwdef_h(bld.env)
106
except Exception:
107
bld.fatal(f"Failed to process hwdef.dat {hwdef_h}")
108
109
110
def build(bld):
111
bld(
112
# build hwdef.h from hwdef.dat. This is needed after a waf clean
113
source=bld.path.ant_glob(bld.env.HWDEF),
114
rule="",
115
group='dynamic_sources',
116
target=[
117
bld.bldnode.find_or_declare('hwdef.h'),
118
]
119
)
120
121