Skip to content

Commit bce91f3

Browse files
Use real python list to make arduino-builder command line
Instead of making a string with spaces and then splitting on " ", just make the list itself with individual parameters. This will allow spaces in paths to be supported properly.
1 parent 908537e commit bce91f3

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

tests/common.sh

+7-6
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ function build_sketches()
6969
local build_cmd="python3 tools/build.py -b generic -v -w all -s 4M1M -v -k --build_cache $cache_dir -p $PWD/$build_dir -n $lwip $build_arg "
7070
if [ "$WINDOWS" = "1" ]; then
7171
# Paths to the arduino builder need to be / referenced, not our native ones
72-
local pwd_win=$(realpath $PWD | sed 's/^\/c//')
73-
local bar_win=$(echo $build_arg | sed 's/^\/c\//')
74-
# Make ARDUINO_IDE_PATH to Windows slashies
75-
export ARDUINO_IDE_PATH=$(realpath $arduino | sed 's/\/c/C:/' | tr / '\\' )
76-
build_cmd="python3 tools/build.py -b generic -v -w all -s 4M1M -v -k -p $pwd_win/$build_dir -n $lwip $bar_win "
72+
build_cmd=$(echo $build_cmd --ide_path $arduino | sed 's/ \/c\// \//g' ) # replace '/c/' with '/'
7773
fi
7874
local sketches=$(find $srcpath -name *.ino | sort)
7975
print_size_info >size.log
@@ -116,7 +112,12 @@ function build_sketches()
116112
echo -e "\n ------------ Building $sketch ------------ \n";
117113
# $arduino --verify $sketch;
118114
if [ "$WINDOWS" == "1" ]; then
119-
sketch=$(echo $sketch | sed 's/\/c/C:/')
115+
sketch=$(echo $sketch | sed 's/^\/c//')
116+
# MINGW will try to be helpful and silently convert args that look like paths to point to a spot inside the MinGW dir. This breaks everything.
117+
# http://www.mingw.org/wiki/Posix_path_conversion
118+
# https://stackoverflow.com/questions/7250130/how-to-stop-mingw-and-msys-from-mangling-path-names-given-at-the-command-line#34386471
119+
export MSYS2_ARG_CONV_EXC="*"
120+
export MSYS_NO_PATHCONV=1
120121
fi
121122
echo "$build_cmd $sketch"
122123
time ($build_cmd $sketch >build.log)

tools/build.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@
3030
import shutil
3131

3232
def compile(tmp_dir, sketch, cache, tools_dir, hardware_dir, ide_path, f, args):
33-
cmd = ide_path + '/arduino-builder '
34-
cmd += '-compile -logger=human '
35-
cmd += '-build-path ' + tmp_dir + ' '
36-
cmd += '-tools ' + ide_path + '/tools-builder '
33+
cmd = []
34+
cmd += [ide_path + '/arduino-builder']
35+
cmd += ['-compile', '-logger=human']
36+
cmd += ['-build-path', tmp_dir]
37+
cmd += ['-tools', ide_path + '/tools-builder']
3738
if cache != "":
38-
cmd += '-build-cache ' + cache + ' '
39+
cmd += ['-build-cache', cache ]
3940
if args.library_path:
4041
for lib_dir in args.library_path:
41-
cmd += '-libraries ' + lib_dir + ' '
42-
cmd += '-hardware ' + ide_path + '/hardware '
42+
cmd += ['-libraries', lib_dir]
43+
cmd += ['-hardware', ide_path + '/hardware']
4344
if args.hardware_dir:
4445
for hw_dir in args.hardware_dir:
45-
cmd += '-hardware ' + hw_dir + ' '
46+
cmd += ['-hardware', hw_dir]
4647
else:
47-
cmd += '-hardware ' + hardware_dir + ' '
48+
cmd += ['-hardware', hardware_dir]
4849
# Debug=Serial,DebugLevel=Core____
49-
cmd += '-fqbn=esp8266com:esp8266:{board_name}:' \
50+
fqbn = '-fqbn=esp8266com:esp8266:{board_name}:' \
5051
'xtal={cpu_freq},' \
5152
'FlashFreq={flash_freq},' \
5253
'FlashMode={flash_mode},' \
@@ -55,24 +56,19 @@ def compile(tmp_dir, sketch, cache, tools_dir, hardware_dir, ide_path, f, args):
5556
'ip={lwIP},' \
5657
'ResetMethod=nodemcu'.format(**vars(args))
5758
if args.debug_port and args.debug_level:
58-
cmd += 'dbg={debug_port},lvl={debug_level}'.format(**vars(args))
59-
cmd += ' '
60-
cmd += '-built-in-libraries ' + ide_path + '/libraries '
61-
cmd += '-ide-version=10607 '
62-
cmd += '-warnings={warnings} '.format(**vars(args))
59+
fqbn += 'dbg={debug_port},lvl={debug_level}'.format(**vars(args))
60+
cmd += [fqbn]
61+
cmd += ['-built-in-libraries', ide_path + '/libraries']
62+
cmd += ['-ide-version=10607']
63+
cmd += ['-warnings={warnings}'.format(**vars(args))]
6364
if args.verbose:
64-
cmd += '-verbose '
65-
cmd += sketch
66-
67-
# Try removing quotes to make arduino-cli work
68-
#if platform.system() == "Windows":
69-
# cmd = cmd.replace('/', '\\')
65+
cmd += ['-verbose']
66+
cmd += [sketch]
7067

7168
if args.verbose:
72-
print('Building: ' + cmd, file=f)
69+
print('Building: ' + " ".join(cmd), file=f)
7370

74-
cmds = cmd.split(' ')
75-
p = subprocess.Popen(cmds, stdout=f, stderr=subprocess.STDOUT)
71+
p = subprocess.Popen(cmd, stdout=f, stderr=subprocess.STDOUT)
7672
p.wait()
7773
return p.returncode
7874

@@ -113,13 +109,18 @@ def main():
113109
args = parse_args()
114110

115111
ide_path = args.ide_path
112+
try:
113+
print("IDE dir1: ", ide_path)
114+
except:
115+
pass
116116
if not ide_path:
117117
ide_path = os.environ.get('ARDUINO_IDE_PATH')
118118
if not ide_path:
119119
print("Please specify Arduino IDE path via --ide_path option"
120120
"or ARDUINO_IDE_PATH environment variable.", file=sys.stderr)
121121
return 2
122122

123+
print("IDE dir2: ", ide_path)
123124
sketch_path = args.sketch_path
124125
tmp_dir = args.build_path
125126
created_tmp_dir = False
@@ -134,6 +135,7 @@ def main():
134135
output_name = tmp_dir + '/' + os.path.basename(sketch_path) + '.bin'
135136

136137
if args.verbose:
138+
print("IDE dir: ", ide_path)
137139
print("Sketch: ", sketch_path)
138140
print("Build dir: ", tmp_dir)
139141
print("Cache dir: ", args.build_cache)

0 commit comments

Comments
 (0)