Skip to content

Commit 99ebb08

Browse files
committed
Added infrastructure to handle 'dependency' field in library index
1 parent 4d36bac commit 99ebb08

File tree

4 files changed

+71
-18
lines changed

4 files changed

+71
-18
lines changed

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

+17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Library struct {
4545
type Release struct {
4646
Author string
4747
Version *semver.Version
48+
Dependencies []*Dependency
4849
Maintainer string
4950
Sentence string
5051
Paragraph string
@@ -57,6 +58,22 @@ type Release struct {
5758
Library *Library `json:"-"`
5859
}
5960

61+
// Dependency is a library dependency
62+
type Dependency struct {
63+
Name string
64+
VersionConstraint semver.Constraint
65+
}
66+
67+
// GetName returns the name of the dependency
68+
func (r *Dependency) GetName() string {
69+
return r.Name
70+
}
71+
72+
// GetConstraint returns the version Constraint of the dependecy
73+
func (r *Dependency) GetConstraint() semver.Constraint {
74+
return r.VersionConstraint
75+
}
76+
6077
func (r *Release) String() string {
6178
return r.Library.Name + "@" + r.Version.String()
6279
}

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

+47-17
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,36 @@ import (
2121
"encoding/json"
2222
"fmt"
2323

24+
"github.com/arduino/arduino-cli/arduino/resources"
2425
"github.com/arduino/go-paths-helper"
2526
semver "go.bug.st/relaxed-semver"
26-
27-
"github.com/arduino/arduino-cli/arduino/resources"
2827
)
2928

3029
type indexJSON struct {
3130
Libraries []indexRelease `json:"libraries"`
3231
}
3332

3433
type indexRelease struct {
35-
Name string `json:"name,required"`
36-
Version *semver.Version `json:"version,required"`
37-
Author string `json:"author"`
38-
Maintainer string `json:"maintainer"`
39-
Sentence string `json:"sentence"`
40-
Paragraph string `json:"paragraph"`
41-
Website string `json:"website"`
42-
Category string `json:"category"`
43-
Architectures []string `json:"architectures"`
44-
Types []string `json:"types"`
45-
URL string `json:"url"`
46-
ArchiveFileName string `json:"archiveFileName"`
47-
Size int64 `json:"size"`
48-
Checksum string `json:"checksum"`
34+
Name string `json:"name,required"`
35+
Version *semver.Version `json:"version,required"`
36+
Author string `json:"author"`
37+
Maintainer string `json:"maintainer"`
38+
Sentence string `json:"sentence"`
39+
Paragraph string `json:"paragraph"`
40+
Website string `json:"website"`
41+
Category string `json:"category"`
42+
Architectures []string `json:"architectures"`
43+
Types []string `json:"types"`
44+
URL string `json:"url"`
45+
ArchiveFileName string `json:"archiveFileName"`
46+
Size int64 `json:"size"`
47+
Checksum string `json:"checksum"`
48+
Dependencies []*indexDependency `json:"dependencies,omitempty"`
49+
}
50+
51+
type indexDependency struct {
52+
Name string `json:"name"`
53+
Version string `json:"version,omitempty"`
4954
}
5055

5156
// LoadIndex reads a library_index.json and create the corresponding Index
@@ -104,10 +109,35 @@ func (indexLib *indexRelease) extractReleaseIn(library *Library) {
104109
Checksum: indexLib.Checksum,
105110
CachePath: "libraries",
106111
},
107-
Library: library,
112+
Library: library,
113+
Dependencies: indexLib.extractDependencies(),
108114
}
109115
library.Releases[indexLib.Version.String()] = release
110116
if library.Latest == nil || library.Latest.Version.LessThan(release.Version) {
111117
library.Latest = release
112118
}
113119
}
120+
121+
func (indexLib *indexRelease) extractDependencies() []*Dependency {
122+
res := []*Dependency{}
123+
if indexLib.Dependencies == nil || len(indexLib.Dependencies) == 0 {
124+
return res
125+
}
126+
for _, indexDep := range indexLib.Dependencies {
127+
res = append(res, indexDep.extractDependency())
128+
}
129+
return res
130+
}
131+
132+
func (indexDep *indexDependency) extractDependency() *Dependency {
133+
var constraint semver.Constraint
134+
if c, err := semver.ParseConstraint(indexDep.Version); err == nil {
135+
constraint = c
136+
} else {
137+
// FIXME: report invalid constraint
138+
}
139+
return &Dependency{
140+
Name: indexDep.Name,
141+
VersionConstraint: constraint,
142+
}
143+
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ require (
3939
github.com/stretchr/testify v1.3.0
4040
go.bug.st/cleanup v1.0.0
4141
go.bug.st/downloader v1.1.0
42-
go.bug.st/relaxed-semver v0.0.0-20181022103824-0265409c5852
42+
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd
4343
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45
4444
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
4545
golang.org/x/net v0.0.0-20190311183353-d8887717615a

Diff for: go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ go.bug.st/downloader v1.1.0 h1:LipC9rqRCe8kwa+ah3ZDfCqneVaf34cB/TKjXZiZt54=
108108
go.bug.st/downloader v1.1.0/go.mod h1:l+RPbNbrTB+MoAIp8nrZsP22nRPDy26XJZQqmm4gNT4=
109109
go.bug.st/relaxed-semver v0.0.0-20181022103824-0265409c5852 h1:NimumSJtLf9QOiV8/LKi0IelbgbaSUGK/NTfKXc/gU8=
110110
go.bug.st/relaxed-semver v0.0.0-20181022103824-0265409c5852/go.mod h1:WWVH9tve4kargu9fsX18qW/UHxE37QcgPXRtE/xSvxY=
111+
go.bug.st/relaxed-semver v0.0.0-20190723141154-67da41656289 h1:f7LANEBiA7305QnaEvAFwPJK0h5bJK5HDeBqLldHVxU=
112+
go.bug.st/relaxed-semver v0.0.0-20190723141154-67da41656289/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
113+
go.bug.st/relaxed-semver v0.0.0-20190814125746-ed9d6e274197 h1:RCYSrmcgsSDYqjkFStAebyMqpfKE/bpzCoAwCIaCGhM=
114+
go.bug.st/relaxed-semver v0.0.0-20190814125746-ed9d6e274197/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
115+
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd h1:0YhstIItvBWi5w/Yhw4nnFUgWCfaLkEtHPaG5JlqEMY=
116+
go.bug.st/relaxed-semver v0.0.0-20190820131229-5407d65c50bd/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
111117
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI=
112118
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
113119
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=

0 commit comments

Comments
 (0)