Skip to content

Commit f9d751c

Browse files
committed
Add RootFolderFiles to gRPC LoadSketchResp
1 parent cc15dde commit f9d751c

File tree

7 files changed

+290
-233
lines changed

7 files changed

+290
-233
lines changed

arduino/builder/sketch_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func TestLoadSketchFolder(t *testing.T) {
6565
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
6666
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
6767
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
68+
require.Len(t, s.RootFolderFiles, 4)
69+
require.Equal(t, "header.h", filepath.Base(s.RootFolderFiles[0].Path))
70+
require.Equal(t, "old.pde", filepath.Base(s.RootFolderFiles[1].Path))
71+
require.Equal(t, "other.ino", filepath.Base(s.RootFolderFiles[2].Path))
72+
require.Equal(t, "s_file.S", filepath.Base(s.RootFolderFiles[3].Path))
6873

6974
// pass the path to the main file
7075
sketchPath = mainFilePath
@@ -79,6 +84,11 @@ func TestLoadSketchFolder(t *testing.T) {
7984
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
8085
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
8186
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
87+
require.Len(t, s.RootFolderFiles, 4)
88+
require.Equal(t, "header.h", filepath.Base(s.RootFolderFiles[0].Path))
89+
require.Equal(t, "old.pde", filepath.Base(s.RootFolderFiles[1].Path))
90+
require.Equal(t, "other.ino", filepath.Base(s.RootFolderFiles[2].Path))
91+
require.Equal(t, "s_file.S", filepath.Base(s.RootFolderFiles[3].Path))
8292
}
8393

8494
func TestLoadSketchFolderPde(t *testing.T) {
@@ -97,6 +107,11 @@ func TestLoadSketchFolderPde(t *testing.T) {
97107
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
98108
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
99109
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
110+
require.Len(t, s.RootFolderFiles, 4)
111+
require.Equal(t, "header.h", filepath.Base(s.RootFolderFiles[0].Path))
112+
require.Equal(t, "old.pde", filepath.Base(s.RootFolderFiles[1].Path))
113+
require.Equal(t, "other.ino", filepath.Base(s.RootFolderFiles[2].Path))
114+
require.Equal(t, "s_file.S", filepath.Base(s.RootFolderFiles[3].Path))
100115
}
101116

102117
func TestLoadSketchFolderBothInoAndPde(t *testing.T) {
@@ -128,6 +143,11 @@ func TestLoadSketchFolderSymlink(t *testing.T) {
128143
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
129144
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
130145
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
146+
require.Len(t, s.RootFolderFiles, 4)
147+
require.Equal(t, "header.h", filepath.Base(s.RootFolderFiles[0].Path))
148+
require.Equal(t, "old.pde", filepath.Base(s.RootFolderFiles[1].Path))
149+
require.Equal(t, "other.ino", filepath.Base(s.RootFolderFiles[2].Path))
150+
require.Equal(t, "s_file.S", filepath.Base(s.RootFolderFiles[3].Path))
131151

132152
// pass the path to the main file
133153
symlinkSketchPath = mainFilePath
@@ -142,6 +162,11 @@ func TestLoadSketchFolderSymlink(t *testing.T) {
142162
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
143163
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
144164
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
165+
require.Len(t, s.RootFolderFiles, 4)
166+
require.Equal(t, "header.h", filepath.Base(s.RootFolderFiles[0].Path))
167+
require.Equal(t, "old.pde", filepath.Base(s.RootFolderFiles[1].Path))
168+
require.Equal(t, "other.ino", filepath.Base(s.RootFolderFiles[2].Path))
169+
require.Equal(t, "s_file.S", filepath.Base(s.RootFolderFiles[3].Path))
145170
}
146171

147172
func TestLoadSketchFolderIno(t *testing.T) {

arduino/sketch/sketch.go

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Sketch struct {
7070
LocationPath string
7171
OtherSketchFiles []*Item
7272
AdditionalFiles []*Item
73+
RootFolderFiles []*Item
7374
}
7475

7576
// New creates an Sketch instance by reading all the files composing a sketch and grouping them
@@ -95,19 +96,24 @@ func New(sketchFolderPath, mainFilePath, buildPath string, allFilesPaths []strin
9596
// organize the Items
9697
additionalFiles := []*Item{}
9798
otherSketchFiles := []*Item{}
99+
rootFolderFiles := []*Item{}
98100
for p, item := range pathToItem {
99101
ext := strings.ToLower(filepath.Ext(p))
100102
if _, found := globals.MainFileValidExtensions[ext]; found {
101103
// item is a valid main file, see if it's stored at the
102104
// sketch root and ignore if it's not.
103105
if filepath.Dir(p) == sketchFolderPath {
104106
otherSketchFiles = append(otherSketchFiles, item)
107+
rootFolderFiles = append(rootFolderFiles, item)
105108
}
106109
} else if _, found := globals.AdditionalFileValidExtensions[ext]; found {
107110
// item is a valid sketch file, grab it only if the buildPath is empty
108111
// or the file is within the buildPath
109112
if buildPath == "" || !strings.Contains(filepath.Dir(p), buildPath) {
110113
additionalFiles = append(additionalFiles, item)
114+
if filepath.Dir(p) == sketchFolderPath {
115+
rootFolderFiles = append(rootFolderFiles, item)
116+
}
111117
}
112118
} else {
113119
return nil, errors.Errorf("unknown sketch file extension '%s'", ext)
@@ -116,6 +122,7 @@ func New(sketchFolderPath, mainFilePath, buildPath string, allFilesPaths []strin
116122

117123
sort.Sort(ItemByPath(additionalFiles))
118124
sort.Sort(ItemByPath(otherSketchFiles))
125+
sort.Sort(ItemByPath(rootFolderFiles))
119126

120127
if err := CheckSketchCasing(sketchFolderPath); err != nil {
121128
return nil, err
@@ -126,6 +133,7 @@ func New(sketchFolderPath, mainFilePath, buildPath string, allFilesPaths []strin
126133
LocationPath: sketchFolderPath,
127134
OtherSketchFiles: otherSketchFiles,
128135
AdditionalFiles: additionalFiles,
136+
RootFolderFiles: rootFolderFiles,
129137
}, nil
130138
}
131139

arduino/sketch/sketch_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ func TestNew(t *testing.T) {
7373
assert.Equal(t, sketchFolderPath, sketch.LocationPath)
7474
assert.Len(t, sketch.OtherSketchFiles, 0)
7575
assert.Len(t, sketch.AdditionalFiles, 1)
76+
assert.Equal(t, sketch.AdditionalFiles[0].Path, paths.New(sketchFolderPath).Join("other.cpp").String())
77+
assert.Len(t, sketch.RootFolderFiles, 1)
78+
assert.Equal(t, sketch.RootFolderFiles[0].Path, paths.New(sketchFolderPath).Join("other.cpp").String())
7679
}
7780

7881
func TestNewSketchCasingWrong(t *testing.T) {
@@ -94,6 +97,7 @@ func TestNewSketchCasingCorrect(t *testing.T) {
9497
assert.Equal(t, mainFilePath, sketch.MainFile.Path)
9598
assert.Len(t, sketch.OtherSketchFiles, 0)
9699
assert.Len(t, sketch.AdditionalFiles, 0)
100+
assert.Len(t, sketch.RootFolderFiles, 0)
97101
}
98102

99103
func TestCheckSketchCasingWrong(t *testing.T) {

commands/instances.go

+6
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,16 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchReq) (*rpc.LoadSketchRes
744744
additionalFiles[i] = file.Path
745745
}
746746

747+
rootFolderFiles := make([]string, len(sketch.RootFolderFiles))
748+
for i, file := range sketch.RootFolderFiles {
749+
rootFolderFiles[i] = file.Path
750+
}
751+
747752
return &rpc.LoadSketchResp{
748753
MainFile: sketch.MainFile.Path,
749754
LocationPath: sketch.LocationPath,
750755
OtherSketchFiles: otherSketchFiles,
751756
AdditionalFiles: additionalFiles,
757+
RootFolderFiles: rootFolderFiles,
752758
}, nil
753759
}

0 commit comments

Comments
 (0)