Skip to content

Minor fix added return value to the compile function in command/compile #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2019
Merged
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
37 changes: 35 additions & 2 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ package compile

import (
"context"
"os"

"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/rpc"

"github.com/arduino/arduino-cli/cli"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -87,6 +90,36 @@ var flags struct {
}

func run(cmd *cobra.Command, args []string) {
// TODO: fill request, parse response
compile.Compile(context.Background(), nil)
instance := cli.CreateInstance()
path := ""

if len(args) > 0 {
path = args[0]
}

compRes, err := compile.Compile(context.Background(), &rpc.CompileReq{
Instance: instance,
Fqbn: flags.fqbn,
SketchPath: path,
ShowProperties: flags.showProperties,
Preprocess: flags.preprocess,
BuildCachePath: flags.buildCachePath,
BuildPath: flags.buildPath,
BuildProperties: flags.buildProperties,
Warnings: flags.warnings,
Verbose: flags.verbose,
Quiet: flags.quiet,
VidPid: flags.vidPid,
ExportFile: flags.exportFile,
})
if err == nil {
outputCompileResp(compRes)
} else {
formatter.PrintError(err, compRes.GetResult().Message)
os.Exit(cli.ErrGeneric)
}
}

func outputCompileResp(details *rpc.CompileResp) {

}
63 changes: 41 additions & 22 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package compile
import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
Expand All @@ -29,8 +28,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
}
sketch, err := cli.InitSketch(sketchPath)
if err != nil {
formatter.PrintError(err, "Error opening sketch.")
os.Exit(cli.ErrGeneric)
return &rpc.CompileResp{
Result: rpc.Error("Error opening sketch", rpc.ErrGeneric),
}, err
}

fqbnIn := req.GetFqbn()
Expand All @@ -39,12 +39,16 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
}
if fqbnIn == "" {
formatter.PrintErrorMessage("No Fully Qualified Board Name provided.")
os.Exit(cli.ErrGeneric)
return &rpc.CompileResp{
Result: rpc.Error("No Fully Qualified Board Name provided.", rpc.ErrGeneric),
}, rpc.Error("No Fully Qualified Board Name provided.", rpc.ErrGeneric)
}
fqbn, err := cores.ParseFQBN(fqbnIn)
if err != nil {
formatter.PrintErrorMessage("Fully Qualified Board Name has incorrect format.")
os.Exit(cli.ErrBadArgument)
return &rpc.CompileResp{
Result: rpc.Error("Fully Qualified Board Name has incorrect format.", rpc.ErrGeneric),
}, err
}

pm, _ := cli.InitPackageAndLibraryManager()
Expand All @@ -58,13 +62,16 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
core.InstallToolRelease(pm, ctags)

if err := pm.LoadHardware(cli.Config); err != nil {
formatter.PrintError(err, "Could not load hardware packages.")
os.Exit(cli.ErrCoreConfig)
return &rpc.CompileResp{
Result: rpc.Error("Could not load hardware packages.", rpc.ErrGeneric),
}, err
}
ctags, _ = getBuiltinCtagsTool(pm)
if !ctags.IsInstalled() {
formatter.PrintErrorMessage("Missing ctags tool.")
os.Exit(cli.ErrCoreConfig)
return &rpc.CompileResp{
Result: rpc.Error("Missing ctags tool.", rpc.ErrGeneric),
}, rpc.Error("Missing ctags tool.", rpc.ErrGeneric)
}
}

Expand All @@ -77,7 +84,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
"\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
cli.AppName+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
formatter.PrintErrorMessage(errorMessage)
os.Exit(cli.ErrCoreConfig)
return &rpc.CompileResp{
Result: rpc.Error(errorMessage, rpc.ErrGeneric),
}, rpc.Error(errorMessage, rpc.ErrGeneric)
}

