Skip to content

Commit d424e15

Browse files
committed
Implemented run function in cli/compile
1 parent b4f7ea4 commit d424e15

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

cli/compile/compile.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ package compile
1919

2020
import (
2121
"context"
22+
"os"
2223

2324
"github.com/arduino/arduino-cli/commands/compile"
25+
"github.com/arduino/arduino-cli/common/formatter"
26+
"github.com/arduino/arduino-cli/rpc"
2427

2528
"github.com/arduino/arduino-cli/cli"
2629
"github.com/spf13/cobra"
@@ -87,6 +90,31 @@ var flags struct {
8790
}
8891

8992
func run(cmd *cobra.Command, args []string) {
93+
instance := cli.CreateInstance()
9094
// TODO: fill request, parse response
91-
compile.Compile(context.Background(), nil)
95+
compRes, err := compile.Compile(context.Background(), &rpc.CompileReq{
96+
Instance: instance,
97+
Fqbn: flags.fqbn,
98+
SketchPath: args[0],
99+
ShowProperties: flags.showProperties,
100+
Preprocess: flags.preprocess,
101+
BuildCachePath: flags.buildCachePath,
102+
BuildPath: flags.buildPath,
103+
BuildProperties: flags.buildProperties,
104+
Warnings: flags.warnings,
105+
Verbose: flags.verbose,
106+
Quiet: flags.quiet,
107+
VidPid: flags.vidPid,
108+
ExportFile: flags.exportFile,
109+
})
110+
if err != nil {
111+
outputCompileResp(compRes)
112+
} else {
113+
formatter.PrintError(err, compRes.GetResult().Message)
114+
os.Exit(cli.ErrGeneric)
115+
}
116+
}
117+
118+
func outputCompileResp(details *rpc.CompileResp) {
119+
92120
}

commands/compile/compile.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
3030
if err != nil {
3131
return &rpc.CompileResp{
3232
Result: rpc.Error("Error opening sketch", rpc.ErrGeneric),
33-
}, nil
33+
}, err
3434
}
3535

3636
fqbnIn := req.GetFqbn()
@@ -41,14 +41,14 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
4141
formatter.PrintErrorMessage("No Fully Qualified Board Name provided.")
4242
return &rpc.CompileResp{
4343
Result: rpc.Error("No Fully Qualified Board Name provided.", rpc.ErrGeneric),
44-
}, nil
44+
}, err
4545
}
4646
fqbn, err := cores.ParseFQBN(fqbnIn)
4747
if err != nil {
4848
formatter.PrintErrorMessage("Fully Qualified Board Name has incorrect format.")
4949
return &rpc.CompileResp{
5050
Result: rpc.Error("Fully Qualified Board Name has incorrect format.", rpc.ErrGeneric),
51-
}, nil
51+
}, err
5252
}
5353

5454
pm, _ := cli.InitPackageAndLibraryManager()
@@ -64,14 +64,14 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
6464
if err := pm.LoadHardware(cli.Config); err != nil {
6565
return &rpc.CompileResp{
6666
Result: rpc.Error("Could not load hardware packages.", rpc.ErrGeneric),
67-
}, nil
67+
}, err
6868
}
6969
ctags, _ = getBuiltinCtagsTool(pm)
7070
if !ctags.IsInstalled() {
7171
formatter.PrintErrorMessage("Missing ctags tool.")
7272
return &rpc.CompileResp{
7373
Result: rpc.Error("Missing ctags tool.", rpc.ErrGeneric),
74-
}, nil
74+
}, err
7575
}
7676
}
7777

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

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

106106
if toolsDir, err := cli.Config.BundleToolsDirectories(); err == nil {
107107
builderCtx.ToolsDirs = toolsDir
108108
} else {
109109
return &rpc.CompileResp{
110110
Result: rpc.Error("Cannot get bundled tools directories.", rpc.ErrGeneric),
111-
}, nil
111+
}, err
112112
}
113113

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

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

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

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

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

230230
return &rpc.CompileResp{}, nil

0 commit comments

Comments
 (0)