Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork436
[breaking] Refactor codebase to use a single Sketch struct#1353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
commands/instances.go Outdated
| // LoadSketch collects and returns all files composing a sketch | ||
| funcLoadSketch(ctx context.Context,req*rpc.LoadSketchRequest) (*rpc.LoadSketchResponse,error) { | ||
| sketch,err:=builder.SketchLoad(req.SketchPath,"") | ||
| // TODO: This a ToRpc function for the Sketch struct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I didn't want to introduce breaking changes with this refactoring but I think changing the gRPC interfaceLoadSketchResponse message to reflect the internalSketch struct would be a nice improvement for the future.
Also I think we should start addingToRpc/FromRpc functions to structs that need to be converted when necessary, as of now that are some functions that handle those conversions scattered around different packages.
| // simpleLocalWalk locally replaces filepath.Walk and/but goes through symlinks | ||
| funcsimpleLocalWalk(rootstring,maxDepthint,walkFnfunc(pathstring,info os.FileInfo,errerror)error)error { | ||
| info,err:=os.Stat(root) | ||
| iferr!=nil { | ||
| returnwalkFn(root,nil,err) | ||
| } | ||
| err=walkFn(root,info,err) | ||
| iferr==filepath.SkipDir { | ||
| returnnil | ||
| } | ||
| ifinfo.IsDir() { | ||
| ifmaxDepth<=0 { | ||
| returnwalkFn(root,info,errors.New("Filesystem bottom is too deep (directory recursion or filesystem really deep): "+root)) | ||
| } | ||
| maxDepth-- | ||
| files,err:=ioutil.ReadDir(root) | ||
| iferr==nil { | ||
| for_,file:=rangefiles { | ||
| err=simpleLocalWalk(root+string(os.PathSeparator)+file.Name(),maxDepth,walkFn) | ||
| iferr==filepath.SkipDir { | ||
| returnnil | ||
| } | ||
| } | ||
| } | ||
| } | ||
| returnnil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This function loops through symlinks... we should implement something similar in go-paths-helper to avoid regressions.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
8bc67da to7d00b83Compareper1234 commentedJul 12, 2021
Doesn't this PR make significant breaking changes to the API of the Go packages? Are those considered part of Arduino CLI's public API? It breaks Arduino Lint. I'm OK with breaking changes if they are necessary. But I think it's important to communicate about it to the users. |
silvanocerza commentedJul 12, 2021
Good point@per1234, I didn't take that into consideration at all. Nonetheless am not sure how we could handle breaking changes of the public API, we don't have versioning for it and neither a clearly defined interface for those that want to use it as a library. I always thought that the breaking changes policy applied only to the CLI and gRPC consumers, changes in the public API is certainly something that we must take into account for the future if we want to keep using the CLI as a library but we first need to define a public/private boundary. |
f852cf7 to69ef64bCompareper1234 commentedJul 12, 2021
It could be handled the same way as any other breaking change:
I've always thought that all exported components of non-internal packages were the interface. This is why I have taken the measure of making the packages of Arduino Lint and
The Go library is advertised as one of the "three pillars of Arduino CLI":
This is where I got the idea that it was intended to be part of the public API of the project. However, I notice now that almost every interface used by the example program in that "Integration Options" article has been broken in the year since it was written. |
69ef64b toac517beComparesilvanocerza commentedJul 12, 2021
Am doing this right now.
Rightly so I'd say, fact is that the CLI is kinda burdened with old decisions that make it hard to separate the public from the private APIs, it would be cool to do it. With the Arduino Lint it has been easier since we started the project from the ground up with a clear idea in mind of what we wanted it to be, not so much for the CLI I'd say.
Yeah, I know that, my main pain point about this is the one I stated above though.
That part of the documentation needs some love probably, the example are really outdated. I think we must avoid using images for those kind of examples, it makes it harder to update. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
ee6b995 tobf30333CompareUh oh!
There was an error while loading.Please reload this page.
per1234 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think it's a really nice improvement Silvano. Thanks for putting up with my nitpickery.
per1234 commentedJul 13, 2021
One last suggestion following on the discussion of breaking changes: there are two things which are supposed to be done to communicate breaking changes: The UPGRADING.md part is done now, but not yet the use of the "[breaking]" prefix on the PR title. I don't think it's so important to add it to the commit messages in this case because when a PR contains multiple commits as this one does, the squashed commit is titled with the PR title. The primary reason for the instructions to use the prefix on commit messages is because if a PR contains only a single commit then the PR title is not used by the merged commit. |
silvanocerza commentedJul 13, 2021
Nitpickery is always welcome. 😁
I'll update the PR title, it uses that when squashing and merging. |
cmaglie left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍🏼
matthijskooijman commentedSep 8, 2021
While revisiting#1201, I came upon this PR and looked at it in a bit more detail. It seems this makes three changes that I'm not entirely sure are intentional:
As I said, for the file error handling of point 1, I'm preparing a draft PR. For 2-4, it would probably be good to modify go-paths-helper's ReadDirRecursive to accept a callback that tests file/dir names (and probably an isDir boolean) for inclusion in the result? |
Before commite7d4eaa ([breaking] Refactor codebase to use a singleSketch struct (arduino#1353)), any sketch file that could not be opened wouldreport a fatal error, but the behavior was changed to silently skip suchfailing files instead.This restores the original behavior and fails to load a sketch of someof the contained files (after filtering on file extension, so this onlyincludes files that are actually intended to be processed), instead ofsilently excluding the files (which likely produces hard to explaincompilation errors later).
Before commite7d4eaa ([breaking] Refactor codebase to use a singleSketch struct (arduino#1353)), any sketch file that could not be opened wouldreport a fatal error, but the behavior was changed to silently skip suchfailing files instead.This restores the original behavior and fails to load a sketch of someof the contained files (after filtering on file extension, so this onlyincludes files that are actually intended to be processed), instead ofsilently excluding the files (which likely produces hard to explaincompilation errors later).
Uh oh!
There was an error while loading.Please reload this page.
Please check if the PR fulfills these requirements
before creating one)
our contributing guidelines
UPGRADING.mdhas been updated with a migration guide (for breaking changes)This enhances the codebase by removing duplicated ways of storing a Sketch data.
There are currently 3 different packages that declare a
Sketchstruct, often keeping track of different informations about a Sketch or using different types for the same underlying data. This made it necessary to have tons of back and forth conversions about the different types often losing information or making it hard to understand the code when working on it.The 3 different packages are:
sketchinarduino/sketch/sketch.gosketchesinarduino/sketches/sketches.gotypesinlegacy/builder/types/types.goWhat is the new behavior?
Now there is only one
Sketchstruct defined in thesketchofarduino/sketch/sketch.go, it contains all the informations neededby the codebase.
titled accordingly?
Yes, only in the exposed public code interface, gRPC and CLI are untouched.
Thisfixes#1178.
It's important that we test this in a thorough manner since it touches the
legacypackage quite a bit.The handling of symlinks when found in the Sketch folder is also enhanced, previously they caused several issues like#358 and#424, both handled by#421 and#462.
The integration test
test_compile_with_sketch_with_symlink_selfloopintroduced by#462 used to verify compilation would fail when trying to compile a Sketch with a symlink loop but now that is handled gracefully when a Sketch is loaded internally, so compilation now succeds.Related to this there is also the unit test
TestNewSketchFolderSymlinkto verify that loading of a Sketch with symlinks works fine, previously this wasTestLoadSketchFolderSymlinkinarduino/builder/sketch_test.gobut has been moved toarduino/sketch/sketch_test.go.Seehow to contribute