builderCtx := &types.Context{}
Expand All @@ -89,15 +98,17 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
if packagesDir, err := cli.Config.HardwareDirectories(); err == nil {
builderCtx.HardwareDirs = packagesDir
} else {
formatter.PrintError(err, "Cannot get hardware directories.")
os.Exit(cli.ErrCoreConfig)
return &rpc.CompileResp{
Result: rpc.Error("Cannot get hardware directories.", rpc.ErrGeneric),
}, err
}

if toolsDir, err := cli.Config.BundleToolsDirectories(); err == nil {
builderCtx.ToolsDirs = toolsDir
} else {
formatter.PrintError(err, "Cannot get bundled tools directories.")
os.Exit(cli.ErrCoreConfig)
return &rpc.CompileResp{
Result: rpc.Error("Cannot get bundled tools directories.", rpc.ErrGeneric),
}, err
}

builderCtx.OtherLibrariesDirs = paths.NewPathList()
Expand All @@ -107,8 +118,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
builderCtx.BuildPath = paths.New(req.GetBuildPath())
err = builderCtx.BuildPath.MkdirAll()
if err != nil {
formatter.PrintError(err, "Cannot create the build directory.")
os.Exit(cli.ErrBadCall)
return &rpc.CompileResp{
Result: rpc.Error("Cannot create the build directory.", rpc.ErrGeneric),
}, err
}
}

Expand All @@ -131,8 +143,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
builderCtx.BuildCachePath = paths.New(req.GetBuildCachePath())
err = builderCtx.BuildCachePath.MkdirAll()
if err != nil {
formatter.PrintError(err, "Cannot create the build cache directory.")
os.Exit(cli.ErrBadCall)
return &rpc.CompileResp{
Result: rpc.Error("Cannot create the build cache directory.", rpc.ErrGeneric),
}, err
}
}

Expand Down Expand Up @@ -166,8 +179,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
}

if err != nil {
formatter.PrintError(err, "Compilation failed.")
os.Exit(cli.ErrGeneric)
return &rpc.CompileResp{
Result: rpc.Error("Compilation failed.", rpc.ErrGeneric),
}, err
}

// FIXME: Make a function to obtain these info...
Expand Down Expand Up @@ -197,8 +211,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
dstHex := exportPath.Join(exportFile + ext)
logrus.WithField("from", srcHex).WithField("to", dstHex).Print("copying sketch build output")
if err = srcHex.CopyTo(dstHex); err != nil {
formatter.PrintError(err, "Error copying output file.")
os.Exit(cli.ErrGeneric)
return &rpc.CompileResp{
Result: rpc.Error("Error copying output file.", rpc.ErrGeneric),
}, err
}

// Copy .elf file to sketch directory
Expand All @@ -207,6 +222,10 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
logrus.WithField("from", srcElf).WithField("to", dstElf).Print("copying sketch build output")
if err = srcElf.CopyTo(dstElf); err != nil {
formatter.PrintError(err, "Error copying elf file.")
os.Exit(cli.ErrGeneric)
return &rpc.CompileResp{
Result: rpc.Error("Error copying elf file.", rpc.ErrGeneric),
}, err
}

return &rpc.CompileResp{}, nil
}
13 changes: 12 additions & 1 deletion daemon/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func main() {
if len(os.Args) != 2 {
if len(os.Args) != 3 {
fmt.Println("Please specify Arduino DATA_DIR as first argument")
os.Exit(1)
}
Expand Down Expand Up @@ -50,6 +50,17 @@ func main() {
fmt.Println("Board name: ", details.GetName())
}

compResp, err := client.Compile(context.Background(), &rpc.CompileReq{
Instance: instance,
Fqbn: "arduino:samd:mkr1000",
SketchPath: os.Args[2],
})

if err != nil {
fmt.Println(compResp.GetResult().Message, err)
os.Exit(1)
}

destroyResp, err := client.Destroy(context.Background(), &rpc.DestroyReq{
Instance: instance,
})
Expand Down
1 change: 1 addition & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/rpc"
"github.com/spf13/cobra"
"google.golang.org/grpc"
Expand Down