Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
8af70b5b
Commit
8af70b5b
authored
Jul 04, 2019
by
Massimiliano Pippi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed SketchSaver command into builder function
parent
4a8523b9
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
116 additions
and
69 deletions
+116
-69
arduino/builder/sketch.go
arduino/builder/sketch.go
+40
-0
arduino/builder/sketch_test.go
arduino/builder/sketch_test.go
+47
-0
arduino/builder/testdata/TestSaveSketch.ino
arduino/builder/testdata/TestSaveSketch.ino
+6
-0
legacy/builder/container_add_prototypes.go
legacy/builder/container_add_prototypes.go
+5
-1
legacy/builder/container_merge_copy_sketch_files.go
legacy/builder/container_merge_copy_sketch_files.go
+9
-11
legacy/builder/create_cmake_rule.go
legacy/builder/create_cmake_rule.go
+0
-1
legacy/builder/preprocess_sketch.go
legacy/builder/preprocess_sketch.go
+9
-7
legacy/builder/sketch_saver.go
legacy/builder/sketch_saver.go
+0
-49
No files found.
arduino/builder/sketch.go
0 → 100644
View file @
8af70b5b
// This file is part of arduino-cli.
//
// Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to modify or
// otherwise use the software for commercial activities involving the Arduino
// software without disclosing the source code of your own applications. To purchase
// a commercial license, send an email to license@arduino.cc.
package
builder
import
(
"io/ioutil"
"os"
"path/filepath"
"github.com/pkg/errors"
)
// SaveSketch saves a preprocessed .cpp sketch file on disk
func
SaveSketch
(
sketchName
string
,
source
string
,
buildPath
string
)
error
{
if
err
:=
os
.
MkdirAll
(
buildPath
,
os
.
FileMode
(
0755
));
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"unable to create a folder to save the sketch"
)
}
destFile
:=
filepath
.
Join
(
buildPath
,
sketchName
+
".cpp"
)
if
err
:=
ioutil
.
WriteFile
(
destFile
,
[]
byte
(
source
),
os
.
FileMode
(
0644
));
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"unable to save the sketch on disk"
)
}
return
nil
}
arduino/builder/sketch_test.go
0 → 100644
View file @
8af70b5b
// This file is part of arduino-cli.
//
// Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to modify or
// otherwise use the software for commercial activities involving the Arduino
// software without disclosing the source code of your own applications. To purchase
// a commercial license, send an email to license@arduino.cc.
package
builder_test
import
(
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/arduino/arduino-cli/arduino/builder"
"github.com/stretchr/testify/assert"
)
func
TestSaveSketch
(
t
*
testing
.
T
)
{
sketchName
:=
t
.
Name
()
+
".ino"
outName
:=
sketchName
+
".cpp"
sketchFile
:=
filepath
.
Join
(
"testdata"
,
sketchName
)
tmp
:=
tmpDirOrDie
()
defer
os
.
RemoveAll
(
tmp
)
source
,
err
:=
ioutil
.
ReadFile
(
sketchFile
)
if
err
!=
nil
{
t
.
Fatalf
(
"unable to read golden file %s: %v"
,
sketchFile
,
err
)
}
builder
.
SaveSketch
(
sketchName
,
string
(
source
),
tmp
)
out
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
tmp
,
outName
))
if
err
!=
nil
{
t
.
Fatalf
(
"unable to read output file %s: %v"
,
outName
,
err
)
}
assert
.
Equal
(
t
,
source
,
out
)
}
arduino/builder/testdata/TestSaveSketch.ino
0 → 100644
View file @
8af70b5b
#include <Bridge.h>
#include <IRremote.h>
#include <IRremoteInt.h>
void
setup
()
{}
void
loop
()
{}
\ No newline at end of file
legacy/builder/container_add_prototypes.go
View file @
8af70b5b
...
...
@@ -30,6 +30,7 @@
package
builder
import
(
bldr
"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/i18n"
"github.com/arduino/arduino-cli/legacy/builder/types"
...
...
@@ -56,7 +57,6 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
&
CTagsTargetFileSaver
{
Source
:
&
ctx
.
SourceGccMinusE
,
TargetFileName
:
constants
.
FILE_CTAGS_TARGET_FOR_GCC_MINUS_E
},
&
CTagsRunner
{},
&
PrototypesAdder
{},
&
SketchSaver
{},
}
for
_
,
command
:=
range
commands
{
...
...
@@ -67,5 +67,9 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
}
}
if
err
:=
bldr
.
SaveSketch
(
ctx
.
Sketch
.
MainFile
.
Name
.
Base
(),
ctx
.
Source
,
ctx
.
SketchBuildPath
.
String
());
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
return
nil
}
legacy/builder/container_merge_copy_sketch_files.go
View file @
8af70b5b
...
...
@@ -30,6 +30,7 @@
package
builder
import
(
bldr
"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/legacy/builder/i18n"
"github.com/arduino/arduino-cli/legacy/builder/types"
)
...
...
@@ -37,20 +38,17 @@ import (
type
ContainerMergeCopySketchFiles
struct
{}
func
(
s
*
ContainerMergeCopySketchFiles
)
Run
(
ctx
*
types
.
Context
)
error
{
commands
:=
[]
types
.
Command
{
&
SketchSourceMerger
{},
&
SketchSaver
{},
&
AdditionalSketchFilesCopier
{},
if
err
:=
new
(
SketchSourceMerger
)
.
Run
(
ctx
);
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
for
_
,
command
:=
range
commands
{
PrintRingNameIfDebug
(
ctx
,
command
)
err
:=
command
.
Run
(
ctx
)
if
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
if
err
:=
bldr
.
SaveSketch
(
ctx
.
Sketch
.
MainFile
.
Name
.
Base
(),
ctx
.
Source
,
ctx
.
SketchBuildPath
.
String
());
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
return
nil
if
err
:=
new
(
AdditionalSketchFilesCopier
)
.
Run
(
ctx
);
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
return
nil
}
legacy/builder/create_cmake_rule.go
View file @
8af70b5b
...
...
@@ -130,7 +130,6 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
//&ContainerMergeCopySketchFiles{},
&
ContainerAddPrototypes
{},
//&FilterSketchSource{Source: &ctx.Source, RemoveLineMarkers: true},
//&SketchSaver{},
}
for
_
,
command
:=
range
commands
{
...
...
legacy/builder/preprocess_sketch.go
View file @
8af70b5b
...
...
@@ -37,6 +37,7 @@ import (
"runtime"
"strings"
bldr
"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/i18n"
"github.com/arduino/arduino-cli/legacy/builder/types"
...
...
@@ -66,12 +67,6 @@ func (s *PreprocessSketchArduino) Run(ctx *types.Context) error {
return
i18n
.
WrapError
(
err
)
}
if
ctx
.
CodeCompleteAt
!=
""
{
commands
=
append
(
commands
,
&
OutputCodeCompletions
{})
}
else
{
commands
=
append
(
commands
,
&
SketchSaver
{})
}
GCCPreprocRunner
(
ctx
,
sourceFile
,
ctx
.
PreprocPath
.
Join
(
constants
.
FILE_CTAGS_TARGET_FOR_GCC_MINUS_E
),
ctx
.
IncludeFolders
)
for
_
,
command
:=
range
commands
{
...
...
@@ -82,7 +77,14 @@ func (s *PreprocessSketchArduino) Run(ctx *types.Context) error {
}
}
return
nil
var
err
error
if
ctx
.
CodeCompleteAt
!=
""
{
err
=
new
(
OutputCodeCompletions
)
.
Run
(
ctx
)
}
else
{
err
=
bldr
.
SaveSketch
(
ctx
.
Sketch
.
MainFile
.
Name
.
Base
(),
ctx
.
Source
,
ctx
.
SketchBuildPath
.
String
())
}
return
err
}
type
ArduinoPreprocessorRunner
struct
{}
...
...
legacy/builder/sketch_saver.go
deleted
100644 → 0
View file @
4a8523b9
/*
* This file is part of Arduino Builder.
*
* Arduino Builder is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*/
package
builder
import
(
"github.com/arduino/arduino-cli/legacy/builder/i18n"
"github.com/arduino/arduino-cli/legacy/builder/types"
)
type
SketchSaver
struct
{}
func
(
s
*
SketchSaver
)
Run
(
ctx
*
types
.
Context
)
error
{
sketch
:=
ctx
.
Sketch
sketchBuildPath
:=
ctx
.
SketchBuildPath
if
err
:=
sketchBuildPath
.
MkdirAll
();
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
err
:=
sketchBuildPath
.
Join
(
sketch
.
MainFile
.
Name
.
Base
()
+
".cpp"
)
.
WriteFile
([]
byte
(
ctx
.
Source
))
return
i18n
.
WrapError
(
err
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment