@@ -22,7 +22,6 @@ package firmwareindex
22
22
import (
23
23
"encoding/json"
24
24
"runtime"
25
- "sort"
26
25
27
26
"github.com/arduino/arduino-cli/arduino/security"
28
27
"github.com/arduino/go-paths-helper"
@@ -48,7 +47,7 @@ type IndexBoard struct {
48
47
UploadTouch bool `json:"upload.use_1200bps_touch"`
49
48
UploadWait bool `json:"upload.wait_for_upload_port"`
50
49
UploaderCommand * IndexUploaderCommand `json:"uploader.command,required"`
51
- Latest * IndexFirmware `json:"-"`
50
+ LatestFirmware * IndexFirmware `json:"-"`
52
51
}
53
52
54
53
type IndexUploaderCommand struct {
@@ -122,30 +121,19 @@ func LoadIndexNoSign(jsonIndexFile *paths.Path) (*Index, error) {
122
121
// Determine latest firmware for each board
123
122
for _ , board := range index .Boards {
124
123
if board .Module == "SARA" {
125
- // TODO implement?? by defualt you have to specify the version
124
+ // TODO implement?? by default you have to specify the version
126
125
continue
127
126
}
128
127
for _ , firmware := range board .Firmwares {
129
- if board .Latest == nil || firmware .Version .GreaterThan (board .Latest .Version ) {
130
- board .Latest = firmware
128
+ if board .LatestFirmware == nil || firmware .Version .GreaterThan (board .LatestFirmware .Version ) {
129
+ board .LatestFirmware = firmware
131
130
}
132
131
}
133
132
}
134
133
135
134
return & index , nil
136
135
}
137
136
138
- // GetLatestFirmware returns the specified IndexFirmware version for this board.
139
- // Returns nil if version is not found.
140
- func (b * IndexBoard ) GetFirmware (version string ) * IndexFirmware {
141
- for _ , firmware := range b .Firmwares {
142
- if firmware .Version == version {
143
- return firmware
144
- }
145
- }
146
- return nil
147
- }
148
-
149
137
// GetBoard returns the IndexBoard for the given FQBN
150
138
func (i * Index ) GetBoard (fqbn string ) * IndexBoard {
151
139
for _ , b := range i .Boards {
@@ -156,6 +144,18 @@ func (i *Index) GetBoard(fqbn string) *IndexBoard {
156
144
return nil
157
145
}
158
146
147
+ // GetLatestFirmware returns the specified IndexFirmware version for this board.
148
+ // Returns nil if version is not found.
149
+ func (b * IndexBoard ) GetFirmware (version string ) * IndexFirmware {
150
+ v := semver .ParseRelaxed (version )
151
+ for _ , firmware := range b .Firmwares {
152
+ if firmware .Version .Equal (v ) {
153
+ return firmware
154
+ }
155
+ }
156
+ return nil
157
+ }
158
+
159
159
func (b * IndexBoard ) GetUploaderCommand () string {
160
160
if runtime .GOOS == "windows" && b .UploaderCommand .Windows != "" {
161
161
return b .UploaderCommand .Linux
0 commit comments