Skip to content

Commit b602888

Browse files
committed
Added gRPC support for git-libraries in profiles
1 parent 2c2baa7 commit b602888

File tree

6 files changed

+168
-24
lines changed

6 files changed

+168
-24
lines changed

commands/service_profile_lib_add.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package commands
1818
import (
1919
"cmp"
2020
"context"
21+
"net/url"
2122
"slices"
2223

2324
"github.com/arduino/arduino-cli/commands/cmderrors"
@@ -59,6 +60,15 @@ func (s *arduinoCoreServerImpl) ProfileLibAdd(ctx context.Context, req *rpc.Prof
5960
addedLib := &sketch.ProfileLibraryReference{InstallDir: path}
6061
profile.Libraries = append(profile.Libraries, addedLib)
6162
addedLibs = append(addedLibs, addedLib)
63+
} else if reqGitLib := req.GetLibrary().GetGitLibrary(); reqGitLib != nil {
64+
// Add a git library
65+
gitURL, err := url.Parse(reqGitLib.GetUrl())
66+
if err != nil {
67+
return nil, &cmderrors.InvalidURLError{Cause: err}
68+
}
69+
addedLib := &sketch.ProfileLibraryReference{GitURL: gitURL}
70+
profile.Libraries = append(profile.Libraries, addedLib)
71+
addedLibs = append(addedLibs, addedLib)
6272
} else if reqIndexLib := req.GetLibrary().GetIndexLibrary(); reqIndexLib != nil {
6373
// Obtain the library index from the manager
6474
li, err := instances.GetLibrariesIndex(req.GetInstance())

internal/arduino/sketch/profiles.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,15 @@ func (l *ProfileLibraryReference) ToRpc() *rpc.ProfileLibraryReference {
480480
},
481481
}
482482
}
483+
if l.GitURL != nil {
484+
return &rpc.ProfileLibraryReference{
485+
Library: &rpc.ProfileLibraryReference_GitLibrary_{
486+
GitLibrary: &rpc.ProfileLibraryReference_GitLibrary{
487+
Url: l.GitURL.String(),
488+
},
489+
},
490+
}
491+
}
483492
return &rpc.ProfileLibraryReference{
484493
Library: &rpc.ProfileLibraryReference_IndexLibrary_{
485494
IndexLibrary: &rpc.ProfileLibraryReference_IndexLibrary{
@@ -500,6 +509,13 @@ func FromRpcProfileLibraryReference(l *rpc.ProfileLibraryReference) (*ProfileLib
500509
}
501510
return &ProfileLibraryReference{InstallDir: path}, nil
502511
}
512+
if gitLib := l.GetGitLibrary(); gitLib != nil {
513+
gitURL, err := url.Parse(gitLib.GetUrl())
514+
if err != nil {
515+
return nil, &cmderrors.InvalidURLError{Cause: err}
516+
}
517+
return &ProfileLibraryReference{GitURL: gitURL}, nil
518+
}
503519
if indexLib := l.GetIndexLibrary(); indexLib != nil {
504520
var version *semver.Version
505521
if indexLib.GetVersion() != "" {

internal/cli/feedback/result/rpc.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,22 @@ func NewIndexUpdateReport_Status(r rpc.IndexUpdateReport_Status) IndexUpdateRepo
11261126
}
11271127
}
11281128

1129+
type ProfileLibraryReference_GitLibraryResult struct {
1130+
Url string `json:"url,omitempty"`
1131+
}
1132+
1133+
func NewProfileLibraryReference_GitLibraryResult(resp *rpc.ProfileLibraryReference_GitLibrary) *ProfileLibraryReference_GitLibraryResult {
1134+
return &ProfileLibraryReference_GitLibraryResult{
1135+
Url: resp.GetUrl(),
1136+
}
1137+
}
1138+
1139+
func (*ProfileLibraryReference_GitLibraryResult) isProfileLibraryReference() {}
1140+
1141+
func (l *ProfileLibraryReference_GitLibraryResult) String() string {
1142+
return fmt.Sprintf("git: %s", l.Url)
1143+
}
1144+
11291145
type ProfileLibraryReference_LocalLibraryResult struct {
11301146
Path string `json:"path,omitempty"`
11311147
}
@@ -1182,6 +1198,12 @@ func NewProfileLibraryReference(resp *rpc.ProfileLibraryReference) *ProfileLibra
11821198
Kind: "index",
11831199
}
11841200
}
1201+
if lib := resp.GetGitLibrary(); lib != nil {
1202+
return &ProfileLibraryReference{
1203+
Library: NewProfileLibraryReference_GitLibraryResult(lib),
1204+
Kind: "git",
1205+
}
1206+
}
11851207
if lib := resp.GetLocalLibrary(); lib != nil {
11861208
return &ProfileLibraryReference{
11871209
Library: NewProfileLibraryReference_LocalLibraryResult(lib),

internal/cli/feedback/result/rpc_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ func TestAllFieldAreMapped(t *testing.T) {
238238
profileLibraryReference_IndexLibraryResult := result.NewProfileLibraryReference_IndexLibraryResult(profileLibraryReference_IndexLibraryRpc)
239239
mustContainsAllPropertyOfRpcStruct(t, profileLibraryReference_IndexLibraryRpc, profileLibraryReference_IndexLibraryResult)
240240

241+
profileLibraryReference_GitLibraryRpc := &rpc.ProfileLibraryReference_GitLibrary{}
242+
profileLibraryReference_GitLibraryResult := result.NewProfileLibraryReference_GitLibraryResult(profileLibraryReference_GitLibraryRpc)
243+
mustContainsAllPropertyOfRpcStruct(t, profileLibraryReference_GitLibraryRpc, profileLibraryReference_GitLibraryResult)
244+
241245
profileLibraryReference_LocalLibraryRpc := &rpc.ProfileLibraryReference_LocalLibrary{}
242246
profileLibraryReference_LocalLibraryResult := result.NewProfileLibraryReference_LocalLibraryResult(profileLibraryReference_LocalLibraryRpc)
243247
mustContainsAllPropertyOfRpcStruct(t, profileLibraryReference_LocalLibraryRpc, profileLibraryReference_LocalLibraryResult)

rpc/cc/arduino/cli/commands/v1/common.pb.go

Lines changed: 110 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/common.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,16 @@ message ProfileLibraryReference {
251251
// Absolute path to the library.
252252
string path = 1;
253253
}
254+
message GitLibrary {
255+
// URL to the git repo (the revision reference is in the fragment part of the URL).
256+
string url = 1;
257+
}
254258
oneof library {
255259
// The library is installed from the Library Index.
256260
IndexLibrary index_library = 1;
257261
// The library is a local library.
258262
LocalLibrary local_library = 2;
263+
// The library is installed from a git repository.
264+
GitLibrary git_library = 3;
259265
}
260266
}

0 commit comments

Comments
 (0)