Skip to content

Commit ff2e895

Browse files
committed
Added library-dep resolution function in core modules
1 parent aee4e0c commit ff2e895

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

arduino/libraries/librariesindex/index.go

Lines changed: 27 additions & 0 deletions
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{}

arduino/libraries/librariesindex/index_test.go

Lines changed: 25 additions & 0 deletions
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, "Arduino_OAuth@0.1.0", oauth010.String())
97+
eccx133 := index.FindRelease(&Reference{Name: "ArduinoECCX08", Version: semver.MustParse("1.3.3")})
98+
require.NotNil(t, eccx133)
99+
require.Equal(t, "ArduinoECCX08@1.3.3", eccx133.String())
100+
bear130 := index.FindRelease(&Reference{Name: "ArduinoBearSSL", Version: semver.MustParse("1.3.0")})
101+
require.NotNil(t, bear130)
102+
require.Equal(t, "ArduinoBearSSL@1.3.0", bear130.String())
103+
http040 := index.FindRelease(&Reference{Name: "ArduinoHttpClient", Version: semver.MustParse("0.4.0")})
104+
require.NotNil(t, http040)
105+
require.Equal(t, "ArduinoHttpClient@0.4.0", 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
}

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +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
4647
google.golang.org/appengine v1.4.0 // indirect
4748
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
4849
google.golang.org/grpc v1.21.1
50+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
4951
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
5052
gopkg.in/yaml.v2 v2.2.2
5153
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
111111
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
112112
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
113113
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
114+
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
114115
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
115116
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
116117
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
118+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
119+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
117120
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
118121
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
119122
go.bug.st/cleanup v1.0.0 h1:XVj1HZxkBXeq3gMT7ijWUpHyIC1j8XAoNSyQ06CskgA=
@@ -128,6 +131,8 @@ go.bug.st/relaxed-semver v0.0.0-20190814125746-ed9d6e274197 h1:RCYSrmcgsSDYqjkFS
128131
go.bug.st/relaxed-semver v0.0.0-20190814125746-ed9d6e274197/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
129132
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd h1:0YhstIItvBWi5w/Yhw4nnFUgWCfaLkEtHPaG5JlqEMY=
130133
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
134+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 h1:F1qxtaFuewctYc/SsHRn+Q7Dtwi+yJGPgVq8YLtQz98=
135+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
131136
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI=
132137
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
133138
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -170,6 +175,7 @@ google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8=
170175
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
171176
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
172177
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
178+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
173179
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=
174180
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
175181
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=

0 commit comments

Comments
 (0)