Skip to content

Commit c2c8cfd

Browse files
committed
Added programmers extraction in arduino/cores module
1 parent 2855123 commit c2c8cfd

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

arduino/cores/cores.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ type PlatformRelease struct {
4040
Resource *resources.DownloadResource
4141
Version *semver.Version
4242
BoardsManifest []*BoardManifest
43-
Dependencies ToolDependencies // The Dependency entries to load tools.
44-
Platform *Platform `json:"-"`
45-
Properties *properties.Map `json:"-"`
46-
Boards map[string]*Board `json:"-"`
47-
Programmers map[string]*properties.Map `json:"-"`
48-
Menus *properties.Map `json:"-"`
49-
InstallDir *paths.Path `json:"-"`
50-
IsIDEBundled bool `json:"-"`
43+
Dependencies ToolDependencies // The Dependency entries to load tools.
44+
Platform *Platform `json:"-"`
45+
Properties *properties.Map `json:"-"`
46+
Boards map[string]*Board `json:"-"`
47+
Programmers map[string]*Programmer `json:"-"`
48+
Menus *properties.Map `json:"-"`
49+
InstallDir *paths.Path `json:"-"`
50+
IsIDEBundled bool `json:"-"`
5151
}
5252

5353
// BoardManifest contains information about a board. These metadata are usually
@@ -117,7 +117,7 @@ func (platform *Platform) GetOrCreateRelease(version *semver.Version) (*Platform
117117
Version: version,
118118
Boards: map[string]*Board{},
119119
Properties: properties.NewMap(),
120-
Programmers: map[string]*properties.Map{},
120+
Programmers: map[string]*Programmer{},
121121
Platform: platform,
122122
}
123123
platform.Releases[tag] = release

arduino/cores/packagemanager/loader.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
284284

285285
// Create programmers properties
286286
if programmersProperties, err := properties.SafeLoad(programmersTxtPath.String()); err == nil {
287-
platform.Programmers = properties.MergeMapsOfProperties(
288-
map[string]*properties.Map{},
289-
platform.Programmers, // TODO: Very weird, why not an empty one?
290-
programmersProperties.FirstLevelOf())
287+
for programmerID, programmerProperties := range programmersProperties.FirstLevelOf() {
288+
platform.Programmers[programmerID] = pm.loadProgrammer(programmerProperties)
289+
platform.Programmers[programmerID].PlatformRelease = platform
290+
}
291291
} else {
292292
return err
293293
}
@@ -299,6 +299,13 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
299299
return nil
300300
}
301301

302+
func (pm *PackageManager) loadProgrammer(programmerProperties *properties.Map) *cores.Programmer {
303+
return &cores.Programmer{
304+
Name: programmerProperties.Get("name"),
305+
Properties: programmerProperties,
306+
}
307+
}
308+
302309
func (pm *PackageManager) loadBoards(platform *cores.PlatformRelease) error {
303310
if platform.InstallDir == nil {
304311
return fmt.Errorf("platform not installed")

arduino/cores/programmers.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package cores
17+
18+
import "github.com/arduino/go-properties-orderedmap"
19+
20+
// Programmer represents an external programmer
21+
type Programmer struct {
22+
Name string
23+
Properties *properties.Map
24+
PlatformRelease *PlatformRelease
25+
}

0 commit comments

Comments
 (0)