Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: "2"

tasks:
docs:gen:commands:
Expand Down Expand Up @@ -65,6 +65,15 @@ tasks:
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/settings/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/debug/*.proto'

protoc-java:
desc: Compile protobuf java bindings
cmds:
# look here https://github.com/grpc/grpc-java/tree/master/compiler for protoc-gen-grpc-java
- '{{ default "protoc" .PROTOC_BINARY }} --plugin={{ default "protoc-gen-grpc-java" .PROTOC_GEN_GRPC_JAVA_BINARY }} --grpc-java_out=rpc/java --proto_path=rpc --java_out=rpc/java ./rpc/commands/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --plugin={{ default "protoc-gen-grpc-java" .PROTOC_GEN_GRPC_JAVA_BINARY }} --grpc-java_out=rpc/java --proto_path=rpc --java_out=rpc/java ./rpc/monitor/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --plugin={{ default "protoc-gen-grpc-java" .PROTOC_GEN_GRPC_JAVA_BINARY }} --grpc-java_out=rpc/java --proto_path=rpc --java_out=rpc/java ./rpc/settings/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --plugin={{ default "protoc-gen-grpc-java" .PROTOC_GEN_GRPC_JAVA_BINARY }} --grpc-java_out=rpc/java --proto_path=rpc --java_out=rpc/java ./rpc/debug/*.proto'

build:
desc: Build the project
cmds:
Expand Down
2 changes: 1 addition & 1 deletion cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func run(cmd *cobra.Command, args []string) {
DryRun: dryRun,
Libraries: libraries,
OptimizeForDebug: optimizeForDebug,
}, os.Stdout, os.Stderr, viper.GetString("logging.level") == "debug")
}, os.Stdout, os.Stderr, nil, viper.GetString("logging.level") == "debug")

if err != nil {
feedback.Errorf("Error during build: %v", err)
Expand Down
23 changes: 17 additions & 6 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
)

// Compile FIXMEDOC
func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.Writer, debug bool) (r *rpc.CompileResp, e error) {
func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.Writer, taskCB commands.TaskProgressCB, debug bool) (r *rpc.CompileResp, e error) {

tags := map[string]string{
"fqbn": req.Fqbn,
Expand Down Expand Up @@ -119,6 +119,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
builderCtx.PackageManager = pm
builderCtx.FQBN = fqbn
builderCtx.SketchLocation = sketch.FullPath
builderCtx.ProgressCB = taskCB

// FIXME: This will be redundant when arduino-builder will be part of the cli
builderCtx.HardwareDirs = configuration.HardwareDirectories()
Expand Down Expand Up @@ -191,14 +192,24 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W

// if --preprocess or --show-properties were passed, we can stop here
if req.GetShowProperties() {
return &rpc.CompileResp{}, builder.RunParseHardwareAndDumpBuildProperties(builderCtx)
} else if req.GetPreprocess() {
return &rpc.CompileResp{}, builder.RunPreprocess(builderCtx)
if err := builder.RunParseHardwareAndDumpBuildProperties(builderCtx); err != nil {
fmt.Fprintf(errStream, "error: %s", err)
return &rpc.CompileResp{Result: rpc.CompileResult_compile_error}, nil
}
return &rpc.CompileResp{Result: rpc.CompileResult_compile_success}, nil
}
if req.GetPreprocess() {
if err := builder.RunPreprocess(builderCtx); err != nil {
fmt.Fprintf(errStream, "error: %s", err)
return &rpc.CompileResp{Result: rpc.CompileResult_compile_error}, nil
}
return &rpc.CompileResp{Result: rpc.CompileResult_compile_success}, nil
}

// if it's a regular build, go on...
if err := builder.RunBuilder(builderCtx); err != nil {
return nil, err
fmt.Fprintf(errStream, "error: %s", err)
return &rpc.CompileResp{Result: rpc.CompileResult_compile_error}, nil
}

if !req.GetDryRun() {
Expand Down Expand Up @@ -239,5 +250,5 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
}

logrus.Tracef("Compile %s for %s successful", sketch.Name, fqbnIn)
return &rpc.CompileResp{}, nil
return &rpc.CompileResp{Result: rpc.CompileResult_compile_success}, nil
}
1 change: 1 addition & 0 deletions commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoC
stream.Context(), req,
utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResp{OutStream: data}) }),
utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResp{ErrStream: data}) }),
func(p *rpc.TaskProgress) { stream.Send(&rpc.CompileResp{TaskProgress: p}) },
false) // Set debug to false
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/arduino/arduino-builder v0.0.0-20200212104243-d59b903f9ee8 h1:QMta31FSrmmLdu9GqHy6gH7rJQ/kOz4chkUA0L25h80=
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT96G8egU7FEb13L4dq3fnCN7lxXhJ86t69+W7s=
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
Expand Down
3 changes: 1 addition & 2 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

bldr "github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/phases"
"github.com/arduino/arduino-cli/legacy/builder/types"
Expand Down Expand Up @@ -194,7 +193,7 @@ func runCommands(ctx *types.Context, commands []types.Command) error {
return errors.WithStack(err)
}
ctx.Progress.CompleteStep()
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
ctx.PushProgress()
}
return nil
}
Expand Down
15 changes: 1 addition & 14 deletions legacy/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"

Expand All @@ -33,18 +32,6 @@ import (
"github.com/pkg/errors"
)

func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {

if !ctx.Progress.PrintEnabled {
return
}

log := ctx.GetLogger()
if log.Name() == "machine" {
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(ctx.Progress.Progress), 'f', 2, 32))
}
}

func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
objectFiles, err := CompileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes)
if err != nil {
Expand Down Expand Up @@ -213,7 +200,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
queue <- source

ctx.Progress.CompleteStep()
PrintProgressIfProgressEnabledAndMachineLogger(ctx)
ctx.PushProgress()
}
close(queue)
wg.Wait()
Expand Down
1 change: 0 additions & 1 deletion legacy/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ const MSG_MISSING_CORE_FOR_BOARD = "Selected board depends on '{0}' core (not in
const MSG_PACKAGE_UNKNOWN = "{0}: Unknown package"
const MSG_PATTERN_MISSING = "{0} pattern is missing"
const MSG_PLATFORM_UNKNOWN = "Platform {0} (package {1}) is unknown"
const MSG_PROGRESS = "Progress {0}"
const MSG_PROP_IN_LIBRARY = "Missing '{0}' from library in {1}"
const MSG_RUNNING_COMMAND = "Ts: {0} - Running: {1}"
const MSG_RUNNING_RECIPE = "Running recipe: {0}"
Expand Down
7 changes: 3 additions & 4 deletions legacy/builder/container_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"

bldr "github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
Expand Down Expand Up @@ -51,7 +50,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
return errors.WithStack(err)
}
ctx.Progress.CompleteStep()
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
ctx.PushProgress()
}

if ctx.SketchLocation != nil {
Expand All @@ -73,7 +72,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
ctx.Sketch = types.SketchToLegacy(sketch)
}
ctx.Progress.CompleteStep()
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
ctx.PushProgress()

commands = []types.Command{
&SetupBuildProperties{},
Expand All @@ -89,7 +88,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
return errors.WithStack(err)
}
ctx.Progress.CompleteStep()
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
ctx.PushProgress()
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion legacy/builder/phases/libraries_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *p
objectFiles = append(objectFiles, libraryObjectFiles...)

ctx.Progress.CompleteStep()
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
ctx.PushProgress()
}

return objectFiles, nil
Expand Down
17 changes: 13 additions & 4 deletions legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ import (
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
"github.com/arduino/arduino-cli/arduino/libraries/librariesresolver"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/legacy/builder/i18n"
rpc "github.com/arduino/arduino-cli/rpc/commands"
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
)

type ProgressStruct struct {
PrintEnabled bool
Progress float32
StepAmount float32
Parent *ProgressStruct
Progress float32
StepAmount float32
Parent *ProgressStruct
}

func (p *ProgressStruct) AddSubSteps(steps int) {
Expand Down Expand Up @@ -138,6 +139,8 @@ type Context struct {

// Dry run, only create progress map
Progress ProgressStruct
// Send progress events to this callback
ProgressCB commands.TaskProgressCB

// Contents of a custom build properties file (line by line)
CustomBuildProperties []string
Expand Down Expand Up @@ -212,3 +215,9 @@ func (ctx *Context) GetLogger() i18n.Logger {
func (ctx *Context) SetLogger(l i18n.Logger) {
ctx.logger = l
}

func (ctx *Context) PushProgress() {
if ctx.ProgressCB != nil {
ctx.ProgressCB(&rpc.TaskProgress{PercentCompleted: ctx.Progress.Progress})
}
}
48 changes: 29 additions & 19 deletions rpc/commands/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rpc/commands/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ message TaskProgress {
// Additional information about the task.
string message = 2;
// Whether the task is complete.
bool completed = 3;
bool completed = 3;
// Amount in percent of the task completion (if available)
float percent_completed = 4;
}
Loading