Skip to content

Commit 7c59a73

Browse files
committed
move types package under arduino/
1 parent 519d87a commit 7c59a73

File tree

102 files changed

+378
-493
lines changed

Some content is hidden

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

102 files changed

+378
-493
lines changed

legacy/builder/types/context.go renamed to arduino/types/context.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2019 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 modify or
12+
// otherwise use the software for commercial activities involving the Arduino
13+
// software without disclosing the source code of your own applications. To purchase
14+
// a commercial license, send an email to [email protected].
15+
116
package types
217

318
import (
@@ -14,12 +29,19 @@ import (
1429
properties "github.com/arduino/go-properties-orderedmap"
1530
)
1631

32+
// ProgressStruct represents a progress state
1733
type ProgressStruct struct {
1834
PrintEnabled bool
1935
Steps float64
2036
Progress float64
2137
}
2238

39+
// LibraryResolutionResult contains the libraries resolution
40+
type LibraryResolutionResult struct {
41+
Library *libraries.Library
42+
NotUsedLibraries []*libraries.Library
43+
}
44+
2345
// Context structure
2446
type Context struct {
2547
// Build options
@@ -35,8 +57,8 @@ type Context struct {
3557
CodeCompleteAt string
3658

3759
// Build options are serialized here
38-
BuildOptionsJson string
39-
BuildOptionsJsonPrevious string
60+
BuildOptionsJSON string
61+
BuildOptionsJSONPrevious string
4062

4163
PackageManager *packagemanager.PackageManager
4264
Hardware *cores.Packages
@@ -117,6 +139,7 @@ type Context struct {
117139
ExecStderr io.Writer
118140
}
119141

142+
// ExtractBuildOptions returns a properties map containing build options
120143
func (ctx *Context) ExtractBuildOptions() *properties.Map {
121144
opts := properties.NewMap()
122145
opts.Set("hardwareFolders", strings.Join(ctx.HardwareDirs.AsStrings(), ","))
@@ -142,6 +165,7 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
142165
return opts
143166
}
144167

168+
// InjectBuildOptions fill the context with fields from a properties map
145169
func (ctx *Context) InjectBuildOptions(opts *properties.Map) {
146170
ctx.HardwareDirs = paths.NewPathList(strings.Split(opts.Get("hardwareFolders"), ",")...)
147171
ctx.ToolsDirs = paths.NewPathList(strings.Split(opts.Get("toolsFolders"), ",")...)
@@ -157,13 +181,15 @@ func (ctx *Context) InjectBuildOptions(opts *properties.Map) {
157181
ctx.CustomBuildProperties = strings.Split(opts.Get("customBuildProperties"), ",")
158182
}
159183

184+
// GetLogger returns a logger
160185
func (ctx *Context) GetLogger() i18n.Logger {
161186
if ctx.logger == nil {
162187
return &i18n.HumanLogger{}
163188
}
164189
return ctx.logger
165190
}
166191

192+
// SetLogger sets a logger
167193
func (ctx *Context) SetLogger(l i18n.Logger) {
168194
ctx.logger = l
169195
}

arduino/types/sketch.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2019 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 modify or
12+
// otherwise use the software for commercial activities involving the Arduino
13+
// software without disclosing the source code of your own applications. To purchase
14+
// a commercial license, send an email to [email protected].
15+
16+
package types
17+
18+
import paths "github.com/arduino/go-paths-helper"
19+
20+
// SketchFile represents a sketch file on disk
21+
type SketchFile struct {
22+
Name *paths.Path
23+
Source string
24+
}
25+
26+
// SketchFileSortByName is a sorted slice of SketchFile
27+
type SketchFileSortByName []SketchFile
28+
29+
func (s SketchFileSortByName) Len() int {
30+
return len(s)
31+
}
32+
33+
func (s SketchFileSortByName) Swap(i, j int) {
34+
s[i], s[j] = s[j], s[i]
35+
}
36+
37+
func (s SketchFileSortByName) Less(i, j int) bool {
38+
return s[i].Name.String() < s[j].Name.String()
39+
}
40+
41+
// Sketch is only used in legacy/builder
42+
type Sketch struct {
43+
MainFile SketchFile
44+
OtherSketchFiles []SketchFile
45+
AdditionalFiles []SketchFile
46+
}

arduino/types/sourcefile.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2019 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 modify or
12+
// otherwise use the software for commercial activities involving the Arduino
13+
// software without disclosing the source code of your own applications. To purchase
14+
// a commercial license, send an email to [email protected].
15+
16+
package types
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/arduino/arduino-cli/arduino/libraries"
22+
paths "github.com/arduino/go-paths-helper"
23+
)
24+
25+
// SourceFile represents a source file
26+
type SourceFile struct {
27+
// Sketch or Library pointer that this source file lives in
28+
Origin interface{}
29+
// Path to the source file within the sketch/library root folder
30+
RelativePath *paths.Path
31+
}
32+
33+
// NewSourceFile creates a SourceFile containing the given source file path within the
34+
// given origin. The given path can be absolute, or relative within the
35+
// origin's root source folder
36+
func NewSourceFile(ctx *Context, origin interface{}, path *paths.Path) (SourceFile, error) {
37+
if path.IsAbs() {
38+
var err error
39+
path, err = sourceRoot(ctx, origin).RelTo(path)
40+
if err != nil {
41+
return SourceFile{}, err
42+
}
43+
}
44+
return SourceFile{Origin: origin, RelativePath: path}, nil
45+
}
46+
47+
// Return the build root for the given origin, where build products will
48+
// be placed. Any directories inside SourceFile.RelativePath will be
49+
// appended here.
50+
func buildRoot(ctx *Context, origin interface{}) *paths.Path {
51+
switch o := origin.(type) {
52+
case *Sketch:
53+
return ctx.SketchBuildPath
54+
case *libraries.Library:
55+
return ctx.LibrariesBuildPath.Join(o.Name)
56+
default:
57+
panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
58+
}
59+
}
60+
61+
// Return the source root for the given origin, where its source files
62+
// can be found. Prepending this to SourceFile.RelativePath will give
63+
// the full path to that source file.
64+
func sourceRoot(ctx *Context, origin interface{}) *paths.Path {
65+
switch o := origin.(type) {
66+
case *Sketch:
67+
return ctx.SketchBuildPath
68+
case *libraries.Library:
69+
return o.SourceDir
70+
default:
71+
panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
72+
}
73+
}
74+
75+
// SourcePath returns the full path to the source file
76+
func (f *SourceFile) SourcePath(ctx *Context) *paths.Path {
77+
return sourceRoot(ctx, f.Origin).JoinPath(f.RelativePath)
78+
}
79+
80+
// ObjectPath returns the full path to the .o file for this source
81+
func (f *SourceFile) ObjectPath(ctx *Context) *paths.Path {
82+
return buildRoot(ctx, f.Origin).Join(f.RelativePath.String() + ".o")
83+
}
84+
85+
// DepfilePath returns the full path to the .d file for this source
86+
func (f *SourceFile) DepfilePath(ctx *Context) *paths.Path {
87+
return buildRoot(ctx, f.Origin).Join(f.RelativePath.String() + ".d")
88+
}
89+
90+
// UniqueSourceFileQueue is a slice of SourceFile
91+
type UniqueSourceFileQueue []SourceFile
92+
93+
func (queue UniqueSourceFileQueue) Len() int { return len(queue) }
94+
func (queue UniqueSourceFileQueue) Less(i, j int) bool { return false }
95+
func (queue UniqueSourceFileQueue) Swap(i, j int) { panic("Who called me?!?") }
96+
97+
// Push add an item if not already present
98+
func (queue *UniqueSourceFileQueue) Push(value SourceFile) {
99+
found := false
100+
for _, elem := range *queue {
101+
if elem.Origin == value.Origin && elem.RelativePath.EqualsTo(value.RelativePath) {
102+
found = true
103+
break
104+
}
105+
}
106+
107+
if !found {
108+
*queue = append(*queue, value)
109+
}
110+
}
111+
112+
// Pop returns the first item of the slice and removes it
113+
func (queue *UniqueSourceFileQueue) Pop() SourceFile {
114+
old := *queue
115+
x := old[0]
116+
*queue = old[1:]
117+
return x
118+
}
119+
120+
// Empty returns whether the slice is empty
121+
func (queue *UniqueSourceFileQueue) Empty() bool {
122+
return queue.Len() == 0
123+
}

arduino/types/types.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2019 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 modify or
12+
// otherwise use the software for commercial activities involving the Arduino
13+
// software without disclosing the source code of your own applications. To purchase
14+
// a commercial license, send an email to [email protected].
15+
16+
package types
17+
18+
import (
19+
"strconv"
20+
)
21+
22+
// PlatforKeyRewrite keeps track of Key values
23+
type PlatforKeyRewrite struct {
24+
Key string
25+
OldValue string
26+
NewValue string
27+
}
28+
29+
// PlatforKeysRewrite is a slice of PlatforKeyRewrite
30+
type PlatforKeysRewrite struct {
31+
Rewrites []PlatforKeyRewrite
32+
}
33+
34+
// Empty returns whether the slice is empty or not
35+
func (p *PlatforKeysRewrite) Empty() bool {
36+
return len(p.Rewrites) == 0
37+
}
38+
39+
// Prototype FIXMEDOC
40+
type Prototype struct {
41+
FunctionName string
42+
File string
43+
Prototype string
44+
Modifiers string
45+
Line int
46+
}
47+
48+
func (proto *Prototype) String() string {
49+
return proto.Modifiers + " " + proto.Prototype + " @ " + strconv.Itoa(proto.Line)
50+
}
51+
52+
// CTag represents a ctag
53+
type CTag struct {
54+
FunctionName string
55+
Kind string
56+
Line int
57+
Code string
58+
Class string
59+
Struct string
60+
Namespace string
61+
Filename string
62+
Typeref string
63+
SkipMe bool
64+
Signature string
65+
66+
Prototype string
67+
PrototypeModifiers string
68+
}
69+
70+
// Command is the interface that every command needs to implement
71+
type Command interface {
72+
Run(ctx *Context) error
73+
}

commands/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import (
2929
"github.com/arduino/arduino-cli/arduino/cores"
3030
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
3131
"github.com/arduino/arduino-cli/arduino/sketches"
32+
"github.com/arduino/arduino-cli/arduino/types"
3233
"github.com/arduino/arduino-cli/cli"
3334
"github.com/arduino/arduino-cli/commands"
3435
"github.com/arduino/arduino-cli/legacy/builder"
3536
"github.com/arduino/arduino-cli/legacy/builder/i18n"
36-
"github.com/arduino/arduino-cli/legacy/builder/types"
3737
rpc "github.com/arduino/arduino-cli/rpc/commands"
3838
paths "github.com/arduino/go-paths-helper"
3939
properties "github.com/arduino/go-properties-orderedmap"

legacy/builder/add_additional_entries_to_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/arduino/arduino-cli/arduino/cores"
3434
"github.com/arduino/arduino-cli/legacy/builder/constants"
3535
"github.com/arduino/arduino-cli/legacy/builder/i18n"
36-
"github.com/arduino/arduino-cli/legacy/builder/types"
36+
"github.com/arduino/arduino-cli/arduino/types"
3737
)
3838

3939
type AddAdditionalEntriesToContext struct{}

legacy/builder/add_build_board_property_if_missing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"strings"
3535

3636
"github.com/arduino/arduino-cli/legacy/builder/constants"
37-
"github.com/arduino/arduino-cli/legacy/builder/types"
37+
"github.com/arduino/arduino-cli/arduino/types"
3838
)
3939

4040
type AddBuildBoardPropertyIfMissing struct{}

legacy/builder/add_missing_build_properties_from_parent_platform_txt_files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ package builder
3131

3232
import (
3333
"github.com/arduino/arduino-cli/legacy/builder/ctags"
34-
"github.com/arduino/arduino-cli/legacy/builder/types"
34+
"github.com/arduino/arduino-cli/arduino/types"
3535
)
3636

3737
type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{}

legacy/builder/additional_sketch_files_copier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"bytes"
3434

3535
"github.com/arduino/arduino-cli/legacy/builder/i18n"
36-
"github.com/arduino/arduino-cli/legacy/builder/types"
36+
"github.com/arduino/arduino-cli/arduino/types"
3737
"github.com/arduino/go-paths-helper"
3838
)
3939

legacy/builder/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"github.com/arduino/arduino-cli/legacy/builder/constants"
4040
"github.com/arduino/arduino-cli/legacy/builder/i18n"
4141
"github.com/arduino/arduino-cli/legacy/builder/phases"
42-
"github.com/arduino/arduino-cli/legacy/builder/types"
42+
"github.com/arduino/arduino-cli/arduino/types"
4343
"github.com/arduino/arduino-cli/legacy/builder/utils"
4444
)
4545

0 commit comments

Comments
 (0)