Skip to content

Commit d940a3d

Browse files
committed
Improved builder globals
1 parent 133ebd1 commit d940a3d

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

Diff for: arduino/globals/globals.go

+21-23
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,31 @@
1616
package globals
1717

1818
var (
19-
empty struct{}
20-
2119
// MainFileValidExtension is the extension that must be used for files in new sketches
2220
MainFileValidExtension string = ".ino"
2321

2422
// MainFileValidExtensions lists valid extensions for a sketch file
25-
MainFileValidExtensions = map[string]struct{}{
26-
MainFileValidExtension: empty,
23+
MainFileValidExtensions = map[string]bool{
24+
MainFileValidExtension: true,
2725
// .pde extension is deprecated and must not be used for new sketches
28-
".pde": empty,
26+
".pde": true,
2927
}
3028

3129
// AdditionalFileValidExtensions lists any file extension the builder considers as valid
32-
AdditionalFileValidExtensions = map[string]struct{}{
33-
".h": empty,
34-
".c": empty,
35-
".hpp": empty,
36-
".hh": empty,
37-
".cpp": empty,
38-
".cxx": empty,
39-
".cc": empty,
40-
".S": empty,
41-
".adoc": empty,
42-
".md": empty,
43-
".json": empty,
44-
".tpp": empty,
45-
".ipp": empty,
30+
AdditionalFileValidExtensions = map[string]bool{
31+
".h": true,
32+
".c": true,
33+
".hpp": true,
34+
".hh": true,
35+
".cpp": true,
36+
".cxx": true,
37+
".cc": true,
38+
".S": true,
39+
".adoc": true,
40+
".md": true,
41+
".json": true,
42+
".tpp": true,
43+
".ipp": true,
4644
}
4745

4846
// SourceFilesValidExtensions lists valid extensions for source files (no headers).
@@ -57,10 +55,10 @@ var (
5755
}
5856

5957
// HeaderFilesValidExtensions lists valid extensions for header files
60-
HeaderFilesValidExtensions = map[string]struct{}{
61-
".h": empty,
62-
".hpp": empty,
63-
".hh": empty,
58+
HeaderFilesValidExtensions = map[string]bool{
59+
".h": true,
60+
".hpp": true,
61+
".hh": true,
6462
}
6563

6664
// DefaultIndexURL is the default index url

Diff for: arduino/sketch/sketch.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func New(path *paths.Path) (*Sketch, error) {
5454
} else if !exist {
5555
return nil, fmt.Errorf("%s: %s", tr("no such file or directory"), path)
5656
}
57-
if _, validIno := globals.MainFileValidExtensions[path.Ext()]; validIno && !path.IsDir() {
57+
if globals.MainFileValidExtensions[path.Ext()] && !path.IsDir() {
5858
path = path.Parent()
5959
}
6060

@@ -121,7 +121,7 @@ func New(path *paths.Path) (*Sketch, error) {
121121
f.Close()
122122

123123
ext := p.Ext()
124-
if _, found := globals.MainFileValidExtensions[ext]; found {
124+
if globals.MainFileValidExtensions[ext] {
125125
if p.EqualsTo(mainFile) {
126126
// The main file must not be included in the lists of other files
127127
continue
@@ -132,7 +132,7 @@ func New(path *paths.Path) (*Sketch, error) {
132132
sketch.OtherSketchFiles.Add(p)
133133
sketch.RootFolderFiles.Add(p)
134134
}
135-
} else if _, found := globals.AdditionalFileValidExtensions[ext]; found {
135+
} else if globals.AdditionalFileValidExtensions[ext] {
136136
// If the user exported the compiles binaries to the Sketch "build" folder
137137
// they would be picked up but we don't want them, so we skip them like so
138138
if p.IsInsideDir(sketch.FullPath.Join("build")) {
@@ -158,12 +158,8 @@ func New(path *paths.Path) (*Sketch, error) {
158158
// supportedFiles reads all files recursively contained in Sketch and
159159
// filter out unneded or unsupported ones and returns them
160160
func (s *Sketch) supportedFiles() (*paths.PathList, error) {
161-
validExtensions := []string{}
162-
for ext := range globals.MainFileValidExtensions {
163-
validExtensions = append(validExtensions, ext)
164-
}
165-
for ext := range globals.AdditionalFileValidExtensions {
166-
validExtensions = append(validExtensions, ext)
161+
filterValidExtensions := func(p *paths.Path) bool {
162+
return globals.MainFileValidExtensions[p.Ext()] || globals.AdditionalFileValidExtensions[p.Ext()]
167163
}
168164

169165
filterOutBuildPaths := func(p *paths.Path) bool {
@@ -174,7 +170,7 @@ func (s *Sketch) supportedFiles() (*paths.PathList, error) {
174170
filterOutBuildPaths,
175171
paths.AndFilter(
176172
paths.FilterOutPrefixes("."),
177-
paths.FilterSuffixes(validExtensions...),
173+
filterValidExtensions,
178174
paths.FilterOutDirectories(),
179175
),
180176
)

Diff for: commands/upload/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ func detectSketchNameFromBuildPath(buildPath *paths.Path) (string, error) {
752752

753753
// Sometimes we may have particular files like:
754754
// Blink.ino.with_bootloader.bin
755-
if _, ok := globals.MainFileValidExtensions[filepath.Ext(name)]; !ok {
755+
if !globals.MainFileValidExtensions[filepath.Ext(name)] {
756756
// just ignore those files
757757
continue
758758
}

0 commit comments

Comments
 (0)