Skip to content

Commit 244e15c

Browse files
committed
Merge branch 'master' into cli-inception
2 parents f1631fd + 3f9e2f0 commit 244e15c

Some content is hidden

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

43 files changed

+2094
-298
lines changed

.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 )

add_missing_build_properties_from_parent_platform_txt_files.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(ctx *types.Con
4040
buildProperties := ctx.BuildProperties
4141

4242
newBuildProperties := ctags.CtagsProperties.Clone()
43+
newBuildProperties.Merge(ArduinoPreprocessorProperties)
4344
newBuildProperties.Merge(buildProperties)
4445
ctx.BuildProperties = newBuildProperties
4546

arduino-builder/main.go

+66-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ import (
3737
"io/ioutil"
3838
"os"
3939
"os/exec"
40+
"runtime"
4041
"strings"
4142
"syscall"
4243

43-
"github.com/arduino/go-paths-helper"
44+
"runtime/pprof"
45+
"runtime/trace"
4446

4547
"github.com/arduino/arduino-builder"
4648
"github.com/arduino/arduino-builder/gohasissues"
49+
"github.com/arduino/arduino-builder/grpc"
4750
"github.com/arduino/arduino-builder/i18n"
4851
"github.com/arduino/arduino-builder/types"
52+
"github.com/arduino/go-paths-helper"
4953
"github.com/arduino/go-properties-map"
5054
"github.com/go-errors/errors"
5155
)
@@ -55,6 +59,7 @@ const VERSION = "1.3.25"
5559
const FLAG_ACTION_COMPILE = "compile"
5660
const FLAG_ACTION_PREPROCESS = "preprocess"
5761
const FLAG_ACTION_DUMP_PREFS = "dump-prefs"
62+
const FLAG_ACTION_CODE_COMPLETE_AT = "code-complete-at"
5863
const FLAG_BUILD_OPTIONS_FILE = "build-options-file"
5964
const FLAG_HARDWARE = "hardware"
6065
const FLAG_TOOLS = "tools"
@@ -79,7 +84,11 @@ const FLAG_LOGGER_HUMAN = "human"
7984
const FLAG_LOGGER_HUMANTAGS = "humantags"
8085
const FLAG_LOGGER_MACHINE = "machine"
8186
const FLAG_VERSION = "version"
87+
const FLAG_DAEMON = "daemon"
8288
const FLAG_VID_PID = "vid-pid"
89+
const FLAG_JOBS = "jobs"
90+
const FLAG_TRACE = "trace"
91+
const FLAG_EXPERIMENTAL = "experimental"
8392

8493
type foldersFlag []string
8594

@@ -119,6 +128,7 @@ func (h *propertiesFlag) Set(value string) error {
119128
var compileFlag *bool
120129
var preprocessFlag *bool
121130
var dumpPrefsFlag *bool
131+
var codeCompleteAtFlag *string
122132
var buildOptionsFileFlag *string
123133
var hardwareFoldersFlag foldersFlag
124134
var toolsFoldersFlag foldersFlag
@@ -136,12 +146,17 @@ var debugLevelFlag *int
136146
var warningsLevelFlag *string
137147
var loggerFlag *string
138148
var versionFlag *bool
149+
var daemonFlag *bool
139150
var vidPidFlag *string
151+
var jobsFlag *int
152+
var traceFlag *bool
153+
var experimentalFeatures *bool
140154

141155
func init() {
142156
compileFlag = flag.Bool(FLAG_ACTION_COMPILE, false, "compiles the given sketch")
143157
preprocessFlag = flag.Bool(FLAG_ACTION_PREPROCESS, false, "preprocess the given sketch")
144158
dumpPrefsFlag = flag.Bool(FLAG_ACTION_DUMP_PREFS, false, "dumps build properties used when compiling")
159+
codeCompleteAtFlag = flag.String(FLAG_ACTION_CODE_COMPLETE_AT, "", "output code completions for sketch at a specific location. Location format is \"file:line:col\"")
145160
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")
146161
flag.Var(&hardwareFoldersFlag, FLAG_HARDWARE, "Specify a 'hardware' folder. Can be added multiple times for specifying multiple 'hardware' folders")
147162
flag.Var(&toolsFoldersFlag, FLAG_TOOLS, "Specify a 'tools' folder. Can be added multiple times for specifying multiple 'tools' folders")
@@ -159,12 +174,40 @@ func init() {
159174
warningsLevelFlag = flag.String(FLAG_WARNINGS, "", "Sets warnings level. Available values are '"+FLAG_WARNINGS_NONE+"', '"+FLAG_WARNINGS_DEFAULT+"', '"+FLAG_WARNINGS_MORE+"' and '"+FLAG_WARNINGS_ALL+"'")
160175
loggerFlag = flag.String(FLAG_LOGGER, FLAG_LOGGER_HUMAN, "Sets type of logger. Available values are '"+FLAG_LOGGER_HUMAN+"', '"+FLAG_LOGGER_HUMANTAGS+"', '"+FLAG_LOGGER_MACHINE+"'")
161176
versionFlag = flag.Bool(FLAG_VERSION, false, "prints version and exits")
177+
daemonFlag = flag.Bool(FLAG_DAEMON, false, "daemonizes and serves its functions via rpc")
162178
vidPidFlag = flag.String(FLAG_VID_PID, "", "specify to use vid/pid specific build properties, as defined in boards.txt")
179+
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")
180+
traceFlag = flag.Bool(FLAG_TRACE, false, "traces the whole process lifecycle")
181+
experimentalFeatures = flag.Bool(FLAG_EXPERIMENTAL, false, "enables experimental features")
163182
}
164183

165184
func main() {
185+
166186
flag.Parse()
167187

188+
if *traceFlag {
189+
f, err := os.Create("trace.out")
190+
if err != nil {
191+
panic(err)
192+
}
193+
defer f.Close()
194+
195+
f2, err := os.Create("profile.out")
196+
if err != nil {
197+
panic(err)
198+
}
199+
defer f2.Close()
200+
201+
pprof.StartCPUProfile(f2)
202+
defer pprof.StopCPUProfile()
203+
204+
err = trace.Start(f)
205+
if err != nil {
206+
panic(err)
207+
}
208+
defer trace.Stop()
209+
}
210+
168211
if *versionFlag {
169212
fmt.Println("Arduino Builder " + VERSION)
170213
fmt.Println("Copyright (C) 2015 Arduino LLC and contributors")
@@ -174,8 +217,28 @@ func main() {
174217
return
175218
}
176219

220+
if *jobsFlag > 0 {
221+
runtime.GOMAXPROCS(*jobsFlag)
222+
} else {
223+
runtime.GOMAXPROCS(runtime.NumCPU())
224+
}
225+
177226
ctx := &types.Context{}
178227

228+
// place here all experimental features that should live under this flag
229+
if *experimentalFeatures {
230+
ctx.UseArduinoPreprocessor = true
231+
}
232+
233+
if *daemonFlag {
234+
var loggerBuffer []string
235+
logger := i18n.AccumulatorLogger{}
236+
logger.Buffer = &loggerBuffer
237+
//logger := i18n.HumanLogger{}
238+
ctx.SetLogger(logger)
239+
jsonrpc.RegisterAndServeJsonRPC(ctx)
240+
}
241+
179242
if *buildOptionsFileFlag != "" {
180243
buildOptions := make(properties.Map)
181244
if _, err := os.Stat(*buildOptionsFileFlag); err == nil {
@@ -330,7 +393,8 @@ func main() {
330393

331394
if *dumpPrefsFlag {
332395
err = builder.RunParseHardwareAndDumpBuildProperties(ctx)
333-
} else if *preprocessFlag {
396+
} else if *preprocessFlag || *codeCompleteAtFlag != "" {
397+
ctx.CodeCompleteAt = *codeCompleteAtFlag
334398
err = builder.RunPreprocess(ctx)
335399
} else {
336400
if flag.NArg() == 0 {

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"
@@ -73,7 +74,7 @@ func (s *Builder) Run(ctx *types.Context) error {
7374
&WarnAboutArchIncompatibleLibraries{},
7475

7576
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Generating function prototypes..."),
76-
&ContainerAddPrototypes{},
77+
&PreprocessSketch{},
7778

7879
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Compiling sketch..."),
7980
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
@@ -112,6 +113,8 @@ func (s *Builder) Run(ctx *types.Context) error {
112113

113114
&PrintUsedLibrariesIfVerbose{},
114115

116+
&ExportProjectCMake{SketchError: mainErr != nil},
117+
115118
&phases.Sizer{SketchError: mainErr != nil},
116119
}
117120
otherErr := runCommands(ctx, commands, false)
@@ -123,6 +126,18 @@ func (s *Builder) Run(ctx *types.Context) error {
123126
return otherErr
124127
}
125128

129+
type PreprocessSketch struct{}
130+
131+
func (s *PreprocessSketch) Run(ctx *types.Context) error {
132+
var commands []types.Command
133+
if ctx.UseArduinoPreprocessor {
134+
commands = append(commands, &PreprocessSketchArduino{})
135+
} else {
136+
commands = append(commands, &ContainerAddPrototypes{})
137+
}
138+
return runCommands(ctx, commands, true)
139+
}
140+
126141
type Preprocess struct{}
127142

128143
func (s *Preprocess) Run(ctx *types.Context) error {
@@ -142,7 +157,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
142157

143158
&WarnAboutArchIncompatibleLibraries{},
144159

145-
&ContainerAddPrototypes{},
160+
&PreprocessSketch{},
146161

147162
&PrintPreprocessedSource{},
148163
}
@@ -165,36 +180,22 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error {
165180
}
166181

167182
func runCommands(ctx *types.Context, commands []types.Command, progressEnabled bool) error {
168-
commandsLength := len(commands)
169-
progressForEachCommand := float32(100) / float32(commandsLength)
170183

171-
progress := float32(0)
184+
ctx.Progress.PrintEnabled = progressEnabled
185+
ctx.Progress.Progress = 0
186+
172187
for _, command := range commands {
173188
PrintRingNameIfDebug(ctx, command)
174-
printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, progress)
189+
ctx.Progress.Steps = 100.0 / float64(len(commands))
190+
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
175191
err := command.Run(ctx)
176192
if err != nil {
177193
return i18n.WrapError(err)
178194
}
179-
progress += progressForEachCommand
180195
}
181-
182-
printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, 100)
183-
184196
return nil
185197
}
186198

187-
func printProgressIfProgressEnabledAndMachineLogger(progressEnabled bool, ctx *types.Context, progress float32) {
188-
if !progressEnabled {
189-
return
190-
}
191-
192-
log := ctx.GetLogger()
193-
if log.Name() == "machine" {
194-
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32))
195-
}
196-
}
197-
198199
func PrintRingNameIfDebug(ctx *types.Context, command types.Command) {
199200
if ctx.DebugLevel >= 10 {
200201
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)