Skip to content

Commit 0f2444f

Browse files
authored
Merge branch 'master' into inoz_experiment
2 parents 9205729 + 8e500a9 commit 0f2444f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2217
-441
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ install:
1414
- go get github.com/arduino/go-timeutils
1515

1616
script:
17+
- go get github.com/arduino/arduino-builder/arduino-builder
1718
- go build -o $HOME/arduino-builder -v github.com/arduino/arduino-builder/arduino-builder
1819
- export TEST_PACKAGES=`go list github.com/arduino/arduino-builder/...`
1920
- RES=0; I=0; for PKG in $TEST_PACKAGES; do go test -v -timeout 30m -covermode=count -coverprofile=coverage.$I.out $PKG; ((RES=RES+$?)); ((I++)); done; ( exit $RES )

Diff for: README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ To build, run the following commands:
6363
go get github.com/go-errors/errors
6464
go get github.com/stretchr/testify
6565
go get github.com/jstemmer/go-junit-report
66-
go get github.com/arduino/go-properties-map
67-
go get github.com/arduino/go-timeutils
66+
go get -u github.com/arduino/go-properties-map
67+
go get -u github.com/arduino/go-timeutils
68+
go get google.golang.org/grpc
69+
go get github.com/golang/protobuf/proto
70+
go get golang.org/x/net/context
71+
go get github.com/fsnotify/fsnotify
6872
go get github.com/arduino/arduino-builder
6973
go build github.com/arduino/arduino-builder/arduino-builder
7074
```
@@ -74,7 +78,7 @@ go build github.com/arduino/arduino-builder/arduino-builder
7478
In order to run the tests, type:
7579

7680
```
77-
go test github.com/arduino/arduino-builder/arduino-builder/...
81+
go test github.com/arduino/arduino-builder/...
7882
```
7983

8084
This runs all tests, showing any failures and a summary at the end.
@@ -88,13 +92,13 @@ To run a single test, use the -run option, which accepts a regular
8892
expression (see also go help testflag).
8993

9094
```
91-
go test github.com/arduino/arduino-builder/arduino-builder/... -run 'TestBuilderEmptySketch'
92-
go test github.com/arduino/arduino-builder/arduino-builder/... -run 'TestPrototypesAdder.*'
95+
go test github.com/arduino/arduino-builder/... -run 'TestBuilderEmptySketch'
96+
go test github.com/arduino/arduino-builder/... -run 'TestPrototypesAdder.*'
9397
```
9498

9599
In jenkins, use
96100
```
97-
go test -v github.com/arduino/arduino-builder/arduino-builder/... | bin/go-junit-report > report.xml
101+
go test -v github.com/arduino/arduino-builder/... | bin/go-junit-report > report.xml
98102
```
99103

100104
The first time you run the tests, some needed files (toolchains and

Diff for: arduino-builder/main.go

+71-16
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,30 @@ import (
3737
"io/ioutil"
3838
"os"
3939
"os/exec"
40+
"path/filepath"
41+
"runtime"
4042
"strings"
4143
"syscall"
4244

45+
"runtime/pprof"
46+
"runtime/trace"
47+
4348
"github.com/arduino/arduino-builder"
4449
"github.com/arduino/arduino-builder/gohasissues"
50+
"github.com/arduino/arduino-builder/grpc"
4551
"github.com/arduino/arduino-builder/i18n"
4652
"github.com/arduino/arduino-builder/types"
4753
"github.com/arduino/arduino-builder/utils"
4854
"github.com/arduino/go-properties-map"
4955
"github.com/go-errors/errors"
5056
)
5157

52-
const VERSION = "1.3.25"
58+
const VERSION = "1.4.2"
5359

5460
const FLAG_ACTION_COMPILE = "compile"
5561
const FLAG_ACTION_PREPROCESS = "preprocess"
5662
const FLAG_ACTION_DUMP_PREFS = "dump-prefs"
63+
const FLAG_ACTION_CODE_COMPLETE_AT = "code-complete-at"
5764
const FLAG_BUILD_OPTIONS_FILE = "build-options-file"
5865
const FLAG_HARDWARE = "hardware"
5966
const FLAG_TOOLS = "tools"
@@ -78,27 +85,20 @@ const FLAG_LOGGER_HUMAN = "human"
7885
const FLAG_LOGGER_HUMANTAGS = "humantags"
7986
const FLAG_LOGGER_MACHINE = "machine"
8087
const FLAG_VERSION = "version"
88+
const FLAG_DAEMON = "daemon"
8189
const FLAG_VID_PID = "vid-pid"
90+
const FLAG_JOBS = "jobs"
91+
const FLAG_TRACE = "trace"
92+
const FLAG_EXPERIMENTAL = "experimental"
8293

8394
type foldersFlag []string
8495

8596
func (h *foldersFlag) String() string {
8697
return fmt.Sprint(*h)
8798
}
8899

89-
func (h *foldersFlag) Set(csv string) error {
90-
var values []string
91-
if strings.Contains(csv, string(os.PathListSeparator)) {
92-
values = strings.Split(csv, string(os.PathListSeparator))
93-
} else {
94-
values = strings.Split(csv, ",")
95-
}
96-
97-
for _, value := range values {
98-
value = strings.TrimSpace(value)
99-
*h = append(*h, value)
100-
}
101-
100+
func (h *foldersFlag) Set(folder string) error {
101+
*h = append(*h, folder)
102102
return nil
103103
}
104104

@@ -118,6 +118,7 @@ func (h *propertiesFlag) Set(value string) error {
118118
var compileFlag *bool
119119
var preprocessFlag *bool
120120
var dumpPrefsFlag *bool
121+
var codeCompleteAtFlag *string
121122
var buildOptionsFileFlag *string
122123
var hardwareFoldersFlag foldersFlag
123124
var toolsFoldersFlag foldersFlag
@@ -135,12 +136,17 @@ var debugLevelFlag *int
135136
var warningsLevelFlag *string
136137
var loggerFlag *string
137138
var versionFlag *bool
139+
var daemonFlag *bool
138140
var vidPidFlag *string
141+
var jobsFlag *int
142+
var traceFlag *bool
143+
var experimentalFeatures *bool
139144

140145
func init() {
141146
compileFlag = flag.Bool(FLAG_ACTION_COMPILE, false, "compiles the given sketch")
142147
preprocessFlag = flag.Bool(FLAG_ACTION_PREPROCESS, false, "preprocess the given sketch")
143148
dumpPrefsFlag = flag.Bool(FLAG_ACTION_DUMP_PREFS, false, "dumps build properties used when compiling")
149+
codeCompleteAtFlag = flag.String(FLAG_ACTION_CODE_COMPLETE_AT, "", "output code completions for sketch at a specific location. Location format is \"file:line:col\"")
144150
buildOptionsFileFlag = flag.String(FLAG_BUILD_OPTIONS_FILE, "", "Instead of specifying --"+FLAG_HARDWARE+", --"+FLAG_TOOLS+" etc every time, you can load all such options from a file")
145151
flag.Var(&hardwareFoldersFlag, FLAG_HARDWARE, "Specify a 'hardware' folder. Can be added multiple times for specifying multiple 'hardware' folders")
146152
flag.Var(&toolsFoldersFlag, FLAG_TOOLS, "Specify a 'tools' folder. Can be added multiple times for specifying multiple 'tools' folders")
@@ -158,12 +164,40 @@ func init() {
158164
warningsLevelFlag = flag.String(FLAG_WARNINGS, "", "Sets warnings level. Available values are '"+FLAG_WARNINGS_NONE+"', '"+FLAG_WARNINGS_DEFAULT+"', '"+FLAG_WARNINGS_MORE+"' and '"+FLAG_WARNINGS_ALL+"'")
159165
loggerFlag = flag.String(FLAG_LOGGER, FLAG_LOGGER_HUMAN, "Sets type of logger. Available values are '"+FLAG_LOGGER_HUMAN+"', '"+FLAG_LOGGER_HUMANTAGS+"', '"+FLAG_LOGGER_MACHINE+"'")
160166
versionFlag = flag.Bool(FLAG_VERSION, false, "prints version and exits")
167+
daemonFlag = flag.Bool(FLAG_DAEMON, false, "daemonizes and serves its functions via rpc")
161168
vidPidFlag = flag.String(FLAG_VID_PID, "", "specify to use vid/pid specific build properties, as defined in boards.txt")
169+
jobsFlag = flag.Int(FLAG_JOBS, 0, "specify how many concurrent gcc processes should run at the same time. Defaults to the number of available cores on the running machine")
170+
traceFlag = flag.Bool(FLAG_TRACE, false, "traces the whole process lifecycle")
171+
experimentalFeatures = flag.Bool(FLAG_EXPERIMENTAL, false, "enables experimental features")
162172
}
163173

164174
func main() {
175+
165176
flag.Parse()
166177

178+
if *traceFlag {
179+
f, err := os.Create("trace.out")
180+
if err != nil {
181+
panic(err)
182+
}
183+
defer f.Close()
184+
185+
f2, err := os.Create("profile.out")
186+
if err != nil {
187+
panic(err)
188+
}
189+
defer f2.Close()
190+
191+
pprof.StartCPUProfile(f2)
192+
defer pprof.StopCPUProfile()
193+
194+
err = trace.Start(f)
195+
if err != nil {
196+
panic(err)
197+
}
198+
defer trace.Stop()
199+
}
200+
167201
if *versionFlag {
168202
fmt.Println("Arduino Builder " + VERSION)
169203
fmt.Println("Copyright (C) 2015 Arduino LLC and contributors")
@@ -173,8 +207,28 @@ func main() {
173207
return
174208
}
175209

210+
if *jobsFlag > 0 {
211+
runtime.GOMAXPROCS(*jobsFlag)
212+
} else {
213+
runtime.GOMAXPROCS(runtime.NumCPU())
214+
}
215+
176216
ctx := &types.Context{}
177217

218+
// place here all experimental features that should live under this flag
219+
if *experimentalFeatures {
220+
ctx.UseArduinoPreprocessor = true
221+
}
222+
223+
if *daemonFlag {
224+
var loggerBuffer []string
225+
logger := i18n.AccumulatorLogger{}
226+
logger.Buffer = &loggerBuffer
227+
//logger := i18n.HumanLogger{}
228+
ctx.SetLogger(logger)
229+
jsonrpc.RegisterAndServeJsonRPC(ctx)
230+
}
231+
178232
if *buildOptionsFileFlag != "" {
179233
buildOptions := make(properties.Map)
180234
if _, err := os.Stat(*buildOptionsFileFlag); err == nil {
@@ -258,7 +312,7 @@ func main() {
258312
printCompleteError(err)
259313
}
260314
}
261-
ctx.BuildPath = buildPath
315+
ctx.BuildPath, _ = filepath.Abs(buildPath)
262316

263317
// FLAG_BUILD_CACHE
264318
buildCachePath, err := gohasissues.Unquote(*buildCachePathFlag)
@@ -330,7 +384,8 @@ func main() {
330384

331385
if *dumpPrefsFlag {
332386
err = builder.RunParseHardwareAndDumpBuildProperties(ctx)
333-
} else if *preprocessFlag {
387+
} else if *preprocessFlag || *codeCompleteAtFlag != "" {
388+
ctx.CodeCompleteAt = *codeCompleteAtFlag
334389
err = builder.RunPreprocess(ctx)
335390
} else {
336391
if flag.NArg() == 0 {

Diff for: builder.go

+22-21
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"strconv"
3636
"time"
3737

38+
"github.com/arduino/arduino-builder/builder_utils"
3839
"github.com/arduino/arduino-builder/constants"
3940
"github.com/arduino/arduino-builder/i18n"
4041
"github.com/arduino/arduino-builder/phases"
@@ -89,7 +90,7 @@ func (s *Builder) Run(ctx *types.Context) error {
8990
&WarnAboutArchIncompatibleLibraries{},
9091

9192
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Generating function prototypes..."),
92-
&ContainerAddPrototypes{},
93+
&PreprocessSketch{},
9394

9495
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Compiling sketch..."),
9596
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
@@ -128,6 +129,8 @@ func (s *Builder) Run(ctx *types.Context) error {
128129

129130
&PrintUsedLibrariesIfVerbose{},
130131

132+
&ExportProjectCMake{SketchError: mainErr != nil},
133+
131134
&phases.Sizer{SketchError: mainErr != nil},
132135
}
133136
otherErr := runCommands(ctx, commands, false)
@@ -139,6 +142,18 @@ func (s *Builder) Run(ctx *types.Context) error {
139142
return otherErr
140143
}
141144

145+
type PreprocessSketch struct{}
146+
147+
func (s *PreprocessSketch) Run(ctx *types.Context) error {
148+
var commands []types.Command
149+
if ctx.UseArduinoPreprocessor {
150+
commands = append(commands, &PreprocessSketchArduino{})
151+
} else {
152+
commands = append(commands, &ContainerAddPrototypes{})
153+
}
154+
return runCommands(ctx, commands, true)
155+
}
156+
142157
type Preprocess struct{}
143158

144159
func (s *Preprocess) Run(ctx *types.Context) error {
@@ -158,7 +173,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
158173

159174
&WarnAboutArchIncompatibleLibraries{},
160175

161-
&ContainerAddPrototypes{},
176+
&PreprocessSketch{},
162177

163178
&PrintPreprocessedSource{},
164179
}
@@ -181,36 +196,22 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error {
181196
}
182197

183198
func runCommands(ctx *types.Context, commands []types.Command, progressEnabled bool) error {
184-
commandsLength := len(commands)
185-
progressForEachCommand := float32(100) / float32(commandsLength)
186199

187-
progress := float32(0)
200+
ctx.Progress.PrintEnabled = progressEnabled
201+
ctx.Progress.Progress = 0
202+
188203
for _, command := range commands {
189204
PrintRingNameIfDebug(ctx, command)
190-
printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, progress)
205+
ctx.Progress.Steps = 100.0 / float64(len(commands))
206+
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
191207
err := command.Run(ctx)
192208
if err != nil {
193209
return i18n.WrapError(err)
194210
}
195-
progress += progressForEachCommand
196211
}
197-
198-
printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, 100)
199-
200212
return nil
201213
}
202214

203-
func printProgressIfProgressEnabledAndMachineLogger(progressEnabled bool, ctx *types.Context, progress float32) {
204-
if !progressEnabled {
205-
return
206-
}
207-
208-
log := ctx.GetLogger()
209-
if log.Name() == "machine" {
210-
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32))
211-
}
212-
}
213-
214215
func PrintRingNameIfDebug(ctx *types.Context, command types.Command) {
215216
if ctx.DebugLevel >= 10 {
216217
ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_COMMAND, strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name())

0 commit comments

Comments
 (0)