-
-
Notifications
You must be signed in to change notification settings - Fork 429
Added gRPC functions to manage libraries in profiles #3019
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
Draft
cmaglie
wants to merge
4
commits into
arduino:master
Choose a base branch
from
cmaglie:grpc-profiles-functions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
47d7788
Added gRPC functions to manage libraries in profiles
cmaglie fe60757
Removed ProfileDump gRPC command.
cmaglie f086d47
Moved SketchProfileLibraryReference in the proper commono.proto file
cmaglie 27fe68b
linter: removed unneeded type specification
cmaglie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// This file is part of arduino-cli. | ||
// | ||
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This software is released under the GNU General Public License version 3, | ||
// which covers the main part of arduino-cli. | ||
// The terms of this license can be found at: | ||
// https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to [email protected]. | ||
|
||
package commands | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/arduino/arduino-cli/commands/cmderrors" | ||
"github.com/arduino/arduino-cli/internal/arduino/sketch" | ||
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" | ||
"github.com/arduino/go-paths-helper" | ||
) | ||
|
||
// ProfileDump dumps the content of the project file. | ||
func (s *arduinoCoreServerImpl) ProfileDump(ctx context.Context, req *rpc.ProfileDumpRequest) (*rpc.ProfileDumpResponse, error) { | ||
sk, err := sketch.New(paths.New(req.GetSketchPath())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
switch req.GetDumpFormat() { | ||
case "yaml": | ||
return &rpc.ProfileDumpResponse{EncodedProfile: sk.Project.AsYaml()}, nil | ||
case "", "json": | ||
data, err := json.MarshalIndent(sk.Project, "", " ") | ||
if err != nil { | ||
return nil, fmt.Errorf("error marshalling settings: %v", err) | ||
} | ||
return &rpc.ProfileDumpResponse{EncodedProfile: string(data)}, nil | ||
default: | ||
return nil, &cmderrors.InvalidArgumentError{Message: fmt.Sprintf("unsupported format: %s", req.GetDumpFormat())} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// This file is part of arduino-cli. | ||
// | ||
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This software is released under the GNU General Public License version 3, | ||
// which covers the main part of arduino-cli. | ||
// The terms of this license can be found at: | ||
// https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to [email protected]. | ||
|
||
package commands | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/arduino/arduino-cli/commands/cmderrors" | ||
"github.com/arduino/arduino-cli/commands/internal/instances" | ||
"github.com/arduino/arduino-cli/internal/arduino/sketch" | ||
"github.com/arduino/arduino-cli/internal/i18n" | ||
"github.com/arduino/arduino-cli/pkg/fqbn" | ||
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" | ||
"github.com/arduino/go-paths-helper" | ||
) | ||
|
||
// InitProfile creates a new project file if it does not exist. If a profile name with the associated FQBN is specified, | ||
// it is added to the project. | ||
func (s *arduinoCoreServerImpl) InitProfile(ctx context.Context, req *rpc.InitProfileRequest) (*rpc.InitProfileResponse, error) { | ||
// Returns an error if the main file is missing from the sketch so there is no need to check if the path exists | ||
sk, err := sketch.New(paths.New(req.GetSketchPath())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
projectFilePath := sk.GetProjectPath() | ||
|
||
if !projectFilePath.Exist() { | ||
err := projectFilePath.WriteFile([]byte("profiles: {}\n")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if req.GetProfileName() != "" { | ||
if req.GetFqbn() == "" { | ||
return nil, &cmderrors.MissingFQBNError{} | ||
} | ||
fqbn, err := fqbn.Parse(req.GetFqbn()) | ||
if err != nil { | ||
return nil, &cmderrors.InvalidFQBNError{Cause: err} | ||
} | ||
|
||
// Check that the profile name is unique | ||
if profile, _ := sk.GetProfile(req.ProfileName); profile != nil { | ||
return nil, &cmderrors.DuplicateProfileError{Profile: req.ProfileName} | ||
} | ||
|
||
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer release() | ||
if pme.Dirty() { | ||
return nil, &cmderrors.InstanceNeedsReinitialization{} | ||
} | ||
|
||
// Automatically detect the target platform if it is installed on the user's machine | ||
_, targetPlatform, _, _, _, err := pme.ResolveFQBN(fqbn) | ||
if err != nil { | ||
if targetPlatform == nil { | ||
return nil, &cmderrors.PlatformNotFoundError{ | ||
Platform: fmt.Sprintf("%s:%s", fqbn.Vendor, fqbn.Architecture), | ||
Cause: errors.New(i18n.Tr("platform not installed")), | ||
} | ||
} | ||
return nil, &cmderrors.InvalidFQBNError{Cause: err} | ||
} | ||
|
||
newProfile := &sketch.Profile{Name: req.GetProfileName(), FQBN: req.GetFqbn()} | ||
// TODO: what to do with the PlatformIndexURL? | ||
newProfile.Platforms = append(newProfile.Platforms, &sketch.ProfilePlatformReference{ | ||
Packager: targetPlatform.Platform.Package.Name, | ||
Architecture: targetPlatform.Platform.Architecture, | ||
Version: targetPlatform.Version, | ||
}) | ||
|
||
sk.Project.Profiles = append(sk.Project.Profiles, newProfile) | ||
// Set the profile as the default one if it's the only one | ||
if req.DefaultProfile || len(sk.Project.Profiles) == 1 { | ||
sk.Project.DefaultProfile = newProfile.Name | ||
} | ||
|
||
err = projectFilePath.WriteFile([]byte(sk.Project.AsYaml())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &rpc.InitProfileResponse{ProjectFilePath: projectFilePath.String()}, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.