Skip to content

Commit c1d33a8

Browse files
committed
Merge branch 'master' into arduifine
2 parents 46f4e32 + efc660a commit c1d33a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+838
-257
lines changed

Diff for: arduino/cores/cores.go

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Platform struct {
3434
Releases map[string]*PlatformRelease // The Releases of this platform, labeled by version.
3535
Package *Package `json:"-"`
3636
ManuallyInstalled bool // true if the Platform has been installed without the CLI
37+
Deprecated bool // true if the Platform has been deprecated
3738
}
3839

3940
// PlatformReleaseHelp represents the help URL for this Platform release

Diff for: arduino/cores/packageindex/index.go

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type indexPlatformRelease struct {
5050
Name string `json:"name,required"`
5151
Architecture string `json:"architecture"`
5252
Version *semver.Version `json:"version,required"`
53+
Deprecated bool `json:"deprecated"`
5354
Category string `json:"category"`
5455
URL string `json:"url"`
5556
ArchiveFileName string `json:"archiveFileName,required"`
@@ -167,6 +168,7 @@ func IndexFromPlatformRelease(pr *cores.PlatformRelease) Index {
167168
Name: pr.Platform.Name,
168169
Architecture: pr.Platform.Architecture,
169170
Version: pr.Version,
171+
Deprecated: pr.Platform.Deprecated,
170172
Category: pr.Platform.Category,
171173
URL: pr.Resource.URL,
172174
ArchiveFileName: pr.Resource.ArchiveFileName,
@@ -205,6 +207,13 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
205207
// FIXME: shall we use the Name and Category of the latest release? or maybe move Name and Category in PlatformRelease?
206208
outPlatform.Name = inPlatformRelease.Name
207209
outPlatform.Category = inPlatformRelease.Category
210+
// If the Platform is installed before deprecation installed.json file does not include "deprecated" field.
211+
// The installed.json is read during loading phase of an installed Platform, if the deprecated field is not found
212+
// the package_index.json field would be overwritten and the deprecation info would be lost.
213+
// This check prevents that behaviour.
214+
if !outPlatform.Deprecated {
215+
outPlatform.Deprecated = inPlatformRelease.Deprecated
216+
}
208217

209218
size, err := inPlatformRelease.Size.Int64()
210219
if err != nil {

Diff for: arduino/libraries/libraries_location.go

+13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const (
3535
ReferencedPlatformBuiltIn
3636
// User are user installed libraries
3737
User
38+
// Unmanaged is for libraries set manually by the user in the CLI command or from the gRPC function.
39+
// Ideally it's used for `libraries` outside folders managed by the CLI.
40+
Unmanaged
3841
)
3942

4043
func (d *LibraryLocation) String() string {
@@ -47,6 +50,8 @@ func (d *LibraryLocation) String() string {
4750
return "ref-platform"
4851
case User:
4952
return "user"
53+
case Unmanaged:
54+
return "unmanaged"
5055
}
5156
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
5257
}
@@ -62,6 +67,8 @@ func (d *LibraryLocation) MarshalJSON() ([]byte, error) {
6267
return json.Marshal("ref-platform")
6368
case User:
6469
return json.Marshal("user")
70+
case Unmanaged:
71+
return json.Marshal("unmanaged")
6572
}
6673
return nil, fmt.Errorf("invalid library location value: %d", *d)
6774
}
@@ -81,6 +88,8 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
8188
*d = ReferencedPlatformBuiltIn
8289
case "user":
8390
*d = User
91+
case "unmanaged":
92+
*d = Unmanaged
8493
}
8594
return fmt.Errorf("invalid library location: %s", s)
8695
}
@@ -96,6 +105,8 @@ func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
96105
return rpc.LibraryLocation_LIBRARY_LOCATION_REFERENCED_PLATFORM_BUILTIN
97106
case User:
98107
return rpc.LibraryLocation_LIBRARY_LOCATION_USER
108+
case Unmanaged:
109+
return rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED
99110
}
100111
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
101112
}
@@ -111,6 +122,8 @@ func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
111122
return ReferencedPlatformBuiltIn
112123
case rpc.LibraryLocation_LIBRARY_LOCATION_USER:
113124
return User
125+
case rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED:
126+
return Unmanaged
114127
}
115128
panic(fmt.Sprintf("invalid rpc.LibraryLocation value %d", l))
116129
}

Diff for: arduino/libraries/librariesmanager/librariesmanager.go

+46-23
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ func (alts *LibraryAlternatives) FindVersion(version *semver.Version) *libraries
8282
}
8383

