Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1e03f58

Browse filesBrowse files
libraries: expose Dependencies field
1 parent 36a4190 commit 1e03f58
Copy full SHA for 1e03f58

File tree

7 files changed

+163
-118
lines changed
Filter options

7 files changed

+163
-118
lines changed

‎commands/service_library_search.go

Copy file name to clipboardExpand all lines: commands/service_library_search.go
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222

2323
"github.com/arduino/arduino-cli/commands/internal/instances"
24+
"github.com/arduino/arduino-cli/internal/arduino/libraries"
2425
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesindex"
2526
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2627
semver "go.bug.st/relaxed-semver"
@@ -116,7 +117,7 @@ func getLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease {
116117
}
117118
}
118119

119-
func getLibraryDependenciesParameter(deps []*librariesindex.Dependency) []*rpc.LibraryDependency {
120+
func getLibraryDependenciesParameter(deps []*libraries.Dependency) []*rpc.LibraryDependency {
120121
res := []*rpc.LibraryDependency{}
121122
for _, dep := range deps {
122123
res = append(res, &rpc.LibraryDependency{

‎internal/arduino/libraries/libraries.go

Copy file name to clipboardExpand all lines: internal/arduino/libraries/libraries.go
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2626
paths "github.com/arduino/go-paths-helper"
2727
properties "github.com/arduino/go-properties-orderedmap"
28+
"go.bug.st/f"
2829
semver "go.bug.st/relaxed-semver"
2930
)
3031

@@ -78,6 +79,7 @@ type Library struct {
7879
License string
7980
Properties *properties.Map
8081
Examples paths.PathList
82+
Dependencies []*Dependency
8183
declaredHeaders []string
8284
sourceHeaders []string
8385
CompatibleWith map[string]bool
@@ -142,6 +144,13 @@ func (library *Library) ToRPCLibrary() (*rpc.Library, error) {
142144
Examples: library.Examples.AsStrings(),
143145
ProvidesIncludes: headers,
144146
CompatibleWith: library.CompatibleWith,
147+
Dependencies: f.Map(library.Dependencies, func(d *Dependency) *rpc.LibraryDependency {
148+
dep := &rpc.LibraryDependency{Name: d.GetName()}
149+
if d.GetConstraint() != nil {
150+
dep.VersionConstraint = d.GetConstraint().String()
151+
}
152+
return dep
153+
}),
145154
}, nil
146155
}
147156

@@ -239,3 +248,19 @@ func (library *Library) SourceHeaders() ([]string, error) {
239248
}
240249
return library.sourceHeaders, nil
241250
}
251+
252+
// Dependency is a library dependency
253+
type Dependency struct {
254+
Name string
255+
VersionConstraint semver.Constraint
256+
}
257+
258+
// GetName returns the name of the dependency
259+
func (r *Dependency) GetName() string {
260+
return r.Name
261+
}
262+
263+
// GetConstraint returns the version Constraint of the dependecy
264+
func (r *Dependency) GetConstraint() semver.Constraint {
265+
return r.VersionConstraint
266+
}

‎internal/arduino/libraries/librariesindex/index.go

Copy file name to clipboardExpand all lines: internal/arduino/libraries/librariesindex/index.go
+3-19Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Library struct {
4545
type Release struct {
4646
Author string
4747
Version *semver.Version
48-
Dependencies []*Dependency
48+
Dependencies []*libraries.Dependency
4949
Maintainer string
5050
Sentence string
5151
Paragraph string
@@ -86,26 +86,10 @@ func (r *Release) GetVersion() *semver.Version {
8686
}
8787

8888
// GetDependencies returns the dependencies of this library.
89-
func (r *Release) GetDependencies() []*Dependency {
89+
func (r *Release) GetDependencies() []*libraries.Dependency {
9090
return r.Dependencies
9191
}
9292

93-
// Dependency is a library dependency
94-
type Dependency struct {
95-
Name string
96-
VersionConstraint semver.Constraint
97-
}
98-
99-
// GetName returns the name of the dependency
100-
func (r *Dependency) GetName() string {
101-
return r.Name
102-
}
103-
104-
// GetConstraint returns the version Constraint of the dependecy
105-
func (r *Dependency) GetConstraint() semver.Constraint {
106-
return r.VersionConstraint
107-
}
108-
10993
func (r *Release) String() string {
11094
return r.Library.Name + "@" + r.Version.String()
11195
}
@@ -155,7 +139,7 @@ func (idx *Index) FindLibraryUpdate(lib *libraries.Library) *Release {
155139
// An optional "override" releases may be passed if we want to exclude the same
156140
// libraries from the index (for example if we want to keep an installed library).
157141
func (idx *Index) ResolveDependencies(lib *Release, overrides []*Release) []*Release {
158-
resolver := semver.NewResolver[*Release, *Dependency]()
142+
resolver := semver.NewResolver[*Release, *libraries.Dependency]()
159143

160144
overridden := map[string]bool{}
161145
for _, override := range overrides {

‎internal/arduino/libraries/librariesindex/json.go

Copy file name to clipboardExpand all lines: internal/arduino/libraries/librariesindex/json.go
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package librariesindex
1818
import (
1919
"errors"
2020

21+
"github.com/arduino/arduino-cli/internal/arduino/libraries"
2122
"github.com/arduino/arduino-cli/internal/arduino/resources"
2223
"github.com/arduino/arduino-cli/internal/i18n"
2324
"github.com/arduino/go-paths-helper"
@@ -124,8 +125,8 @@ func (indexLib *indexRelease) extractReleaseIn(library *Library) {
124125
}
125126
}
126127

127-
func (indexLib *indexRelease) extractDependencies() []*Dependency {
128-
res := []*Dependency{}
128+
func (indexLib *indexRelease) extractDependencies() []*libraries.Dependency {
129+
res := []*libraries.Dependency{}
129130
if len(indexLib.Dependencies) == 0 {
130131
return res
131132
}
@@ -135,13 +136,13 @@ func (indexLib *indexRelease) extractDependencies() []*Dependency {
135136
return res
136137
}
137138

138-
func (indexDep *indexDependency) extractDependency() *Dependency {
139+
func (indexDep *indexDependency) extractDependency() *libraries.Dependency {
139140
var constraint semver.Constraint
140141
if c, err := semver.ParseConstraint(indexDep.Version); err == nil {
141142
constraint = c
142143
}
143144
// FIXME: else { report invalid constraint }
144-
return &Dependency{
145+
return &libraries.Dependency{
145146
Name: indexDep.Name,
146147
VersionConstraint: constraint,
147148
}

‎internal/arduino/libraries/loader.go

Copy file name to clipboardExpand all lines: internal/arduino/libraries/loader.go
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
130130
library.LDflags = strings.TrimSpace(libProperties.Get("ldflags"))
131131
library.Properties = libProperties
132132
library.InDevelopment = libraryDir.Join(".development").Exist()
133+
if dependencies := libProperties.Get("depends"); dependencies != "" {
134+
for dep := range strings.SplitSeq(strings.TrimSpace(libProperties.Get("depends")), ",") {
135+
var depConstraint semver.Constraint
136+
depName := strings.TrimSpace(dep)
137+
idx := strings.LastIndex(dep, " (")
138+
if idx != -1 {
139+
depName = dep[:idx]
140+
depConstraint, _ = semver.ParseConstraint(dep[idx+1:])
141+
}
142+
library.Dependencies = append(library.Dependencies, &Dependency{
143+
Name: depName,
144+
VersionConstraint: depConstraint,
145+
})
146+
}
147+
}
133148
return library, nil
134149
}
135150

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.