Skip to content

Commit

Permalink
Implemented run function in cli/compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Rocketct committed Mar 25, 2019
1 parent b4f7ea4 commit d424e15
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
30 changes: 29 additions & 1 deletion 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,31 @@ var flags struct {
}

func run(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
// TODO: fill request, parse response
compile.Compile(context.Background(), nil)
compRes, err := compile.Compile(context.Background(), &rpc.CompileReq{
Instance: instance,
Fqbn: flags.fqbn,
SketchPath: args[0],
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) {

}
26 changes: 13 additions & 13 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
if err != nil {
return &rpc.CompileResp{
Result: rpc.Error("Error opening sketch", rpc.ErrGeneric),
}, nil
}, err
}

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

pm, _ := cli.InitPackageAndLibraryManager()
Expand All @@ -64,14 +64,14 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
if err := pm.LoadHardware(cli.Config); err != nil {
return &rpc.CompileResp{
Result: rpc.Error("Could not load hardware packages.", rpc.ErrGeneric),
}, nil
}, err
}
ctags, _ = getBuiltinCtagsTool(pm)
if !ctags.IsInstalled() {
formatter.PrintErrorMessage("Missing ctags tool.")
return &rpc.CompileResp{
Result: rpc.Error("Missing ctags tool.", rpc.ErrGeneric),
}, nil
}, err
}
}

Expand All @@ -86,7 +86,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
formatter.PrintErrorMessage(errorMessage)
return &rpc.CompileResp{
Result: rpc.Error(errorMessage, rpc.ErrGeneric),
}, nil
}, err
}

builderCtx := &types.Context{}
Expand All @@ -100,15 +100,15 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
} else {
return &rpc.CompileResp{
Result: rpc.Error("Cannot get hardware directories.", rpc.ErrGeneric),
}, nil
}, err
}

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

builderCtx.OtherLibrariesDirs = paths.NewPathList()
Expand All @@ -120,7 +120,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
if err != nil {
return &rpc.CompileResp{
Result: rpc.Error("Cannot create the build directory.", rpc.ErrGeneric),
}, nil
}, err
}
}

Expand All @@ -145,7 +145,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
if err != nil {
return &rpc.CompileResp{
Result: rpc.Error("Cannot create the build cache directory.", rpc.ErrGeneric),
}, nil
}, err
}
}

Expand Down Expand Up @@ -181,7 +181,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
if err != nil {
return &rpc.CompileResp{
Result: rpc.Error("Compilation failed.", rpc.ErrGeneric),
}, nil
}, err
}

// FIXME: Make a function to obtain these info...
Expand Down Expand Up @@ -213,7 +213,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
if err = srcHex.CopyTo(dstHex); err != nil {
return &rpc.CompileResp{
Result: rpc.Error("Error copying output file.", rpc.ErrGeneric),
}, nil
}, err
}

// Copy .elf file to sketch directory
Expand All @@ -224,7 +224,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
formatter.PrintError(err, "Error copying elf file.")
return &rpc.CompileResp{
Result: rpc.Error("Error copying elf file.", rpc.ErrGeneric),
}, nil
}, err
}

return &rpc.CompileResp{}, nil
Expand Down

0 comments on commit d424e15

Please sign in to comment.