Skip to content

Commit 8941e40

Browse files
committed
Add ProfileLibList method
1 parent 3cd499a commit 8941e40

File tree

5 files changed

+1245
-675
lines changed

5 files changed

+1245
-675
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package commands
17+
18+
import (
19+
"context"
20+
21+
"github.com/arduino/arduino-cli/commands/cmderrors"
22+
"github.com/arduino/arduino-cli/internal/arduino/sketch"
23+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
24+
paths "github.com/arduino/go-paths-helper"
25+
"go.bug.st/f"
26+
)
27+
28+
// ProfileLibList lists the libraries in the build profile.
29+
func (s *arduinoCoreServerImpl) ProfileLibList(ctx context.Context, req *rpc.ProfileLibListRequest) (*rpc.ProfileLibListResponse, error) {
30+
sk, err := sketch.New(paths.New(req.GetSketchPath()))
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
// If no profile is specified, try to use the default one
36+
profileName := sk.Project.DefaultProfile
37+
if req.GetProfileName() != "" {
38+
profileName = req.GetProfileName()
39+
}
40+
if profileName == "" {
41+
return nil, &cmderrors.MissingProfileError{}
42+
}
43+
44+
profile, err := sk.GetProfile(profileName)
45+
if err != nil {
46+
return nil, &cmderrors.UnknownProfileError{Profile: profileName}
47+
}
48+
49+
return &rpc.ProfileLibListResponse{
50+
Libraries: f.Map(profile.Libraries, (*sketch.ProfileLibraryReference).ToRpc),
51+
ProfileName: profileName,
52+
}, nil
53+
}

internal/arduino/sketch/profiles.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,26 @@ func (l *ProfileLibraryReference) String() string {
392392
return fmt.Sprintf("%s@%s", l.Library, l.Version)
393393
}
394394

395+
func (l *ProfileLibraryReference) ToRpc() *rpc.ProfileLibraryReference {
396+
if l.InstallDir != nil {
397+
return &rpc.ProfileLibraryReference{
398+
Library: &rpc.ProfileLibraryReference_LocalLibrary_{
399+
LocalLibrary: &rpc.ProfileLibraryReference_LocalLibrary{
400+
Path: l.InstallDir.String(),
401+
},
402+
},
403+
}
404+
}
405+
return &rpc.ProfileLibraryReference{
406+
Library: &rpc.ProfileLibraryReference_IndexLibrary_{
407+
IndexLibrary: &rpc.ProfileLibraryReference_IndexLibrary{
408+
Name: l.Library,
409+
Version: l.Version.String(),
410+
},
411+
},
412+
}
413+
}
414+
395415
// InternalUniqueIdentifier returns the unique identifier for this object
396416
func (l *ProfileLibraryReference) InternalUniqueIdentifier() string {
397417
f.Assert(l.InstallDir == nil,

0 commit comments

Comments
 (0)