-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdodo.py
150 lines (108 loc) · 4.29 KB
/
dodo.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import os
import sys
from doit.tools import create_folder
sys.path.append('dependencies/doit_helpers')
from doit_helpers.arduino import env as arduino_env
from doit_helpers import file_utils
from doit_helpers import gcc_utils
DOIT_CONFIG = {'default_tasks': ['build_exe']}
# ---------------------------------------------------------------------
# Build settings
PROJECT_NAME = 'goggles'
BUILD_DIR = 'build'
OBJ_DIR = os.path.join(BUILD_DIR, 'obj')
ARDUINO_ROOT = '/home/uozu/uozu/apps/arduino-1.8.1'
# ARDUINO_HARDWARE = 'uno'
ARDUINO_HARDWARE = 'pro_mini_8mhz'
ARDUINO_ENV = arduino_env.ArduinoEnv(PROJECT_NAME, ARDUINO_ROOT, BUILD_DIR, ARDUINO_HARDWARE)
SERIAL_PORT = '/dev/ttyUSB0'
SOURCE_DIRS = [
'src',
'src/themes',
os.path.join('dependencies', 'neopixel')
]
INCLUDE_DIRS = [
'src',
os.path.join('dependencies', 'neopixel')
]
INCLUDE_DIRS += ARDUINO_ENV.cincludes
if ARDUINO_HARDWARE == 'uno':
C_DEFS = ARDUINO_ENV.cdefs + ['UNO_HARDWARE']
CPP_DEFS = ARDUINO_ENV.cdefs + ['UNO_HARDWARE']
elif ARDUINO_HARDWARE == 'pro_mini_8mhz':
C_DEFS = ARDUINO_ENV.cdefs + ['PRO_MINI_8MHZ_HARDWARE']
CPP_DEFS = ARDUINO_ENV.cdefs + ['PRO_MINI_8MHZ_HARDWARE']
# ---------------------------------------------------------------------
# data
class BuildData:
def __init__(self):
self.c_sources = []
self.cpp_sources = []
for path in SOURCE_DIRS:
self.c_sources += file_utils.find(path, '*.c')
self.cpp_sources += file_utils.find(path, ['*.cpp', '*.ino'])
self.objs = [self.get_obj_path(x) for x in self.c_sources + self.cpp_sources]
self.objs += [ARDUINO_ENV.core_lib_output_path]
self.deps = gcc_utils.get_dependency_dict(BUILD_DIR)
def get_obj_path(self, source_path):
return os.path.join(OBJ_DIR, os.path.basename(source_path) + '.o')
def get_dep_path(self, source_path):
return os.path.join(OBJ_DIR, os.path.basename(source_path) + '.d')
build_data = BuildData()
# ---------------------------------------------------------------------
# utilities
def get_source_dependencies(source):
obj = build_data.get_obj_path(source)
if obj in build_data.deps:
return build_data.deps[obj]
else:
return [source]
def get_c_compile_command_str(source, obj):
return gcc_utils.get_compile_cmd_str(source, obj,
compiler=ARDUINO_ENV.c_compiler,
defs=C_DEFS,
includes=INCLUDE_DIRS,
flags=ARDUINO_ENV.cflags)
def get_cpp_compile_command_str(source, obj):
return gcc_utils.get_compile_cmd_str(source, obj,
compiler=ARDUINO_ENV.cpp_compiler,
defs=CPP_DEFS,
includes=INCLUDE_DIRS,
flags=ARDUINO_ENV.cppflags)
# ---------------------------------------------------------------------
# tasks
def task_build_arduino_core():
for task in ARDUINO_ENV.get_build_core_tasks():
yield task
def task_compile_c():
for source in build_data.c_sources:
obj = build_data.get_obj_path(source)
dep = build_data.get_dep_path(source)
yield {
'name': obj,
'actions': [(create_folder, [os.path.dirname(obj)]),
get_c_compile_command_str(source, obj)],
'targets': [obj, dep],
'file_dep': get_source_dependencies(source),
'clean': True
}
def task_compile_cpp():
for source in build_data.cpp_sources:
obj = build_data.get_obj_path(source)
dep = build_data.get_dep_path(source)
yield {
'name': obj,
'actions': [(create_folder, [os.path.dirname(obj)]),
get_cpp_compile_command_str(source, obj)],
'targets': [obj, dep],
'file_dep': get_source_dependencies(source),
'clean': True
}
def task_build_exe():
for task in ARDUINO_ENV.get_build_exe_tasks(PROJECT_NAME, build_data.objs):
yield task
def task_upload():
return ARDUINO_ENV.get_upload_task(SERIAL_PORT)
if __name__ == '__main__':
ARDUINO_ENV.get_build_core_tasks()
print ARDUINO_ENV