Skip to content

Commit 6240477

Browse files
author
vinay-lanka
committed
add git library imports
have added a --git-url flag to lib install takes the git url and extracts it to the libraries directory
1 parent a14c037 commit 6240477

File tree

10 files changed

+413
-154
lines changed

10 files changed

+413
-154
lines changed

arduino/libraries/librariesmanager/install.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"io"
23-
"log"
2423
"os"
2524
"path/filepath"
2625
"strings"
@@ -29,6 +28,7 @@ import (
2928
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
3029
"github.com/arduino/arduino-cli/arduino/utils"
3130
paths "github.com/arduino/go-paths-helper"
31+
"gopkg.in/src-d/go-git.v4"
3232
)
3333

3434
var (
@@ -100,7 +100,7 @@ func (lm *LibrariesManager) InstallZipLib(libPath string) error {
100100
}
101101
err := Unzip(libPath, libsDir.String())
102102
if err != nil {
103-
log.Fatal(err)
103+
return err
104104
}
105105
return nil
106106
}
@@ -161,3 +161,29 @@ func Unzip(src string, dest string) error {
161161
}
162162
return nil
163163
}
164+
165+
//InstallGitLib installs a library hosted on a git repository on the specified path.
166+
func (lm *LibrariesManager) InstallGitLib(Name string, gitURL string) error {
167+
libsDir := lm.getUserLibrariesDir()
168+
if libsDir == nil {
169+
return fmt.Errorf("User directory not set")
170+
}
171+
err := Fetch(Name, gitURL, libsDir.String())
172+
if err != nil {
173+
return err
174+
}
175+
return nil
176+
}
177+
178+
//Fetch Clones the repository to LibsDir
179+
func Fetch(name string, url string, dest string) error {
180+
directory := dest + "/" + name
181+
_, err := git.PlainClone(directory, false, &git.CloneOptions{
182+
URL: url,
183+
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
184+
})
185+
if err != nil {
186+
return err
187+
}
188+
return nil
189+
}

cli/lib/install.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,25 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
5757
if installFlags.zipPath != "" {
5858
ZiplibraryInstallReq := &rpc.ZipLibraryInstallReq{
5959
Instance: instance,
60-
Path: installFlags.zipPath,
60+
Path: installFlags.zipPath,
6161
}
6262
_, err := lib.ZipLibraryInstall(context.Background(), ZiplibraryInstallReq)
6363
if err != nil {
6464
feedback.Errorf("Error installing Zip Library %v", err)
6565
os.Exit(errorcodes.ErrGeneric)
6666
}
67-
}else{
67+
} else if installFlags.gitURL != "" {
68+
GitlibraryInstallReq := &rpc.GitLibraryInstallReq{
69+
Instance: instance,
70+
Name: args[0],
71+
Url: installFlags.gitURL,
72+
}
73+
_, err := lib.GitLibraryInstall(context.Background(), GitlibraryInstallReq)
74+
if err != nil {
75+
feedback.Errorf("Error installing Git Library %v", err)
76+
os.Exit(errorcodes.ErrGeneric)
77+
}
78+
} else {
6879
libRefs, err := ParseLibraryReferenceArgsAndAdjustCase(instance, args)
6980
if err != nil {
7081
feedback.Errorf("Arguments error: %v", err)

commands/daemon/daemon.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,8 @@ func (s *ArduinoCoreServerImpl) LibraryList(ctx context.Context, req *rpc.Librar
292292
func (s *ArduinoCoreServerImpl) ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallReq) (*rpc.ZipLibraryInstallResp, error) {
293293
return lib.ZipLibraryInstall(ctx, req)
294294
}
295+
296+
//GitLibraryInstall FIXMEDOC
297+
func (s *ArduinoCoreServerImpl) GitLibraryInstall(ctx context.Context, req *rpc.GitLibraryInstallReq) (*rpc.GitLibraryInstallResp, error) {
298+
return lib.GitLibraryInstall(ctx, req)
299+
}

commands/lib/install.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,24 @@ func installZipLibrary(lm *librariesmanager.LibrariesManager, libPath string) er
9696
}
9797
return nil
9898
}
99+
100+
//GitLibraryInstall FIXMEDOC
101+
func GitLibraryInstall(ctx context.Context, req *rpc.GitLibraryInstallReq) (*rpc.GitLibraryInstallResp, error) {
102+
res := &rpc.GitLibraryInstallResp{}
103+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
104+
URL := req.GetUrl()
105+
Name := req.GetName()
106+
if err := installGitLibrary(lm, Name, URL); err != nil {
107+
res.Status = "Error installing Git Library"
108+
return res, err
109+
}
110+
res.Status = "Success! Installed Git Library"
111+
return res, nil
112+
}
113+
114+
func installGitLibrary(lm *librariesmanager.LibrariesManager, Name string, gitURL string) error {
115+
if err := lm.InstallGitLib(Name, gitURL); err != nil {
116+
return err
117+
}
118+
return nil
119+
}

go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ require (
2323
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect
2424
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect
2525
github.com/juju/testing v0.0.0-20190429233213-dfc56b8c09fc // indirect
26+
github.com/kr/pretty v0.2.0 // indirect
27+
github.com/kr/text v0.2.0 // indirect
2628
github.com/mattn/go-colorable v0.1.2
2729
github.com/mattn/go-runewidth v0.0.2 // indirect
2830
github.com/miekg/dns v1.0.5 // indirect
31+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
2932
github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 // indirect
3033
github.com/pkg/errors v0.9.1
3134
github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583
3235
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
3336
github.com/schollz/closestmatch v2.1.0+incompatible
3437
github.com/segmentio/stats/v4 v4.5.3
38+
github.com/sergi/go-diff v1.1.0 // indirect
3539
github.com/sirupsen/logrus v1.4.2
3640
github.com/spf13/cobra v0.0.5
3741
github.com/spf13/jwalterweatherman v1.0.0
@@ -42,12 +46,14 @@ require (
4246
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18
4347
go.bug.st/serial v1.0.0
4448
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 // indirect
45-
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
46-
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect
49+
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71 // indirect
50+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
51+
golang.org/x/sys v0.0.0-20200408040146-ea54a3c99b9b // indirect
4752
golang.org/x/text v0.3.2
4853
google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90 // indirect
4954
google.golang.org/grpc v1.27.0
50-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
55+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
5156
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
57+
gopkg.in/src-d/go-git.v4 v4.13.1
5258
gopkg.in/yaml.v2 v2.2.4
5359
)

0 commit comments

Comments
 (0)