Skip to content

Commit 5b58865

Browse files
committed
Removed dependency from bcmi-labs/arduino-modules
Fix #98
1 parent 6b57916 commit 5b58865

File tree

243 files changed

+65
-67179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+65
-67179
lines changed

Gopkg.lock

+2-119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

arduino/sketches/sketches.go

+55-14
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package sketches
1919

2020
import (
21-
"github.com/arduino/go-paths-helper"
21+
"encoding/json"
22+
"fmt"
2223

23-
"github.com/bcmi-labs/arduino-modules/sketches"
24+
"github.com/arduino/go-paths-helper"
2425
)
2526

2627
// SketchBook is a sketchbook
@@ -30,15 +31,20 @@ type SketchBook struct {
3031

3132
// Sketch is a sketch for Arduino
3233
type Sketch struct {
33-
Name string
34-
Path string
35-
BoardMetadata *BoardMetadata `json:"board"`
34+
Name string
35+
FullPath *paths.Path
36+
Metadata *Metadata
37+
}
38+
39+
// Metadata is the kind of data associated to a project such as the connected board
40+
type Metadata struct {
41+
CPU BoardMetadata `json:"cpu,omitempty" gorethink:"cpu"`
3642
}
3743

3844
// BoardMetadata represents the board metadata for the sketch
3945
type BoardMetadata struct {
4046
Fqbn string `json:"fqbn,required"`
41-
Name string `json:"name,required"`
47+
Name string `json:"name,omitempty"`
4248
}
4349

4450
// NewSketchBook returns a new SketchBook object
@@ -49,21 +55,56 @@ func NewSketchBook(path *paths.Path) *SketchBook {
4955
}
5056

5157
// NewSketch loads a sketch from the sketchbook
52-
func (sketchbook *SketchBook) NewSketch(name string) (*sketches.Sketch, error) {
53-
sketch := sketches.Sketch{
54-
FullPath: sketchbook.Path.Join(name).String(),
58+
func (sketchbook *SketchBook) NewSketch(name string) (*Sketch, error) {
59+
sketch := &Sketch{
60+
FullPath: sketchbook.Path.Join(name),
5561
Name: name,
5662
}
5763
sketch.ImportMetadata()
58-
return &sketch, nil
64+
return sketch, nil
5965
}
6066

6167
// NewSketchFromPath loads a sketch from the specified path
62-
func NewSketchFromPath(path *paths.Path) (*sketches.Sketch, error) {
63-
sketch := sketches.Sketch{
64-
FullPath: path.String(),
68+
func NewSketchFromPath(path *paths.Path) (*Sketch, error) {
69+
sketch := &Sketch{
70+
FullPath: path,
6571
Name: path.Base(),
6672
}
6773
sketch.ImportMetadata()
68-
return &sketch, nil
74+
return sketch, nil
75+
}
76+
77+
// ImportMetadata imports metadata into the sketch from a sketch.json file in the root
78+
// path of the sketch.
79+
func (s *Sketch) ImportMetadata() error {
80+
sketchJSON := s.FullPath.Join("sketch.json")
81+
content, err := sketchJSON.ReadFile()
82+
if err != nil {
83+
return fmt.Errorf("reading sketch metadata %s: %s", sketchJSON, err)
84+
}
85+
var meta Metadata
86+
err = json.Unmarshal(content, &meta)
87+
if err != nil {
88+
if s.Metadata == nil {
89+
s.Metadata = new(Metadata)
90+
}
91+
return fmt.Errorf("encoding sketch metadata: %s", err)
92+
}
93+
s.Metadata = &meta
94+
return nil
95+
}
96+
97+
// ExportMetadata writes sketch metadata into a sketch.json file in the root path of
98+
// the sketch
99+
func (s *Sketch) ExportMetadata() error {
100+
d, err := json.MarshalIndent(&s.Metadata, "", " ")
101+
if err != nil {
102+
return fmt.Errorf("decoding sketch metadata: %s", err)
103+
}
104+
105+
sketchJSON := s.FullPath.Join("sketch.json")
106+
if err := sketchJSON.WriteFile(d); err != nil {
107+
return fmt.Errorf("writing sketch metadata %s: %s", sketchJSON, err)
108+
}
109+
return nil
69110
}

commands/board/attach.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626

2727
"github.com/arduino/arduino-cli/arduino/cores"
2828
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
29+
"github.com/arduino/arduino-cli/arduino/sketches"
2930
"github.com/arduino/arduino-cli/commands"
3031
"github.com/arduino/arduino-cli/common/formatter"
3132
discovery "github.com/arduino/board-discovery"
3233
paths "github.com/arduino/go-paths-helper"
33-
"github.com/bcmi-labs/arduino-modules/sketches"
3434
"github.com/sirupsen/logrus"
3535
"github.com/spf13/cobra"
3636
)
@@ -79,7 +79,7 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
7979
pm := commands.InitPackageManager()
8080

8181
if fqbn != nil {
82-
sketch.Metadata.CPU = sketches.MetadataCPU{
82+
sketch.Metadata.CPU = sketches.BoardMetadata{
8383
Fqbn: fqbn.String(),
8484
}
8585
} else {
@@ -90,14 +90,11 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
9090
}
9191

9292
var findBoardFunc func(*packagemanager.PackageManager, *discovery.Monitor, *url.URL) *cores.Board
93-
var Type string
9493
switch deviceURI.Scheme {
9594
case "serial", "tty":
9695
findBoardFunc = findSerialConnectedBoard
97-
Type = "serial"
9896
case "http", "https", "tcp", "udp":
9997
findBoardFunc = findNetworkConnectedBoard
100-
Type = "network"
10198
default:
10299
formatter.PrintErrorMessage("Invalid device port type provided. Accepted types are: serial://, tty://, http://, https://, tcp://, udp://.")
103100
os.Exit(commands.ErrBadCall)
@@ -122,10 +119,9 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
122119
}
123120
formatter.Print("Board found: " + board.Name())
124121

125-
sketch.Metadata.CPU = sketches.MetadataCPU{
122+
sketch.Metadata.CPU = sketches.BoardMetadata{
126123
Fqbn: board.FQBN(),
127124
Name: board.Name(),
128-
Type: Type,
129125
}
130126
}
131127

commands/commands.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2929
"github.com/arduino/arduino-cli/arduino/sketches"
3030
"github.com/arduino/arduino-cli/configs"
31-
sk "github.com/bcmi-labs/arduino-modules/sketches"
3231

3332
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
3433
"github.com/arduino/arduino-cli/common/formatter"
@@ -168,7 +167,7 @@ func UpdateLibrariesIndex(lm *librariesmanager.LibrariesManager) {
168167
}
169168
}
170169

171-
func InitSketch(sketchPath *paths.Path) (*sk.Sketch, error) {
170+
func InitSketch(sketchPath *paths.Path) (*sketches.Sketch, error) {
172171
if sketchPath != nil {
173172
return sketches.NewSketchFromPath(sketchPath)
174173
}

commands/compile/compile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func run(cmd *cobra.Command, args []string) {
158158
ctx := &types.Context{}
159159
ctx.PackageManager = pm
160160
ctx.FQBN = fqbn
161-
ctx.SketchLocation = paths.New(sketch.FullPath)
161+
ctx.SketchLocation = sketch.FullPath
162162

163163
// FIXME: This will be redundant when arduino-builder will be part of the cli
164164
if packagesDir, err := commands.Config.HardwareDirectories(); err == nil {
@@ -257,7 +257,7 @@ func run(cmd *cobra.Command, args []string) {
257257
var exportPath *paths.Path
258258
var exportFile string
259259
if flags.exportFile == "" {
260-
exportPath = paths.New(sketch.FullPath)
260+
exportPath = sketch.FullPath
261261
exportFile = sketch.Name + "." + fqbnSuffix
262262
} else {
263263
exportPath = paths.New(flags.exportFile).Parent()

0 commit comments

Comments
 (0)