Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

arduino-builder improperly escapes some paths in machine output #493

Closed
Assignees
cmaglie
Milestone
@matthijskooijman

Description

@matthijskooijman

This is a problem inarduino-builder, I believe only in legacy code, but since all the relevant code lives in this repo, I thought to report this in this repository.

In some (debug) output lines of the Arduino builder, in machine-readable logger mode, paths are not properly escaped. This causes problems with spaces in the path, where the IDE shows e.g.

Using board 'uno' from platform in folder C:\Program

(I typed this error message from memory, since I did not have a broken setup to reproduce it at hand).

I think this is easy to reproduce by installing the IDE in a path with spaces (which is the default on Windows).

To show the problem by runningarduino-builder manually, we need a hardware folder with spaces. E.g.:

git clone https://github.com/arduino/ArduinoCore-avr hardware\ with\ spaces/arduino/avr

Then, you can runarduino-builder against that. e.g. comparearduino-builder 1.4.4:

$ arduino-builder-1.4.4 -verbose=true -logger machine -hardware hardware\ with\ spaces/ -tools ~/.arduino15/packages/arduino/tools/ -fqbn arduino:avr:uno -compile Sketch/  |grep Using===info ||| Using board '{0}' from platform in folder: {1} ||| [uno %2Fhome%2Fmatthijs%2Fhardware+with+spaces%2Farduino%2Favr]===info ||| Using core '{0}' from platform in folder: {1} ||| [arduino %2Fhome%2Fmatthijs%2Fhardware+with+spaces%2Farduino%2Favr]

And current master:

$ arduino-builder -verbose=true -logger machine -hardware hardware\ with\ spaces/ -tools ~/.arduino15/packages/arduino/tools/ -fqbn arduino:avr:uno -compile Sketch/  |grep Using===info ||| Using board '{0}' from platform in folder: {1} ||| [uno /home/matthijs/hardware with spaces/arduino/avr]===info ||| Using core '{0}' from platform in folder: {1} ||| [arduino /home/matthijs/hardware with spaces/arduino/avr]

As you can see, the path was encoded originally, but no longer since the arduino-cli inception happened.

The reason is that the path printed changed from a string:
https://github.com/arduino/arduino-builder/blob/cb100d0e47f68cba82430f376157d860d79c1d83/target_board_resolver.go#L104-L105
https://github.com/arduino/arduino-builder/blob/cb100d0e47f68cba82430f376157d860d79c1d83/types/types.go#L140

To apaths.Path object:

logger.Println(constants.LOG_LEVEL_INFO,constants.MSG_USING_BOARD,targetBoard.BoardID,targetPlatform.InstallDir)
logger.Println(constants.LOG_LEVEL_INFO,constants.MSG_USING_CORE,core,actualPlatform.InstallDir)

InstallDir*paths.Path`json:"-"`

However, the machine logger only treats strings specially by encoding them, and passes all values as-is tofmt.Fprintf():

funcprintMachineFormattedLogLine(w io.Writer,levelstring,formatstring,a []interface{}) {
a=append([]interface{}(nil),a...)
foridx,value:=rangea {
typeof:=reflect.Indirect(reflect.ValueOf(value)).Kind()
iftypeof==reflect.String {
a[idx]=url.QueryEscape(value.(string))
}
}
fprintf(w,"===%s ||| %s ||| %s\n",level,format,a)
}

I guess this is to encode strings, but leave floats and integers unchanged? Or are there other types that do their own encoding? I'm not too familiar with this code, or the machine-readable logger interface.

A fix that works is to simply useInstallDir.String(), forcing these paths to be a string. This approach is not ideal, since it is easy to forget the String (though if this code is to be removed soon, that might be ok). The code should be checked for similar cases, though.

An alternative would be to fix this in the logger, perhaps by checking all arguments to see if they implement theStringer interface (i.e. have aString() method) and if so, call that and encode the resulting string (I guess this is also what Fprintf does withStringer types, except for the encoding). Unless there are types that need to do their own encoding, but I doubt that (would also be bad design, really).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp