Skip to content
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
Next Next commit
add convention to func names
  • Loading branch information
masci committed Jul 19, 2019
commit 0d1e3db852e14d739a03cbee03388bd47d89bb88
12 changes: 6 additions & 6 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func QuoteCppString(str string) string {
return "\"" + str + "\""
}

// SaveSketchItemCpp saves a preprocessed .cpp sketch file on disk
func SaveSketchItemCpp(item *sketch.Item, buildPath string) error {
// SketchSaveItemCpp saves a preprocessed .cpp sketch file on disk
func SketchSaveItemCpp(item *sketch.Item, buildPath string) error {

sketchName := filepath.Base(item.Path)

Expand All @@ -57,10 +57,10 @@ func SaveSketchItemCpp(item *sketch.Item, buildPath string) error {
return nil
}

// LoadSketch collects all the files composing a sketch.
// SketchLoad collects all the files composing a sketch.
// The parameter `sketchPath` holds a path pointing to a single sketch file or a sketch folder,
// the path must be absolute.
func LoadSketch(sketchPath, buildPath string) (*sketch.Sketch, error) {
func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) {
stat, err := os.Stat(sketchPath)
if err != nil {
return nil, errors.Wrap(err, "unable to stat Sketch location")
Expand Down Expand Up @@ -133,8 +133,8 @@ func LoadSketch(sketchPath, buildPath string) (*sketch.Sketch, error) {
return sketch.New(sketchFolder, mainSketchFile, buildPath, files)
}

// MergeSketchSources merges all the source files included in a sketch
func MergeSketchSources(sketch *sketch.Sketch) (int, string) {
// SketchMergeSources merges all the source files included in a sketch
func SketchMergeSources(sketch *sketch.Sketch) (int, string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if these functions (SketchMergeSources, SketchCopyAdditionalFiles, etc.) may become methods of sketch.Sketch?

lineOffset := 0
mergedSource := ""

Expand Down
18 changes: 9 additions & 9 deletions arduino/builder/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSaveSketch(t *testing.T) {
t.Fatalf("unable to read golden file %s: %v", sketchFile, err)
}

builder.SaveSketchItemCpp(&sketch.Item{Path: sketchName, Source: source}, tmp)
builder.SketchSaveItemCpp(&sketch.Item{Path: sketchName, Source: source}, tmp)

out, err := ioutil.ReadFile(filepath.Join(tmp, outName))
if err != nil {
Expand All @@ -52,7 +52,7 @@ func TestLoadSketchFolder(t *testing.T) {
// pass the path to the sketch folder
sketchPath := filepath.Join("testdata", t.Name())
mainFilePath := filepath.Join(sketchPath, t.Name()+".ino")
s, err := builder.LoadSketch(sketchPath, "")
s, err := builder.SketchLoad(sketchPath, "")
assert.Nil(t, err)
assert.NotNil(t, s)
assert.Equal(t, mainFilePath, s.MainFile.Path)
Expand All @@ -67,7 +67,7 @@ func TestLoadSketchFolder(t *testing.T) {

// pass the path to the main file
sketchPath = mainFilePath
s, err = builder.LoadSketch(sketchPath, "")
s, err = builder.SketchLoad(sketchPath, "")
assert.Nil(t, err)
assert.NotNil(t, s)
assert.Equal(t, mainFilePath, s.MainFile.Path)
Expand All @@ -82,18 +82,18 @@ func TestLoadSketchFolder(t *testing.T) {

func TestLoadSketchFolderWrongMain(t *testing.T) {
sketchPath := filepath.Join("testdata", t.Name())
_, err := builder.LoadSketch(sketchPath, "")
_, err := builder.SketchLoad(sketchPath, "")
assert.Error(t, err)
assert.Contains(t, err.Error(), "unable to find the main sketch file")

_, err = builder.LoadSketch("does/not/exist", "")
_, err = builder.SketchLoad("does/not/exist", "")
assert.Error(t, err)
assert.Contains(t, err.Error(), "no such file or directory")
}

func TestMergeSketchSources(t *testing.T) {
// borrow the sketch from TestLoadSketchFolder to avoid boilerplate
s, err := builder.LoadSketch(filepath.Join("testdata", "TestLoadSketchFolder"), "")
s, err := builder.SketchLoad(filepath.Join("testdata", "TestLoadSketchFolder"), "")
assert.Nil(t, err)
assert.NotNil(t, s)

Expand All @@ -104,17 +104,17 @@ func TestMergeSketchSources(t *testing.T) {
t.Fatalf("unable to read golden file %s: %v", mergedPath, err)
}

offset, source := builder.MergeSketchSources(s)
offset, source := builder.SketchMergeSources(s)
assert.Equal(t, 2, offset)
assert.Equal(t, string(mergedBytes), source)
}

func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
s, err := builder.LoadSketch(filepath.Join("testdata", t.Name()), "")
s, err := builder.SketchLoad(filepath.Join("testdata", t.Name()), "")
assert.Nil(t, err)
assert.NotNil(t, s)

// ensure not to include Arduino.h when it's already there
_, source := builder.MergeSketchSources(s)
_, source := builder.SketchMergeSources(s)
assert.Equal(t, 1, strings.Count(source, "<Arduino.h>"))
}
2 changes: 1 addition & 1 deletion legacy/builder/container_add_prototypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
}
}

if err := bldr.SaveSketchItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String()); err != nil {
if err := bldr.SketchSaveItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String()); err != nil {
return i18n.WrapError(err)
}

Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/container_merge_copy_sketch_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ 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.MergeSketchSources(sk)
offset, source := bldr.SketchMergeSources(sk)
ctx.LineOffset = offset
ctx.Source = source

if err := bldr.SaveSketchItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String()); err != nil {
if err := bldr.SketchSaveItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String()); err != nil {
return i18n.WrapError(err)
}

Expand Down
2 changes: 1 addition & 1 deletion legacy/builder/container_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
}

// load sketch
sketch, err := bldr.LoadSketch(sketchLocation.String(), ctx.BuildPath.String())
sketch, err := bldr.SketchLoad(sketchLocation.String(), ctx.BuildPath.String())
if err != nil {
return i18n.WrapError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion legacy/builder/preprocess_sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *PreprocessSketchArduino) Run(ctx *types.Context) error {
if ctx.CodeCompleteAt != "" {
err = new(OutputCodeCompletions).Run(ctx)
} else {
err = bldr.SaveSketchItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String())
err = bldr.SketchSaveItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String())
}

return err
Expand Down