forked from arduino/arduino-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibraries.go
139 lines (125 loc) · 4.19 KB
/
libraries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].
package libraries
import (
"github.com/arduino/arduino-cli/arduino/cores"
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
semver "go.bug.st/relaxed-semver"
)
// MandatoryProperties FIXMEDOC
var MandatoryProperties = []string{"name", "version", "author", "maintainer"}
// OptionalProperties FIXMEDOC
var OptionalProperties = []string{"sentence", "paragraph", "url"}
// ValidCategories FIXMEDOC
var ValidCategories = map[string]bool{
"Display": true,
"Communication": true,
"Signal Input/Output": true,
"Sensors": true,
"Device Control": true,
"Timing": true,
"Data Storage": true,
"Data Processing": true,
"Other": true,
"Uncategorized": true,
}
// Library represents a library in the system
type Library struct {
Name string
Author string
Maintainer string
Sentence string
Paragraph string
Website string
Category string
Architectures []string
Types []string `json:"types,omitempty"`
InstallDir *paths.Path
SourceDir *paths.Path
UtilityDir *paths.Path
Location LibraryLocation
ContainerPlatform *cores.PlatformRelease `json:""`
Layout LibraryLayout
RealName string
DotALinkage bool
Precompiled bool
PrecompiledWithSources bool
LDflags string
IsLegacy bool
Version *semver.Version
License string
Properties *properties.Map
}
func (library *Library) String() string {
if library.Version.String() == "" {
return library.Name
}
return library.Name + "@" + library.Version.String()
}
// SupportsAnyArchitectureIn returns true if any of the following is true:
// - the library supports at least one of the given architectures
// - the library is architecture independent
// - the library doesn't specify any `architecture` field in library.properties
func (library *Library) SupportsAnyArchitectureIn(archs ...string) bool {
if library.IsArchitectureIndependent() {
return true
}
for _, arch := range archs {
if arch == "*" || library.IsOptimizedForArchitecture(arch) {
return true
}
}
return false
}
// IsOptimizedForArchitecture returns true if the library declares to be
// explicitly compatible for a specific architecture (the `architecture` field
// in library.properties contains the architecture passed as parameter)
func (library *Library) IsOptimizedForArchitecture(arch string) bool {
for _, libArch := range library.Architectures {
if libArch == arch {
return true
}
}
return false
}
// IsArchitectureIndependent returns true if the library declares to be
// compatible with all architectures (the `architecture` field in
// library.properties contains the `*` item)
func (library *Library) IsArchitectureIndependent() bool {
return library.IsOptimizedForArchitecture("*") || library.Architectures == nil || len(library.Architectures) == 0
}
// SourceDir represents a source dir of a library
type SourceDir struct {
Dir *paths.Path
Recurse bool
}
// SourceDirs return all the source directories of a library
func (library *Library) SourceDirs() []SourceDir {
dirs := []SourceDir{}
dirs = append(dirs,
SourceDir{
Dir: library.SourceDir,
Recurse: library.Layout == RecursiveLayout,
})
if library.UtilityDir != nil {
dirs = append(dirs,
SourceDir{
Dir: library.UtilityDir,
Recurse: false,
})
}
return dirs
}