@@ -84,22 +84,25 @@ type Core struct {
8484
8585func DownloadCoresAndToolsAndLibraries (t * testing.T ) {
8686 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 " },
8989 }
9090
9191 boardsManagerCores := []Core {
92- Core {Maintainer : "arduino" , Arch : "samd" , Version : "1.6.1 " },
92+ Core {Maintainer : "arduino" , Arch : "samd" , Version : "1.6.2 " },
9393 }
9494
9595 boardsManagerRedBearCores := []Core {
9696 Core {Maintainer : "RedBearLab" , Arch : "avr" , Version : "1.0.0" , Url : "https://redbearlab.github.io/arduino/Blend/blend_boards.zip" },
9797 }
9898
99+ toolsMultipleVersions := []Tool {
100+ Tool {Name : "bossac" , Version : "1.6.1-arduino" },
101+ Tool {Name : "bossac" , Version : "1.5-arduino" },
102+ }
103+
99104 tools := []Tool {
100105 Tool {Name : "avrdude" , Version : "6.0.1-arduino5" },
101- Tool {Name : "bossac" , Version : "1.3a-arduino" },
102- Tool {Name : "bossac" , Version : "1.5-arduino" },
103106 Tool {Name : "avr-gcc" , Version : "4.8.1-arduino5" },
104107 Tool {Name : "arm-none-eabi-gcc" , Version : "4.8.3-2014q1" },
105108 Tool {Name : "coan" , Version : "5.2" , OsUrls : []OsUrl {
@@ -133,7 +136,7 @@ func DownloadCoresAndToolsAndLibraries(t *testing.T) {
133136 Library {Name : "Robot IR Remote" , Version : "1.0.2" },
134137 }
135138
136- download (t , cores , boardsManagerCores , boardsManagerRedBearCores , tools , boardsManagerTools , boardsManagerRFduinoTools , libraries )
139+ download (t , cores , boardsManagerCores , boardsManagerRedBearCores , tools , toolsMultipleVersions , boardsManagerTools , boardsManagerRFduinoTools , libraries )
137140
138141 patchFiles (t )
139142}
@@ -157,7 +160,7 @@ func patchFiles(t *testing.T) {
157160 }
158161}
159162
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 ) {
161164 allCoresDownloaded , err := allCoresAlreadyDownloadedAndUnpacked (HARDWARE_FOLDER , cores )
162165 NoError (t , err )
163166 if allCoresDownloaded &&
@@ -166,6 +169,7 @@ func download(t *testing.T, cores, boardsManagerCores, boardsManagerRedBearCores
166169 allBoardsManagerToolsAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerTools ) &&
167170 allBoardsManagerToolsAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerRFduinoTools ) &&
168171 allToolsAlreadyDownloadedAndUnpacked (TOOLS_FOLDER , tools ) &&
172+ allToolsAlreadyDownloadedAndUnpacked (TOOLS_FOLDER , toolsMultipleVersions ) &&
169173 allLibrariesAlreadyDownloadedAndUnpacked (LIBRARIES_FOLDER , libraries ) {
170174 return
171175 }
@@ -182,6 +186,9 @@ func download(t *testing.T, cores, boardsManagerCores, boardsManagerRedBearCores
182186 err = downloadTools (tools , index )
183187 NoError (t , err )
184188
189+ err = downloadToolsMultipleVersions (toolsMultipleVersions , index )
190+ NoError (t , err )
191+
185192 err = downloadBoardsManagerTools (boardsManagerTools , index )
186193 NoError (t , err )
187194
@@ -279,7 +286,36 @@ func downloadTools(tools []Tool, index map[string]interface{}) error {
279286 if err != nil {
280287 return utils .WrapError (err )
281288 }
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 )
283319 if err != nil {
284320 return utils .WrapError (err )
285321 }
@@ -422,6 +458,14 @@ func downloadAndUnpackCore(core Core, url string, targetPath string) error {
422458 }
423459 defer os .RemoveAll (unpackFolder )
424460
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+
425469 if len (files ) == 1 && files [0 ].IsDir () {
426470 err = os .MkdirAll (filepath .Join (targetPath , core .Maintainer ), os .FileMode (0755 ))
427471 if err != nil {
@@ -463,6 +507,14 @@ func downloadAndUnpackBoardManagerCore(core Core, url string, targetPath string)
463507 }
464508 defer os .RemoveAll (unpackFolder )
465509
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+
466518 if len (files ) == 1 && files [0 ].IsDir () {
467519 err = os .MkdirAll (filepath .Join (targetPath , core .Maintainer , "hardware" , core .Arch ), os .FileMode (0755 ))
468520 if err != nil {
@@ -529,7 +581,7 @@ func downloadAndUnpackBoardsManagerTool(tool Tool, url string, targetPath string
529581 return nil
530582}
531583
532- func downloadAndUnpackTool (tool Tool , url string , targetPath string ) error {
584+ func downloadAndUnpackTool (tool Tool , url string , targetPath string , deleteIfMissing bool ) error {
533585 if toolAlreadyDownloadedAndUnpacked (targetPath , tool ) {
534586 return nil
535587 }
@@ -545,11 +597,13 @@ func downloadAndUnpackTool(tool Tool, url string, targetPath string) error {
545597 }
546598 defer os .RemoveAll (unpackFolder )
547599
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+ }
553607 }
554608 }
555609
0 commit comments