Skip to content

Commit 7acf4be

Browse files
committed
Added library-dep resolution function in core modules
1 parent a10f042 commit 7acf4be

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

Diff for: arduino/libraries/librariesindex/index.go

+27
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,33 @@ func (idx *Index) FindLibraryUpdate(lib *libraries.Library) *Release {
126126
return nil
127127
}
128128

129+
// ResolveDependencies returns the dependencies of a library release.
130+
func (idx *Index) ResolveDependencies(lib *Release) []*Release {
131+
// Box lib index *Release to be digested by dep-resolver
132+
// (TODO: There is a better use of golang interfaces to avoid this?)
133+
allReleases := map[string]semver.Releases{}
134+
for _, indexLib := range idx.Libraries {
135+
releases := semver.Releases{}
136+
for _, indexLibRelease := range indexLib.Releases {
137+
releases = append(releases, indexLibRelease)
138+
}
139+
allReleases[indexLib.Name] = releases
140+
}
141+
142+
// Perform lib resolution
143+
archive := &semver.Archive{
144+
Releases: allReleases,
145+
}
146+
deps := archive.Resolve(lib)
147+
148+
// Unbox resolved deps back into *Release
149+
res := []*Release{}
150+
for _, dep := range deps {
151+
res = append(res, dep.(*Release))
152+
}
153+
return res
154+
}
155+
129156
// Versions returns an array of all versions available of the library
130157
func (library *Library) Versions() []*semver.Version {
131158
res := []*semver.Version{}

Diff for: arduino/libraries/librariesindex/index_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,29 @@ func TestIndexer(t *testing.T) {
8585

8686
rtcInexistent2 := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero-blah", Version: semver.MustParse("1.0.0")})
8787
require.Nil(t, rtcInexistent2)
88+
89+
resolve1 := index.ResolveDependencies(alp.Releases["1.2.1"])
90+
require.Len(t, resolve1, 2)
91+
require.Contains(t, resolve1, alp.Releases["1.2.1"])
92+
require.Contains(t, resolve1, rtc.Releases["1.6.0"])
93+
94+
oauth010 := index.FindRelease(&Reference{Name: "Arduino_OAuth", Version: semver.MustParse("0.1.0")})
95+
require.NotNil(t, oauth010)
96+
require.Equal(t, "[email protected]", oauth010.String())
97+
eccx133 := index.FindRelease(&Reference{Name: "ArduinoECCX08", Version: semver.MustParse("1.3.3")})
98+
require.NotNil(t, eccx133)
99+
require.Equal(t, "[email protected]", eccx133.String())
100+
bear130 := index.FindRelease(&Reference{Name: "ArduinoBearSSL", Version: semver.MustParse("1.3.0")})
101+
require.NotNil(t, bear130)
102+
require.Equal(t, "[email protected]", bear130.String())
103+
http040 := index.FindRelease(&Reference{Name: "ArduinoHttpClient", Version: semver.MustParse("0.4.0")})
104+
require.NotNil(t, http040)
105+
require.Equal(t, "[email protected]", http040.String())
106+
107+
resolve2 := index.ResolveDependencies(oauth010)
108+
require.Len(t, resolve2, 4)
109+
require.Contains(t, resolve2, oauth010)
110+
require.Contains(t, resolve2, eccx133)
111+
require.Contains(t, resolve2, bear130)
112+
require.Contains(t, resolve2, http040)
88113
}

Diff for: go.mod

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ require (
3636
github.com/sirupsen/logrus v1.4.2
3737
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
3838
github.com/spf13/cobra v0.0.5
39-
github.com/stretchr/testify v1.3.0
39+
github.com/stretchr/objx v0.2.0 // indirect
40+
github.com/stretchr/testify v1.4.0
4041
go.bug.st/cleanup v1.0.0
4142
go.bug.st/downloader v1.1.0
42-
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd
43+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18
4344
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45
4445
golang.org/x/net v0.0.0-20190311183353-d8887717615a
4546
golang.org/x/text v0.3.0
47+
google.golang.org/appengine v1.4.0 // indirect
4648
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
4749
google.golang.org/grpc v1.21.1
50+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
4851
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
4952
gopkg.in/yaml.v2 v2.2.2
5053
)

Diff for: go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
109109
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
110110
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
111111
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
112+
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
112113
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
113114
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
114115
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
116+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
117+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
115118
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
116119
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
117120
go.bug.st/cleanup v1.0.0 h1:XVj1HZxkBXeq3gMT7ijWUpHyIC1j8XAoNSyQ06CskgA=
@@ -126,6 +129,8 @@ go.bug.st/relaxed-semver v0.0.0-20190814125746-ed9d6e274197 h1:RCYSrmcgsSDYqjkFS
126129
go.bug.st/relaxed-semver v0.0.0-20190814125746-ed9d6e274197/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
127130
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd h1:0YhstIItvBWi5w/Yhw4nnFUgWCfaLkEtHPaG5JlqEMY=
128131
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
132+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 h1:F1qxtaFuewctYc/SsHRn+Q7Dtwi+yJGPgVq8YLtQz98=
133+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
129134
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI=
130135
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
131136
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -168,6 +173,7 @@ google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8=
168173
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
169174
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
170175
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
176+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
171177
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=
172178
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
173179
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=

0 commit comments

Comments
 (0)