Skip to content

Load contents of source files only when needed #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[skip changelog] Let SketchMergeSources return error
This adds an error return value, which is currently always nil. This
prepares for making changes that require returning errors.
  • Loading branch information
matthijskooijman committed Jan 16, 2020
commit 7b31ac3fca049eeefc581b9fd92eb7b1a2f049a4
4 changes: 2 additions & 2 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) {
}

// SketchMergeSources merges all the source files included in a sketch
func SketchMergeSources(sketch *sketch.Sketch) (int, string) {
func SketchMergeSources(sketch *sketch.Sketch) (int, string, error) {
lineOffset := 0
mergedSource := ""

Expand All @@ -235,7 +235,7 @@ func SketchMergeSources(sketch *sketch.Sketch) (int, string) {
mergedSource += item.GetSourceStr() + "\n"
}

return lineOffset, mergedSource
return lineOffset, mergedSource, nil
}

// SketchCopyAdditionalFiles copies the additional files for a sketch to the
Expand Down
6 changes: 4 additions & 2 deletions arduino/builder/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ func TestMergeSketchSources(t *testing.T) {
t.Fatalf("unable to read golden file %s: %v", mergedPath, err)
}

offset, source := builder.SketchMergeSources(s)
offset, source, err := builder.SketchMergeSources(s)
require.Nil(t, err)
require.Equal(t, 2, offset)
require.Equal(t, string(mergedBytes), source)
}
Expand All @@ -191,7 +192,8 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
require.NotNil(t, s)

// ensure not to include Arduino.h when it's already there
_, source := builder.SketchMergeSources(s)
_, source, err := builder.SketchMergeSources(s)
require.Nil(t, err)
require.Equal(t, 1, strings.Count(source, "<Arduino.h>"))
}

Expand Down
5 changes: 4 additions & 1 deletion legacy/builder/container_merge_copy_sketch_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func (s *ContainerMergeCopySketchFiles) Run(ctx *types.Context) error {
if sk == nil {
return i18n.WrapError(errors.New("unable to convert legacy sketch to the new type"))
}
offset, source := bldr.SketchMergeSources(sk)
offset, source, err := bldr.SketchMergeSources(sk)
if err != nil {
return err
}
ctx.LineOffset = offset
ctx.Source = source

Expand Down