Skip to content

Commit ca9cf98

Browse files
committed
ParseObjFilePath should be finished, tests are passing
1 parent 9c2469b commit ca9cf98

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

cmd/compile.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,24 @@ func parseOutput(cmdOutToParse []byte) (*paths.Path, *ReturnJson) {
137137
return nil, &returnJson //TODO remove
138138
}
139139

140+
// ParseObjFilePath is a function that takes a line from the compiler output
141+
// it returns a string with the path of the object file generated during the compile process
142+
//(recognizing it by .ino.cpp.o extension) if the extension is found in the string, "" otherwise
140143
func ParseObjFilePath(compilerOutLine string) (objFilePath string) {
141144
var endChar string
142145
if index := strings.Index(compilerOutLine, ".ino.cpp.o"); index != -1 {
143146
sketchEndIndex := index + len(".ino.cpp.o")
144-
if sketchEndIndex >= len(compilerOutLine) { // this means the path terminates with the `o` and thus the last character is space
145-
endChar = " "
147+
if sketchEndIndex >= len(compilerOutLine) { // this means the path terminates with the `o` and thus the end character is space
148+
endChar = " " // we set it this way to avoid index out of bound
146149
} else {
147150
endChar = string(compilerOutLine[sketchEndIndex])
148151
}
149-
// TODO see conversation with silvano: if endchar is preceded by / proceed in the search
150-
sketchStartIndex := strings.LastIndex(compilerOutLine[:sketchEndIndex], endChar) + 1
151-
objFilePath = compilerOutLine[sketchStartIndex:sketchEndIndex]
152+
sketchStartIndex := strings.LastIndex(compilerOutLine[:sketchEndIndex], endChar)
153+
// we continue to search if the endChar is preceded by backslash (this means the endChar it's escaped)
154+
for string(compilerOutLine[sketchStartIndex-1]) == `\` {
155+
sketchStartIndex = strings.LastIndex(compilerOutLine[:sketchStartIndex], endChar)
156+
}
157+
objFilePath = compilerOutLine[sketchStartIndex+1 : sketchEndIndex]
152158
return objFilePath
153159
} else {
154160
return ""

cmd/compile_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ var goodPath = []struct {
1010
cliOut string
1111
path string
1212
}{
13-
{"/home/umberto/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_MKRWAN1310 -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8059 -DUSBCON \"-DUSB_MANUFACTURER=\"Arduino LLC\"\" \"-DUSB_PRODUCT=\"Arduino MKR WAN 1310\"\" -DUSE_BQ24195L_PMIC -DVERY_LOW_POWER -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated-avr-comp -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/variants/mkrwan1300 -I/home/umberto/Arduino/libraries/MKRWAN/src /tmp/arduino-sketch-6631A0D1FB86504F68374499C713AA5D/sketch/getdeveui.ino.cpp -o /tmp/arduino-sketch-6631A0D1FB86504F68374499C713AA5D/sketch/getdeveui.ino.cpp.o", "/tmp/arduino-sketch-6631A0D1FB86504F68374499C713AA5D/sketch/getdeveui.ino.cpp.o"},
14-
{"/home/umberto/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_MKRWAN1310 -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8059 -DUSBCON \"-DUSB_MANUFACTURER=\"Arduino LLC\"\" \"-DUSB_PRODUCT=\"Arduino MKR WAN 1310\"\" -DUSE_BQ24195L_PMIC -DVERY_LOW_POWER -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated-avr-comp -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/variants/mkrwan1300 -I/home/umberto/Arduino/libraries/MKRWAN/src \"/tmp/arduino-sketch-184EE89862BF2EE5FF75311EE55FC1DD/sketch/getdeveui (copy).ino.cpp\" -o \"/tmp/arduino-sketch-184EE89862BF2EE5FF75311EE55FC1DD/sketch/getdeveui (copy).ino.cpp.o\"", "/tmp/arduino-sketch-184EE89862BF2EE5FF75311EE55FC1DD/sketch/getdeveui (copy).ino.cpp.o"},
15-
{"/home/umberto/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_MKRWAN1310 -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8059 -DUSBCON \"-DUSB_MANUFACTURER=\"Arduino LLC\"\" \"-DUSB_PRODUCT=\"Arduino MKR WAN 1310\"\" -DUSE_BQ24195L_PMIC -DVERY_LOW_POWER -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated-avr-comp -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/variants/mkrwan1300 -I/home/umberto/Arduino/libraries/MKRWAN/src \"/tmp/arduino-sketch-A51E030A1327FDE41CD99CC549EF531E/sketch/getdeveui (another \"copy\").ino.cpp\" -o \"/tmp/arduino-sketch-A51E030A1327FDE41CD99CC549EF531E/sketch/getdeveui (another \"copy\").ino.cpp.o\"", "/tmp/arduino-sketch-A51E030A1327FDE41CD99CC549EF531E/sketch/getdeveui (another \"copy\").ino.cpp.o"},
13+
{`/home/umberto/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_MKRWAN1310 -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8059 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKR WAN 1310\"" -DUSE_BQ24195L_PMIC -DVERY_LOW_POWER -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated-avr-comp -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/variants/mkrwan1300 -I/home/umberto/Arduino/libraries/MKRWAN/src /tmp/arduino-sketch-6631A0D1FB86504F68374499C713AA5D/sketch/getdeveui.ino.cpp -o /tmp/arduino-sketch-6631A0D1FB86504F68374499C713AA5D/sketch/getdeveui.ino.cpp.o`, `/tmp/arduino-sketch-6631A0D1FB86504F68374499C713AA5D/sketch/getdeveui.ino.cpp.o`},
14+
{`/home/umberto/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_MKRWAN1310 -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8059 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKR WAN 1310\"" -DUSE_BQ24195L_PMIC -DVERY_LOW_POWER -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated-avr-comp -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/variants/mkrwan1300 -I/home/umberto/Arduino/libraries/MKRWAN/src "/tmp/arduino-sketch-184EE89862BF2EE5FF75311EE55FC1DD/sketch/getdeveui (copy).ino.cpp" -o "/tmp/arduino-sketch-184EE89862BF2EE5FF75311EE55FC1DD/sketch/getdeveui (copy).ino.cpp.o"`, `/tmp/arduino-sketch-184EE89862BF2EE5FF75311EE55FC1DD/sketch/getdeveui (copy).ino.cpp.o`},
15+
{`/home/umberto/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_MKRWAN1310 -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8059 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKR WAN 1310\"" -DUSE_BQ24195L_PMIC -DVERY_LOW_POWER -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/umberto/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino/api/deprecated-avr-comp -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/cores/arduino -I/home/umberto/.arduino15/packages/arduino/hardware/samd/1.8.12/variants/mkrwan1300 -I/home/umberto/Arduino/libraries/MKRWAN/src "/tmp/arduino-sketch-A51E030A1327FDE41CD99CC549EF531E/sketch/getdeveui (another \"copy\").ino.cpp" -o "/tmp/arduino-sketch-A51E030A1327FDE41CD99CC549EF531E/sketch/getdeveui (another \"copy\").ino.cpp.o"`, `/tmp/arduino-sketch-A51E030A1327FDE41CD99CC549EF531E/sketch/getdeveui (another \"copy\").ino.cpp.o`},
16+
// TODO add path on windows
1617
}
1718

18-
func TestObjFileParse(t *testing.T) {
19+
func TestObjFilePathParse(t *testing.T) {
1920
for _, test := range goodPath {
2021
objFilePath := ParseObjFilePath(test.cliOut)
21-
assert.Equal(t, objFilePath, test.path)
22+
assert.Equal(t, test.path, objFilePath)
2223
}
2324

2425
}

0 commit comments

Comments
 (0)