@@ -17,13 +17,14 @@ package compile
17
17
18
18
import (
19
19
"context"
20
- "errors "
20
+ "fmt "
21
21
"io"
22
22
"path/filepath"
23
23
"sort"
24
24
"strconv"
25
25
"strings"
26
26
27
+ "github.com/arduino/arduino-cli/arduino"
27
28
bldr "github.com/arduino/arduino-cli/arduino/builder"
28
29
"github.com/arduino/arduino-cli/arduino/cores"
29
30
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
@@ -89,29 +90,29 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
89
90
90
91
pm := commands .GetPackageManager (req .GetInstance ().GetId ())
91
92
if pm == nil {
92
- return nil , & commands .InvalidInstanceError {}
93
+ return nil , & arduino .InvalidInstanceError {}
93
94
}
94
95
95
96
logrus .Tracef ("Compile %s for %s started" , req .GetSketchPath (), req .GetFqbn ())
96
97
if req .GetSketchPath () == "" {
97
- return nil , & commands .MissingSketchPathError {}
98
+ return nil , & arduino .MissingSketchPathError {}
98
99
}
99
100
sketchPath := paths .New (req .GetSketchPath ())
100
101
sk , err := sketch .New (sketchPath )
101
102
if err != nil {
102
- return nil , & commands .CantOpenSketchError {Cause : err }
103
+ return nil , & arduino .CantOpenSketchError {Cause : err }
103
104
}
104
105
105
106
fqbnIn := req .GetFqbn ()
106
107
if fqbnIn == "" && sk != nil && sk .Metadata != nil {
107
108
fqbnIn = sk .Metadata .CPU .Fqbn
108
109
}
109
110
if fqbnIn == "" {
110
- return nil , & commands .MissingFQBNError {}
111
+ return nil , & arduino .MissingFQBNError {}
111
112
}
112
113
fqbn , err := cores .ParseFQBN (fqbnIn )
113
114
if err != nil {
114
- return nil , & commands .InvalidFQBNError {Cause : err }
115
+ return nil , & arduino .InvalidFQBNError {Cause : err }
115
116
}
116
117
117
118
targetPlatform := pm .FindPlatform (& packagemanager.PlatformReference {
@@ -124,7 +125,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
124
125
// "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
125
126
// version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
126
127
// feedback.Error(errorMessage)
127
- return nil , & commands .PlatformNotFound {Platform : targetPlatform .String (), Cause : errors . New (tr ("platform not installed" ))}
128
+ return nil , & arduino .PlatformNotFound {Platform : targetPlatform .String (), Cause : fmt . Errorf (tr ("platform not installed" ))}
128
129
}
129
130
130
131
builderCtx := & types.Context {}
@@ -147,7 +148,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
147
148
builderCtx .BuildPath = paths .New (req .GetBuildPath ()).Canonical ()
148
149
}
149
150
if err = builderCtx .BuildPath .MkdirAll (); err != nil {
150
- return nil , & commands .PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
151
+ return nil , & arduino .PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
151
152
}
152
153
builderCtx .CompilationDatabase = bldr .NewCompilationDatabase (
153
154
builderCtx .BuildPath .Join ("compile_commands.json" ),
@@ -177,7 +178,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
177
178
builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
178
179
err = builderCtx .BuildCachePath .MkdirAll ()
179
180
if err != nil {
180
- return nil , & commands .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
181
+ return nil , & arduino .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
181
182
}
182
183
}
183
184
@@ -222,20 +223,20 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
222
223
if req .GetShowProperties () {
223
224
compileErr := builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
224
225
if compileErr != nil {
225
- compileErr = & commands .CompileFailedError {Message : err .Error ()}
226
+ compileErr = & arduino .CompileFailedError {Message : err .Error ()}
226
227
}
227
228
return r , compileErr
228
229
} else if req .GetPreprocess () {
229
230
compileErr := builder .RunPreprocess (builderCtx )
230
231
if compileErr != nil {
231
- compileErr = & commands .CompileFailedError {Message : err .Error ()}
232
+ compileErr = & arduino .CompileFailedError {Message : err .Error ()}
232
233
}
233
234
return r , compileErr
234
235
}
235
236
236
237
// if it's a regular build, go on...
237
238
if err := builder .RunBuilder (builderCtx ); err != nil {
238
- return r , & commands .CompileFailedError {Message : err .Error ()}
239
+ return r , & arduino .CompileFailedError {Message : err .Error ()}
239
240
}
240
241
241
242
// If the export directory is set we assume you want to export the binaries
@@ -257,17 +258,17 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
257
258
}
258
259
logrus .WithField ("path" , exportPath ).Trace ("Saving sketch to export path." )
259
260
if err := exportPath .MkdirAll (); err != nil {
260
- return r , & commands .PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
261
+ return r , & arduino .PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
261
262
}
262
263
263
264
// Copy all "sketch.ino.*" artifacts to the export directory
264
265
baseName , ok := builderCtx .BuildProperties .GetOk ("build.project_name" ) // == "sketch.ino"
265
266
if ! ok {
266
- return r , & commands .MissingPlatformPropertyError {Property : "build.project_name" }
267
+ return r , & arduino .MissingPlatformPropertyError {Property : "build.project_name" }
267
268
}
268
269
buildFiles , err := builderCtx .BuildPath .ReadDir ()
269
270
if err != nil {
270
- return r , & commands .PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
271
+ return r , & arduino .PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
271
272
}
272
273
buildFiles .FilterPrefix (baseName )
273
274
for _ , buildFile := range buildFiles {
@@ -277,7 +278,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
277
278
WithField ("dest" , exportedFile ).
278
279
Trace ("Copying artifact." )
279
280
if err = buildFile .CopyTo (exportedFile ); err != nil {
280
- return r , & commands .PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
281
+ return r , & arduino .PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
281
282
}
282
283
}
283
284
}
@@ -286,7 +287,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
286
287
for _ , lib := range builderCtx .ImportedLibraries {
287
288
rpcLib , err := lib .ToRPCLibrary ()
288
289
if err != nil {
289
- return r , & commands .PermissionDeniedError {Message : tr ("Error getting information for library %s" , lib .Name ), Cause : err }
290
+ return r , & arduino .PermissionDeniedError {Message : tr ("Error getting information for library %s" , lib .Name ), Cause : err }
290
291
}
291
292
importedLibs = append (importedLibs , rpcLib )
292
293
}
0 commit comments