8484
// Names returns an array with all the names of the installed libraries.
85-
func (sc LibrariesManager) Names() []string {
86-
res := make([]string, len(sc.Libraries))
85+
func (lm LibrariesManager) Names() []string {
86+
res := make([]string, len(lm.Libraries))
8787
i := 0
88-
for n := range sc.Libraries {
88+
for n := range lm.Libraries {
8989
res[i] = n
9090
i++
9191
}
@@ -109,27 +109,27 @@ func NewLibraryManager(indexDir *paths.Path, downloadsDir *paths.Path) *Librarie
109109

110110
// LoadIndex reads a library_index.json from a file and returns
111111
// the corresponding Index structure.
112-
func (sc *LibrariesManager) LoadIndex() error {
113-
index, err := librariesindex.LoadIndex(sc.IndexFile)
112+
func (lm *LibrariesManager) LoadIndex() error {
113+
index, err := librariesindex.LoadIndex(lm.IndexFile)
114114
if err != nil {
115-
sc.Index = librariesindex.EmptyIndex
115+
lm.Index = librariesindex.EmptyIndex
116116
return err
117117
}
118-
sc.Index = index
118+
lm.Index = index
119119
return nil
120120
}
121121

122122
// AddLibrariesDir adds path to the list of directories
123123
// to scan when searching for libraries. If a path is already
124124
// in the list it is ignored.
125-
func (sc *LibrariesManager) AddLibrariesDir(path *paths.Path, location libraries.LibraryLocation) {
126-
for _, dir := range sc.LibrariesDir {
125+
func (lm *LibrariesManager) AddLibrariesDir(path *paths.Path, location libraries.LibraryLocation) {
126+
for _, dir := range lm.LibrariesDir {
127127
if dir.Path.EquivalentTo(path) {
128128
return
129129
}
130130
}
131131
logrus.WithField("dir", path).WithField("location", location.String()).Info("Adding libraries dir")
132-
sc.LibrariesDir = append(sc.LibrariesDir, &LibrariesDir{
132+
lm.LibrariesDir = append(lm.LibrariesDir, &LibrariesDir{
133133
Path: path,
134134
Location: location,
135135
})
@@ -138,36 +138,36 @@ func (sc *LibrariesManager) AddLibrariesDir(path *paths.Path, location libraries
138138
// AddPlatformReleaseLibrariesDir add the libraries directory in the
139139
// specified PlatformRelease to the list of directories to scan when
140140
// searching for libraries.
141-
func (sc *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *cores.PlatformRelease, location libraries.LibraryLocation) {
141+
func (lm *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *cores.PlatformRelease, location libraries.LibraryLocation) {
142142
path := plaftormRelease.GetLibrariesDir()
143143
if path == nil {
144144
return
145145
}
146-
for _, dir := range sc.LibrariesDir {
146+
for _, dir := range lm.LibrariesDir {
147147
if dir.Path.EquivalentTo(path) {
148148
return
149149
}
150150
}
151151
logrus.WithField("dir", path).WithField("location", location.String()).Info("Adding libraries dir")
152-
sc.LibrariesDir = append(sc.LibrariesDir, &LibrariesDir{
152+
lm.LibrariesDir = append(lm.LibrariesDir, &LibrariesDir{
153153
Path: path,
154154
Location: location,
155155
PlatformRelease: plaftormRelease,
156156
})
157157
}
158158

159159
// RescanLibraries reload all installed libraries in the system.
160-
func (sc *LibrariesManager) RescanLibraries() error {
161-
for _, dir := range sc.LibrariesDir {
162-
if err := sc.LoadLibrariesFromDir(dir); err != nil {
160+
func (lm *LibrariesManager) RescanLibraries() error {
161+
for _, dir := range lm.LibrariesDir {
162+
if err := lm.LoadLibrariesFromDir(dir); err != nil {
163163
return fmt.Errorf("loading libs from %s: %s", dir.Path, err)
164164
}
165165
}
166166
return nil
167167
}
168168

169-
func (sc *LibrariesManager) getUserLibrariesDir() *paths.Path {
170-
for _, dir := range sc.LibrariesDir {
169+
func (lm *LibrariesManager) getUserLibrariesDir() *paths.Path {
170+
for _, dir := range lm.LibrariesDir {
171171
if dir.Location == libraries.User {
172172
return dir.Path
173173
}
@@ -177,7 +177,7 @@ func (sc *LibrariesManager) getUserLibrariesDir() *paths.Path {
177177

178178
// LoadLibrariesFromDir loads all libraries in the given directory. Returns
179179
// nil if the directory doesn't exists.
180-
func (sc *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) error {
180+
func (lm *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) error {
181181
subDirs, err := librariesDir.Path.ReadDir()
182182
if os.IsNotExist(err) {
183183
return nil
@@ -194,22 +194,45 @@ func (sc *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) err
194194
return fmt.Errorf("loading library from %s: %s", subDir, err)
195195
}
196196
library.ContainerPlatform = librariesDir.PlatformRelease
197-
alternatives, ok := sc.Libraries[library.Name]
197+
alternatives, ok := lm.Libraries[library.Name]
198198
if !ok {
199199
alternatives = &LibraryAlternatives{}
200-
sc.Libraries[library.Name] = alternatives
200+
lm.Libraries[library.Name] = alternatives
201201
}
202202
alternatives.Add(library)
203203
}
204204
return nil
205205
}
206206

207+
// LoadLibraryFromDir loads one single library from the libRootDir.
208+
// libRootDir must point to the root of a valid library.
209+
// An error is returned if the path doesn't exist or loading of the library fails.
210+
func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location libraries.LibraryLocation) error {
211+
if libRootDir.NotExist() {
212+
return fmt.Errorf("library path does not exist: %s", libRootDir)
213+
}
214+
215+
library, err := libraries.Load(libRootDir, location)
216+
if err != nil {
217+
return fmt.Errorf("loading library from %s: %s", libRootDir, err)
218+
}
219+
220+
alternatives, ok := lm.Libraries[library.Name]
221+
if !ok {
222+
alternatives = &LibraryAlternatives{}
223+
lm.Libraries[library.Name] = alternatives
224+
}
225+
alternatives.Add(library)
226+
227+
return nil
228+
}
229+
207230
// FindByReference return the installed library matching the Reference
208231
// name and version or, if the version is nil, the library installed
209232
// in the User folder.
210-
func (sc *LibrariesManager) FindByReference(libRef *librariesindex.Reference) *libraries.Library {
233+
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference) *libraries.Library {
211234
saneName := utils.SanitizeName(libRef.Name)
212-
alternatives, have := sc.Libraries[saneName]
235+
alternatives, have := lm.Libraries[saneName]
213236
if !have {
214237
return nil
215238
}

Diff for: arduino/libraries/librariesresolver/cpp.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func computePriority(lib *libraries.Library, header, arch string) int {
121121
header = strings.TrimSuffix(header, filepath.Ext(header))
122122
header = simplify(header)
123123
name := simplify(lib.Name)
124+
realName := simplify(lib.RealName)
124125

125126
priority := 0
126127

@@ -137,15 +138,17 @@ func computePriority(lib *libraries.Library, header, arch string) int {
137138
priority += 0
138139
}
139140

140-
if name == header {
141+
if realName == header && name == header {
142+
priority += 600
143+
} else if realName == header || name == header {
141144
priority += 500
142-
} else if name == header+"-master" {
145+
} else if realName == header+"-master" || name == header+"-master" {
143146
priority += 400
144-
} else if strings.HasPrefix(name, header) {
147+
} else if strings.HasPrefix(realName, header) || strings.HasPrefix(name, header) {
145148
priority += 300
146-
} else if strings.HasSuffix(name, header) {
149+
} else if strings.HasSuffix(realName, header) || strings.HasSuffix(name, header) {
147150
priority += 200
148-
} else if strings.Contains(name, header) {
151+
} else if strings.Contains(realName, header) || strings.Contains(name, header) {
149152
priority += 100
150153
}
151154

@@ -158,6 +161,8 @@ func computePriority(lib *libraries.Library, header, arch string) int {
158161
priority += 2
159162
case libraries.User:
160163
priority += 3
164+
case libraries.Unmanaged:
165+
priority += 4
161166
default:
162167
panic(fmt.Sprintf("Invalid library location: %d", lib.Location))
163168
}

Diff for: arduino/libraries/librariesresolver/cpp_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,18 @@ func TestCppHeaderResolver(t *testing.T) {
143143
require.Equal(t, "Calculus Unified Lib", resolve("calculus_lib.h", l6, l7))
144144
require.Equal(t, "Calculus Unified Lib", resolve("calculus_lib.h", l7, l6))
145145
}
146+
147+
func TestCppHeaderResolverWithLibrariesInStrangeDirectoryNames(t *testing.T) {
148+
resolver := NewCppResolver()
149+
librarylist := libraries.List{}
150+
librarylist.Add(&libraries.Library{Name: "onewire_2_3_4", RealName: "OneWire", Architectures: []string{"*"}})
151+
librarylist.Add(&libraries.Library{Name: "onewireng_2_3_4", RealName: "OneWireNg", Architectures: []string{"avr"}})
152+
resolver.headers["OneWire.h"] = librarylist
153+
require.Equal(t, "onewire_2_3_4", resolver.ResolveFor("OneWire.h", "avr").Name)
154+
155+
librarylist2 := libraries.List{}
156+
librarylist2.Add(&libraries.Library{Name: "OneWire", RealName: "OneWire", Architectures: []string{"*"}})
157+
librarylist2.Add(&libraries.Library{Name: "onewire_2_3_4", RealName: "OneWire", Architectures: []string{"avr"}})
158+
resolver.headers["OneWire.h"] = librarylist2
159+
require.Equal(t, "OneWire", resolver.ResolveFor("OneWire.h", "avr").Name)
160+
}

0 commit comments

Comments
 (0)