Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose golang fqbn package for public use #2768

Merged
merged 6 commits into from
Dec 11, 2024

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Nov 28, 2024

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

This is a tentative design for exporting some of the internals of the Arduino CLI for reuse in other projects.

What is the current behavior?

The FQBN struct is not exported.

What is the new behavior?

The FQBN struct is exported through a public fqbn package.

Does this PR introduce a breaking change, and is titled accordingly?

Other information

Importing the newly created fqbn package as-is would cause a small dependency hell:

require (
	github.com/arduino/go-paths-helper v1.12.1 // indirect
	github.com/arduino/go-properties-orderedmap v1.8.1 // indirect
	github.com/leonelquinteros/gotext v1.7.0 // indirect
	github.com/sirupsen/logrus v1.9.3 // indirect
	golang.org/x/sys v0.27.0 // indirect
)

I also suspect that the Arduino CLI locales are bundled as part of the dependencies. To reduce this burden I've isolated the i18n.Tr function from the rest of the locales handling, and moved those latter functions to the locales package. I've also replaced the gotext.Po instance with an interface with only the Get method required for i18n to work properly.
If the translations are not used in the importing project, a thin wrapper is used instead of gotext.Po.
This change has reduced the dependencies to the minimum:

require (
	github.com/arduino/go-paths-helper v1.12.1 // indirect
	github.com/arduino/go-properties-orderedmap v1.8.1 // indirect
)

and also reduced the executable size by 300KB (that I suppose are the locales that are no longer bundled).

Because it may turn out useful for other projects.
@cmaglie cmaglie added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Nov 28, 2024
@cmaglie cmaglie self-assigned this Nov 28, 2024
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 82.14286% with 15 lines in your changes missing coverage. Please review.

Project coverage is 67.57%. Comparing base (a9597d6) to head (ea29e02).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
internal/locales/i18n.go 61.53% 4 Missing and 1 partial ⚠️
internal/cli/board/list.go 0.00% 4 Missing ⚠️
commands/service_upload.go 50.00% 2 Missing ⚠️
commands/instances.go 0.00% 1 Missing ⚠️
...al/arduino/cores/packagemanager/package_manager.go 90.00% 1 Missing ⚠️
internal/i18n/i18n.go 83.33% 1 Missing ⚠️
internal/locales/detect_windows.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2768      +/-   ##
==========================================
+ Coverage   67.54%   67.57%   +0.03%     
==========================================
  Files         237      238       +1     
  Lines       22362    22362              
==========================================
+ Hits        15104    15111       +7     
+ Misses       6066     6062       -4     
+ Partials     1192     1189       -3     
Flag Coverage Δ
unit 67.57% <82.14%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This changes allows to make a clean i18n package (without dependency on
a specific implementation of the translation package) that, in turn,
allows to export packages that internally use i18n with the minimal
dependency load.
@cmaglie cmaglie force-pushed the extract_fqbn_package branch from 45062fb to ea29e02 Compare November 29, 2024 11:00
@cmaglie cmaglie marked this pull request as ready for review December 2, 2024 14:00
Copy link
Contributor

@alessio-perugini alessio-perugini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super

@cmaglie cmaglie linked an issue Dec 4, 2024 that may be closed by this pull request
3 tasks
@cmaglie cmaglie merged commit 84fc413 into arduino:master Dec 11, 2024
106 checks passed
@cmaglie cmaglie deleted the extract_fqbn_package branch December 11, 2024 16:06
@dankeboy36
Copy link
Contributor

Hello, will this package get a public doc similar to what exists, for example, for arduino/go-paths-helper: https://pkg.go.dev/github.com/arduino/go-paths-helper?

I want to reference this new official implementation from my library. However, I could not find anything related to FQBN here: https://pkg.go.dev/search?q=arduino&m=package. Does it take some time to get published? I do not know how this works.

Thanks, and keep up the great work 💪

@alessio-perugini
Copy link
Contributor

@dankeboy36 👋 it will become available once we tag the next release. If you want to see it right now you have to navigate the following URL:
https://pkg.go.dev/github.com/arduino/arduino-cli@master
At the bottom once you click for the fqbn pkg it will redirect you to:
https://pkg.go.dev/github.com/arduino/[email protected]/pkg/fqbn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose a golang package to handle FQBNs
3 participants