Skip to content

Commit f32295a

Browse files
committed
Added gRPC support for git-libraries in profiles
1 parent 333f550 commit f32295a

File tree

6 files changed

+157
-22
lines changed

6 files changed

+157
-22
lines changed

commands/service_profile_lib_add.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package commands
1717

1818
import (
1919
"context"
20+
"net/url"
2021

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

internal/arduino/sketch/profiles.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ func (l *ProfileLibraryReference) Match(other *ProfileLibraryReference) bool {
430430
if l.InstallDir != nil {
431431
return other.InstallDir != nil && l.InstallDir.EqualsTo(other.InstallDir)
432432
}
433+
if l.GitURL != nil {
434+
return other.GitURL != nil && l.GitURL.String() == other.GitURL.String()
435+
}
433436
if other.InstallDir != nil {
434437
return false
435438
}
@@ -453,6 +456,15 @@ func (l *ProfileLibraryReference) ToRpc() *rpc.SketchProfileLibraryReference {
453456
},
454457
}
455458
}
459+
if l.GitURL != nil {
460+
return &rpc.SketchProfileLibraryReference{
461+
Library: &rpc.SketchProfileLibraryReference_GitLibrary_{
462+
GitLibrary: &rpc.SketchProfileLibraryReference_GitLibrary{
463+
Url: l.GitURL.String(),
464+
},
465+
},
466+
}
467+
}
456468
return &rpc.SketchProfileLibraryReference{
457469
Library: &rpc.SketchProfileLibraryReference_IndexLibrary_{
458470
IndexLibrary: &rpc.SketchProfileLibraryReference_IndexLibrary{
@@ -472,6 +484,13 @@ func FromRpcProfileLibraryReference(l *rpc.SketchProfileLibraryReference) (*Prof
472484
}
473485
return &ProfileLibraryReference{InstallDir: path}, nil
474486
}
487+
if gitLib := l.GetGitLibrary(); gitLib != nil {
488+
gitURL, err := url.Parse(gitLib.GetUrl())
489+
if err != nil {
490+
return nil, &cmderrors.InvalidURLError{Cause: err}
491+
}
492+
return &ProfileLibraryReference{GitURL: gitURL}, nil
493+
}
475494
if indexLib := l.GetIndexLibrary(); indexLib != nil {
476495
var version *semver.Version
477496
if indexLib.GetVersion() != "" {

internal/cli/feedback/result/rpc.go

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

1129+
type SketchProfileLibraryReference_GitLibraryResult struct {
1130+
Url string `json:"url,omitempty"`
1131+
}
1132+
1133+
func NewSketchProfileLibraryReference_GitLibraryResult(resp *rpc.SketchProfileLibraryReference_GitLibrary) *SketchProfileLibraryReference_GitLibraryResult {
1134+
return &SketchProfileLibraryReference_GitLibraryResult{
1135+
Url: resp.GetUrl(),
1136+
}
1137+
}
1138+
11291139
type SketchProfileLibraryReference_LocalLibraryResult struct {
11301140
Path string `json:"path,omitempty"`
11311141
}

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
sketchProfileLibraryReference_IndexLibraryResult := result.NewSketchProfileLibraryReference_IndexLibraryResult(sketchProfileLibraryReference_IndexLibraryRpc)
239239
mustContainsAllPropertyOfRpcStruct(t, sketchProfileLibraryReference_IndexLibraryRpc, sketchProfileLibraryReference_IndexLibraryResult)
240240

241+
sketchProfileLibraryReference_GitLibraryRpc := &rpc.SketchProfileLibraryReference_GitLibrary{}
242+
sketchProfileLibraryReference_GitLibraryResult := result.NewSketchProfileLibraryReference_GitLibraryResult(sketchProfileLibraryReference_GitLibraryRpc)
243+
mustContainsAllPropertyOfRpcStruct(t, sketchProfileLibraryReference_GitLibraryRpc, sketchProfileLibraryReference_GitLibraryResult)
244+
241245
sketchProfileLibraryReference_LocalLibraryRpc := &rpc.SketchProfileLibraryReference_LocalLibrary{}
242246
sketchProfileLibraryReference_LocalLibraryResult := result.NewSketchProfileLibraryReference_LocalLibraryResult(sketchProfileLibraryReference_LocalLibraryRpc)
243247
mustContainsAllPropertyOfRpcStruct(t, sketchProfileLibraryReference_LocalLibraryRpc, sketchProfileLibraryReference_LocalLibraryResult)

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

Lines changed: 108 additions & 22 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
@@ -249,10 +249,16 @@ message SketchProfileLibraryReference {
249249
// Absolute path to the library.
250250
string path = 1;
251251
}
252+
message GitLibrary {
253+
// URL to the git repo (the revision reference is in the fragment part of the URL).
254+
string url = 1;
255+
}
252256
oneof library {
253257
// The library is installed from the Library Index.
254258
IndexLibrary index_library = 1;
255259
// The library is a local library.
256260
LocalLibrary local_library = 2;
261+
// The library is installed from a git repository.
262+
GitLibrary git_library = 3;
257263
}
258264
}

0 commit comments

Comments
 (0)