@@ -21,31 +21,36 @@ import (
21
21
"encoding/json"
22
22
"fmt"
23
23
24
+ "github.com/arduino/arduino-cli/arduino/resources"
24
25
"github.com/arduino/go-paths-helper"
25
26
semver "go.bug.st/relaxed-semver"
26
-
27
- "github.com/arduino/arduino-cli/arduino/resources"
28
27
)
29
28
30
29
type indexJSON struct {
31
30
Libraries []indexRelease `json:"libraries"`
32
31
}
33
32
34
33
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"`
49
54
}
50
55
51
56
// LoadIndex reads a library_index.json and create the corresponding Index
@@ -104,10 +109,35 @@ func (indexLib *indexRelease) extractReleaseIn(library *Library) {
104
109
Checksum : indexLib .Checksum ,
105
110
CachePath : "libraries" ,
106
111
},
107
- Library : library ,
112
+ Library : library ,
113
+ Dependencies : indexLib .extractDependencies (),
108
114
}
109
115
library .Releases [indexLib .Version .String ()] = release
110
116
if library .Latest == nil || library .Latest .Version .LessThan (release .Version ) {
111
117
library .Latest = release
112
118
}
113
119
}
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
+ }
0 commit comments