@@ -84,22 +84,25 @@ type Core struct {
84
84
85
85
func DownloadCoresAndToolsAndLibraries (t * testing.T ) {
86
86
cores := []Core {
87
- Core {Maintainer : "arduino" , Arch : "avr" , Version : "1.6.8 " },
88
- Core {Maintainer : "arduino" , Arch : "sam" , Version : "1.6.4 " },
87
+ Core {Maintainer : "arduino" , Arch : "avr" , Version : "1.6.9 " },
88
+ Core {Maintainer : "arduino" , Arch : "sam" , Version : "1.6.5 " },
89
89
}
90
90
91
91
boardsManagerCores := []Core {
92
- Core {Maintainer : "arduino" , Arch : "samd" , Version : "1.6.1 " },
92
+ Core {Maintainer : "arduino" , Arch : "samd" , Version : "1.6.2 " },
93
93
}
94
94
95
95
boardsManagerRedBearCores := []Core {
96
96
Core {Maintainer : "RedBearLab" , Arch : "avr" , Version : "1.0.0" , Url : "https://redbearlab.github.io/arduino/Blend/blend_boards.zip" },
97
97
}
98
98
99
+ toolsMultipleVersions := []Tool {
100
+ Tool {Name : "bossac" , Version : "1.6.1-arduino" },
101
+ Tool {Name : "bossac" , Version : "1.5-arduino" },
102
+ }
103
+
99
104
tools := []Tool {
100
105
Tool {Name : "avrdude" , Version : "6.0.1-arduino5" },
101
- Tool {Name : "bossac" , Version : "1.3a-arduino" },
102
- Tool {Name : "bossac" , Version : "1.5-arduino" },
103
106
Tool {Name : "avr-gcc" , Version : "4.8.1-arduino5" },
104
107
Tool {Name : "arm-none-eabi-gcc" , Version : "4.8.3-2014q1" },
105
108
Tool {Name : "coan" , Version : "5.2" , OsUrls : []OsUrl {
@@ -133,7 +136,7 @@ func DownloadCoresAndToolsAndLibraries(t *testing.T) {
133
136
Library {Name : "Robot IR Remote" , Version : "1.0.2" },
134
137
}
135
138
136
- download (t , cores , boardsManagerCores , boardsManagerRedBearCores , tools , boardsManagerTools , boardsManagerRFduinoTools , libraries )
139
+ download (t , cores , boardsManagerCores , boardsManagerRedBearCores , tools , toolsMultipleVersions , boardsManagerTools , boardsManagerRFduinoTools , libraries )
137
140
138
141
patchFiles (t )
139
142
}
@@ -157,7 +160,7 @@ func patchFiles(t *testing.T) {
157
160
}
158
161
}
159
162
160
- func download (t * testing.T , cores , boardsManagerCores , boardsManagerRedBearCores []Core , tools , boardsManagerTools , boardsManagerRFduinoTools []Tool , libraries []Library ) {
163
+ func download (t * testing.T , cores , boardsManagerCores , boardsManagerRedBearCores []Core , tools , toolsMultipleVersions , boardsManagerTools , boardsManagerRFduinoTools []Tool , libraries []Library ) {
161
164
allCoresDownloaded , err := allCoresAlreadyDownloadedAndUnpacked (HARDWARE_FOLDER , cores )
162
165
NoError (t , err )
163
166
if allCoresDownloaded &&
@@ -166,6 +169,7 @@ func download(t *testing.T, cores, boardsManagerCores, boardsManagerRedBearCores
166
169
allBoardsManagerToolsAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerTools ) &&
167
170
allBoardsManagerToolsAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerRFduinoTools ) &&
168
171
allToolsAlreadyDownloadedAndUnpacked (TOOLS_FOLDER , tools ) &&
172
+ allToolsAlreadyDownloadedAndUnpacked (TOOLS_FOLDER , toolsMultipleVersions ) &&
169
173
allLibrariesAlreadyDownloadedAndUnpacked (LIBRARIES_FOLDER , libraries ) {
170
174
return
171
175
}
@@ -182,6 +186,9 @@ func download(t *testing.T, cores, boardsManagerCores, boardsManagerRedBearCores
182
186
err = downloadTools (tools , index )
183
187
NoError (t , err )
184
188
189
+ err = downloadToolsMultipleVersions (toolsMultipleVersions , index )
190
+ NoError (t , err )
191
+
185
192
err = downloadBoardsManagerTools (boardsManagerTools , index )
186
193
NoError (t , err )
187
194
@@ -279,7 +286,36 @@ func downloadTools(tools []Tool, index map[string]interface{}) error {
279
286
if err != nil {
280
287
return utils .WrapError (err )
281
288
}
282
- err = downloadAndUnpackTool (tool , url , TOOLS_FOLDER )
289
+ err = downloadAndUnpackTool (tool , url , TOOLS_FOLDER , true )
290
+ if err != nil {
291
+ return utils .WrapError (err )
292
+ }
293
+ }
294
+
295
+ return nil
296
+ }
297
+
298
+ func downloadToolsMultipleVersions (tools []Tool , index map [string ]interface {}) error {
299
+ host := translateGOOSGOARCHToPackageIndexValue ()
300
+
301
+ for _ , tool := range tools {
302
+ if ! toolAlreadyDownloadedAndUnpacked (TOOLS_FOLDER , tool ) {
303
+ _ , err := os .Stat (filepath .Join (TOOLS_FOLDER , tool .Name ))
304
+ if err == nil {
305
+ err = os .RemoveAll (filepath .Join (TOOLS_FOLDER , tool .Name ))
306
+ if err != nil {
307
+ return utils .WrapError (err )
308
+ }
309
+ }
310
+ }
311
+ }
312
+
313
+ for _ , tool := range tools {
314
+ url , err := findToolUrl (index , tool , host )
315
+ if err != nil {
316
+ return utils .WrapError (err )
317
+ }
318
+ err = downloadAndUnpackTool (tool , url , TOOLS_FOLDER , false )
283
319
if err != nil {
284
320
return utils .WrapError (err )
285
321
}
@@ -422,6 +458,14 @@ func downloadAndUnpackCore(core Core, url string, targetPath string) error {
422
458
}
423
459
defer os .RemoveAll (unpackFolder )
424
460
461
+ _ , err = os .Stat (filepath .Join (targetPath , core .Maintainer , core .Arch ))
462
+ if err == nil {
463
+ err = os .RemoveAll (filepath .Join (targetPath , core .Maintainer , core .Arch ))
464
+ if err != nil {
465
+ return utils .WrapError (err )
466
+ }
467
+ }
468
+
425
469
if len (files ) == 1 && files [0 ].IsDir () {
426
470
err = os .MkdirAll (filepath .Join (targetPath , core .Maintainer ), os .FileMode (0755 ))
427
471
if err != nil {
@@ -463,6 +507,14 @@ func downloadAndUnpackBoardManagerCore(core Core, url string, targetPath string)
463
507
}
464
508
defer os .RemoveAll (unpackFolder )
465
509
510
+ _ , err = os .Stat (filepath .Join (targetPath , core .Maintainer , "hardware" , core .Arch ))
511
+ if err == nil {
512
+ err = os .RemoveAll (filepath .Join (targetPath , core .Maintainer , "hardware" , core .Arch ))
513
+ if err != nil {
514
+ return utils .WrapError (err )
515
+ }
516
+ }
517
+
466
518
if len (files ) == 1 && files [0 ].IsDir () {
467
519
err = os .MkdirAll (filepath .Join (targetPath , core .Maintainer , "hardware" , core .Arch ), os .FileMode (0755 ))
468
520
if err != nil {
@@ -529,7 +581,7 @@ func downloadAndUnpackBoardsManagerTool(tool Tool, url string, targetPath string
529
581
return nil
530
582
}
531
583
532
- func downloadAndUnpackTool (tool Tool , url string , targetPath string ) error {
584
+ func downloadAndUnpackTool (tool Tool , url string , targetPath string , deleteIfMissing bool ) error {
533
585
if toolAlreadyDownloadedAndUnpacked (targetPath , tool ) {
534
586
return nil
535
587
}
@@ -545,11 +597,13 @@ func downloadAndUnpackTool(tool Tool, url string, targetPath string) error {
545
597
}
546
598
defer os .RemoveAll (unpackFolder )
547
599
548
- _ , err = os .Stat (filepath .Join (targetPath , tool .Name ))
549
- if err == nil {
550
- err = os .RemoveAll (filepath .Join (targetPath , tool .Name ))
551
- if err != nil {
552
- return utils .WrapError (err )
600
+ if deleteIfMissing {
601
+ _ , err = os .Stat (filepath .Join (targetPath , tool .Name ))
602
+ if err == nil {
603
+ err = os .RemoveAll (filepath .Join (targetPath , tool .Name ))
604
+ if err != nil {
605
+ return utils .WrapError (err )
606
+ }
553
607
}
554
608
}
555
609
0 commit comments