forked from espressif/arduino-esp32
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·130 lines (114 loc) · 4.67 KB
/
build.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# build.py — build a sketch using arduino-builder
#
# Wrapper script around arduino-builder which accepts some ESP8266-specific
# options and translates them into FQBN
#
# Copyright © 2016 Ivan Grokhotkov
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
from __future__ importprint_function
importsys
importos
importargparse
importsubprocess
importtempfile
importshutil
defcompile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
cmd=ide_path+'/arduino-builder '
cmd+='-compile -logger=human '
cmd+='-build-path "'+tmp_dir+'" '
cmd+='-tools "'+ide_path+'/tools-builder" '
ifargs.library_path:
forlib_dirinargs.library_path:
cmd+='-libraries "'+lib_dir+'" '
cmd+='-hardware "'+ide_path+'/hardware" '
ifargs.hardware_dir:
forhw_dirinargs.hardware_dir:
cmd+='-hardware "'+hw_dir+'" '
else:
cmd+='-hardware "'+hardware_dir+'" '
# Debug=Serial,DebugLevel=Core____
cmd+='-fqbn=espressif:esp32:{board_name}:' \
'FlashFreq={flash_freq},' \
'UploadSpeed=921600'.format(**vars(args))
cmd+=' '
cmd+='-ide-version=10607 '
cmd+='-warnings={warnings} '.format(**vars(args))
ifargs.verbose:
cmd+='-verbose '
cmd+=sketch
ifargs.verbose:
print('Building: '+cmd, file=f)
cmds=cmd.split(' ')
p=subprocess.Popen(cmds, stdout=f, stderr=subprocess.STDOUT)
p.wait()
returnp.returncode
defparse_args():
parser=argparse.ArgumentParser(description='Sketch build helper')
parser.add_argument('-v', '--verbose', help='Enable verbose output',
action='store_true')
parser.add_argument('-i', '--ide_path', help='Arduino IDE path')
parser.add_argument('-p', '--build_path', help='Build directory')
parser.add_argument('-l', '--library_path', help='Additional library path',
action='append')
parser.add_argument('-d', '--hardware_dir', help='Additional hardware path',
action='append')
parser.add_argument('-b', '--board_name', help='Board name', default='esp32')
parser.add_argument('-w', '--warnings', help='Compilation warnings level',
default='none', choices=['none', 'all', 'more'])
parser.add_argument('-o', '--output_binary', help='File name for output binary')
parser.add_argument('-k', '--keep', action='store_true',
help='Don\'t delete temporary build directory')
parser.add_argument('--flash_freq', help='Flash frequency', default=40,
type=int, choices=[40, 80])
parser.add_argument('sketch_path', help='Sketch file path')
returnparser.parse_args()
defmain():
args=parse_args()
ide_path=args.ide_path
ifnotide_path:
ide_path=os.environ.get('ARDUINO_IDE_PATH')
ifnotide_path:
print("Please specify Arduino IDE path via --ide_path option"
"or ARDUINO_IDE_PATH environment variable.", file=sys.stderr)
return2
sketch_path=args.sketch_path
tmp_dir=args.build_path
created_tmp_dir=False
ifnottmp_dir:
tmp_dir=tempfile.mkdtemp()
created_tmp_dir=True
tools_dir=os.path.dirname(os.path.realpath(__file__)) +'/../tools'
# this is not the correct hardware folder to add.
hardware_dir=os.path.dirname(os.path.realpath(__file__)) +'/../cores'
output_name=tmp_dir+'/'+os.path.basename(sketch_path) +'.bin'
ifargs.verbose:
print("Sketch: ", sketch_path)
print("Build dir: ", tmp_dir)
print("Output: ", output_name)
ifargs.verbose:
f=sys.stdout
else:
f=open(tmp_dir+'/build.log', 'w')
res=compile(tmp_dir, sketch_path, tools_dir, hardware_dir, ide_path, f, args)
ifres!=0:
returnres
ifargs.output_binaryisnotNone:
shutil.copy(output_name, args.output_binary)
ifcreated_tmp_dirandnotargs.keep:
shutil.rmtree(tmp_dir, ignore_errors=True)
if__name__=='__main__':
sys.exit(main())